From: P J P <ppandit@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: Alexander Bulekov <alxndr@bu.edu>,
QEMU Developers <qemu-devel@nongnu.org>,
Stefan Hajnoczi <stefanha@redhat.com>,
Prasad J Pandit <pjp@fedoraproject.org>
Subject: [PATCH 1/2] sd: check bit number before setting card_status flag
Date: Wed, 20 May 2020 20:54:49 +0530 [thread overview]
Message-ID: <20200520152450.200362-2-ppandit@redhat.com> (raw)
In-Reply-To: <20200520152450.200362-1-ppandit@redhat.com>
From: Prasad J Pandit <pjp@fedoraproject.org>
SD card emulator sets 'sd->card_status' while performing block
write commands. While doing so, it tests the corresponding bit
derived from 's->data_start' address. This may lead to OOB access.
Add check to avoid it.
Reported-by: Alex <alxndr@bu.edu>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
hw/sd/sd.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 71a9af09ab..916e9fff58 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -802,7 +802,12 @@ static void sd_function_switch(SDState *sd, uint32_t arg)
static inline bool sd_wp_addr(SDState *sd, uint64_t addr)
{
- return test_bit(sd_addr_to_wpnum(addr), sd->wp_groups);
+ uint64_t bit = sd_addr_to_wpnum(addr);
+
+ if (bit < sd->wpgrps_size) {
+ return test_bit(bit, sd->wp_groups);
+ }
+ return true;
}
static void sd_lock_command(SDState *sd)
--
2.26.2
next prev parent reply other threads:[~2020-05-20 15:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 15:24 [PATCH 0/2] avoid OOB access in SD card emulator P J P
2020-05-20 15:24 ` P J P [this message]
2020-05-20 16:40 ` [PATCH 1/2] sd: check bit number before setting card_status flag Philippe Mathieu-Daudé
2020-05-20 15:24 ` [PATCH 2/2] sd: disable sdhci-pci device by default P J P
2020-05-20 15:39 ` Peter Maydell
2020-05-20 16:33 ` Philippe Mathieu-Daudé
2020-05-21 10:08 ` P J P
2020-05-20 16:38 ` Daniel P. Berrangé
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=20200520152450.200362-2-ppandit@redhat.com \
--to=ppandit@redhat.com \
--cc=alxndr@bu.edu \
--cc=f4bug@amsat.org \
--cc=pjp@fedoraproject.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).