Skip to contentSkip to conversation

ahci: fix ncq aiocb-related segfault

PATCH In review John Snow 2 participants 4 messages Sep 22, 2016 – Sep 26, 2016

lore
Share & tools
lore

John Snow

author
#0 lore raw

cover ahci: fix ncq aiocb-related segfault

Fix ncq_cb to prevent a segfault on sys_reset.

John Snow (1):
ahci: clear aiocb in ncq_cb

 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/1 ahci: clear aiocb in ncq_cb

Similar to existing fixes for IDE and ATAPI, the AIOCB must be cleared in the callback. Otherwise, we may accidentally try to reset it after the object has been released.

---
 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)
hw/ide/ahci.c +1 -0
index f3438ad..63ead21 100644
@@ -948,6 +948,7 @@ static void ncq_cb(void *opaque, int ret)
     NCQTransferState *ncq_tfs = (NCQTransferState *)opaque;
     IDEState *ide_state = &ncq_tfs->drive->port.ifs[0];
 
+    ncq_tfs->aiocb = NULL;
     if (ret == -ECANCELED) {
         return;
     }
Signature · 1 line
2.7.4
Reviewed-by on the v1 series
#2 lore raw
In reply to John Snow
Quoted 10 lines · John Snow

Fix ncq_cb to prevent a segfault on sys_reset.

John Snow (1):
ahci: clear aiocb in ncq_cb

 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
2.7.4

Maybe worth adding as a clarification:

The issue is when bdrv_aio_cancel() is called after ncq_cb() was already invoked. The aiocb will be a dangling pointer.

author Applied
#3 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · John Snow

Fix ncq_cb to prevent a segfault on sys_reset.

John Snow (1):
ahci: clear aiocb in ncq_cb

 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 8 lines
Quoted 2 lines

--
2.7.4

Maybe worth adding as a clarification:

The issue is when bdrv_aio_cancel() is called after ncq_cb() was already invoked. The aiocb will be a dangling pointer.

Done.

Quoted 2 lines

Thanks, applied to my IDE tree:

https://github.com/jnsnow/qemu/commits/ide
https://github.com/jnsnow/qemu.git

--js