Skip to contentSkip to conversation

block/linux-aio: explictly clear laiocb->co

PATCH In review Stefan Hajnoczi 4 participants 4 messages May 27, 2019 – May 30, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/linux-aio: explictly clear laiocb->co

qemu_aio_get() does not zero allocated memory. Explicitly initialize laiocb->co to prevent an uninitialized memory access in qemu_laio_process_completion().

Note that this bug has never manifested itself. I guess we're lucky!

---
I challenge you to find a place where laiocb->co is initialized and then we can drop this patch. I've double-checked and cannot find it...

 block/linux-aio.c | 1 +
 1 file changed, 1 insertion(+)
block/linux-aio.c +1 -0
index d4b61fb251..a097653be6 100644
@@ -440,6 +440,7 @@ BlockAIOCB *laio_submit(BlockDriverState *bs, LinuxAioState *s, int fd,
     int ret;
 
     laiocb = qemu_aio_get(&laio_aiocb_info, bs, cb, opaque);
+    laiocb->co = NULL;
     laiocb->nbytes = nb_sectors * BDRV_SECTOR_SIZE;
     laiocb->ctx = s;
     laiocb->ret = -EINPROGRESS;
Signature · 1 line
2.21.0
#1 lore raw

Am 27.05.2019 um 11:23 hat Stefan Hajnoczi geschrieben:

Quoted 7 lines

qemu_aio_get() does not zero allocated memory. Explicitly initialize laiocb->co to prevent an uninitialized memory access in qemu_laio_process_completion().

Note that this bug has never manifested itself. I guess we're lucky!

That the bug never manifested itself might be because it's in an unused function. How about we finally just remove the unused callback-based laio_submit() from the code?

At the time when I converted linux-aio to coroutines, someone (maybe Paolo?) insisted that we keep the old interface because we might add a new user sometime with possible shortcuts that bypass the whole coroutine path, but it hasn't happened and I think we've moved even further in the opposite direction since then.

Kevin

Quoted 21 lines

I challenge you to find a place where laiocb->co is initialized and then we can drop this patch. I've double-checked and cannot find it...

 block/linux-aio.c | 1 +
 1 file changed, 1 insertion(+)
block/linux-aio.c +1 -0
index d4b61fb251..a097653be6 100644
@@ -440,6 +440,7 @@ BlockAIOCB *laio_submit(BlockDriverState *bs, LinuxAioState *s, int fd,
     int ret;
 
     laiocb = qemu_aio_get(&laio_aiocb_info, bs, cb, opaque);
+    laiocb->co = NULL;
     laiocb->nbytes = nb_sectors * BDRV_SECTOR_SIZE;
     laiocb->ctx = s;
     laiocb->ret = -EINPROGRESS;
Signature · 1 line
2.21.0
#2 lore raw
Quoted 13 lines · Kevin Wolf

Am 27.05.2019 um 11:23 hat Stefan Hajnoczi geschrieben:

Quoted 7 lines

qemu_aio_get() does not zero allocated memory. Explicitly initialize laiocb->co to prevent an uninitialized memory access in qemu_laio_process_completion().

Note that this bug has never manifested itself. I guess we're lucky!

That the bug never manifested itself might be because it's in an unused function. How about we finally just remove the unused callback-based laio_submit() from the code?

Quoted 5 lines

At the time when I converted linux-aio to coroutines, someone (maybe Paolo?) insisted that we keep the old interface because we might add a new user sometime with possible shortcuts that bypass the whole coroutine path, but it hasn't happened and I think we've moved even further in the opposite direction since then.

Yes, I suppose it's time. Spending time fixing bugs in dead code is always a sign that it's time. :)

Paolo

#3 lore raw
Quoted 14 lines · Paolo Bonzini
Quoted 13 lines · Kevin Wolf

Am 27.05.2019 um 11:23 hat Stefan Hajnoczi geschrieben:

Quoted 7 lines

qemu_aio_get() does not zero allocated memory. Explicitly initialize laiocb->co to prevent an uninitialized memory access in qemu_laio_process_completion().

Note that this bug has never manifested itself. I guess we're lucky!

That the bug never manifested itself might be because it's in an unused function. How about we finally just remove the unused callback-based laio_submit() from the code?

Quoted 8 lines
Quoted 5 lines

At the time when I converted linux-aio to coroutines, someone (maybe Paolo?) insisted that we keep the old interface because we might add a new user sometime with possible shortcuts that bypass the whole coroutine path, but it hasn't happened and I think we've moved even further in the opposite direction since then.

Yes, I suppose it's time. Spending time fixing bugs in dead code is always a sign that it's time. :)

Great, I'll clean it up.

Best regards, Julia Suvorova.