* [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice
@ 2016-06-23 7:30 Kevin Wolf
2016-06-23 12:24 ` Eric Blake
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kevin Wolf @ 2016-06-23 7:30 UTC (permalink / raw)
To: qemu-block; +Cc: kwolf, qemu-devel
BlockBackend has only a single pointer to its guest device, so it makes
sure that only a single guest device is attached to it. device-add
returns an error if you try to attach a second device to a BB. In order
to make the error message nicer, -device that manually connects to a
if=none block device get a different message than -drive that implicitly
creates a guest device. The if=... option is stored in DriveInfo.
However, since blockdev-add exists, not every BlockBackend has a
DriveInfo any more. Check that it exists before we dereference it.
QMP reproducer resulting in a segfault:
{"execute":"blockdev-add","arguments":{"options":{"id":"disk","driver":"file","filename":"/tmp/test.img"}}}
{"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
{"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/core/qdev-properties-system.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 623be94..c5cc9cf 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -91,7 +91,7 @@ static void parse_drive(DeviceState *dev, const char *str, void **ptr,
if (blk_attach_dev(blk, dev) < 0) {
DriveInfo *dinfo = blk_legacy_dinfo(blk);
- if (dinfo->type != IF_NONE) {
+ if (dinfo && dinfo->type != IF_NONE) {
error_setg(errp, "Drive '%s' is already in use because "
"it has been automatically connected to another "
"device (did you need 'if=none' in the drive options?)",
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice
2016-06-23 7:30 [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice Kevin Wolf
@ 2016-06-23 12:24 ` Eric Blake
2016-06-24 10:05 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-06-29 9:51 ` [Qemu-devel] " Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2016-06-23 12:24 UTC (permalink / raw)
To: Kevin Wolf, qemu-block; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]
On 06/23/2016 01:30 AM, Kevin Wolf wrote:
> BlockBackend has only a single pointer to its guest device, so it makes
> sure that only a single guest device is attached to it. device-add
> returns an error if you try to attach a second device to a BB. In order
> to make the error message nicer, -device that manually connects to a
> if=none block device get a different message than -drive that implicitly
> creates a guest device. The if=... option is stored in DriveInfo.
>
> However, since blockdev-add exists, not every BlockBackend has a
> DriveInfo any more. Check that it exists before we dereference it.
>
> QMP reproducer resulting in a segfault:
>
> {"execute":"blockdev-add","arguments":{"options":{"id":"disk","driver":"file","filename":"/tmp/test.img"}}}
> {"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
> {"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> hw/core/qdev-properties-system.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH] block/qdev: Fix NULL access when using BB twice
2016-06-23 7:30 [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice Kevin Wolf
2016-06-23 12:24 ` Eric Blake
@ 2016-06-24 10:05 ` Stefan Hajnoczi
2016-06-29 9:51 ` [Qemu-devel] " Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2016-06-24 10:05 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-block, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]
On Thu, Jun 23, 2016 at 09:30:01AM +0200, Kevin Wolf wrote:
> BlockBackend has only a single pointer to its guest device, so it makes
> sure that only a single guest device is attached to it. device-add
> returns an error if you try to attach a second device to a BB. In order
> to make the error message nicer, -device that manually connects to a
> if=none block device get a different message than -drive that implicitly
> creates a guest device. The if=... option is stored in DriveInfo.
>
> However, since blockdev-add exists, not every BlockBackend has a
> DriveInfo any more. Check that it exists before we dereference it.
>
> QMP reproducer resulting in a segfault:
>
> {"execute":"blockdev-add","arguments":{"options":{"id":"disk","driver":"file","filename":"/tmp/test.img"}}}
> {"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
> {"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> hw/core/qdev-properties-system.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice
2016-06-23 7:30 [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice Kevin Wolf
2016-06-23 12:24 ` Eric Blake
2016-06-24 10:05 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
@ 2016-06-29 9:51 ` Kevin Wolf
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2016-06-29 9:51 UTC (permalink / raw)
To: qemu-block; +Cc: qemu-devel
Am 23.06.2016 um 09:30 hat Kevin Wolf geschrieben:
> BlockBackend has only a single pointer to its guest device, so it makes
> sure that only a single guest device is attached to it. device-add
> returns an error if you try to attach a second device to a BB. In order
> to make the error message nicer, -device that manually connects to a
> if=none block device get a different message than -drive that implicitly
> creates a guest device. The if=... option is stored in DriveInfo.
>
> However, since blockdev-add exists, not every BlockBackend has a
> DriveInfo any more. Check that it exists before we dereference it.
>
> QMP reproducer resulting in a segfault:
>
> {"execute":"blockdev-add","arguments":{"options":{"id":"disk","driver":"file","filename":"/tmp/test.img"}}}
> {"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
> {"execute":"device_add","arguments":{"driver":"virtio-blk-pci","drive":"disk"}}
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Applied to my block branch.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-06-29 9:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-23 7:30 [Qemu-devel] [PATCH] block/qdev: Fix NULL access when using BB twice Kevin Wolf
2016-06-23 12:24 ` Eric Blake
2016-06-24 10:05 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-06-29 9:51 ` [Qemu-devel] " Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).