From nobody Mon Feb 9 21:37:18 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=1630667296; cv=none; d=zohomail.com; s=zohoarc; b=P7oRNnmm7SW2zu96+6H+0FkOdIDLfkjW8e+JOcpykQMKuLJ2i26V1FCc4d0/OgolCZr5wyiLKBIOnJ+4WAknk4HAM1uSBtGV2zMFGsNc96cpDHFv0djg8oKIIcobVotgwnMCVoWlZKvCpuDjIhEJByGyd1kPhMH9A+NKIWxtZfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667296; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=DAHpDs712oI1Di1eaFqrdG2Typ24HrNYG4qVZsBh0cw=; b=fDaPMSAFukk0Pyb5vQaJK1G/M6+MmVfm37b3ZLJuLd4dcTVuY8JRSEHhj9usqt6ljuAUIM0WD+gJnIMlNx4CV5KBObaqNnmiZqC9kf5mjGepc3ERlKKleRQYPAinurM/27LN1/bqJiy1DAre9R5eBxlLsSlHDuiavRqeB+M0eIU= 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 1630667296829212.51600894509306; Fri, 3 Sep 2021 04:08:16 -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-600-aCsyFR1VOFSVzaTcV2Y5OA-1; Fri, 03 Sep 2021 07:08:14 -0400 Received: by mail-wm1-f70.google.com with SMTP id h1-20020a05600c350100b002e751bf6733so1833394wmq.8 for ; Fri, 03 Sep 2021 04:08:14 -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 y21sm4191900wmc.11.2021.09.03.04.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667295; 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=DAHpDs712oI1Di1eaFqrdG2Typ24HrNYG4qVZsBh0cw=; b=HYGjJmNmp/IhpXP+YCtHnhsVxDa6Uaq4dWnEvO6T7TTWucEpSF6nPG6YWDTKF7NfatWNoY s7RXvt6K+4L+9iUCuBEs2yLMglFT4GUPt3wZbXp9A4o4lYLWmUTy8rnBFsJfZrVW+k+1gz lrCQh7gyitpkdKItA6tWI+g/TN/dItU= X-MC-Unique: aCsyFR1VOFSVzaTcV2Y5OA-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=DAHpDs712oI1Di1eaFqrdG2Typ24HrNYG4qVZsBh0cw=; b=B9pmeRp8pJcR+OMkIrCB0RJCux8MbdmMECL2Bfq43TtcszmmlnOoGDKWnnqDj+mAwe LJ1M6J4xldOdZsoFc1hzh/u2tEHqcI8a4fbpoA/FpwMA/0heTwAi2Ov0+c4iwiNSaWDK X7os35cTORACp+wyq2GsTxB83Ps6dzDi7Jkfggragnm+ijddVjy/w8thBE2uZn0KCh/m uWTfPNenkSc6fMNLyZ68pWvmWmtvTov7FVto2Cwi/ftNestPPTc1vYjGi7R8KIQxaLq0 ruJAU5pkdmXI6tk+p0lRrkCrrjSZXr+TsKnaqKVxBecxZ8U368i6sB2Q8wr6Q+vY/gYt 7qSA== X-Gm-Message-State: AOAM5311f17cmA20pa1c2yczD8GIjCVAtOeD2DusBK3zkfZVLDji6mD1 AbYM9SnXuc10NIL2unqp7TC1HE8W4GaSkgctKrfARfa7dpdndYAjY9ELi7nx4wlzE4cxZswY468 FNN8Q1G71Gvjrkg== X-Received: by 2002:adf:db83:: with SMTP id u3mr3485669wri.363.1630667293635; Fri, 03 Sep 2021 04:08:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhSQcK5FJTs0sGhQbUmpLfHDCygADufnlCA9XiiEfi1zCH7QtVMSqQu/dZo926/mNxJx5weg== X-Received: by 2002:adf:db83:: with SMTP id u3mr3485647wri.363.1630667293467; Fri, 03 Sep 2021 04:08:13 -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 12/28] hw/i386/multiboot: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:46 +0200 Message-Id: <20210903110702.588291-13-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: 1630667297967100001 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/i386/multiboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c index 9e7d69d4705..f536e3c8c96 100644 --- a/hw/i386/multiboot.c +++ b/hw/i386/multiboot.c @@ -387,7 +387,7 @@ int load_multiboot(FWCfgState *fw_cfg, mb_debug(" mb_mods_count =3D %d", mbs.mb_mods_count); =20 /* save bootinfo off the stack */ - mb_bootinfo_data =3D g_memdup(bootinfo, sizeof(bootinfo)); + mb_bootinfo_data =3D g_memdup2_qemu(bootinfo, sizeof(bootinfo)); =20 /* Pass variables to option rom */ fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, mh_entry_addr); --=20 2.31.1