Skip to content

Commit

Permalink
hw/sd: fix out-of-bounds check for multi block reads
Browse files Browse the repository at this point in the history
The current code checks if the next block exceeds the size of the card.
This generates an error while reading the last block of the card.
Do the out-of-bounds check when starting to read a new block to fix this.

This issue became visible with increased error checking in Linux 4.13.

Cc: qemu-stable@nongnu.org
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Message-id: 20170916091611.10241-1-m.olbrich@pengutronix.de
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
michaelolbrich authored and pm215 committed Oct 6, 2017
1 parent 77077a8 commit 8573378
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hw/sd/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1797,8 +1797,13 @@ uint8_t sd_read_data(SDState *sd)
break;

case 18: /* CMD18: READ_MULTIPLE_BLOCK */
if (sd->data_offset == 0)
if (sd->data_offset == 0) {
if (sd->data_start + io_len > sd->size) {
sd->card_status |= ADDRESS_ERROR;
return 0x00;
}
BLK_READ_BLOCK(sd->data_start, io_len);
}
ret = sd->data[sd->data_offset ++];

if (sd->data_offset >= io_len) {
Expand All @@ -1812,11 +1817,6 @@ uint8_t sd_read_data(SDState *sd)
break;
}
}

if (sd->data_start + io_len > sd->size) {
sd->card_status |= ADDRESS_ERROR;
break;
}
}
break;

Expand Down

0 comments on commit 8573378

Please sign in to comment.