All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
	qemu-ppc@nongnu.org
Subject: Re: [Qemu-trivial] [PATCH for 2.10 v2 19/20] spapr_vio: fix overflow of qdevs in spapr_dt_vdevice()
Date: Thu, 27 Jul 2017 13:43:04 +1000	[thread overview]
Message-ID: <20170727034304.GJ8978@umbus.fritz.box> (raw)
In-Reply-To: <20170727024224.22900-19-f4bug@amsat.org>

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

On Wed, Jul 26, 2017 at 11:42:23PM -0300, Philippe Mathieu-Daudé wrote:
> sizeof(ptr) was used instead of sizeof(struct)...
> 
> also use g_malloc_n() which take care of possible type overflow.
> 
> hw/ppc/spapr_vio.c:641:22: warning: The code calls sizeof() on a pointer type. This can produce an unexpected result
>     qdevs = g_malloc(sizeof(qdev) * num);
>                      ^     ~~~~~~
> hw/ppc/spapr_vio.c:648:23: warning: The code calls sizeof() on a pointer type. This can produce an unexpected result
>     qsort(qdevs, num, sizeof(qdev), compare_reg);
>                       ^     ~~~~~~
> 
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Nack.

Have a closer look, what's going in the array really is pointers, not
structures.  This is a false warning from clang, we need to find a
different way to suppress it.

> ---
>  hw/ppc/spapr_vio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
> index ea3bc8bd9e..9991b44c9f 100644
> --- a/hw/ppc/spapr_vio.c
> +++ b/hw/ppc/spapr_vio.c
> @@ -638,14 +638,14 @@ void spapr_dt_vdevice(VIOsPAPRBus *bus, void *fdt)
>      }
>  
>      /* Copy out into an array of pointers */
> -    qdevs = g_malloc(sizeof(qdev) * num);
> +    qdevs = g_malloc_n(num, sizeof(*qdev));
>      num = 0;
>      QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
>          qdevs[num++] = kid->child;
>      }
>  
>      /* Sort the array */
> -    qsort(qdevs, num, sizeof(qdev), compare_reg);
> +    qsort(qdevs, num, sizeof(*qdev), compare_reg);
>  
>      /* Hack alert. Give the devices to libfdt in reverse order, we happen
>       * to know that will mean they are in forward order in the tree. */

-- 
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é" <f4bug@amsat.org>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Alexander Graf" <agraf@suse.de>,
	qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
	qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH for 2.10 v2 19/20] spapr_vio: fix overflow of qdevs in spapr_dt_vdevice()
Date: Thu, 27 Jul 2017 13:43:04 +1000	[thread overview]
Message-ID: <20170727034304.GJ8978@umbus.fritz.box> (raw)
In-Reply-To: <20170727024224.22900-19-f4bug@amsat.org>

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

On Wed, Jul 26, 2017 at 11:42:23PM -0300, Philippe Mathieu-Daudé wrote:
> sizeof(ptr) was used instead of sizeof(struct)...
> 
> also use g_malloc_n() which take care of possible type overflow.
> 
> hw/ppc/spapr_vio.c:641:22: warning: The code calls sizeof() on a pointer type. This can produce an unexpected result
>     qdevs = g_malloc(sizeof(qdev) * num);
>                      ^     ~~~~~~
> hw/ppc/spapr_vio.c:648:23: warning: The code calls sizeof() on a pointer type. This can produce an unexpected result
>     qsort(qdevs, num, sizeof(qdev), compare_reg);
>                       ^     ~~~~~~
> 
> Reported-by: Clang Static Analyzer
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Nack.

Have a closer look, what's going in the array really is pointers, not
structures.  This is a false warning from clang, we need to find a
different way to suppress it.

