qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: Dorinda Bassey <dbassey@redhat.com>
Cc: qemu-devel@nongnu.org, aesteve@redhat.com, sgarzare@redhat.com
Subject: Re: [PATCH v2] virtio-dmabuf: Ensure UUID persistence for hash table insertion
Date: Tue, 2 Dec 2025 17:50:55 +0400	[thread overview]
Message-ID: <CAJ+F1CLRkDKVojdk2DbNeSO3Z9Z4BHN7Ds8N1mwzf9qF9HmCsQ@mail.gmail.com> (raw)
In-Reply-To: <20241107180309.1713601-1-dbassey@redhat.com>

Hi

On Thu, Nov 7, 2024 at 10:04 PM Dorinda Bassey <dbassey@redhat.com> wrote:
>
> In `virtio_add_resource` function, the UUID used as a key for
> `g_hash_table_insert` was temporary, which could lead to
> invalid lookups when accessed later. This patch ensures that
> the UUID remains valid by duplicating it into a newly allocated
> memory space. The value is then inserted into the hash table
> with this persistent UUID key to ensure that the key stored in
> the hash table remains valid as long as the hash table entry
> exists.
>
> Fixes: faefdba847 ("hw/display: introduce virtio-dmabuf")
>
> Signed-off-by: Dorinda Bassey <dbassey@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

We missed this patch during the -rc period. Can it be included?

it fixes invalid memory access / use-after-free .

Note: I think the original intent was that the @uuid argument
ownership was passed:
virtio_add_dmabuf/virtio_add_vhost_device
 * @uuid: new resource's UUID

It could be clarified and be passed as const like getters to eventually help...

> ---
>  hw/display/virtio-dmabuf.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/display/virtio-dmabuf.c b/hw/display/virtio-dmabuf.c
> index 3dba4577ca7..5e0395be77c 100644
> --- a/hw/display/virtio-dmabuf.c
> +++ b/hw/display/virtio-dmabuf.c
> @@ -35,11 +35,13 @@ static bool virtio_add_resource(QemuUUID *uuid, VirtioSharedObject *value)
>      if (resource_uuids == NULL) {
>          resource_uuids = g_hash_table_new_full(qemu_uuid_hash,
>                                                 uuid_equal_func,
> -                                               NULL,
> +                                               g_free,
>                                                 g_free);
>      }
>      if (g_hash_table_lookup(resource_uuids, uuid) == NULL) {
> -        g_hash_table_insert(resource_uuids, uuid, value);
> +        g_hash_table_insert(resource_uuids,
> +                            g_memdup2(uuid, sizeof(*uuid)),
> +                            value);
>      } else {
>          result = false;
>      }
> --
> 2.47.0
>
>


-- 
Marc-André Lureau


  parent reply	other threads:[~2025-12-02 13:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 18:00 [PATCH v2] virtio-dmabuf: Ensure UUID persistence for hash table insertion Dorinda Bassey
2024-11-08  9:29 ` Stefano Garzarella
2025-09-15  9:16   ` Dorinda Bassey
2025-09-15  9:23     ` Albert Esteve
2025-12-02 13:50 ` Marc-André Lureau [this message]
2025-12-02 14:01   ` Stefano Garzarella
  -- strict thread matches above, loose matches on Subject: below --
2025-12-04 15:26 Dorinda Bassey
2025-12-04 15:43 ` Michael S. Tsirkin

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=CAJ+F1CLRkDKVojdk2DbNeSO3Z9Z4BHN7Ds8N1mwzf9qF9HmCsQ@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=aesteve@redhat.com \
    --cc=dbassey@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    /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).