From nobody Mon Feb 9 14:33:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1630667347; cv=none; d=zohomail.com; s=zohoarc; b=Uu4yPO6GIwXuho7/K6Mvw4IH3zn98J1eiF+UzUPXH7eHkUYpaWzhTEFqTYnrDpDPrAlh5KPw2mAMNERGav0wQpoaAEprS+bcUSmCJr8mkAeQ4AtghxUrGBWmENfuuP5uiXJ3H4uqUXbaD8tmxHAKcYwoIJCKATpuN3+Kw4JjJoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667347; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=mHnJ0cVcteOlyXY2WQSoPOrlbaqqNkIp409L2/nVF/Q=; b=L45Ya4pEtzR4P2ZWrPUHREPqOSQ9Mca1Lhi9GCvCnzLn/DXcghtYgTUQaNb5EjRELtfMdrVGeYyFN2mXJggXB9mQ3z9DN2pyKnLfyuTaMGZnZavc+cA9bn470ssRDKLSilYaLR/sSclMqPzRuM+gZLbcQ14q3jCCnPz8t2J2lG8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1630667347711712.135995560981; Fri, 3 Sep 2021 04:09:07 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-GLs5TWSjNZuN4SryFdvpnw-1; Fri, 03 Sep 2021 07:09:05 -0400 Received: by mail-wm1-f70.google.com with SMTP id a201-20020a1c7fd2000000b002e748bf0544so2528970wmd.2 for ; Fri, 03 Sep 2021 04:09:05 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id q13sm3880071wmj.46.2021.09.03.04.09.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mHnJ0cVcteOlyXY2WQSoPOrlbaqqNkIp409L2/nVF/Q=; b=M2ROo9jOdA0dEmH7NZ6XV6jrasXxWZ1DfsjZPPft+EgBQZFIRJmPrHpG56Txl7TkOk40ZC FuICsvWd6rzDmB0GwFK4hMdIuquRM88Ltpcz4OzizDTSz0fLqHyllBau1NWBnVWXutX4Mt 5n+JCnT4S+NciUQVp0xfzzi7+a72QqY= X-MC-Unique: GLs5TWSjNZuN4SryFdvpnw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mHnJ0cVcteOlyXY2WQSoPOrlbaqqNkIp409L2/nVF/Q=; b=n6M1tROt+3VU1DfUeg82uHd+DpgnVy6t1eupsPv8Ebf5eYw4GY9J03QB2cEKsrvb/0 15BX3ssoUQ8b58rBngyWLdUPaef8O/mbeBRB5/7MAS07K2n7Vj7//P6PnWFAoNqmF9V7 HV4dFmwvTlYFuKfryVk9NKiJ3UKEq2qDWVSyY6k5d5cuyNhLOQId5dYIDqsEeZtZLoMP g4Ez9mQ8tLEPHxWX5UPFSvttbkBO/lH9Hc14rsYKgM9cdMVhEAn/P4xOsTTMUk0tvRW+ gv58dWN1hE8dp8B/K/vXHolXLCtCGofGXBK1cdHKBNp3t8AT5LWIWVgxvCaAO5gW4yb6 nMFQ== X-Gm-Message-State: AOAM530FfZ/aCRRKjibgfPPd7VFjYowQ6jzq5w2BgHqXZGhAGI7SJMit /YB7STbaSmtxON250XYuzLNHgtdELJOPi2MsLCQ8yvQJ3FGdpOqhKrwcDC9SwJJQoXhoCn9ecBv nif08DmoIAL9JKw== X-Received: by 2002:a05:600c:2210:: with SMTP id z16mr7583390wml.70.1630667344632; Fri, 03 Sep 2021 04:09:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzXN5Abat+u5GhU97+T79No5Nl13oW/wgdhYam21QjGlUyuHjSwW1tSLBF2QoToAE6kZSvQQ== X-Received: by 2002:a05:600c:2210:: with SMTP id z16mr7583359wml.70.1630667344397; Fri, 03 Sep 2021 04:09:04 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , Igor Mammedov , Laurent Vivier , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Zhang Chen , Shannon Zhao , Richard Henderson , Alex Williamson , Eduardo Habkost , Markus Armbruster , Eric Blake , Stefan Weil , John Snow , Mahmoud Mandour , Li Zhijian , Marcel Apfelbaum , qemu-block@nongnu.org, Helge Deller , "Michael S. Tsirkin" , David Gibson , Peter Xu , "Gonglei (Arei)" , Gerd Hoffmann , Fam Zheng , Jason Wang , Vladimir Sementsov-Ogievskiy , Christian Schoenebeck , Kevin Wolf , Yuval Shaia , Paolo Bonzini , Peter Maydell , qemu-arm@nongnu.org, Thomas Huth , Laurent Vivier , Greg Kurz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-ppc@nongnu.org, David Hildenbrand Subject: [RFC PATCH 21/28] ui/clipboard: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:55 +0200 Message-Id: <20210903110702.588291-22-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210903110702.588291-1-philmd@redhat.com> References: <20210903110702.588291-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630667349179100001 Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdu= p2-now/5538 The old API took the size of the memory to duplicate as a guint, whereas most memory functions take memory sizes as a gsize. This made it easy to accidentally pass a gsize to g_memdup(). For large values, that would lead to a silent truncation of the size from 64 to 32 bits, and result in a heap area being returned which is significantly smaller than what the caller expects. This can likely be exploited in various modules to cause a heap buffer overflow. Replace g_memdup() by the safer g_memdup2_qemu() wrapper. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- TODO: audit qemu_clipboard_set_data() calls --- ui/clipboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/clipboard.c b/ui/clipboard.c index d7b008d62a0..0e12a55d3e5 100644 --- a/ui/clipboard.c +++ b/ui/clipboard.c @@ -123,7 +123,7 @@ void qemu_clipboard_set_data(QemuClipboardPeer *peer, } =20 g_free(info->types[type].data); - info->types[type].data =3D g_memdup(data, size); + info->types[type].data =3D g_memdup2_qemu(data, size); info->types[type].size =3D size; info->types[type].available =3D true; =20 --=20 2.31.1