> ---
>  hw/ppc/spapr_vio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
> index ea3bc8bd9e..9991b44c9f 100644
> --- a/hw/ppc/spapr_vio.c
> +++ b/hw/ppc/spapr_vio.c
> @@ -638,14 +638,14 @@ void spapr_dt_vdevice(VIOsPAPRBus *bus, void *fdt)
>      }
>  
>      /* Copy out into an array of pointers */
> -    qdevs = g_malloc(sizeof(qdev) * num);
> +    qdevs = g_malloc_n(num, sizeof(*qdev));
>      num = 0;
>      QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {
>          qdevs[num++] = kid->child;
>      }
>  
>      /* Sort the array */
> -    qsort(qdevs, num, sizeof(qdev), compare_reg);
> +    qsort(qdevs, num, sizeof(*qdev), compare_reg);
>  
>      /* Hack alert. Give the devices to libfdt in reverse order, we happen
>       * to know that will mean they are in forward order in the tree. */

-- 
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:[~2017-07-27  4:04 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27  2:42 [Qemu-trivial] [PATCH for 2.10 v2 00/20] fix bugs reported by Clang Static Analyzer Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 01/20] tests: add missing dependency to build QTEST_QEMU_BINARY Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 02/20] loader: check get_image_size() return value Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 03/20] ivshmem: fix incorrect error handling in ivshmem_recv_msg() Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 04/20] nbd: fix memory leak in nbd_opt_go() Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27 11:25   ` [Qemu-trivial] " Eric Blake
2017-07-27 11:25     ` [Qemu-devel] " Eric Blake
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 05/20] qcow2: fix null pointer dereference Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 06/20] ui/vnc: fix leak of SocketAddress ** Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 07/20] net/eth: fix incorrect check of iov_to_buf() return value Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 08/20] vfio/platform: fix use of freed memory Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 09/20] vfio/pci: " Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 10/20] m68k/translate: fix incorrect copy/paste Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  4:55   ` [Qemu-trivial] " Richard Henderson
2017-07-27  4:55     ` [Qemu-devel] " Richard Henderson
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 11/20] linux-user/sh4: fix incorrect memory write Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 12/20] syscall: fix dereference of undefined pointer Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  6:39   ` [Qemu-trivial] " Laurent Vivier
2017-07-27  6:39     ` [Qemu-devel] " Laurent Vivier
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 13/20] syscall: fix use of uninitialized values Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 14/20] syscall: check inotify() and eventfd() return value Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  6:39   ` [Qemu-trivial] " Laurent Vivier
2017-07-27  6:39     ` [Qemu-devel] " Laurent Vivier
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 15/20] thunk: assert nb_fields is valid Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 17/20] bt-sdp: fix memory leak in sdp_service_record_build() Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27 14:54   ` [Qemu-trivial] " Paolo Bonzini
2017-07-27 14:54     ` Paolo Bonzini
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 18/20] 9pfs: avoid sign conversion error simplifying the code Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27 11:40   ` [Qemu-trivial] " Greg Kurz
2017-07-27 11:40     ` [Qemu-devel] " Greg Kurz
2017-07-27 19:18     ` [Qemu-trivial] " Philippe Mathieu-Daudé
2017-07-27 19:18       ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-28  7:49       ` Greg Kurz
2017-07-28  7:49         ` [Qemu-devel] " Greg Kurz
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 19/20] spapr_vio: fix overflow of qdevs in spapr_dt_vdevice() Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  3:43   ` David Gibson [this message]
2017-07-27  3:43     ` David Gibson
2017-07-27  4:35     ` [Qemu-trivial] " Philippe Mathieu-Daudé
2017-07-27  4:35       ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42 ` [Qemu-trivial] [PATCH for 2.10 v2 20/20] i2c/exynos4210: fix write to I2CADD register, bit 0 is not mapped Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-devel] " Philippe Mathieu-Daudé
2017-07-27  2:42   ` [Qemu-arm] " Philippe Mathieu-Daudé
2017-07-28 11:44   ` [Qemu-trivial] " Michael Tokarev
2017-07-28 11:44     ` [Qemu-devel] " Michael Tokarev
2017-07-28 11:44     ` [Qemu-arm] " Michael Tokarev
2017-07-28 11:45 ` [Qemu-trivial] [PATCH for 2.10 v2 00/20] fix bugs reported by Clang Static Analyzer Michael Tokarev
2017-07-28 11:45   ` [Qemu-devel] " Michael Tokarev

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=20170727034304.GJ8978@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=eblake@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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.