From nobody Mon Feb 9 10:58:21 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=1630667280; cv=none; d=zohomail.com; s=zohoarc; b=IXOnqzdabUFKYEKa65TwDBtjpgRGkOjyNxevEqhwH47Im3ZDWG5AZuz/DO6YTOEYIwpY0HQNuam0ghv5ETZhQv1PtZfAJSOq1+2/aRb6/ZoYEGf01eTl2jVROs/uJBDrXYeyGGWh2YToWKoSgOBEVKIsNcdf8iuFKnZjw3Zefn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667280; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=jdbGO9h9jnqrOlFY+xUPTR+ImPF+i+blj+6DLU+L+so=; b=meakhc7rFt7GWbBjigz2wE7ScbKdHvJ5I6eBczPMeGeSeMZ6LNH6A4M1yEZldvwDm4d/+J9ID/dTr8ucd8H2E+Ik8dr4ChJUyXEbhEf3xQxYjVDo8fnrcEZQ76ssZJxOEqaAD8P+5gGwZSZEQwTN05SbmQclFvve6YPvstCTh64= 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 1630667280022148.7914445980158; Fri, 3 Sep 2021 04:08:00 -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-230-Pv9r5M1YNGicuve3aoWNdQ-1; Fri, 03 Sep 2021 07:07:58 -0400 Received: by mail-wm1-f70.google.com with SMTP id o20-20020a05600c379400b002e755735eedso1861617wmr.0 for ; Fri, 03 Sep 2021 04:07:57 -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 l124sm4039567wml.8.2021.09.03.04.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667279; 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=jdbGO9h9jnqrOlFY+xUPTR+ImPF+i+blj+6DLU+L+so=; b=Kps/7ugDjxtyTCdW8xTjS1hPapwN//3dW7TJZaSHIOGdoeGpnV+bozJ3Z/T+TVp8IIaopN inj2grkGyDXjNjJoG8Hh5p1IrYiXg8NFMZNxLG5onWRc6zQiZlyY1zNsO0WyhhiPBgBY8N X+Am8CikF9Iy7wqaJ42ycSfr2lB6F1I= X-MC-Unique: Pv9r5M1YNGicuve3aoWNdQ-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=jdbGO9h9jnqrOlFY+xUPTR+ImPF+i+blj+6DLU+L+so=; b=jKe2rL0s6DBwxvO014raxwDaHYDhAa3DJUU7R/a3roKTRliokm2LEmZM4M+IxSqkba lqr1WhWG16omxImd45l5HxOkbw9uU3pnuFDpY40pknLfPTM2kLWzIc8jWOKmZnnuWX6E IlT/PzjZHSzsxRIutKmZEpLTKI8W6w51yyGkKX4eMOH32big8zwsHmd858aySndqsUIX LysxFPsTV3JuuQ+/S59BYhY/XkfK5MMwKTJIfWbzy2EsRNsfuVLA1rOMch50zXGjkSb5 tAZFMZSjixYVsdvxvjU26LH4GE7ODLcem5Pqg6zUO2w8es8h1PMI7poibRWl3NvpT26c zHMg== X-Gm-Message-State: AOAM53392UOfqJSsEQngwsSzh/gcK+jnU57JzNTmXN7BQztDH7IQkjgf fG3SFSjO2i7TvoCJ+We9tIiGbAzz2vznClRRCHOO9sRC5PLgb1T4ylpcnIx3abbA15FVGNg5vdo FBKh+Bhim+DzbWw== X-Received: by 2002:a05:600c:230c:: with SMTP id 12mr2762187wmo.41.1630667276890; Fri, 03 Sep 2021 04:07:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaAweBFiZwGaMpvEF57j+Ip2CFlgT7mOREgnEpdZoNjDiORDuB5ABI4Md7tnxGgAvNN6sfhA== X-Received: by 2002:a05:600c:230c:: with SMTP id 12mr2762155wmo.41.1630667276703; Fri, 03 Sep 2021 04:07:56 -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 09/28] hw/acpi: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:43 +0200 Message-Id: <20210903110702.588291-10-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: 1630667282121100001 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 Acked-by: Igor Mammedov --- hw/acpi/core.c | 3 ++- hw/i386/acpi-build.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/acpi/core.c b/hw/acpi/core.c index 1e004d0078d..9dd2cf09a0b 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -637,7 +637,8 @@ void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *pare= nt, suspend[3] =3D 1 | ((!disable_s3) << 7); suspend[4] =3D s4_val | ((!disable_s4) << 7); =20 - fw_cfg_add_file(fw_cfg, "etc/system-states", g_memdup(suspend, 6),= 6); + fw_cfg_add_file(fw_cfg, "etc/system-states", + g_memdup2_qemu(suspend, 6), 6); } } =20 diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index aa269914b49..54494ca1f65 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2785,7 +2785,7 @@ void acpi_setup(void) */ unsigned rsdp_size =3D acpi_data_len(tables.rsdp); =20 - build_state->rsdp =3D g_memdup(tables.rsdp->data, rsdp_size); + build_state->rsdp =3D g_memdup2_qemu(tables.rsdp->data, rsdp_size); fw_cfg_add_file_callback(x86ms->fw_cfg, ACPI_BUILD_RSDP_FILE, acpi_build_update, NULL, build_state, build_state->rsdp, rsdp_size, true); --=20 2.31.1