qemu-e2k/block
Deepa Srinivasan c060332c76 block: Fix qemu crash when using scsi-block
Starting qemu with the following arguments causes qemu to segfault:
... -device lsi,id=lsi0 -drive file=iscsi:<...>,format=raw,if=none,node-name=
iscsi1 -device scsi-block,bus=lsi0.0,id=<...>,drive=iscsi1

This patch fixes blk_aio_ioctl() so it does not pass stack addresses to
blk_aio_ioctl_entry() which may be invoked after blk_aio_ioctl() returns. More
details about the bug follow.

blk_aio_ioctl() invokes blk_aio_prwv() with blk_aio_ioctl_entry as the
coroutine parameter. blk_aio_prwv() ultimately calls aio_co_enter().

When blk_aio_ioctl() is executed from within a coroutine context (e.g.
iscsi_bh_cb()), aio_co_enter() adds the coroutine (blk_aio_ioctl_entry) to
the current coroutine's wakeup queue. blk_aio_ioctl() then returns.

When blk_aio_ioctl_entry() executes later, it accesses an invalid pointer:
....
    BlkRwCo *rwco = &acb->rwco;

    rwco->ret = blk_co_ioctl(rwco->blk, rwco->offset,
                             rwco->qiov->iov[0].iov_base);  <--- qiov is
                                                                 invalid here
...

In the case when blk_aio_ioctl() is called from a non-coroutine context,
blk_aio_ioctl_entry() executes immediately. But if bdrv_co_ioctl() calls
qemu_coroutine_yield(), blk_aio_ioctl() will return. When the coroutine
execution is complete, control returns to blk_aio_ioctl_entry() after the call
to blk_co_ioctl(). There is no invalid reference after this point, but the
function is still holding on to invalid pointers.

The fix is to change blk_aio_prwv() to accept a void pointer for the IO buffer
rather than a QEMUIOVector. blk_aio_prwv() passes this through in BlkRwCo and the
coroutine function casts it to QEMUIOVector or uses the void pointer directly.

Signed-off-by: Deepa Srinivasan <deepa.srinivasan@oracle.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Mark Kanda <mark.kanda@oracle.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2018-03-08 15:43:11 +00:00
..
accounting.c
backup.c
blkdebug.c
blkreplay.c
blkverify.c
block-backend.c block: Fix qemu crash when using scsi-block 2018-03-08 15:43:11 +00:00
bochs.c
cloop.c
commit.c
crypto.c Block layer patches 2018-03-06 11:20:44 +00:00
crypto.h
curl.c
dirty-bitmap.c
dmg-bz2.c
dmg.c
dmg.h
file-posix.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
file-win32.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
gluster.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
io.c block: extract AIO_WAIT_WHILE() from BlockDriverState 2018-03-02 18:39:07 +01:00
iscsi-opts.c
iscsi.c Block layer patches 2018-03-06 11:20:44 +00:00
linux-aio.c
Makefile.objs
mirror.c
nbd-client.c
nbd-client.h
nbd.c Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
nfs.c Block layer patches 2018-03-06 11:20:44 +00:00
null.c
nvme.c
parallels.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
parallels.h
qapi.c Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
qcow2-bitmap.c qcow2: Replace align_offset() with ROUND_UP() 2018-03-02 18:39:56 +01:00
qcow2-cache.c
qcow2-cluster.c qcow2: Replace align_offset() with ROUND_UP() 2018-03-02 18:39:56 +01:00
qcow2-refcount.c qcow2: Replace align_offset() with ROUND_UP() 2018-03-02 18:39:56 +01:00
qcow2-snapshot.c qcow2: Replace align_offset() with ROUND_UP() 2018-03-02 18:39:56 +01:00
qcow2.c Block layer patches 2018-03-06 11:20:44 +00:00
qcow2.h qcow2: Replace align_offset() with ROUND_UP() 2018-03-02 18:39:56 +01:00
qcow.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
qed-check.c
qed-cluster.c
qed-l2-cache.c
qed-table.c
qed.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
qed.h
quorum.c Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
raw-format.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
rbd.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
replication.c
sheepdog.c Block layer patches 2018-03-06 11:20:44 +00:00
snapshot.c
ssh.c Block layer patches 2018-03-06 11:20:44 +00:00
stream.c
throttle-groups.c Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
throttle.c
trace-events
vdi.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
vhdx-endian.c
vhdx-log.c
vhdx.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
vhdx.h
vmdk.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
vpc.c block: rename .bdrv_create() to .bdrv_co_create_opts() 2018-03-02 18:39:07 +01:00
vvfat.c vvfat: Switch to .bdrv_co_block_status() 2018-03-02 18:39:07 +01:00
vxhs.c
win32-aio.c
write-threshold.c Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00