From: Tao Cui <cui.tao@linux.dev>
To: qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, pbonzini@redhat.com,
cuitao@kylinos.cn, cui.tao@linux.dev
Subject: [PATCH v1 1/2] accel/tcg: fix crash on instruction straddling address-space end
Date: Thu, 9 Jul 2026 10:05:28 +0800 [thread overview]
Message-ID: <20260709020529.126652-2-cui.tao@linux.dev> (raw)
In-Reply-To: <20260709020529.126652-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
translator_ld() reads the bytes of a page-crossing instruction into a
contiguous buffer. When computing the second page address it assumes the
two pages are virtually contiguous (second = page0 + TARGET_PAGE_SIZE)
and asserts that the read pointer pc is on that page.
On targets whose address space is narrower than vaddr (the 32-bit
targets, e.g. i386 or ARM AArch32 Thumb), an instruction at the very end
of the address space wraps the second page back to the start of the
address space. The target advances its fetch PC as a target_ulong, so pc
wraps to 0, while the linear page0 + TARGET_PAGE_SIZE stays at
0x1_0000_0000; the assert fails and QEMU aborts. A guest can trigger this
by mapping the last page executable and running a straddling instruction,
i.e. a guest-triggered host crash (DoS).
Instead of asserting, take the second page from pc: if the linear
page0 + TARGET_PAGE_SIZE does not land on pc's page, use pc's page. This
is correct for both the normal contiguous case and the wraparound case,
without needing to know the address-space width.
Tested with a minimal i386 multiboot payload that executes an instruction
at 0xfffffffe: before this change QEMU aborts (translator.c:296), after it
translates and runs normally.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
accel/tcg/translator.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index cd7d079fe0..750c132bbc 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -283,16 +283,16 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db,
}
/*
- * The read must conclude on the second page and not extend to a third.
- *
- * TODO: We could allow the two pages to be virtually discontiguous,
- * since we already allow the two pages to be physically discontiguous.
- * The only reasonable use case would be executing an insn at the end
- * of the address space wrapping around to the beginning. For that,
- * we would need to know the current width of the address space.
- * In the meantime, assert.
+ * The read must conclude on the second page and must not extend to a
+ * third. An instruction that straddles the end of the address space
+ * wraps the second page back to the start of the address space, so the
+ * linear page0 + TARGET_PAGE_SIZE does not land on pc's page; in that
+ * case take the second page from pc instead of asserting.
*/
base = (base & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
+ if (((base ^ pc) & TARGET_PAGE_MASK) != 0) {
+ base = pc & TARGET_PAGE_MASK;
+ }
assert(((base ^ pc) & TARGET_PAGE_MASK) == 0);
assert(((base ^ last) & TARGET_PAGE_MASK) == 0);
host = db->host_addr[1];
--
2.43.0
next prev parent reply other threads:[~2026-07-09 2:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 2:05 [PATCH v1 0/2] accel/tcg: fix crash on instruction straddling address-space end Tao Cui
2026-07-09 2:05 ` Tao Cui [this message]
2026-07-09 2:05 ` [PATCH v1 2/2] tests/multiboot: add regression test for translator_ld wraparound Tao Cui
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=20260709020529.126652-2-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=cuitao@kylinos.cn \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@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 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.