From nobody Mon Feb 9 07:55: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=1630667268; cv=none; d=zohomail.com; s=zohoarc; b=U1OEKcaH4xIP685bAkKseNp06Qil2SaVwaLLUZT1QCzo2DDjG4xiXHKxRNbPdWzbK6CzP59+zY0UO7i2TAwRkOn0hRAfNA87xbamifNQ7xpGyJrFqKePjFfrcNGwGBA3hrPIBq1FuxhyhTN0CysGWLdYM9MCjeTIHdiFgkp6Fcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630667268; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=E9PypJHZFiMU1wwHSEPf1Pz6upK9EcgUKxTQXXjwTWw=; b=Z8NOb7Tg9vu+8qkAK/yQM15QuikmomIEc+eEEvR5rxP30qY84mtINKa8KL4x15zUZEw4BdTG1XDIxdj9PaSlw0fzWfklM8GUweSGt+IB7fy6ZlJo2/eWhpDA5VXxA4rz+Pe+2/SwWgLRVXV10cqANkVun1X2aDqBvAidA9X/BaA= 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 1630667268885804.5933390237286; Fri, 3 Sep 2021 04:07:48 -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-106-lx5QfJeQO1ag04Iqnk_ubA-1; Fri, 03 Sep 2021 07:07:46 -0400 Received: by mail-wm1-f70.google.com with SMTP id b126-20020a1c8084000000b002f152a868a2so1706164wmd.1 for ; Fri, 03 Sep 2021 04:07:46 -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 o5sm4341463wrw.17.2021.09.03.04.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 04:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630667267; 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=E9PypJHZFiMU1wwHSEPf1Pz6upK9EcgUKxTQXXjwTWw=; b=GSRKkGqvlIogjHFds+ZsksoNN2PBmHOpXGybVcc/N8xVWfkQ91KCnAsj7+P20BVb2psImS lCNOWk1XKpJWc3Jj7ogqGhf+MiQonaheIW1unLC8fByzWk1lAlC7kTOppt8rELWuN4XXTv ZV2jqY6KsXajDITwVRrTy6UQy9aB4+g= X-MC-Unique: lx5QfJeQO1ag04Iqnk_ubA-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=E9PypJHZFiMU1wwHSEPf1Pz6upK9EcgUKxTQXXjwTWw=; b=hMTBhZsVoqKYDRz7MFcP+LdG3adJQK3NMNdbMp2qM3t5+TYMF1b1JhZ203mPgL2Cli gS37eW5ixqEFlt5MBPnKT6Xcx199dq8FQqW2kHBrLM7yYrO1auO6b0dvj0BkVms322Kv 4PXA9qEHcWzZ9jQ/GzdDP4XBwrtkEP8EiRyf312JUeiYbllxSk6jnjg1DV9har1UoHAg lG8Vk/HgDhNq6uxmaCBc6BUl380c6rEl+6mYKSqT8kp4f0q6Gj3VqWh1ZscMCV1frz8Z 6Q2Sk3OjZhFK4jBALjrlJnCUEBHVgoHfiO7X2VnBppqOZOIcoWrNLxh+iD49JFyGUlTG CFfw== X-Gm-Message-State: AOAM532RWE7tpqH6Fh9NEKyraXD+bOCeAt/jN5Sp3E/6SMwP8ufx1i7f aajtQAv7A7VW7EEVR1zIiHKXfdMnwiG0zb60N2u/33IFK3qRxIKOqZd/Lt3HXXOZxLXYW16b7Cu BM1UyNgPxEqKrPw== X-Received: by 2002:adf:e887:: with SMTP id d7mr3332688wrm.79.1630667265701; Fri, 03 Sep 2021 04:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOpfMVNquMJIWDXetxTHCuL3Fzb8lZKKWemq9NT4HySMg6qKhGx6koZ2JlS7tbzuIj9REIrw== X-Received: by 2002:adf:e887:: with SMTP id d7mr3332646wrm.79.1630667265554; Fri, 03 Sep 2021 04:07:45 -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 07/28] hw/9pfs: Replace g_memdup() by g_memdup2_qemu() Date: Fri, 3 Sep 2021 13:06:41 +0200 Message-Id: <20210903110702.588291-8-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: 1630667270948100001 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/9pfs/9p-synth.c | 2 +- hw/9pfs/9p.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index b38088e0664..7d983574af5 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -497,7 +497,7 @@ static int synth_name_to_path(FsContext *ctx, V9fsPath = *dir_path, out: /* Copy the node pointer to fid */ g_free(target->data); - target->data =3D g_memdup(&node, sizeof(void *)); + target->data =3D g_memdup2_qemu(&node, sizeof(void *)); target->size =3D sizeof(void *); return 0; } diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 2815257f425..5bf1bd7229f 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -202,7 +202,7 @@ void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src) { v9fs_path_free(dst); dst->size =3D src->size; - dst->data =3D g_memdup(src->data, src->size); + dst->data =3D g_memdup2_qemu(src->data, src->size); } =20 int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, --=20 2.31.1