From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
qemu-block@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Bin Meng" <bmeng.cn@gmail.com>,
qemu-stable@nongnu.org
Subject: [PATCH-for-9.1? v2 4/4] hw/sd/sdhci: Check ADMA descriptors can be accessed
Date: Wed, 31 Jul 2024 23:25:01 +0200 [thread overview]
Message-ID: <20240731212501.44385-5-philmd@linaro.org> (raw)
In-Reply-To: <20240731212501.44385-1-philmd@linaro.org>
Since malicious guest can write invalid addresses to
the ADMASYSADDR register, we need to check whether the
descriptor could be correctly filled or not.
Cc: qemu-stable@nongnu.org
Fixes: d7dfca0807 ("hw/sdhci: introduce standard SD host controller")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/sdhci.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 2d8fa3151a..6794ee2267 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -701,13 +701,18 @@ static void trace_adma_description(const char *type, const ADMADescr *dscr)
static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
{
hwaddr entry_addr = (hwaddr)s->admasysaddr;
+ MemTxResult res;
+
switch (SDHC_DMA_TYPE(s->hostctl1)) {
case SDHC_CTRL_ADMA2_32:
{
uint64_t adma2 = 0;
- dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2),
- MEMTXATTRS_UNSPECIFIED);
+ res = dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2),
+ MEMTXATTRS_UNSPECIFIED);
+ if (res != MEMTX_OK) {
+ break;
+ }
adma2 = le64_to_cpu(adma2);
/*
* The spec does not specify endianness of descriptor table.
@@ -724,8 +729,11 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
{
uint32_t adma1 = 0;
- dma_memory_read(s->dma_as, entry_addr, &adma1, sizeof(adma1),
- MEMTXATTRS_UNSPECIFIED);
+ res = dma_memory_read(s->dma_as, entry_addr, &adma1, sizeof(adma1),
+ MEMTXATTRS_UNSPECIFIED);
+ if (res != MEMTX_OK) {
+ break;
+ }
adma1 = le32_to_cpu(adma1);
dscr->addr = (hwaddr)(adma1 & ~0xfff);
dscr->attr = (uint8_t)extract32(adma1, 0, 7);
@@ -748,8 +756,11 @@ static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
} QEMU_PACKED adma2;
QEMU_BUILD_BUG_ON(sizeof(adma2) != 12);
- dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2),
- MEMTXATTRS_UNSPECIFIED);
+ res = dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2),
+ MEMTXATTRS_UNSPECIFIED);
+ if (res != MEMTX_OK) {
+ break;
+ }
dscr->length = le16_to_cpu(adma2.length);
dscr->addr = le64_to_cpu(adma2.addr);
dscr->attr = adma2.attr & (uint8_t) ~0xc0;
--
2.45.2
next prev parent reply other threads:[~2024-07-31 21:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 21:24 [PATCH-for-9.1? v2 0/4] hw/sd/sdhci: Check ADMA descriptors can be accessed Philippe Mathieu-Daudé
2024-07-31 21:24 ` [PATCH-for-9.1? v2 1/4] hw/sd/sdhci: Reduce variables scope in sdhci_do_adma() Philippe Mathieu-Daudé
2024-07-31 21:24 ` [PATCH-for-9.1? v2 2/4] hw/sd/sdhci: Reduce variables scope in get_adma_description() Philippe Mathieu-Daudé
2024-07-31 21:25 ` [PATCH-for-9.1? v2 3/4] hw/sd/sdhci: Read ADMA2_64 descriptor with a single dma_memory_read() Philippe Mathieu-Daudé
2024-07-31 21:25 ` Philippe Mathieu-Daudé [this message]
2024-12-20 21:11 ` [PATCH-for-9.1? v2 4/4] hw/sd/sdhci: Check ADMA descriptors can be accessed Michael Tokarev
2024-08-05 18:14 ` [PATCH-for-9.1? v2 0/4] " Philippe Mathieu-Daudé
2025-01-09 12:59 ` Philippe Mathieu-Daudé
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=20240731212501.44385-5-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=bmeng.cn@gmail.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=richard.henderson@linaro.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).