From nobody Mon Feb 9 12:26:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1630667325; cv=none; d=zohomail.com; s=zohoarc; b=V1xesifpqAltL7XxfF6HFZF2Hqpo89x2NEYuWHJnczx9y7pfBdpGSYfhgBF02U/QMg+gog5sMQTr3R1+nS4aM7qgFeyDtjNP+1wDjRDa/mcFrK7N9taK3rYIgMekaGi2b5pnVhGZnqP45JMRjLVC1Q4WW1rc5DTM69NknqCxZ5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667325; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=dyVB6AzxmMS8BlTCGJx6yUBvjK62NisiC2d6bnlid2E=; b=ReFg03YVwxLsy6tOQnSn1cvc/RLXTs00OPMVuhumB5I80ah3Sikd/hn5XG5ycAtZTRH6X4JyqrwoSpPnLUqM9XbTpXARM1SdqJYEGCnkpo9ezb/DuYnqI1pGNtg/Rvo9cNcegGQbJM0De1DmxkNW6JfeBFlwaUunNJI13KKyvnA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1630667325240730.7979052727192; Fri, 3 Sep 2021 04:08:45 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-xGuOMbRHPtOVLxQilOdRAQ-1; Fri, 03 Sep 2021 07:08:43 -0400 Received: by mail-wr1-f72.google.com with SMTP id h6-20020a5d4fc6000000b00157503046afso1451472wrw.3 for ; Fri, 03 Sep 2021 04:08:42 -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 w9sm4439669wrs.7.2021.09.03.04.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667324; 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=dyVB6AzxmMS8BlTCGJx6yUBvjK62NisiC2d6bnlid2E=; b=V4WrOfve+2o/sCv5zyC3jTO9ur6gUOUZr5C6+PFzI2mN9p7oPx/nLghhhfRIPPfw2pYG77 hOczQ/GIlZiKaff2JxzX4E2skWqmU4rOZ9M536pvKczctqiO5GELGkOHtc0lUkYtTZp75k PjRAgPKW1DmRrh+OfxsoHqhRg9m1tAY= X-MC-Unique: xGuOMbRHPtOVLxQilOdRAQ-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=dyVB6AzxmMS8BlTCGJx6yUBvjK62NisiC2d6bnlid2E=; b=ek9te1Jd8RbZHK+YWNxOPOz58OwQS5l6RWvl8m/MNlMQpZ26/WYzBKcEJIx2Gay8mr 0GMnCCXpLdG8uxWJU2MmTOr/nqrjNFeHuGgG1XOUMdJdPHYfhWiOOqvtcT4OWdRF3RHX PnKxS+QEXH529EnfdqL8XEA3B2hlT79WrVniAuYhWMgQQyuoFgp7dcY1uZd94VcqEGlp FBquF2CjwsCa4B5XU6EegjPkMMbmP6iaAM7JyZZTmByPXgNeriI+PWQocdEfP6i7Pkbg S7dgnpNSW7zMwbYChs5F6eXl1cP7p7ZouzdsHcY2ubJfAxNnjXG/V9uieTGU1bcpFuMD blcg== X-Gm-Message-State: AOAM533d3rPqttCbu3JSfitwTK5+pPam3NHpep50tnttDR4vfMkBs3aF F+mgPJHH307/M/ybzW3SLa79T9p4yUpNlz0Da7vCqJOX96MTPVASZCI72LGaU3rLhIagmx1FORQ Qx4CTbbR9qKba/Q== X-Received: by 2002:a05:600c:5102:: with SMTP id o2mr2733906wms.104.1630667321940; Fri, 03 Sep 2021 04:08:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb4sgtV74rpbNMK7lro6Zp2a1Bicv7CxBMUuULP/VYB1PgOM9RnbhlKgyVZuLyyqF/XcA8KA== X-Received: by 2002:a05:600c:5102:: with SMTP id o2mr2733882wms.104.1630667321792; Fri, 03 Sep 2021 04:08:41 -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: [PATCH 17/28] hw/rdma: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:51 +0200 Message-Id: <20210903110702.588291-18-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: 1630667326912100001 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 --- hw/rdma/rdma_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/rdma/rdma_utils.c b/hw/rdma/rdma_utils.c index 98df58f6897..9792b1c8ef5 100644 --- a/hw/rdma/rdma_utils.c +++ b/hw/rdma/rdma_utils.c @@ -71,7 +71,7 @@ void rdma_protected_gqueue_append_int64(RdmaProtectedGQue= ue *list, int64_t value) { qemu_mutex_lock(&list->lock); - g_queue_push_tail(list->list, g_memdup(&value, sizeof(value))); + g_queue_push_tail(list->list, g_memdup2_qemu(&value, sizeof(value))); qemu_mutex_unlock(&list->lock); } =20 --=20 2.31.1