From: Michael Olbrich <m.olbrich@pengutronix.de>
To: qemu-devel@nongnu.org
Cc: Michael Olbrich <m.olbrich@pengutronix.de>
Subject: [Qemu-devel] [PATCH v2] hw/sd: fix out-of-bounds check for multi block reads
Date: Sat, 16 Sep 2017 12:35:23 +0200 [thread overview]
Message-ID: <20170916103523.1482-1-m.olbrich@pengutronix.de> (raw)
In-Reply-To: <150555367996.36.15771330325496067998@69b6ddf88678>
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.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
Changes in v2:
- fixed warning
I'm not quite sure if 0x00 is the correct return value, but it's used
elsewhere in the same function when an error occurs, so it seems
reasonable.
hw/sd/sd.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index ba47bff4db80..35347a5bbcde 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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) {
@@ -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;
--
2.14.1
next prev parent reply other threads:[~2017-09-16 10:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-16 9:16 [Qemu-devel] [PATCH] hw/sd: fix out-of-bounds check for multi block reads Michael Olbrich
2017-09-16 9:21 ` no-reply
2017-09-16 10:35 ` Michael Olbrich [this message]
2017-09-18 21:28 ` [Qemu-devel] [PATCH v2] " Alistair Francis
2017-09-19 8:23 ` Michael Olbrich
2017-09-20 0:09 ` Alistair Francis
2017-09-20 6:19 ` Michael Olbrich
2017-09-25 19:27 ` Peter Maydell
2017-09-25 21:16 ` Alistair Francis
2017-09-25 22:38 ` Peter Maydell
2017-09-25 22:53 ` Alistair Francis
2017-09-25 23:07 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170916103523.1482-1-m.olbrich@pengutronix.de \
--to=m.olbrich@pengutronix.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).