All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: Dmitry Frolov <frolov@swemel.ru>
Cc: pbonzini@redhat.com, sdl.qemu@linuxtesting.org,
	qemu-devel@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH] hw/i386: fix NULL-dereference
Date: Thu, 7 Nov 2024 17:04:16 +0800	[thread overview]
Message-ID: <ZyyCkFQX548AgEye@intel.com> (raw)
In-Reply-To: <20241107070415.694662-2-frolov@swemel.ru>

+Philippe for ISAPC

On Thu, Nov 07, 2024 at 10:04:10AM +0300, Dmitry Frolov wrote:
> Date: Thu,  7 Nov 2024 10:04:10 +0300
> From: Dmitry Frolov <frolov@swemel.ru>
> Subject: [PATCH] hw/i386: fix NULL-dereference
> 
> If pcmc->pci_enabled is false, pcms->pcibus is NULL and is passed
> to pc_nic_init() where it is being dereferenced.
> 
> Found making check with enabled sanitizers.
> 
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> ---
>  hw/i386/pc_piix.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 2bf6865d40..2a92d2dbb7 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -313,9 +313,9 @@ static void pc_init1(MachineState *machine, const char *pci_type)
>      /* init basic PC hardware */
>      pc_basic_device_init(pcms, isa_bus, x86ms->gsi, x86ms->rtc,
>                           !MACHINE_CLASS(pcmc)->no_floppy, 0x4);
> -
> -    pc_nic_init(pcmc, isa_bus, pcms->pcibus);
> -
> +    if (pcmc->pci_enabled) {
> +        pc_nic_init(pcmc, isa_bus, pcms->pcibus);
> +    }
>  #ifdef CONFIG_IDE_ISA
>      if (!pcmc->pci_enabled) {
>          DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];

In principle, I think the fix is right. Currently only ISAPC's
pci_enabled is false.

I think ISAPC shouldn't need nic, so it's safe. Is this right, Phil? :)

The potential issue lies in pci_init_nic_devices() with "&bus->qbus".
Although "bus" (which is pcibus here) is NULL, the compiler seems to
optimize this, making &bus->qbus also NULL. Therefore, I did not
encounter any errors when attempting to start ISAPC.

Thanks,
Zhao




  reply	other threads:[~2024-11-07  8:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07  7:04 [PATCH] hw/i386: fix NULL-dereference Dmitry Frolov
2024-11-07  9:04 ` Zhao Liu [this message]
2024-11-07 19:10   ` Bernhard Beschow
2024-11-07  9:19 ` Bernhard Beschow
2024-11-07 19:09   ` Bernhard Beschow

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=ZyyCkFQX548AgEye@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=frolov@swemel.ru \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sdl.qemu@linuxtesting.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.