From nobody Fri May 3 12:35:07 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1489523660874741.9518907424133; Tue, 14 Mar 2017 13:34:20 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1cnt90-0004Xx-Pz; Tue, 14 Mar 2017 21:34:10 +0100 Received: from mxa2.seznam.cz ([77.75.76.90]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1cnt8p-0004Wn-9b for seabios@seabios.org; Tue, 14 Mar 2017 21:34:08 +0100 Received: from email.seznam.cz by email-smtpc6a.ng.seznam.cz (email-smtpc6a.ng.seznam.cz [10.23.10.165]) id 63643391b3198e4c67da7ede; Tue, 14 Mar 2017 21:33:57 +0100 (CET) Received: from unknown ([::ffff:94.78.181.79]) by email.seznam.cz (szn-ebox-4.5.223) with HTTP; Tue, 14 Mar 2017 21:33:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1489523637; bh=3Ba/ViJFi6guHMywc8OHYM6xA9PxcbSyvnMYaTWHQAc=; h=Received:From:To:Subject:Date:Message-Id:Mime-Version:X-Mailer: Content-Type:Content-Transfer-Encoding; b=TQm1eLXio80or+PJKTgEwIlacg/G42CEwlZil8M9+eZFdAnIj8rNwsCI1wA+Vuvpl 3s7OFAX3M7ymfxsix6zp5kYZhxtN88ZNkLMBAkWesXgsmi10CyzlGhN8yCxivrqHoQ j//bbXShZDe/MaNl4O6qRpldHR3FFel13lciea2U= From: To: Date: Tue, 14 Mar 2017 21:33:53 +0100 (CET) Message-Id: Mime-Version: 1.0 (szn-mime-2.0.14) X-Mailer: szn-ebox-4.5.223 X-Spam-Score: -0.4 (/) Subject: [SeaBIOS] [PATCH] config: Add function to check if fw_cfg exists X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From 405de6e571a2bf332452a17ae98f7b3a0613365e Mon Sep 17 00:00:00 2001 From: Petr Berky Date: Tue, 14 Mar 2017 20:30:52 +0100 Subject: [PATCH] config: Add function to check if fw_cfg exists It was found qemu_get_present_cpus_count may return impossible number of cpus because of not checking if fw_cfg exists before using it. That may lead to undefined behavior of emulator, in particular Bochs that freezes. Signed-off-by: Petr Berky Reviewed-by: Laszlo Ersek --- src/fw/paravirt.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 707502d..b2cfc23 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -220,6 +220,21 @@ qemu_cfg_select(u16 f) outw(f, PORT_QEMU_CFG_CTL); } =20 +static int +qemu_cfg_check_signature(void) +{ + int i; + char *sig =3D "QEMU"; + + qemu_cfg_select(QEMU_CFG_SIGNATURE); + for (i =3D 0; i < 4; i++) { + if (inb(PORT_QEMU_CFG_DATA) !=3D sig[i]) { + return -1; + } + } + return 0; +} + static void qemu_cfg_dma_transfer(void *address, u32 length, u32 control) { @@ -392,7 +407,9 @@ u16 qemu_get_present_cpus_count(void) { u16 smp_count =3D 0; - qemu_cfg_read_entry(&smp_count, QEMU_CFG_NB_CPUS, sizeof(smp_count)); + if (qemu_cfg_check_signature() =3D=3D 0) { + qemu_cfg_read_entry(&smp_count, QEMU_CFG_NB_CPUS, sizeof(smp_count= )); + } u16 cmos_cpu_count =3D rtc_read(CMOS_BIOS_SMP_COUNT) + 1; if (smp_count < cmos_cpu_count) { smp_count =3D cmos_cpu_count; @@ -563,12 +580,9 @@ void qemu_cfg_init(void) return; =20 // Detect fw_cfg interface. - qemu_cfg_select(QEMU_CFG_SIGNATURE); - char *sig =3D "QEMU"; - int i; - for (i =3D 0; i < 4; i++) - if (inb(PORT_QEMU_CFG_DATA) !=3D sig[i]) - return; + if (qemu_cfg_check_signature() !=3D 0) { + return; + } =20 dprintf(1, "Found QEMU fw_cfg\n"); =20 --=20 2.11.0 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://www.coreboot.org/mailman/listinfo/seabios