target-ppc: fix left shift overflow in hpte_page_shift
PATCH 1/1 target-ppc: fix left shift overflow in hpte_page_shift
ps->pte_enc is a 32-bit value, which is shifted left and then compared to a 64-bit value. It needs a cast before the shift.
Reported by Coverity.
Signed-off-by Paolo Bonzini <[email protected]>
--- target-ppc/mmu-hash64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-ppc/mmu-hash64.c +1 -1
@@ -479,7 +479,7 @@ static unsigned hpte_page_shift(const struct ppc_one_seg_page_size *sps, mask = ((1ULL << ps->page_shift) -1 ) &HPTE64_R_RPN ; -if ((pte1 & mask) == (ps->pte_enc <<HPTE64_R_RPN_SHIFT )) { +if ((pte1 & mask) == ((uint64_t )ps->pte_enc <<HPTE64_R_RPN_SHIFT )) {return ps->page_shift; } }
Signature · 1 line
2.7.4
David Gibson
AppliedQuoted 6 lines · Paolo Bonzini
ps->pte_encis a 32-bit value, which is shifted left and then compared to a 64-bit value. It needs a cast before the shift.Reported by Coverity.
Signed-off-by Paolo Bonzini <[email protected]>
Applied to ppc-for-2.7, thanks.
Quoted 17 lines
--- target-ppc/mmu-hash64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-ppc/mmu-hash64.c +1
-1@@ -479,7 +479,7 @@ static unsigned hpte_page_shift(const struct ppc_one_seg_page_size *sps, mask = ((1ULL << ps->page_shift) -1 ) &HPTE64_R_RPN ; -if ((pte1 & mask) == (ps->pte_enc <<HPTE64_R_RPN_SHIFT )) { +if ((pte1 & mask) == ((uint64_t )ps->pte_enc <<HPTE64_R_RPN_SHIFT )) {return ps->page_shift; } }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson