Skip to contentSkip to conversation

target/hppa: Fix possible overflow in TLB size calculation

PATCH In review Helge Deller 2 participants 2 messages Nov 10, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/hppa: Fix possible overflow in TLB size calculation

Coverty found that the shift of TARGET_PAGE_SIZE (32-bit type) might overflow. Fix it by casting TARGET_PAGE_SIZE to a 64-bit type before doing the shift (CID 1523902 and CID 1523908).

target/hppa/mem_helper.c +2 -2
index f100c26290..30f0415d1b 100644
@@ -460,7 +460,7 @@ static void itlbt_pa20(CPUHPPAState *env, target_ulong r1,
     int mask_shift;
 
     mask_shift = 2 * (r1 & 0xf);
-    va_size = TARGET_PAGE_SIZE << mask_shift;
+    va_size = ((uint64_t) TARGET_PAGE_SIZE) << mask_shift;
     va_b &= -va_size;
     va_e = va_b + va_size - 1;
 
@@ -522,7 +522,7 @@ static void ptlb_work(CPUState *cpu, run_on_cpu_data data)
      */
     end = start & 0xf;
     start &= TARGET_PAGE_MASK;
-    end = TARGET_PAGE_SIZE << (2 * end);
+    end = ((vaddr) TARGET_PAGE_SIZE) << (2 * end);
     end = start + end - 1;
 
     hppa_flush_tlb_range(env, start, end);