ide: ahci: add check to avoid null dereference (CVE-2019-12067)
PATCH 1/1 ide: ahci: add check to avoid null dereference (CVE-2019-12067)
From: Prasad J Pandit <[email protected]>
AHCI emulator while committing DMA buffer in ahci_commit_buf() may do a NULL dereference if the command header 'ad->cur_cmd' is null. Add check to avoid it.
--- hw/ide/ahci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ide/ahci.c +4 -2
@@ -1458,8 +1458,10 @@ static void ahci_commit_buf(IDEDMA *dma, uint32_t tx_bytes) {AHCIDevice *ad =DO_UPCAST (AHCIDevice, dma, dma); - tx_bytes +=le32_to_cpu (ad->cur_cmd->status); - ad->cur_cmd->status =cpu_to_le32 (tx_bytes); +if (ad->cur_cmd) { + tx_bytes +=le32_to_cpu (ad->cur_cmd->status); + ad->cur_cmd->status =cpu_to_le32 (tx_bytes); + } }static int ahci_dma_rw_buf (IDEDMA *dma,int is_write)
Signature · 1 line
2.21.0
Hi Prasad,
Quoted 17 lines · P J P
From: Prasad J Pandit <[email protected]>
AHCI emulator while committing DMA buffer in
ahci_commit_buf()may do a NULL dereference if the command header 'ad->cur_cmd' is null. Add check to avoid it.Reported-by Bugs SysSec <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/ide/ahci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ide/ahci.c +0
-0
hw/ide/ahci.c static void ahci_commit_buf(IDEDMA *dma, uint32_t tx_bytes) · line 1461
Quoted 6 lines
hw/ide/ahci.c +1
-2@@ -1458,8 +1458,10 @@ static void ahci_commit_buf(IDEDMA *dma, uint32_t tx_bytes) {AHCIDevice *ad =DO_UPCAST (AHCIDevice, dma, dma); - tx_bytes +=le32_to_cpu (ad->cur_cmd->status); - ad->cur_cmd->status =cpu_to_le32 (tx_bytes); +if (ad->cur_cmd) {
My 2 cents, John will correct me:
This is not a valid condition, so an assert() might be more appropriate here.
Why is dma_buf_commit() being called with a null command? This check should go elsewhere to avoid the call.
Quoted 7 lines
hw/ide/ahci.c +3
-0+ tx_bytes +=le32_to_cpu (ad->cur_cmd->status); + ad->cur_cmd->status =cpu_to_le32 (tx_bytes); + } }static int ahci_dma_rw_buf (IDEDMA *dma,int is_write)
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Prasad,
Quoted 17 lines · P J P
From: Prasad J Pandit <[email protected]>
AHCI emulator while committing DMA buffer in
ahci_commit_buf()may do a NULL dereference if the command header 'ad->cur_cmd' is null. Add check to avoid it.Reported-by Bugs SysSec <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/ide/ahci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/ide/ahci.c +0
-0hw/ide/ahci.c static void ahci_commit_buf(IDEDMA *dma, uint32_t tx_bytes) · line 1461
Quoted 6 lines
hw/ide/ahci.c +1
-2@@ -1458,8 +1458,10 @@ static void ahci_commit_buf(IDEDMA *dma, uint32_t tx_bytes) {AHCIDevice *ad =DO_UPCAST (AHCIDevice, dma, dma); - tx_bytes +=le32_to_cpu (ad->cur_cmd->status); - ad->cur_cmd->status =cpu_to_le32 (tx_bytes); +if (ad->cur_cmd) {My 2 cents, John will correct me:
Quoted 6 lines
This is not a valid condition, so an
assert()might be more appropriate here.Why is
dma_buf_commit()being called with a null command? This check should go elsewhere to avoid the call.
Yes, something else is broken.
Can you please give a reproducer or more detailed report so I can fix this properly?
This likely is just adding a whole host of new undefined problems waiting to happen by adding an if (...), so while it's not nice to have a host assert() it's probably better than taking the state machine off the rails and seeing what else breaks.
Quoted 7 lines
Quoted 7 lines
hw/ide/ahci.c +3
-0+ tx_bytes +=le32_to_cpu (ad->cur_cmd->status); + ad->cur_cmd->status =cpu_to_le32 (tx_bytes); + } }static int ahci_dma_rw_buf (IDEDMA *dma,int is_write)