From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Oliver Upton <oupton@google.com>
Cc: lkp@intel.com, kbuild-all@lists.01.org,
linux-kernel@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: [kbuild] arch/x86/kvm/x86.c:4988 kvm_arch_tsc_set_attr() warn: check for integer overflow 'offset'
Date: Mon, 10 Oct 2022 17:15:40 +0300 [thread overview]
Message-ID: <202210102159.8nYEC0Hl-lkp@intel.com> (raw)
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 493ffd6605b2d3d4dc7008ab927dba319f36671f
commit: 828ca89628bfcb1b8f27535025f69dd00eb55207 KVM: x86: Expose TSC offset controls to userspace
config: x86_64-randconfig-m001-20221010
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
arch/x86/kvm/x86.c:4988 kvm_arch_tsc_set_attr() warn: check for integer overflow 'offset'
vim +/offset +4988 arch/x86/kvm/x86.c
828ca89628bfcb Oliver Upton 2021-09-16 4962 static int kvm_arch_tsc_set_attr(struct kvm_vcpu *vcpu,
828ca89628bfcb Oliver Upton 2021-09-16 4963 struct kvm_device_attr *attr)
828ca89628bfcb Oliver Upton 2021-09-16 4964 {
828ca89628bfcb Oliver Upton 2021-09-16 4965 u64 __user *uaddr = (u64 __user *)(unsigned long)attr->addr;
828ca89628bfcb Oliver Upton 2021-09-16 4966 struct kvm *kvm = vcpu->kvm;
828ca89628bfcb Oliver Upton 2021-09-16 4967 int r;
828ca89628bfcb Oliver Upton 2021-09-16 4968
828ca89628bfcb Oliver Upton 2021-09-16 4969 if ((u64)(unsigned long)uaddr != attr->addr)
828ca89628bfcb Oliver Upton 2021-09-16 4970 return -EFAULT;
828ca89628bfcb Oliver Upton 2021-09-16 4971
828ca89628bfcb Oliver Upton 2021-09-16 4972 switch (attr->attr) {
828ca89628bfcb Oliver Upton 2021-09-16 4973 case KVM_VCPU_TSC_OFFSET: {
828ca89628bfcb Oliver Upton 2021-09-16 4974 u64 offset, tsc, ns;
828ca89628bfcb Oliver Upton 2021-09-16 4975 unsigned long flags;
828ca89628bfcb Oliver Upton 2021-09-16 4976 bool matched;
828ca89628bfcb Oliver Upton 2021-09-16 4977
828ca89628bfcb Oliver Upton 2021-09-16 4978 r = -EFAULT;
828ca89628bfcb Oliver Upton 2021-09-16 4979 if (get_user(offset, uaddr))
828ca89628bfcb Oliver Upton 2021-09-16 4980 break;
828ca89628bfcb Oliver Upton 2021-09-16 4981
828ca89628bfcb Oliver Upton 2021-09-16 4982 raw_spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags);
828ca89628bfcb Oliver Upton 2021-09-16 4983
828ca89628bfcb Oliver Upton 2021-09-16 4984 matched = (vcpu->arch.virtual_tsc_khz &&
828ca89628bfcb Oliver Upton 2021-09-16 4985 kvm->arch.last_tsc_khz == vcpu->arch.virtual_tsc_khz &&
828ca89628bfcb Oliver Upton 2021-09-16 4986 kvm->arch.last_tsc_offset == offset);
828ca89628bfcb Oliver Upton 2021-09-16 4987
828ca89628bfcb Oliver Upton 2021-09-16 @4988 tsc = kvm_scale_tsc(vcpu, rdtsc(), vcpu->arch.l1_tsc_scaling_ratio) + offset;
Smatch hates obvious user triggerable integer overflows... No checking
on offset.
828ca89628bfcb Oliver Upton 2021-09-16 4989 ns = get_kvmclock_base_ns();
828ca89628bfcb Oliver Upton 2021-09-16 4990
828ca89628bfcb Oliver Upton 2021-09-16 4991 __kvm_synchronize_tsc(vcpu, offset, tsc, ns, matched);
828ca89628bfcb Oliver Upton 2021-09-16 4992 raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags);
828ca89628bfcb Oliver Upton 2021-09-16 4993
828ca89628bfcb Oliver Upton 2021-09-16 4994 r = 0;
828ca89628bfcb Oliver Upton 2021-09-16 4995 break;
828ca89628bfcb Oliver Upton 2021-09-16 4996 }
828ca89628bfcb Oliver Upton 2021-09-16 4997 default:
828ca89628bfcb Oliver Upton 2021-09-16 4998 r = -ENXIO;
828ca89628bfcb Oliver Upton 2021-09-16 4999 }
828ca89628bfcb Oliver Upton 2021-09-16 5000
828ca89628bfcb Oliver Upton 2021-09-16 5001 return r;
828ca89628bfcb Oliver Upton 2021-09-16 5002 }
next reply other threads:[~2022-10-10 14:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 14:15 Dan Carpenter [this message]
2022-10-10 18:39 ` [kbuild] arch/x86/kvm/x86.c:4988 kvm_arch_tsc_set_attr() warn: check for integer overflow 'offset' Sean Christopherson
2022-10-11 13:02 ` Paolo Bonzini
2022-10-12 6:34 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202210102159.8nYEC0Hl-lkp@intel.com \
--to=dan.carpenter@oracle.com \
--cc=kbuild-all@lists.01.org \
--cc=kbuild@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox