From ddcc0ab2b4eb301d4e31800736590e4315b1b6b1 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 27 Nov 2019 04:55:13 -0800 Subject: [PATCH] arm: Make sure not to shift off of the end of a uint32_t in KVM. The methods which set or get an attribute from the virtual GIC use a shift constant which is 32, but they store their result in a 32 bit variable and, according to clang, are used to shift 32 bit inputs. This is undefined behavior in terms of the shift, and will truncate off the value regardless. Change-Id: Ie9543ab9e6e1d5f86317a9210d220928b23ffaf8 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23129 Tested-by: kokoro Reviewed-by: Ciro Santilli Maintainer: Giacomo Travaglini --- src/arch/arm/kvm/gic.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arch/arm/kvm/gic.cc b/src/arch/arm/kvm/gic.cc index afb0f076d..12f9db5bc 100644 --- a/src/arch/arm/kvm/gic.cc +++ b/src/arch/arm/kvm/gic.cc @@ -115,8 +115,8 @@ KvmKernelGicV2::getGicReg(unsigned group, unsigned vcpu, unsigned offset) uint64_t reg; assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK); - const uint32_t attr( - (vcpu << KVM_DEV_ARM_VGIC_CPUID_SHIFT) | + const uint64_t attr( + ((uint64_t)vcpu << KVM_DEV_ARM_VGIC_CPUID_SHIFT) | (offset << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)); kdev.getAttrPtr(group, attr, ®); @@ -130,8 +130,8 @@ KvmKernelGicV2::setGicReg(unsigned group, unsigned vcpu, unsigned offset, uint64_t reg = value; assert(vcpu <= KVM_ARM_IRQ_VCPU_MASK); - const uint32_t attr( - (vcpu << KVM_DEV_ARM_VGIC_CPUID_SHIFT) | + const uint64_t attr( + ((uint64_t)vcpu << KVM_DEV_ARM_VGIC_CPUID_SHIFT) | (offset << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)); kdev.setAttrPtr(group, attr, ®); -- 2.30.2