From nobody Mon Feb 9 08:10:02 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=1630667302; cv=none; d=zohomail.com; s=zohoarc; b=ZllWSRUR3A8A3Tg1sk9l0Odq3xJih8RkVYvHwPMGYA+mrKxtToW+EG6ZUtfaem2bZWs0H6dykwvSCAkZQ6MO83/cZFFkMTH2p5f9tA8E15n194BsedGWLMKbmbH4wkzkQISSw6cvASrCNMf8XPudYkS9vpbxCMPdrrcu7gPMu30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667302; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=9Eu7asELFex4yFplfKK/zMZmk6Z93QlAJxAwuUJzsvI=; b=gm9ixERSf/Dlvlk2JMtVWJ4hsE6qin5SkDg5c4Alz+A9sGuij85rViuaWAavWMV8UaNuGTCNU0qhEcNcHSJKtUNyjxRXkGK8tqjrYYwAa4TH8mGAkQCkAw0BO2+JgjGSscfNAY+CmblQBLKmNzW3zka04kqrywsEO8FTfXRV9Lc= 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 1630667302932459.5296677253806; Fri, 3 Sep 2021 04:08:22 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-ftM7GVBEMwOLWC-6sHs3ew-1; Fri, 03 Sep 2021 07:08:20 -0400 Received: by mail-wm1-f72.google.com with SMTP id n16-20020a1c7210000000b002ea2ed60dc6so1719547wmc.0 for ; Fri, 03 Sep 2021 04:08:20 -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 d7sm4401782wrs.39.2021.09.03.04.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667301; 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=9Eu7asELFex4yFplfKK/zMZmk6Z93QlAJxAwuUJzsvI=; b=e21X5GWCAve3KOomfkQzUWT+KYD87WXIsJvwJeuG4tmuwj5n36zbzcGPVu+nKNwS5cZevC 9StqwynqiOCNOID8smA+fx377cMaYyPrV9eGzRmSQ3yp0+iMchIwO8vfed+o7gu1+HrYO6 75CI+HBbe/Hnqz9lsE5FSasoLra5lGs= X-MC-Unique: ftM7GVBEMwOLWC-6sHs3ew-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=9Eu7asELFex4yFplfKK/zMZmk6Z93QlAJxAwuUJzsvI=; b=Ig9vXJhjgDkOeX9xvJfgIQpR+s8flq3V/1HM4swht87e/hgFKxg+S8J/OM1AwdYC86 PrRmbFfUVkAwOaucGM0lj00xIEbAYKhyxT8wyUJYUuw1qRYC0P/tg30LDRA1tI5ed9IO efEAKkGIWsBD1+TxYI64BlWbTOBuWP2Iz1EKwEFnIgxPdjeXF4o53tebP4mgrd5kjNDI 4U45coNjb6gbXYzgWMTLRfZR8TMf3LwXvMvBnm2wXWD8QSnNi/rb2FFXRcep2FlldmuL yI0BQJG8aW53+PJajONCjcwiWMGdS11V4q85MqTO4SPFdkhJ6Zz0V/x2VoSzikLANOSj KSXw== X-Gm-Message-State: AOAM532hXVAMnNYCQ3kTcxd1G7T2nhqAQETm+AKbYWoof+Nr7kmj+CHI u6/qsjZ7EXg7OUuRKeWL5AMKgnfvbkdhAVjwiVLZj2ITGZwBowulghLk4jEddColckqZWdulQa2 ciHjzG1B8KywezA== X-Received: by 2002:a1c:3102:: with SMTP id x2mr7947486wmx.122.1630667299711; Fri, 03 Sep 2021 04:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlUaVFt+tJT5LaJ3kyuGO1VaY8TUngaLwcpu0pipKrSkdlOz7rImuHU2SzJPLLISqxx4e5tQ== X-Received: by 2002:a1c:3102:: with SMTP id x2mr7947440wmx.122.1630667299523; Fri, 03 Sep 2021 04:08:19 -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 13/28] hw/net/eepro100: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:47 +0200 Message-Id: <20210903110702.588291-14-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: 1630667304829100001 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/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 16e95ef9cc9..ed2bc54c052 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1872,7 +1872,7 @@ static void e100_nic_realize(PCIDevice *pci_dev, Erro= r **errp) =20 qemu_register_reset(nic_reset, s); =20 - s->vmstate =3D g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100)); + s->vmstate =3D g_memdup2_qemu(&vmstate_eepro100, sizeof(vmstate_eepro1= 00)); s->vmstate->name =3D qemu_get_queue(s->nic)->model; vmstate_register(VMSTATE_IF(&pci_dev->qdev), VMSTATE_INSTANCE_ID_ANY, s->vmstate, s); --=20 2.31.1