ide: check BlockBackend object in ide_cancel_dma_sync
PATCH 1/1 ide: check BlockBackend object in ide_cancel_dma_sync
From: Prasad J Pandit <[email protected]>
When cancelling pending DMA requests in ide_cancel_dma_sync, the s->blk object could be null, leading to a null dereference. Add check to avoid it.
--- hw/ide/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ide/core.c +4 -2
@@ -681,8 +681,10 @@ void ide_cancel_dma_sync(IDEState *s)#ifdef DEBUG_IDE printf ("%s: draining all remaining requests" , __func__);#endif -blk_drain (s->blk); -assert (s->bus->dma->aiocb ==NULL ); +if (s->blk) { +blk_drain (s->blk); +assert (s->bus->dma->aiocb ==NULL ); + } } }
Signature · 1 line
2.9.4
Quoted 5 lines · P J P
From: Prasad J Pandit <[email protected]>
When cancelling pending DMA requests in
ide_cancel_dma_sync, thes->blkobject could be null, leading to a null dereference. Add check to avoid it.
Please include details on how to reproduce the bug and/or which code path triggers this NULL dereference.
Quoted 27 lines
Reported-by Chensongnian <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/ide/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ide/core.c +4
-2@@ -681,8 +681,10 @@ void ide_cancel_dma_sync(IDEState *s)#ifdef DEBUG_IDE printf ("%s: draining all remaining requests" , __func__);#endif -blk_drain (s->blk); -assert (s->bus->dma->aiocb ==NULL ); +if (s->blk) { +blk_drain (s->blk); +assert (s->bus->dma->aiocb ==NULL ); + } } }Signature · 1 line
2.9.4
hw/ide/core.c void ide_cancel_dma_sync(IDEState *s) · line 685
Quoted 3 lines · P J P
From: Prasad J Pandit <[email protected]>
hw/ide/core.c +0
-2-blk_drain (s->blk); -assert (s->bus->dma->aiocb ==NULL );
This assert looks weird
Quoted 4 lines
hw/ide/core.c +4
-0+if (s->blk) { +blk_drain (s->blk); +assert (s->bus->dma->aiocb ==NULL ); + }
Quoted 20 lines · P J P
From: Prasad J Pandit <[email protected]>
When cancelling pending DMA requests in
ide_cancel_dma_sync, thes->blkobject could be null, leading to a null dereference. Add check to avoid it.Reported-by Chensongnian <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/ide/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ide/core.c +0
-0@@ -681,8 +681,10 @@ void ide_cancel_dma_sync(IDEState *s)#ifdef DEBUG_IDE printf ("%s: draining all remaining requests" , __func__);
hw/ide/core.c void ide_cancel_dma_sync(IDEState *s) · line 690
Quoted 10 lines
hw/ide/core.c +4
-2#endif -blk_drain (s->blk); -assert (s->bus->dma->aiocb ==NULL ); +if (s->blk) { +blk_drain (s->blk); +assert (s->bus->dma->aiocb ==NULL ); + } } }
I guess this occurs through
ide_exec_cmd
cmd_device_reset
ide_cancel_dma_sync
though if s->blk does not exist, we should usually not be able to address this device with a reset command as such. (core.c:2021) -- but this is only for secondary devices. I guess we don't guard against nonexistent primary devices......?
Further, how do we have s->bus->dma->aiocb if there's no blk device? What DMA request did we accept...?
Can you please submit a stack that illustrates the code path followed so this fix can be properly verified and tested?
Thanks,
--John