All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: "Jason Wang" <jasowang@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v2 08/14] virtio-net: Fix duplex=... and speed=... error handling
Date: Wed, 22 Apr 2020 10:24:39 -0400	[thread overview]
Message-ID: <20200422102422-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20200422130719.28225-9-armbru@redhat.com>

On Wed, Apr 22, 2020 at 03:07:13PM +0200, Markus Armbruster wrote:
> virtio_net_device_realize() rejects invalid duplex and speed values.
> The error handling is broken:
> 
>     $ ../qemu/bld-sani/x86_64-softmmu/qemu-system-x86_64 -S -display none -monitor stdio
>     QEMU 4.2.93 monitor - type 'help' for more information
>     (qemu) device_add virtio-net,duplex=x
>     Error: 'duplex' must be 'half' or 'full'
>     (qemu) c
>     =================================================================
>     ==15654==ERROR: AddressSanitizer: heap-use-after-free on address 0x62e000014590 at pc 0x560b75c8dc13 bp 0x7fffdf1a6950 sp 0x7fffdf1a6940
>     READ of size 8 at 0x62e000014590 thread T0
> 	#0 0x560b75c8dc12 in object_dynamic_cast_assert /work/armbru/qemu/qom/object.c:826
> 	#1 0x560b74c38ac0 in virtio_vmstate_change /work/armbru/qemu/hw/virtio/virtio.c:3210
> 	#2 0x560b74d9765e in vm_state_notify /work/armbru/qemu/softmmu/vl.c:1271
> 	#3 0x560b7494ba72 in vm_prepare_start /work/armbru/qemu/cpus.c:2156
> 	#4 0x560b7494bacd in vm_start /work/armbru/qemu/cpus.c:2162
> 	#5 0x560b75a7d890 in qmp_cont /work/armbru/qemu/monitor/qmp-cmds.c:160
> 	#6 0x560b75a8d70a in hmp_cont /work/armbru/qemu/monitor/hmp-cmds.c:1043
> 	#7 0x560b75a799f2 in handle_hmp_command /work/armbru/qemu/monitor/hmp.c:1082
>     [...]
> 
>     0x62e000014590 is located 33168 bytes inside of 42288-byte region [0x62e00000c400,0x62e000016930)
>     freed by thread T1 here:
> 	#0 0x7feadd39491f in __interceptor_free (/lib64/libasan.so.5+0x10d91f)
> 	#1 0x7feadcebcd7c in g_free (/lib64/libglib-2.0.so.0+0x55d7c)
> 	#2 0x560b75c8fd40 in object_unref /work/armbru/qemu/qom/object.c:1128
> 	#3 0x560b7498a625 in memory_region_unref /work/armbru/qemu/memory.c:1762
> 	#4 0x560b74999fa4 in do_address_space_destroy /work/armbru/qemu/memory.c:2788
> 	#5 0x560b762362fc in call_rcu_thread /work/armbru/qemu/util/rcu.c:283
> 	#6 0x560b761c8884 in qemu_thread_start /work/armbru/qemu/util/qemu-thread-posix.c:519
> 	#7 0x7fead9be34bf in start_thread (/lib64/libpthread.so.0+0x84bf)
> 
>     previously allocated by thread T0 here:
> 	#0 0x7feadd394d18 in __interceptor_malloc (/lib64/libasan.so.5+0x10dd18)
> 	#1 0x7feadcebcc88 in g_malloc (/lib64/libglib-2.0.so.0+0x55c88)
> 	#2 0x560b75c8cf8a in object_new /work/armbru/qemu/qom/object.c:699
> 	#3 0x560b75010ad9 in qdev_device_add /work/armbru/qemu/qdev-monitor.c:654
> 	#4 0x560b750120c2 in qmp_device_add /work/armbru/qemu/qdev-monitor.c:805
> 	#5 0x560b75012c1b in hmp_device_add /work/armbru/qemu/qdev-monitor.c:905
>     [...]
>     ==15654==ABORTING
> 
> Cause: virtio_net_device_realize() neglects to bail out after setting
> the error.  Fix that.
> 
> Fixes: 9473939ed7addcaaeb8fde5c093918fb7fa0919c
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Jason Wang <jasowang@redhat.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

Feel free to merge with the rest of the patchset.

> ---
>  hw/net/virtio-net.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index a46e3b37a7..b52ff4ab63 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -2947,6 +2947,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
>              n->net_conf.duplex = DUPLEX_FULL;
>          } else {
>              error_setg(errp, "'duplex' must be 'half' or 'full'");
> +            return;
>          }
>          n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX);
>      } else {
> @@ -2955,7 +2956,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
>  
>      if (n->net_conf.speed < SPEED_UNKNOWN) {
>          error_setg(errp, "'speed' must be between 0 and INT_MAX");
> -    } else if (n->net_conf.speed >= 0) {
> +        return;
> +    }
> +    if (n->net_conf.speed >= 0) {
>          n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX);
>      }
>  
> -- 
> 2.21.1



  reply	other threads:[~2020-04-22 14:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22 13:07 [PATCH v2 00/14] Miscellaneous error handling fixes Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 01/14] cryptodev: Fix cryptodev_builtin_cleanup() error API violation Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 02/14] block/file-posix: Fix check_cache_dropped() error handling Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 03/14] cpus: Fix configure_icount() error API violation Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 04/14] cpus: Proper range-checking for -icount shift=N Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 05/14] arm/virt: Fix virt_machine_device_plug_cb() error API violation Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 06/14] fdc: Fix fallback=auto error handling Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 07/14] bochs-display: Fix vgamem=SIZE " Markus Armbruster
2020-04-23 11:30   ` Gerd Hoffmann
2020-04-22 13:07 ` [PATCH v2 08/14] virtio-net: Fix duplex=... and speed=... " Markus Armbruster
2020-04-22 14:24   ` Michael S. Tsirkin [this message]
2020-04-22 13:07 ` [PATCH v2 09/14] xen/pt: Fix flawed conversion to realize() Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 10/14] io: Fix qio_channel_socket_close() error handling Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 11/14] migration/colo: Fix qmp_xen_colo_do_checkpoint() " Markus Armbruster
2020-04-22 13:07 ` [PATCH v2 12/14] tests/test-logging: Fix test for -dfilter 0..0xffffffffffffffff Markus Armbruster
2020-04-22 13:35   ` Philippe Mathieu-Daudé
2020-04-22 14:49     ` Eric Blake
2020-04-22 16:28       ` Philippe Mathieu-Daudé
2020-04-22 15:19     ` Markus Armbruster
2020-04-22 16:30       ` Philippe Mathieu-Daudé
2020-04-22 13:07 ` [PATCH v2 13/14] qga: Fix qmp_guest_get_memory_blocks() error handling Markus Armbruster
2020-04-22 13:14   ` Eric Blake
2020-04-22 13:07 ` [PATCH v2 14/14] qga: Fix qmp_guest_suspend_{disk, ram}() " Markus Armbruster
2020-04-22 13:19   ` Eric Blake
2020-04-22 13:41   ` Philippe Mathieu-Daudé
2020-04-22 15:17     ` Markus Armbruster
2020-04-22 16:07       ` Philippe Mathieu-Daudé
2020-04-23  8:35         ` Markus Armbruster
2020-04-22 20:21 ` [PATCH v2 00/14] Miscellaneous error handling fixes no-reply
2020-04-29  7:14 ` Markus Armbruster

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=20200422102422-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@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.