From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, mcb30@ipxe.org
Subject: [PATCH 0/5] target/i386: Fix physical address masking bugs
Date: Fri, 22 Dec 2023 18:59:46 +0100 [thread overview]
Message-ID: <20231222175951.172669-1-pbonzini@redhat.com> (raw)
The address translation logic in get_physical_address() will currently
truncate physical addresses to 32 bits unless long mode is enabled.
This is incorrect when using physical address extensions (PAE) outside
of long mode, with the result that a 32-bit operating system using PAE
to access memory above 4G will experience undefined behaviour.
Instead, truncation must be applied only to non-paging mode, because
all paths that go through page table accesses already produce a
correctly-masked address.
Furthermore, when inspecting the code I noticed that the A20 mask is
applied incorrectly when NPT is active. The mask should not be applied
to the addresses that are looked up in the NPT, only to the physical
addresses. Obviously no hypervisor is going to leave A20 masking on,
but the code actually becomes simpler so let's do it.
Patches 1 and 2 fix cases in which the addresses must be masked,
or overflow is otherwise invalid, for MMU_PHYS_IDX accesses.
Patch 3 fixes the bug, by limiting the masking to the case of CR0.PG=0.
Patches 4 and 5 further clean up the MMU functions to centralize
application of the A20 mask and fix bugs in the process.
Untested except for running the SVM tests from kvm-unit-tests
(which is better than nothing, still).
Supersedes: <0102018c8d11471f-9a6d73eb-0c34-4f61-8d37-5a4418f9e0d7-000000@eu-west-1.amazonses.com>
Paolo Bonzini (5):
target/i386: mask high bits of CR3 in 32-bit mode
target/i386: check validity of VMCB addresses
target/i386: Fix physical address truncation
target/i386: remove unnecessary/wrong application of the A20 mask
target/i386: leave the A20 bit set in the final NPT walk
target/i386/tcg/sysemu/excp_helper.c | 44 ++++++++++++----------------
target/i386/tcg/sysemu/misc_helper.c | 3 ++
target/i386/tcg/sysemu/svm_helper.c | 27 +++++++++++++----
3 files changed, 43 insertions(+), 31 deletions(-)
--
2.43.0
next reply other threads:[~2023-12-22 18:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-22 17:59 Paolo Bonzini [this message]
2023-12-22 17:59 ` [PATCH 1/5] target/i386: mask high bits of CR3 in 32-bit mode Paolo Bonzini
2023-12-25 20:33 ` Richard Henderson
2024-01-18 8:04 ` Michael Tokarev
2024-01-23 11:11 ` Paolo Bonzini
2023-12-22 17:59 ` [PATCH 2/5] target/i386: check validity of VMCB addresses Paolo Bonzini
2023-12-22 17:59 ` [PATCH 3/5] target/i386: Fix physical address truncation Paolo Bonzini
2023-12-23 10:34 ` Michael Brown
2023-12-23 11:47 ` Paolo Bonzini
2023-12-28 16:00 ` Michael Brown
2023-12-22 17:59 ` [PATCH 4/5] target/i386: remove unnecessary/wrong application of the A20 mask Paolo Bonzini
2023-12-22 17:59 ` [PATCH 5/5] target/i386: leave the A20 bit set in the final NPT walk Paolo Bonzini
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=20231222175951.172669-1-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=mcb30@ipxe.org \
--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 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).