From: Harshit Mukhedkar <harshit007k@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Bin Meng" <bmeng.cn@gmail.com>,
qemu-block@nongnu.org,
"Harshit Mukhedkar" <harshit007k@gmail.com>,
qemu-stable@nongnu.org
Subject: [PATCH] hw/sd/sd: validate migrated blk_len in post_load
Date: Wed, 21 Oct 2026 01:26:55 +0530 [thread overview]
Message-ID: <20261020195655.135632-1-harshit007k@gmail.com> (raw)
Migration streams are untrusted input. A crafted stream can set
blk_len larger than the 512 byte data[] buffer, so a later block
read passes that length to blk_pread() and overflows data[] on
the host heap.
Reject such state in post_load.
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4725
Reported-by: Karl Mehltretter
Signed-off-by: Harshit Mukhedkar <harshit007k@gmail.com>
---
hw/sd/sd.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index b1b3b1226a..6e7d04e25c 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1073,11 +1073,24 @@ static int sd_vmstate_pre_load(void *opaque)
return 0;
}
+static int sd_vmstate_post_load(void *opaque, int version_id)
+{
+ SDState *sd = opaque;
+
+ /* Check for blk_len that overflows data[] */
+ if (sd->blk_len > sizeof(sd->data)) {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static const VMStateDescription sd_vmstate = {
.name = "sd-card",
.version_id = 2,
.minimum_version_id = 2,
.pre_load = sd_vmstate_pre_load,
+ .post_load = sd_vmstate_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UNUSED(4),
VMSTATE_INT32(state, SDState),
--
2.56.0
reply other threads:[~2026-10-20 21:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261020195655.135632-1-harshit007k@gmail.com \
--to=harshit007k@gmail.com \
--cc=bmeng.cn@gmail.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.