From: Peter Maydell <1911351@bugs.launchpad.net>
To: qemu-devel@nongnu.org
Subject: [Bug 1911351] Re: x86-64 MTTCG Does not update page table entries atomically
Date: Tue, 12 Jan 2021 23:26:08 -0000 [thread overview]
Message-ID: <161049396823.23359.5940862336839190125.malone@soybean.canonical.com> (raw)
In-Reply-To: 161049230444.13717.10732991676985431455.malonedeb@gac.canonical.com
Yeah, it's a long standing API deficiency inside QEMU that we don't have
a way to do atomic modifications in things like page-table-walk code:
mostly you don't notice unless you go looking for it, but we really
ought to fix this. Thanks for the unit test.
** Changed in: qemu
Status: New => Confirmed
--
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1911351
Title:
x86-64 MTTCG Does not update page table entries atomically
Status in QEMU:
Confirmed
Bug description:
It seems like the qemu tcg code for x86-64 doesn't write the access
and dirty flags of the page table entries atomically. Instead, they
first read the entry, see if they need to set the page table entry,
and then overwrite the entry. So if you have two threads running at
the same time, one accessing the virtual address over and over again,
and the other modifying the page table entry, it is possible that
after the second thread modifies the page table entry, qemu overwrites
the value with the old page table entry value, with the access/dirty
flags set.
Here's a unit test that reproduces this behavior:
https://github.com/mvanotti/kvm-unit-
tests/commit/09f9722807271226a714b04f25174776454b19cd
You can run it with:
```
/usr/bin/qemu-system-x86_64 --no-reboot -nodefaults \
-device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 \
-vnc none -serial stdio -device pci-testdev \
-smp 4 -machine q35 --accel tcg,thread=multi \
-kernel x86/mmu-race.flat # -initrd /tmp/tmp.avvPpezMFf
```
Expected output (failure):
```
kvm-unit-tests$ make && /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -smp 4 -machine q35 --accel tcg,thread=multi -kernel x86/mmu-race.flat # -initrd /tmp/tmp.avvPpezMFf
enabling apic
enabling apic
enabling apic
enabling apic
paging enabled
cr0 = 80010011
cr3 = 627000
cr4 = 20
found 4 cpus
PASS: Need more than 1 CPU
Detected overwritten PTE:
want: 0x000000000062e007
got: 0x000000000062d027
FAIL: PTE not overwritten
PASS: All Reads were zero
SUMMARY: 3 tests, 1 unexpected failures
```
This bug has allows user-to-root privilege escalation inside the guest
VM: if the user is able overwrite an entry that belongs to a second-
to-last level page table, and is able to allocate the referenced page,
then the user would be in control of a last-level page table, being
able to map any memory they want. This is not uncommon in situations
where memory is being decomitted.
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1911351/+subscriptions
next prev parent reply other threads:[~2021-01-12 23:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 22:58 [Bug 1911351] [NEW] x86-64 MTTCG Does not update page table entries atomically Marco
2021-01-12 23:26 ` Peter Maydell [this message]
2021-01-13 0:50 ` [Bug 1911351] " Marco
2021-01-29 14:20 ` Philippe Mathieu-Daudé
2021-01-29 14:42 ` Peter Maydell
2021-01-31 9:07 ` Marco
2021-02-02 4:58 ` Venkatesh Srinivas
2021-02-02 9:52 ` Peter Maydell
2021-02-02 9:52 ` Peter Maydell
2021-05-12 11:22 ` Thomas Huth
2021-05-12 18:51 ` Marco
2021-05-12 18:52 ` Marco
2021-05-12 18:52 ` Marco
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=161049396823.23359.5940862336839190125.malone@soybean.canonical.com \
--to=1911351@bugs.launchpad.net \
--cc=qemu-devel@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.