All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: qemu-devel@nongnu.org, "Laurent Vivier" <lvivier@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Eric Blake" <eblake@redhat.com>, "John Snow" <jsnow@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Hanna Reitz" <hreitz@redhat.com>,
	qemu-block@nongnu.org, qemu-ppc@nongnu.org,
	"Daniel P . Berrange" <berrange@redhat.com>
Subject: Re: [PATCH v3 16/28] hw/ppc/spapr_pci: Replace g_memdup() by g_memdup2()
Date: Sat, 4 Sep 2021 13:38:36 +1000	[thread overview]
Message-ID: <YTLqPHswPmg0yFQW@yekko> (raw)
In-Reply-To: <20210903174510.751630-17-philmd@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1978 bytes --]

On Fri, Sep 03, 2021 at 07:44:58PM +0200, Philippe Mathieu-Daudé wrote:
> Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdup2-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() wrapper.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Acked-by: David Gibson <david@gibson.dropber.id.au>

> ---
>  hw/ppc/spapr_pci.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> 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 version_id)
>      int i;
>  
>      for (i = 0; i < sphb->msi_devs_num; ++i) {
> -        key = g_memdup(&sphb->msi_devs[i].key,
> -                       sizeof(sphb->msi_devs[i].key));
> -        value = g_memdup(&sphb->msi_devs[i].value,
> -                         sizeof(sphb->msi_devs[i].value));
> +        key = g_memdup2(&sphb->msi_devs[i].key, sizeof(sphb->msi_devs[i].key));
> +        value = 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);

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: David Gibson <david@gibson.dropbear.id.au>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
	qemu-devel@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	qemu-block@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	qemu-arm@nongnu.org, "John Snow" <jsnow@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	qemu-ppc@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH v3 16/28] hw/ppc/spapr_pci: Replace g_memdup() by g_memdup2()
Date: Sat, 4 Sep 2021 13:38:36 +1000	[thread overview]
Message-ID: <YTLqPHswPmg0yFQW@yekko> (raw)
In-Reply-To: <20210903174510.751630-17-philmd@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1978 bytes --]

On Fri, Sep 03, 2021 at 07:44:58PM +0200, Philippe Mathieu-Daudé wrote:
> Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdup2-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() wrapper.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Acked-by: David Gibson <david@gibson.dropber.id.au>

