All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Николай Зорин" <zorin@swemel.ru>
Cc: qemu-devel@nongnu.org, jasowang@redhat.com, armbru@redhat.com
Subject: Re: [PATCH] util/error, hw/net/virtio-net: fix NULL pointer dereference in error_vprepend
Date: Tue, 15 Sep 2026 12:47:43 -0400	[thread overview]
Message-ID: <20260915124114-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <500d4850-f7d7-45fb-91e5-74d32d35fde2@swemel.ru>

Thanks for the patch! Some questions:

On Tue, Sep 15, 2026 at 07:24:39PM +0300, Николай Зорин wrote:
> SWSA#b0709cee-9722-4603-a30c-dc857dc87961

what is this?

> The `error_vprepend()` function modifies the error message inside an
> existing Error object. However, it only validated if the `errp` pointer
> itself was non-NULL, missing a check for whether the underlying Error
> object `*errp` is `NULL`.
> 
> Calling `error_reportf_err(local_error, ...)` when `local_error` is `NULL`
> invokes `error_vprepend(&local_error, ...)`, which subsequently crashes
> via a `NULL` pointer dereference during `(*errp)->msg` access.

but you then go on to remove such calls? then why do we need to change this?

> 
> Fix `util/error.c` by adding a defensive `!*errp` check inside
> `error_vprepend()`.
> 
> Additionally, fix the invalid error reporting patterns in
> `hw/net/virtio-net.c`:
> - In `vhost_user_net_save_state()` and `vhost_user_net_load_state()`, when
>   `vhdev == NULL`,

and when is that?

> calling `error_reportf_err()` with an unallocated/NULL
>   `local_error` is incorrect and unsafe. Replace it with a straightforward
>   `error_report()` call.
> - Fix a cosmetic double-space typo in "Error loading  back-end state".
> 
> 

why two empty lines here?

Fixes tag please?

> Signed-off-by: Nikolay N Zorin <zorin@swemel.ru>
> ---
>  hw/net/virtio-net.c | 14 +++++++-------
>  util/error.c        |  2 +-
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 4362e866..d505fb86 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -3406,9 +3406,9 @@ static int vhost_user_net_save_state(QEMUFile *f, void
> *pv, size_t size,
> 
>      vhdev = virtio_net_get_vhost(vdev);
>      if (vhdev == NULL) {
> -        error_reportf_err(local_error,
> -                          "Error getting vhost back-end of %s device %s: ",
> -                          vdev->name, vdev->parent_obj.canonical_path);
> +        error_report("Error getting vhost back-end of %s device %s: "
> +                     "device is not using vhost\n",
> +                     vdev->name, vdev->parent_obj.canonical_path);
>          return -1;
>      }
> 
> @@ -3434,16 +3434,16 @@ static int vhost_user_net_load_state(QEMUFile *f,
> void *pv, size_t size,
> 
>      vhdev = virtio_net_get_vhost(vdev);
>      if (vhdev == NULL) {
> -        error_reportf_err(local_error,
> -                          "Error getting vhost back-end of %s device %s: ",
> -                          vdev->name, vdev->parent_obj.canonical_path);
> +        error_report("Error getting vhost back-end of %s device %s: "
> +                     "device is not using vhost\n",
> +                     vdev->name, vdev->parent_obj.canonical_path);
>          return -1;
>      }
> 
>      ret = vhost_load_backend_state(vhdev, f, &local_error);
>      if (ret < 0) {
>          error_reportf_err(local_error,
> -                          "Error loading  back-end state of %s device %s: ",
> +                          "Error loading back-end state of %s device %s: ",
>                            vdev->name, vdev->parent_obj.canonical_path);
>          return ret;
>      }
> diff --git a/util/error.c b/util/error.c
> index 673011b8..db8b5e43 100644
> --- a/util/error.c
> +++ b/util/error.c
> @@ -133,7 +133,7 @@ void error_vprepend(Error *const *errp, const char *fmt,
> va_list ap)
>  {
>      GString *newmsg;
> 
> -    if (!errp) {
> +    if (!errp || !*errp) {
>          return;
>      }
> 
> -- 
> 2.43.0



  reply	other threads:[~2026-09-15 16:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 16:24 [PATCH] util/error, hw/net/virtio-net: fix NULL pointer dereference in error_vprepend Николай Зорин
2026-09-15 16:47 ` Michael S. Tsirkin [this message]
2026-09-16 12:48 ` Markus Armbruster
2026-09-16 13:48   ` Николай Зорин
2026-09-16 15:21     ` Michael S. Tsirkin
2026-09-17  9:55     ` Markus Armbruster

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=20260915124114-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zorin@swemel.ru \
    /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.