Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp630397pxb; Tue, 2 Feb 2021 13:45:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRPkJvlpcrpuRtRXE9+ENyEQLcZoplub9+fFkVaG/qXRi+tTiXdqmvEFo6NaL83s6OKsGC X-Received: by 2002:a17:906:ca0d:: with SMTP id jt13mr47439ejb.170.1612302309885; Tue, 02 Feb 2021 13:45:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612302309; cv=none; d=google.com; s=arc-20160816; b=axOH2E7nxlq7zUx3I5o7Hk8QsL7Amv4T7Mv4p7lDEWeP/H3ATGzYPLnpxwoZEtJysd RL91B7o2d9K4cjMhruNuaGLtCBRG+X+esXsKgu+p3qJmZIXRIAdctBVlhl2G+TBOMk0d Emo5LxC/Whap0uI/+3yfoSu2sJsz2v7k50262X6I1m4xt36QvGXy0rIQnjn/WkHgp48P TWP2nYh1J5dZvqUqAd1LuxWaO8Wl6UPKAXj8+DLfr6Cz4inAI5y1N9xhlNbpt/CGGRGj HUeRWz0tgf6nNVQrAoXidZreCV8xLBPdMhg26O7fzsFYjeGHy5Ni8bYz+zfMHdli0EkC ww6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zAiSxPcGT63da3PbxDyA3ZpGr/gA5a8oSl3h27sPzPA=; b=iGDOCcoekYYO5B/qT1Tmf0D8kzfl8P5WWDoBgZU+gJnsDY5nirUJ6sV2sa1tQHCgtl HiCt4UR9t9CSDlVZGlnzvbyF/uIJE2x5bu0p863fTE+IcPjvasNxt+aqWu2RSyOijRgn 7olBdnROKEoUteAI3wlbUSi5mxdu8BY52LOMYDqaomX1QlLAULKajMEpz+vm9F6Of5MD UM2XZMunN2XjapD++FHB8YPpz4IpmpFbC8yzwQqrGp6mHTXD+5Ss9cW6NAnozS1a1yGV PyygcMx/Gt+4nAOXSFeUT9lfCfkiHUIZrKs24fVQQKZB+7N1mO66bKiYm8kWZgmxnbTo PNGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FYVjNIrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a73si5218edf.23.2021.02.02.13.44.45; Tue, 02 Feb 2021 13:45:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FYVjNIrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233116AbhBBNvk (ORCPT + 99 others); Tue, 2 Feb 2021 08:51:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:37810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232779AbhBBNq3 (ORCPT ); Tue, 2 Feb 2021 08:46:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F2F264E06; Tue, 2 Feb 2021 13:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612273280; bh=ULHNUsBU0TA3UgsHvnQcg6AzzcpI+kkD+CMNNCfAFls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FYVjNIrSrQdxSS7kWk/bphOgtqhAl7zQ7AZloshL4PGK3eRh9i2jcuD2My9Sn32PY w87ozBD3noW+wmnLKSaB3KHTIVK+5oNjSW+orkgMLIdpJufYH5rvkpmWfQH2oT+jRA IE+dRLmJ8/GVu7bJ//r33K192xrNvLo/tCBEIaBg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+ae488dc136a4cc6ba32b@syzkaller.appspotmail.com, Like Xu , Paolo Bonzini Subject: [PATCH 5.10 040/142] KVM: x86/pmu: Fix UBSAN shift-out-of-bounds warning in intel_pmu_refresh() Date: Tue, 2 Feb 2021 14:36:43 +0100 Message-Id: <20210202132959.372325703@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210202132957.692094111@linuxfoundation.org> References: <20210202132957.692094111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu commit e61ab2a320c3dfd6209efe18a575979e07470597 upstream. 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: Like Xu Message-Id: <20210118025800.34620-1-like.xu@linux.intel.com> Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx/pmu_intel.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -345,7 +345,9 @@ static void intel_pmu_refresh(struct kvm pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters, x86_pmu.num_counters_gp); + eax.split.bit_width = min_t(int, eax.split.bit_width, x86_pmu.bit_width_gp); pmu->counter_bitmask[KVM_PMC_GP] = ((u64)1 << eax.split.bit_width) - 1; + eax.split.mask_length = min_t(int, eax.split.mask_length, x86_pmu.events_mask_len); pmu->available_event_types = ~entry->ebx & ((1ull << eax.split.mask_length) - 1); @@ -355,6 +357,8 @@ static void intel_pmu_refresh(struct kvm pmu->nr_arch_fixed_counters = min_t(int, edx.split.num_counters_fixed, x86_pmu.num_counters_fixed); + edx.split.bit_width_fixed = min_t(int, + edx.split.bit_width_fixed, x86_pmu.bit_width_fixed); pmu->counter_bitmask[KVM_PMC_FIXED] = ((u64)1 << edx.split.bit_width_fixed) - 1; }