From: Paolo Bonzini Date: Tue, 22 Dec 2020 10:20:43 +0000 (-0500) Subject: KVM: x86: fix shift out of bounds reported by UBSAN X-Git-Tag: v4.14.215~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=35c84ee5287715c617093b725bc1d3cef9bf1847;p=users%2Fdwmw2%2Flinux.git KVM: x86: fix shift out of bounds reported by UBSAN commit 2f80d502d627f30257ba7e3655e71c373b7d1a5a upstream. Since we know that e >= s, we can reassociate the left shift, changing the shifted number from 1 to 2 in exchange for decreasing the right hand side by 1. Reported-by: syzbot+e87846c48bf72bc85311@syzkaller.appspotmail.com Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 816a626b62508..e76f5963aa7d0 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -53,7 +53,7 @@ static inline u64 rsvd_bits(int s, int e) if (e < s) return 0; - return ((1ULL << (e - s + 1)) - 1) << s; + return ((2ULL << (e - s)) - 1) << s; } void kvm_mmu_set_mmio_spte_mask(u64 mmio_mask, u64 mmio_value);