Bugfix: TCG cross-page overflow for 32 bit guest
cover Bugfix: TCG cross-page overflow for 32 bit guest
The bug being resolved is that the current code in mmu_lookup() assumes a valid 64-bit address space. If a guest has a 32-bit address space, a page translation that crosses beyond the last page in the address space will overflow out of the allocated guest virtual memory space in the QEMU application and cause it to crash. In this case the first page will be the last of the 32-bit address space (for example 0xFFFFF000 for 4K page sizes) and the second page will overflow to a page beyond the 32-bit address space (0x100000000 in the very same example). An invalid translation will be added to the cpu translation table from the second page. Thought the translation will be for page address 0x100000000, checks in other parts of the codebase actually enforce using only 32 bits, and will match this translation. Part of the stored translation is the effective address, and another part is the addend to be used to offset into the QEMU process's virtual memory space. The addend will incorporate the 0x100000000 and offset into likely invalid virtual address space.
The fix in the diff checks if the target is 32 bits and wraps the second page address to the beginning of the memory space. Along with this we have submitted a test to show this using Pegasos2
Singed off by: Percival Engineering <[email protected]>
[email protected] (2):
Fix: TCG cross-page overflow for 32 bit guest
Added TCG cross-page overflow test
accel/tcg/cputlb.c | 7 +++ tests/functional/meson.build | 1 + tests/functional/test_ppc_pegasos2.py | 69 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100755 tests/functional/test_ppc_pegasos2.py
Signature · 1 line
2.45.3
PATCH 1/2 Fix: TCG cross-page overflow for 32 bit guest
From: [email protected] <[email protected]>
--- accel/tcg/cputlb.c | 7 +++++++ 1 file changed, 7 insertions(+)
accel/tcg/cputlb.c +7 -0
@@ -1767,6 +1767,13 @@ static bool mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi, l->page[1 ].size = l->page[0 ].size - size0; l->page[0 ].size = size0; +/* check for wrapping address space on page crossing if target is 32 bit */ +#if TARGET_LONG_BITS ==32 +if (l->page[1 ].addr >= (1UL <<TARGET_LONG_BITS )) { + l->page[1 ].addr %= (1UL <<TARGET_LONG_BITS ); + } +# endif +/* * Lookup both pages, recognizing exceptions from either. If the * second lookup potentially resized, refresh first CPUTLBEntryFull.
Signature · 1 line
2.45.3
PATCH 2/2 Added TCG cross-page overflow test
In reply to ~percival_fossFrom: [email protected] <[email protected]>
--- tests/functional/meson.build | 1 + tests/functional/test_ppc_pegasos2.py | 69 +++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 tests/functional/test_ppc_pegasos2.py
tests/functional/meson.build +1 -0
@@ -213,6 +213,7 @@ tests_ppc_system_thorough = [ 'ppc_bamboo', 'ppc_mac', 'ppc_mpc8544ds', + 'ppc_pegasos2', 'ppc_replay', 'ppc_sam460ex', 'ppc_tuxrun',
tests/functional/test_ppc_pegasos2.py new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.45.3