Skip to content

Commit

Permalink
target/loongarch/tcg/tlb_helper: fix ubsan with right shift
Browse files Browse the repository at this point in the history
Found with functional test func-loongarch64-loongarch64_virt.

../target/loongarch/tcg/tlb_helper.c:470:31: runtime error: shift exponent 244 is too large for 64-bit type 'long unsigned int'
    #0 0x560036305470 in helper_invtlb_page_asid_or_g ../target/loongarch/tcg/tlb_helper.c:470

Signed-off-by: Pierrick Bouvier <[email protected]>
  • Loading branch information
pbo-linaro committed Jan 17, 2025
1 parent fe6a26c commit 05f9d3b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions target/loongarch/tcg/tlb_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ void helper_invtlb_page_asid_or_g(CPULoongArchState *env,
tlb_vppn = FIELD_EX64(tlb->tlb_misc, TLB_MISC, VPPN);
vpn = (addr & TARGET_VIRT_MASK) >> (tlb_ps + 1);
compare_shift = tlb_ps + 1 - R_TLB_MISC_VPPN_SHIFT;
compare_shift = MIN(64, compare_shift);

if ((tlb_g || (tlb_asid == asid)) &&
(vpn == (tlb_vppn >> compare_shift))) {
Expand Down

0 comments on commit 05f9d3b

Please sign in to comment.