Skip to contentSkip to conversation

ide: ahci: reset ncq object to unused on error

PATCH Applied P J P 3 participants 7 messages Jan 8, 2016 – Jan 11, 2016

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v2 1/1 ide: ahci: reset ncq object to unused on error

From: Prasad J Pandit <[email protected]>

When processing NCQ commands, ACHI device emulation prepares a NCQ transfer object; To which an aio control block(aiocb) object is assigned in 'execute_ncq_command'. In case, when the NCQ command is invalid, the 'aiocb' object is not assigned, and NCQ transfer object is left as 'used'. This leads to a use after free kind of error in 'bdrv_aio_cancel_async' via 'ahci_reset_port'. Reset NCQ transfer object to 'unused' to avoid it.

---
 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)

Update as per review in
-> https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg01175.html

hw/ide/ahci.c +1 -0
index dd1912e..17f1cbd 100644
@@ -910,6 +910,7 @@ static void ncq_err(NCQTransferState *ncq_tfs)
     ide_state->error = ABRT_ERR;
     ide_state->status = READY_STAT | ERR_STAT;
     ncq_tfs->drive->port_regs.scr_err |= (1 << ncq_tfs->tag);
+    ncq_tfs->used = 0;
 }
 
 static void ncq_finish(NCQTransferState *ncq_tfs)
Signature · 1 line
2.4.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 25 lines · P J P

From: Prasad J Pandit <[email protected]>

When processing NCQ commands, ACHI device emulation prepares a NCQ transfer object; To which an aio control block(aiocb) object is assigned in 'execute_ncq_command'. In case, when the NCQ command is invalid, the 'aiocb' object is not assigned, and NCQ transfer object is left as 'used'. This leads to a use after free kind of error in 'bdrv_aio_cancel_async' via 'ahci_reset_port'. Reset NCQ transfer object to 'unused' to avoid it.

---
 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)

Update as per review in
-> https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg01175.html

hw/ide/ahci.c +0 -0
index dd1912e..17f1cbd 100644

hw/ide/ahci.c static void ncq_err(NCQTransferState *ncq_tfs) · line 916

Quoted 7 lines
hw/ide/ahci.c +1 -0
@@ -910,6 +910,7 @@ static void ncq_err(NCQTransferState *ncq_tfs)
     ide_state->error = ABRT_ERR;
     ide_state->status = READY_STAT | ERR_STAT;
     ncq_tfs->drive->port_regs.scr_err |= (1 << ncq_tfs->tag);
+    ncq_tfs->used = 0;
 }
 
 static void ncq_finish(NCQTransferState *ncq_tfs)
Applied
#2 lore raw
In reply to P J P
Quoted 25 lines · P J P

From: Prasad J Pandit <[email protected]>

When processing NCQ commands, ACHI device emulation prepares a NCQ transfer object; To which an aio control block(aiocb) object is assigned in 'execute_ncq_command'. In case, when the NCQ command is invalid, the 'aiocb' object is not assigned, and NCQ transfer object is left as 'used'. This leads to a use after free kind of error in 'bdrv_aio_cancel_async' via 'ahci_reset_port'. Reset NCQ transfer object to 'unused' to avoid it.

---
 hw/ide/ahci.c | 1 +
 1 file changed, 1 insertion(+)

Update as per review in
-> https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg01175.html

hw/ide/ahci.c +0 -0
index dd1912e..17f1cbd 100644

hw/ide/ahci.c static void ncq_err(NCQTransferState *ncq_tfs) · line 916

Quoted 7 lines
hw/ide/ahci.c +1 -0
@@ -910,6 +910,7 @@ static void ncq_err(NCQTransferState *ncq_tfs)
     ide_state->error = ABRT_ERR;
     ide_state->status = READY_STAT | ERR_STAT;
     ncq_tfs->drive->port_regs.scr_err |= (1 << ncq_tfs->tag);
+    ncq_tfs->used = 0;
 }
 
 static void ncq_finish(NCQTransferState *ncq_tfs)

Thanks, applied to my IDE tree:

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

--js

author
#3 lore raw
+-- On Fri, 8 Jan 2016, John Snow wrote --+
| >      ide_state->status = READY_STAT | ERR_STAT;
| >      ncq_tfs->drive->port_regs.scr_err |= (1 << ncq_tfs->tag);
| > +    ncq_tfs->used = 0;
| >  }
| 
| Thanks, applied to my IDE tree:
| 
| https://github.com/jnsnow/qemu/commits/ide
| https://github.com/jnsnow/qemu.git

Great! Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#4 lore raw
In reply to P J P

Am 08.01.2016 um 20:48 hat P J P geschrieben:

Quoted 3 lines

From: Prasad J Pandit <[email protected]>

When processing NCQ commands, ACHI device emulation prepares a

s/ACHI/AHCI/

Can you still fix this in your tree, John?

Kevin

Quoted 9 lines

NCQ transfer object; To which an aio control block(aiocb) object is assigned in 'execute_ncq_command'. In case, when the NCQ command is invalid, the 'aiocb' object is not assigned, and NCQ transfer object is left as 'used'. This leads to a use after free kind of error in 'bdrv_aio_cancel_async' via 'ahci_reset_port'. Reset NCQ transfer object to 'unused' to avoid it.

#5 lore raw
Quoted 11 lines · Kevin Wolf

Am 08.01.2016 um 20:48 hat P J P geschrieben:

Quoted 3 lines

From: Prasad J Pandit <[email protected]>

When processing NCQ commands, ACHI device emulation prepares a

s/ACHI/AHCI/

Can you still fix this in your tree, John?

Kevin

Yes, thanks.

Quoted 10 lines
Quoted 9 lines

NCQ transfer object; To which an aio control block(aiocb) object is assigned in 'execute_ncq_command'. In case, when the NCQ command is invalid, the 'aiocb' object is not assigned, and NCQ transfer object is left as 'used'. This leads to a use after free kind of error in 'bdrv_aio_cancel_async' via 'ahci_reset_port'. Reset NCQ transfer object to 'unused' to avoid it.

author
#6 lore raw
+-- On Mon, 11 Jan 2016, John Snow wrote --+
| On 01/11/2016 10:00 AM, Kevin Wolf wrote:
| >> When processing NCQ commands, ACHI device emulation prepares a
| > 
| > s/ACHI/AHCI/

Ah, sorry.:(

| > Can you still fix this in your tree, John?
| Yes, thanks.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F