[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 55/77] hw/sd/sdcard: Do not switch to ReceivingData if address is
From: |
Michael Roth |
Subject: |
[PATCH 55/77] hw/sd/sdcard: Do not switch to ReceivingData if address is invalid |
Date: |
Thu, 3 Sep 2020 15:59:13 -0500 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
Only move the state machine to ReceivingData if there is no
pending error. This avoids later OOB access while processing
commands queued.
"SD Specifications Part 1 Physical Layer Simplified Spec. v3.01"
4.3.3 Data Read
Read command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR
occurred and no data transfer is performed.
4.3.4 Data Write
Write command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR
occurred and no data transfer is performed.
WP_VIOLATION errors are not modified: the error bit is set, we
stay in receive-data state, wait for a stop command. All further
data transfer is ignored. See the check on sd->card_status at the
beginning of sd_read_data() and sd_write_data().
Fixes: CVE-2020-13253
Cc: qemu-stable@nongnu.org
Reported-by: Alexander Bulekov <alxndr@bu.edu>
Buglink: https://bugs.launchpad.net/qemu/+bug/1880822
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20200630133912.9428-6-f4bug@amsat.org>
(cherry picked from commit 790762e5487114341cccc5bffcec4cb3c022c3cd)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
hw/sd/sd.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index b927f7966d..837fe9053d 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1156,13 +1156,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
SDRequest req)
case 17: /* CMD17: READ_SINGLE_BLOCK */
switch (sd->state) {
case sd_transfer_state:
- sd->state = sd_sendingdata_state;
- sd->data_start = addr;
- sd->data_offset = 0;
- if (sd->data_start + sd->blk_len > sd->size) {
+ if (addr + sd->blk_len > sd->size) {
sd->card_status |= ADDRESS_ERROR;
+ return sd_r1;
}
+
+ sd->state = sd_sendingdata_state;
+ sd->data_start = addr;
+ sd->data_offset = 0;
return sd_r1;
default:
@@ -1173,13 +1175,15 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
SDRequest req)
case 18: /* CMD18: READ_MULTIPLE_BLOCK */
switch (sd->state) {
case sd_transfer_state:
- sd->state = sd_sendingdata_state;
- sd->data_start = addr;
- sd->data_offset = 0;
- if (sd->data_start + sd->blk_len > sd->size) {
+ if (addr + sd->blk_len > sd->size) {
sd->card_status |= ADDRESS_ERROR;
+ return sd_r1;
}
+
+ sd->state = sd_sendingdata_state;
+ sd->data_start = addr;
+ sd->data_offset = 0;
return sd_r1;
default:
@@ -1219,14 +1223,17 @@ 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->blk_len > sd->size) {
+ sd->card_status |= ADDRESS_ERROR;
+ return sd_r1;
+ }
+
sd->state = sd_receivingdata_state;
sd->data_start = addr;
sd->data_offset = 0;
sd->blk_written = 0;
- if (sd->data_start + sd->blk_len > sd->size) {
- sd->card_status |= ADDRESS_ERROR;
- }
if (sd_wp_addr(sd, sd->data_start)) {
sd->card_status |= WP_VIOLATION;
}
@@ -1246,14 +1253,17 @@ 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->blk_len > sd->size) {
+ sd->card_status |= ADDRESS_ERROR;
+ return sd_r1;
+ }
+
sd->state = sd_receivingdata_state;
sd->data_start = addr;
sd->data_offset = 0;
sd->blk_written = 0;
- if (sd->data_start + sd->blk_len > sd->size) {
- sd->card_status |= ADDRESS_ERROR;
- }
if (sd_wp_addr(sd, sd->data_start)) {
sd->card_status |= WP_VIOLATION;
}
--
2.17.1
- [PATCH 50/77] tests/acceptance/boot_linux: Expand SD card image to power of 2, (continued)
- [PATCH 50/77] tests/acceptance/boot_linux: Expand SD card image to power of 2, Michael Roth, 2020/09/03
- [PATCH 47/77] tests/acceptance: allow console interaction with specific VMs, Michael Roth, 2020/09/03
- [PATCH 04/77] 9p: Lock directory streams with a CoMutex, Michael Roth, 2020/09/03
- [PATCH 48/77] tests/acceptance: refactor boot_linux to allow code reuse, Michael Roth, 2020/09/03
- [PATCH 49/77] tests/acceptance: refactor boot_linux_console test to allow code reuse, Michael Roth, 2020/09/03
- [PATCH 52/77] hw/sd/sdcard: Simplify realize() a bit, Michael Roth, 2020/09/03
- [PATCH 51/77] hw/sd/sdcard: Restrict Class 6 commands to SCSD cards, Michael Roth, 2020/09/03
- [PATCH 53/77] hw/sd/sdcard: Do not allow invalid SD card sizes, Michael Roth, 2020/09/03
- [PATCH 54/77] hw/sd/sdcard: Update coding style to make checkpatch.pl happy, Michael Roth, 2020/09/03
- [PATCH 56/77] target/hppa: Free some temps in do_sub, Michael Roth, 2020/09/03
- [PATCH 55/77] hw/sd/sdcard: Do not switch to ReceivingData if address is invalid,
Michael Roth <=
- [PATCH 57/77] tpm: tpm_spapr: Exit on TPM backend failures, Michael Roth, 2020/09/03
- [PATCH 59/77] qdev: Fix device_add DRIVER,help to print to monitor, Michael Roth, 2020/09/03
- [PATCH 62/77] virtio-balloon: always indicate S_DONE when migration fails, Michael Roth, 2020/09/03
- [PATCH 58/77] tests: tpm: Skip over pcrUpdateCounter byte in result comparison, Michael Roth, 2020/09/03
- [PATCH 60/77] virtio-balloon: Prevent guest from starting a report when we didn't request one, Michael Roth, 2020/09/03
- [PATCH 63/77] linux-headers: update against Linux 5.7-rc3, Michael Roth, 2020/09/03
- [PATCH 61/77] virtio-balloon: Add locking to prevent possible race when starting hinting, Michael Roth, 2020/09/03
- [PATCH 71/77] migration/block-dirty-bitmap: fix dirty_bitmap_mig_before_vm_start, Michael Roth, 2020/09/03
- [PATCH 65/77] virtio: list legacy-capable devices, Michael Roth, 2020/09/03
- [PATCH 66/77] virtio: verify that legacy support is not accidentally on, Michael Roth, 2020/09/03