From nobody Mon Feb 9 12:43:12 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=1630667367; cv=none; d=zohomail.com; s=zohoarc; b=VONme80GdO5orhMEcGnga0AsKiU1WHVHjLW8RyRX5g89G+P5idx9GSSx43zu4dIHHYzwdXQ1jEsPNyIfospwFGbMwk9xdyKryoqY5dUZOFf8y7jGsJxLmR+ClyIgG7fpDrGITXrGvk6zKoIAl+rr2lZiW9Z3FuTdFu3jzNKOXig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667367; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=n0triH/V2nmMAjnP2t96Jm0J8HMx9Dls9aYUNoC2xTc=; b=KXXNrUR/31DGYwk+4xKLh02/cR42CPVY3DoxRZ4THbQ+ozDwURYIlP6MXm5hbP7O7e1uSLi3xahChkJ/1ebI60Je477mYqe01NuF4fn3iX85BfSoHrdgCtUWxECbbHg9caD0oy3qSJhbPxXA5WLfMzPLwWVs25b+WcSbhcJjeVo= 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 1630667367245680.3742204096559; Fri, 3 Sep 2021 04:09:27 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-LI7IqLGWOSqqT0_SLLAFUA-1; Fri, 03 Sep 2021 07:09:23 -0400 Received: by mail-wm1-f71.google.com with SMTP id x125-20020a1c3183000000b002e73f079eefso2543495wmx.0 for ; Fri, 03 Sep 2021 04:09:22 -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 r25sm4622504wra.12.2021.09.03.04.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667365; 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=n0triH/V2nmMAjnP2t96Jm0J8HMx9Dls9aYUNoC2xTc=; b=VYX4nRG50ihDo5TqBTuQOPEb/Fzb+rVYeQqxvAZNQ18DcnAaGd0lkCWtE7Fwym7CsHey5k lASAv+fu9NXndVPSp9Gc+6iMeahfVf/jHOxChAZOgh9tD5u/4p1kLyQWQQS5p8Moe+hrse nvy+Bm+Xh+pL3sPHRVX8CDnr+TclLgc= X-MC-Unique: LI7IqLGWOSqqT0_SLLAFUA-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=n0triH/V2nmMAjnP2t96Jm0J8HMx9Dls9aYUNoC2xTc=; b=Dquxks1Kv/hLO/CCQ1dVHz2q5rRIDs6ubI+7SSaF42R37OHK6nwSGvyWDq9Lwl7Yr8 gxfIpFPE2LMyAKCIU9eY0vQO57l51BZLaB3Q1xEFa7YdH6CAupPpwFBIRf1rGSKFP4Dl V7gEM0D38s2a6rU/IwU7o9y10FugqEXxF76WXVlkc1/7K+laqorkp1dwhnZGp58d7jOj ryXfu/9aZOKIY5ALwhoX1yGlkje0a5JRQQ6NejOa635q/X6STZhMs+H8GoXCqYD36QIp +eCbq6qLVGM+B4lM22Co5LS0wrw2eE4DvhM91gXDxWLyILrn9uUpHuZzItHMhfLg+zY6 xKTA== X-Gm-Message-State: AOAM533TCjVSbbrcrLDb9YWEegZ7hTcS0j2kcJAVULnNfNp7oohu8xoS CS2c5w5SnpwReDf8V2suYkGhLBx5ihKP0ma0NHjH5DPFQDjsuq5mu20x0qRiOzo3brtzz3CEwKw gIBd8xY7umkb96Q== X-Received: by 2002:a05:6000:34e:: with SMTP id e14mr3400048wre.401.1630667361811; Fri, 03 Sep 2021 04:09:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygD1LHKrazXWd2ti6h3NF8Ii1KKU0zYPFqQVcCVwcY1zpr1xnUywyPoJmcGRu+BhfGJLIRwQ== X-Received: by 2002:a05:6000:34e:: with SMTP id e14mr3400010wre.401.1630667361655; Fri, 03 Sep 2021 04:09:21 -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 24/28] tests/qtest: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:58 +0200 Message-Id: <20210903110702.588291-25-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: 1630667369545100001 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 --- tests/qtest/libqos/ahci.c | 6 +++--- tests/qtest/libqos/qgraph.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/qtest/libqos/ahci.c b/tests/qtest/libqos/ahci.c index fba3e7a954e..8ef1bda7c1c 100644 --- a/tests/qtest/libqos/ahci.c +++ b/tests/qtest/libqos/ahci.c @@ -639,8 +639,8 @@ void ahci_exec(AHCIQState *ahci, uint8_t port, AHCIOpts *opts; uint64_t buffer_in; =20 - opts =3D g_memdup((opts_in =3D=3D NULL ? &default_opts : opts_in), - sizeof(AHCIOpts)); + opts =3D g_memdup2_qemu((opts_in =3D=3D NULL ? &default_opts : opts_in= ), + sizeof(AHCIOpts)); =20 buffer_in =3D opts->buffer; =20 @@ -860,7 +860,7 @@ AHCICommand *ahci_command_create(uint8_t command_name) g_assert(!props->ncq || props->lba48); =20 /* Defaults and book-keeping */ - cmd->props =3D g_memdup(props, sizeof(AHCICommandProp)); + cmd->props =3D g_memdup2_qemu(props, sizeof(AHCICommandProp)); cmd->name =3D command_name; cmd->xbytes =3D props->size; cmd->prd_size =3D 4096; diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c index d1dc4919305..c2e7719bed9 100644 --- a/tests/qtest/libqos/qgraph.c +++ b/tests/qtest/libqos/qgraph.c @@ -93,7 +93,7 @@ static void add_edge(const char *source, const char *dest, edge->type =3D type; edge->dest =3D g_strdup(dest); edge->edge_name =3D g_strdup(opts->edge_name ?: dest); - edge->arg =3D g_memdup(opts->arg, opts->size_arg); + edge->arg =3D g_memdup2_qemu(opts->arg, opts->size_arg); =20 edge->before_cmd_line =3D opts->before_cmd_line ? g_strconcat(" ", opts->before_cmd_line, NU= LL) : NULL; --=20 2.31.1