From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEE2EC433F5 for ; Sat, 4 Sep 2021 05:41:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2FA3260FDC for ; Sat, 4 Sep 2021 05:41:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2FA3260FDC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:50112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMOQT-000395-6k for qemu-devel@archiver.kernel.org; Sat, 04 Sep 2021 01:41:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMOM2-0000Hq-Tn; Sat, 04 Sep 2021 01:36:40 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:46111 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMOM0-0000Xg-TU; Sat, 04 Sep 2021 01:36:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1630733791; bh=hODncbRxZb+5J14YcZnIgq6EXW9tP5Fmu8R04Gf2lsE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eULuJIkwjFK1cuIpwPcSOeBngDp84uxzYSVQKOLf3dvQj+dUDJeY2pm+7wFEf+Boz BMXLliSV61bFVXVzXEEwACAGilcGPpuDq3MbFV9ViPDCLisCOeVwfpZlp2hSH7G+lf L6tn5RqPNyygvXd9SsKukwE64RtqbKEw8jEJHYs0= Received: by ozlabs.org (Postfix, from userid 1007) id 4H1k1C5wJfz9sW5; Sat, 4 Sep 2021 15:36:31 +1000 (AEST) Date: Sat, 4 Sep 2021 13:38:36 +1000 From: David Gibson To: Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= Subject: Re: [PATCH v3 16/28] hw/ppc/spapr_pci: Replace g_memdup() by g_memdup2() Message-ID: References: <20210903174510.751630-1-philmd@redhat.com> <20210903174510.751630-17-philmd@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="M3+GtE8/tO4A26e2" Content-Disposition: inline In-Reply-To: <20210903174510.751630-17-philmd@redhat.com> Received-SPF: pass client-ip=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , Jason Wang , Christian Schoenebeck , qemu-devel@nongnu.org, Gerd Hoffmann , Eric Blake , qemu-block@nongnu.org, Alex =?iso-8859-1?Q?Benn=E9e?= , David Hildenbrand , Markus Armbruster , Laurent Vivier , Thomas Huth , Eduardo Habkost , Richard Henderson , qemu-arm@nongnu.org, John Snow , Kevin Wolf , Vladimir Sementsov-Ogievskiy , "Daniel P . Berrange" , Hanna Reitz , qemu-ppc@nongnu.org, Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --M3+GtE8/tO4A26e2 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 03, 2021 at 07:44:58PM +0200, Philippe Mathieu-Daud=E9 wrote: > Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-mem= dup2-now/5538 >=20 > 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. >=20 > Replace g_memdup() by the safer g_memdup2() wrapper. >=20 > Signed-off-by: Philippe Mathieu-Daud=E9 Acked-by: David Gibson > --- > hw/ppc/spapr_pci.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) >=20 > diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c > index 7430bd63142..8e36cffab79 100644 > --- a/hw/ppc/spapr_pci.c > +++ b/hw/ppc/spapr_pci.c > @@ -2201,10 +2201,9 @@ static int spapr_pci_post_load(void *opaque, int v= ersion_id) > int i; > =20 > for (i =3D 0; i < sphb->msi_devs_num; ++i) { > - key =3D g_memdup(&sphb->msi_devs[i].key, > - sizeof(sphb->msi_devs[i].key)); > - value =3D g_memdup(&sphb->msi_devs[i].value, > - sizeof(sphb->msi_devs[i].value)); > + key =3D g_memdup2(&sphb->msi_devs[i].key, sizeof(sphb->msi_devs[= i].key)); > + value =3D g_memdup2(&sphb->msi_devs[i].value, > + sizeof(sphb->msi_devs[i].value)); > g_hash_table_insert(sphb->msi, key, value); > } > g_free(sphb->msi_devs); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --M3+GtE8/tO4A26e2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmEy6jwACgkQbDjKyiDZ s5J7ixAAsneh6qhvTS9tA+ZAoRedPtcXclRP5xkl0BUJ4PHYARVO2BgOPK5GsxCF qFmwoX5ipNASF9PAlheCrIUVzLOGxWqGqbDdA9xQjbzZGOaK34GJrGFwI9EBX3Bm Goro0bp9j4ns5d1igU7MyIpY73yPTXwRYdNQea7p4FD6LdLnOteJTImbesKHJEFG BFoOPsihbl0LFOeT5B5pX6xmuN5oNBc3ylARXZ79S/pCQuP4o8P0OveSnUAEODGd WooYtcEgbQl5moe+1qZ3vKL+WqLubg4OJjHjeD5XOgHNvaf7XnJwHciBw/QGDm3F xh9k9JeojX8Jd0VpvCt7et7nt82BkzPFn8c6VdcLw5Pk6fNh//AMvgJ8PxpSrr5V 8SRs/MkJlh07s8hbQLWo7KSrs9ecb9m1PSykWaHryiYA06rKpw6ePHkvrb7WpcQi A83F6P7d92oe/HM9nxJfZCoxClphDzShw1zjXlwZZ7xXVIOO4xopziLYc/ZKIeeO 4wATZtriWub27Mqk04N4gc2wsMed1mljBMPrg5HjzG+6GTbyrn4L98deosxmjx68 XUkI7AT1Gd38TVHUxkdOoEdiuOIT98SnEc1de5loknay1+NPFMNLi2onlzYfaRhT j9qva+td5VLYjgtlveTBM7983yDGr3pgjayAjtHkPDzUTtd9kXA= =ub2z -----END PGP SIGNATURE----- --M3+GtE8/tO4A26e2--