From nobody Sat Nov 23 19:43:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730983979; cv=none; d=zohomail.com; s=zohoarc; b=DLcavFPcCPw8zuxsx4R4/+9LliwQHp0XfSIfmn+x/dzyQyWz36fr7RJ9FQJHtoTPbyUdAyOqkjGV3gvPwH47VLFcvYHrFCADrmVpa4g5NL3bqB1pQHtvwy0ry8aSSvtk/akzHRxTBZZyb7eO7vot9V2mBT2thHVODawXqCjPMgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730983979; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UWSbhocGk2G4x0WBfgN2OYC7v1K1AdCmmIxocVE3cG0=; b=MzN6EoB4vF+YYaptn+D9PEf8PYJlR3pUF8/Z0Ni9jcqiAIsti2s6dmukJFq4kOJvUA9c+sb4ffA/A0DbkAccUBtpHp08RUllTHqkQ34muuyedEWMpIUSkdrIF6rA81qpzNKBX6JbAFbNhwQcQyD332imfHAGjdYcuKMh8TuUyoQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730983979097600.565795949752; Thu, 7 Nov 2024 04:52:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t91zr-0003D6-4C; Thu, 07 Nov 2024 07:52:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t91zn-0003Ci-0K for qemu-devel@nongnu.org; Thu, 07 Nov 2024 07:52:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t91zk-00058p-1Q for qemu-devel@nongnu.org; Thu, 07 Nov 2024 07:52:18 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-ut-v8x5RPIKSQkqw_U9O_w-1; Thu, 07 Nov 2024 07:52:10 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C53EA1955BC9 for ; Thu, 7 Nov 2024 12:52:09 +0000 (UTC) Received: from corp.redhat.com (unknown [10.39.194.232]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 82359195E480; Thu, 7 Nov 2024 12:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730983933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UWSbhocGk2G4x0WBfgN2OYC7v1K1AdCmmIxocVE3cG0=; b=ZjIJ2J1g9HkFUVOqnBPQ1WKLeXabHrsRmMTPcB6OgNIuRi5SFGIgUoSNfin8HqlobXIqaE int2DBcUh6XP224lSFB+PBkgzsJMCMJy5Q013AAGifng+A8jd9hT7g5RLzudBylwW+IHcP qv1ch8VjgYEoyadrhmMRLcTrqo7Z13M= X-MC-Unique: ut-v8x5RPIKSQkqw_U9O_w-1 X-Mimecast-MFC-AGG-ID: ut-v8x5RPIKSQkqw_U9O_w From: Dorinda Bassey To: qemu-devel@nongnu.org Cc: aesteve@redhat.com, sgarzare@redhat.com, marcandre.lureau@redhat.com, Dorinda Bassey Subject: [PATCH] virtio-dmabuf: Ensure UUID persistence for hash table insertion Date: Thu, 7 Nov 2024 13:52:01 +0100 Message-ID: <20241107125201.1640759-1-dbassey@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=dbassey@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730983981394116600 Content-Type: text/plain; charset="utf-8" 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 (persistent_uuid). 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. Signed-off-by: Dorinda Bassey Reviewed-by: Albert Esteve --- hw/display/virtio-dmabuf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/display/virtio-dmabuf.c b/hw/display/virtio-dmabuf.c index 3dba4577ca7..4353970bc87 100644 --- a/hw/display/virtio-dmabuf.c +++ b/hw/display/virtio-dmabuf.c @@ -39,7 +39,12 @@ static bool virtio_add_resource(QemuUUID *uuid, VirtioSh= aredObject *value) g_free); } if (g_hash_table_lookup(resource_uuids, uuid) =3D=3D NULL) { - g_hash_table_insert(resource_uuids, uuid, value); + QemuUUID *persistent_uuid =3D g_memdup2(uuid, sizeof(QemuUUID)); + if (persistent_uuid =3D=3D NULL) { + result =3D false; + } else { + g_hash_table_insert(resource_uuids, persistent_uuid, value); + } } else { result =3D false; } --=20 2.47.0