• Like Xu's avatar
    KVM: x86/pmu: Fix UBSAN shift-out-of-bounds warning in intel_pmu_refresh() · e61ab2a3
    Like Xu authored
    Since we know vPMU will not work properly when (1) the guest bit_width(s)
    of the [gp|fixed] counters are greater than the host ones, or (2) guest
    requested architectural events exceeds the range supported by the host, so
    we can setup a smaller left shift value and refresh the guest cpuid entry,
    thus fixing the following UBSAN shift-out-of-bounds warning:
    
    shift exponent 197 is too large for 64-bit type 'long long unsigned int'
    
    Call Trace:
     __dump_stack lib/dump_stack.c:79 [inline]
     dump_stack+0x107/0x163 lib/dump_stack.c:120
     ubsan_epilogue+0xb/0x5a lib/ubsan.c:148
     __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x181 lib/ubsan.c:395
     intel_pmu_refresh.cold+0x75/0x99 arch/x86/kvm/vmx/pmu_intel.c:348
     kvm_vcpu_after_set_cpuid+0x65a/0xf80 arch/x86/kvm/cpuid.c:177
     kvm_vcpu_ioctl_set_cpuid2+0x160/0x440 arch/x86/kvm/cpuid.c:308
     kvm_arch_vcpu_ioctl+0x11b6/0x2d70 arch/x86/kvm/x86.c:4709
     kvm_vcpu_ioctl+0x7b9/0xdb0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:3386
     vfs_ioctl fs/ioctl.c:48 [inline]
     __do_sys_ioctl fs/ioctl.c:753 [inline]
     __se_sys_ioctl fs/ioctl.c:739 [inline]
     __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:739
     do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
     entry_SYSCALL_64_after_hwframe+0x44/0xa9
    
    Reported-by: syzbot+ae488dc136a4cc6ba32b@syzkaller.appspotmail.com
    Signed-off-by: default avatarLike Xu <like.xu@linux.intel.com>
    Message-Id: <20210118025800.34620-1-like.xu@linux.intel.com>
    Cc: stable@vger.kernel.org
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    e61ab2a3
pmu_intel.c 12.1 KB