qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bernhard Beschow <shentey@gmail.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	David Woodhouse <dwmw@amazon.co.uk>
Subject: Re: [PATCH] hw/i386/pc: Don't try to init PCI NICs if there is no PCI bus
Date: Thu, 07 Nov 2024 19:09:24 +0000	[thread overview]
Message-ID: <BA0D6E03-7273-4707-8AE3-236FD0AF83AD@gmail.com> (raw)
In-Reply-To: <20241105171813.3031969-1-peter.maydell@linaro.org>



Am 5. November 2024 17:18:13 UTC schrieb Peter Maydell <peter.maydell@linaro.org>:
>The 'isapc' machine type has no PCI bus, but pc_nic_init() still
>calls pci_init_nic_devices() passing it a NULL bus pointer.  This
>causes the clang sanitizer to complain:
>
>$ ./build/clang/qemu-system-i386 -M isapc
>../../hw/pci/pci.c:1866:39: runtime error: member access within null pointer of type 'PCIBus' (aka 'struct PCIBus')
>SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../hw/pci/pci.c:1866:39 in
>
>This is because pci_init_nic_devices() does
> &bus->qbus
>which is undefined behaviour on a NULL pointer even though we're not
>actually dereferencing the pointer. (We don't actually crash as
>a result, so if you aren't running a sanitizer build then there
>are no user-visible effects.)
>
>Make pc_nic_init() avoid trying to initialize PCI NICs on a non-PCI
>system.
>
>Cc: qemu-stable@nongnu.org
>Fixes: 8d39f9ba14d64 ("hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices()")
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---
>This shows up if you run "make check" on a ubsan build.
>---
> hw/i386/pc.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
>diff --git a/hw/i386/pc.c b/hw/i386/pc.c
>index 2047633e4cf..1af1a1a1823 100644
>--- a/hw/i386/pc.c
>+++ b/hw/i386/pc.c
>@@ -1251,7 +1251,9 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
>     }
> 
>     /* Anything remaining should be a PCI NIC */
>-    pci_init_nic_devices(pci_bus, mc->default_nic);
>+    if (pci_bus) {
>+        pci_init_nic_devices(pci_bus, mc->default_nic);
>+    }

Reviewed-by: Bernhard Beschow <shentey@gmail.com>

> 
>     rom_reset_order_override();
> }


  parent reply	other threads:[~2024-11-07 19:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 17:18 [PATCH] hw/i386/pc: Don't try to init PCI NICs if there is no PCI bus Peter Maydell
2024-11-05 17:22 ` Peter Maydell
2024-11-07 19:09 ` Bernhard Beschow [this message]
2024-11-08  8:25 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BA0D6E03-7273-4707-8AE3-236FD0AF83AD@gmail.com \
    --to=shentey@gmail.com \
    --cc=dwmw@amazon.co.uk \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).