Skip to contentSkip to conversation

ide: check BlockBackend object in ide_cancel_dma_sync

PATCH In review P J P 4 participants 4 messages Jul 14, 2017 – Jul 19, 2017

lore
Share & tools
lore

P J P

author
#0 lore raw

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
index 0b48b64..04474b3 100644
@@ -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
#1 lore raw
Quoted 5 lines · P J P

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.

Please include details on how to reproduce the bug and/or which code path triggers this NULL dereference.

Quoted 27 lines
---
 hw/ide/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ide/core.c +4 -2
index 0b48b64..04474b3 100644
@@ -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
#2 lore raw
In reply to P J P

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);
+        }
#3 lore raw
In reply to P J P
Quoted 20 lines · P J P

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 +0 -0
index 0b48b64..04474b3 100644
@@ -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