hw/sd/sdcard: Verify CMD24 (Block Write) address is valid
PATCH 1/1 hw/sd/sdcard: Verify CMD24 (Block Write) address is valid
Avoid OOB access by verifying the requested address belong to the actual card size. Return ADDRESS_ERROR when not in range.
"SD Specifications Part 1 Physical Layer Simplified Spec. v3.01"
4.3.4 Data Write
* Block Write
Write command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed.
---
Cc: Prasad J Pandit <[email protected]>
--- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/sd/sd.c +4 -0
@@ -1211,6 +1211,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Writing in SPI mode not implemented. */ if (sd->spi)break ; +if (addr >= sd->size) { + sd->card_status |=ADDRESS_ERROR ; +return sd_r1; + } sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset =0 ;
Signature · 1 line
2.21.3
Quoted 28 lines · Philippe Mathieu-Daudé
Avoid OOB access by verifying the requested address belong to the actual card size. Return
ADDRESS_ERRORwhen not in range."SD Specifications Part 1 Physical Layer Simplified Spec. v3.01"
4.3.4 Data Write
* Block Write
Write command is rejected if
BLOCK_LEN_ERRORorADDRESS_ERRORoccurred and no data transfer is performed.Fixes CVE-2020-13253Reported-by Alexander Bulekov <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Prasad J Pandit <[email protected]>--- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+)hw/sd/sd.c +0
-0
hw/sd/sd.c static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) · line 1220
Quoted 10 lines
hw/sd/sd.c +4
-0@@ -1211,6 +1211,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Writing in SPI mode not implemented. */ if (sd->spi)break ; +if (addr >= sd->size) { + sd->card_status |=ADDRESS_ERROR ; +return sd_r1; + } sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset =0 ;
I'm not sure if you want me to queue it, but I did. Probably we should add [email protected] to the hw/sd stanza.
Paolo
Quoted 33 lines · Paolo Bonzini
Quoted 32 lines · Philippe Mathieu-Daudé
Avoid OOB access by verifying the requested address belong to the actual card size. Return
ADDRESS_ERRORwhen not in range."SD Specifications Part 1 Physical Layer Simplified Spec. v3.01"
4.3.4 Data Write
* Block Write
Write command is rejected if
BLOCK_LEN_ERRORorADDRESS_ERRORoccurred and no data transfer is performed.Fixes CVE-2020-13253Reported-by Alexander Bulekov <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Prasad J Pandit <[email protected]>--- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+)hw/sd/sd.c +2
-0@@ -1211,6 +1211,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Writing in SPI mode not implemented. */ if (sd->spi)break ; +if (addr >= sd->size) { + sd->card_status |=ADDRESS_ERROR ;
Quoted 8 lines
hw/sd/sd.c static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) · line 1220
Quoted 6 lines
hw/sd/sd.c +2
-0+return sd_r1; + } sd->state = sd_receivingdata_state; sd->data_start = addr; sd->data_offset =0 ;I'm not sure if you want me to queue it, but I did.
Hmm I guess I typed "^RPrasad" in my shell to have the last git-publish command with his email, and I didn't noticed you were also there...
Anyway looking at it again, this patch is wrong because I should check for addr + blksize < sd_size instead. Can you drop it please?
Quoted 2 lines
Probably we should
add [email protected] to the hw/sd stanza.
OK will do.
Quoted 3 lines
Paolo