> ---
>  hw/ppc/spapr_pci.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> 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 version_id)
>      int i;
>  
>      for (i = 0; i < sphb->msi_devs_num; ++i) {
> -        key = g_memdup(&sphb->msi_devs[i].key,
> -                       sizeof(sphb->msi_devs[i].key));
> -        value = g_memdup(&sphb->msi_devs[i].value,
> -                         sizeof(sphb->msi_devs[i].value));
> +        key = g_memdup2(&sphb->msi_devs[i].key, sizeof(sphb->msi_devs[i].key));
> +        value = 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);

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-09-04  5:36 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 17:44 [PATCH v3 00/28] glib: Replace g_memdup() by g_memdup2() Philippe Mathieu-Daudé
2021-09-03 17:44 ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 01/28] hw/hyperv/vmbus: Remove unused vmbus_load/save_req() Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 02/28] glib-compat: Introduce g_memdup2() wrapper Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 20:37   ` Eric Blake
2021-09-03 20:37     ` Eric Blake
2021-12-16 14:11   ` Alex Bennée
2021-12-16 14:11     ` Alex Bennée
2021-12-16 18:39     ` Philippe Mathieu-Daudé
2021-12-16 18:39       ` Philippe Mathieu-Daudé
2021-12-17 11:10       ` Alex Bennée
2021-12-17 11:10         ` Alex Bennée
2021-12-17 11:41         ` Laurent Vivier
2021-12-17 11:41           ` Laurent Vivier
2021-12-17 12:15           ` Alex Bennée
2021-12-17 12:15             ` Alex Bennée
2021-12-17 13:39         ` Daniel P. Berrangé
2021-12-17 13:39           ` Daniel P. Berrangé
2021-12-17 13:43     ` Daniel P. Berrangé
2021-12-17 13:43       ` Daniel P. Berrangé
2021-12-17 14:53       ` Alex Bennée
2021-12-17 14:53         ` Alex Bennée
2021-12-17 15:01         ` Daniel P. Berrangé
2021-12-17 15:01           ` Daniel P. Berrangé
2021-12-17 10:55   ` Laurent Vivier
2021-12-17 10:55     ` Laurent Vivier
2021-09-03 17:44 ` [PATCH v3 03/28] qapi: Replace g_memdup() by g_memdup2() Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 21:10   ` Eric Blake
2021-09-03 21:10     ` Eric Blake
2021-09-03 17:44 ` [PATCH v3 04/28] accel/tcg: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 05/28] block/qcow2-bitmap: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 21:13   ` Eric Blake
2021-09-03 21:13     ` Eric Blake
2021-09-03 21:14     ` Philippe Mathieu-Daudé
2021-09-03 21:14       ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 06/28] softmmu: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 07/28] hw/9pfs: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-04 12:25   ` Christian Schoenebeck
2021-09-03 17:44 ` [PATCH v3 08/28] hw/acpi: Avoid truncating acpi_data_len() to 32-bit Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 09/28] hw/acpi: Replace g_memdup() by g_memdup2() Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 10/28] hw/core/machine: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 11/28] hw/hppa/machine: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 12/28] hw/i386/multiboot: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 13/28] hw/net/eepro100: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 14/28] hw/nvram/fw_cfg: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 15/28] hw/scsi/mptsas: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:44 ` [PATCH v3 16/28] hw/ppc/spapr_pci: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-04  3:38   ` David Gibson [this message]
2021-09-04  3:38     ` David Gibson
2021-09-03 17:44 ` [PATCH v3 17/28] hw/rdma: " Philippe Mathieu-Daudé
2021-09-03 17:44   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [PATCH v3 18/28] hw/vfio/pci: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [RFC PATCH v3 19/28] hw/virtio: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2022-04-01 10:50   ` Eugenio Perez Martin
2022-04-01 10:50     ` Eugenio Perez Martin
2021-09-03 17:45 ` [PATCH v3 20/28] net/colo: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [RFC PATCH v3 21/28] ui/clipboard: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [RFC PATCH v3 22/28] linux-user: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [PATCH v3 23/28] tests/unit: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [PATCH v3 24/28] tests/qtest: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-04  5:48   ` Thomas Huth
2021-09-04  5:48     ` Thomas Huth
2021-12-17 10:56   ` Laurent Vivier
2021-12-17 10:56     ` Laurent Vivier
2021-09-03 17:45 ` [PATCH v3 25/28] target/arm: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [PATCH v3 26/28] target/ppc: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-04  3:38   ` David Gibson
2021-09-04  3:38     ` David Gibson
2021-09-03 17:45 ` [PATCH v3 27/28] contrib: " Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 17:45 ` [PATCH v3 28/28] checkpatch: Do not allow deprecated g_memdup() Philippe Mathieu-Daudé
2021-09-03 17:45   ` Philippe Mathieu-Daudé
2021-09-03 21:17   ` Eric Blake
2021-09-03 21:17     ` Eric Blake
2021-12-17 10:58   ` Laurent Vivier
2021-12-17 10:58     ` Laurent Vivier
2021-12-15 16:54 ` [PATCH v3 00/28] glib: Replace g_memdup() by g_memdup2() Philippe Mathieu-Daudé
2021-12-15 16:54   ` Philippe Mathieu-Daudé
2021-12-17 10:59   ` Laurent Vivier
2021-12-17 10:59     ` Laurent Vivier
2024-05-08 21:22 ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YTLqPHswPmg0yFQW@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=david@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.