Skip to contentSkip to conversation

target/arm: Fix 32-bit address truncation

PATCH Applied Ard Biesheuvel 2 participants 2 messages Jan 19, 2018 – Jan 22, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Fix 32-bit address truncation

Commit ("3b39d734141a target/arm: Handle page table walk load failures correctly") modified both versions of the page table walking code (i.e., arm_ldl_ptw and arm_ldq_ptw) to record the result of the translation in a temporary 'data' variable so that it can be inspected before being returned. However, arm_ldq_ptw() returns an uint64_t, and using a temporary uint32_t variable truncates the upper bits, corrupting the result. This causes problems when using more than 4 GB of memory in a TCG guest. So use a uint64_t instead.

---
 target/arm/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
index 67059033019c..a41b6c3a1b82 100644
@@ -8368,7 +8368,7 @@ static uint64_t arm_ldq_ptw(CPUState *cs, hwaddr addr, bool is_secure,
     MemTxAttrs attrs = {};
     MemTxResult result = MEMTX_OK;
     AddressSpace *as;
-    uint32_t data;
+    uint64_t data;
 
     attrs.secure = is_secure;
     as = arm_addressspace(cs, attrs);
Signature · 1 line
2.11.0
#1 lore raw
Quoted 10 lines · Ard Biesheuvel

Commit ("3b39d734141a target/arm: Handle page table walk load failures correctly") modified both versions of the page table walking code (i.e., arm_ldl_ptw and arm_ldq_ptw) to record the result of the translation in a temporary 'data' variable so that it can be inspected before being returned. However, arm_ldq_ptw() returns an uint64_t, and using a temporary uint32_t variable truncates the upper bits, corrupting the result. This causes problems when using more than 4 GB of memory in a TCG guest. So use a uint64_t instead.

Oops. As you probably guessed, I wrote the 32-bit load function first and then failed to update it correctly when writing the 64-bit version...

Applied to target-arm.next, thanks.

-- PMM