All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Nikolay Kuratov <kniv@yandex-team.ru>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	 qemu-devel@nongnu.org, qemu-stable@nongnu.org
Subject: Re: [PATCH] qmp: Check vhost protocol features for NULL prior to dumping
Date: Thu, 19 Mar 2026 14:59:24 +0100	[thread overview]
Message-ID: <871phfx6mb.fsf@pond.sub.org> (raw)
In-Reply-To: <20260319085050.1982608-1-kniv@yandex-team.ru> (Nikolay Kuratov's message of "Thu, 19 Mar 2026 11:50:50 +0300")

Nikolay Kuratov <kniv@yandex-team.ru> writes:

> vhost_dev->protocol_features field can be legitimately set to NULL
> as apparently it's vhost-user only field. At least I was able to get
> NULL deref with a vhost-net VM.
>
> Without that check querying vhost-net device:
> info virtio-status /machine/peripheral-anon/device[0]/virtio-backend
> will lead to SIGSEGV.
>
> Fixes: 8a8287981d1169f534894d983ecfd3b70b71918b ("hmp: add virtio commands")
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
> ---
>  hw/virtio/virtio-hmp-cmds.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/hw/virtio/virtio-hmp-cmds.c b/hw/virtio/virtio-hmp-cmds.c
> index 1daae482d3..b9980197ef 100644
> --- a/hw/virtio/virtio-hmp-cmds.c
> +++ b/hw/virtio/virtio-hmp-cmds.c
> @@ -15,6 +15,9 @@
>  static void hmp_virtio_dump_protocols(Monitor *mon,
>                                        VhostDeviceProtocols *pcol)
>  {
> +    if (pcol == NULL) {
> +        return;
> +    }
>      strList *pcol_list = pcol->protocols;
>      while (pcol_list) {
>          monitor_printf(mon, "\t%s", pcol_list->value);

I fear this papers over the real bug.

Here's the only caller:

    void hmp_virtio_status(Monitor *mon, const QDict *qdict)
    {
        Error *err = NULL;
        const char *path = qdict_get_try_str(qdict, "path");
        VirtioStatus *s = qmp_x_query_virtio_status(path, &err);

        if (err != NULL) {

Aside: I'd prefer if (!s) here.

            hmp_handle_error(mon, err);
            return;
        }

        [...]

        if (s->vhost_dev) {
            [...]
            monitor_printf(mon, "    Protocol features:\n");
            hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features);

We're passing VirtioStatus member @protocol-features.  It's not supposed
to be null, because ...

        }

        qapi_free_VirtioStatus(s);
    }

In qapi/virtio.json:

    { 'struct': 'VhostStatus',
      'data': { 'n-mem-sections': 'int',
                'n-tmp-sections': 'int',
                'nvqs': 'uint32',
                'vq-index': 'int',
                'features': 'VirtioDeviceFeatures',
                'acked-features': 'VirtioDeviceFeatures',
                'backend-features': 'VirtioDeviceFeatures',
                'protocol-features': 'VhostDeviceProtocols',

... member @protocol-features is *not* optional.

Since you obseved it to be null, whatever created s->vhost_dev must have
screwed up.

If s->vhost_dev->protocol-features needs to be null in certain
situations, you must declare it optional in the QAPI schema.

                'max-queues': 'uint64',
                'backend-cap': 'uint64',
                'log-enabled': 'bool',
                'log-size': 'uint64' } }



  reply	other threads:[~2026-03-19 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  8:50 [PATCH] qmp: Check vhost protocol features for NULL prior to dumping Nikolay Kuratov
2026-03-19 13:59 ` Markus Armbruster [this message]
2026-03-19 15:13   ` Nikolay Kuratov

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=871phfx6mb.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=kniv@yandex-team.ru \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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 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.