lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 31 Mar 2021 17:15:22 +0800
From:   Yang Li <yang.lee@...ux.alibaba.com>
To:     pbonzini@...hat.com
Cc:     seanjc@...gle.com, vkuznets@...hat.com, wanpengli@...cent.com,
        jmattson@...gle.com, joro@...tes.org, tglx@...utronix.de,
        mingo@...hat.com, bp@...en8.de, x86@...nel.org, hpa@...or.com,
        kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
        Yang Li <yang.lee@...ux.alibaba.com>
Subject: [PATCH] KVM: x86: Fix potential memory access error

Using __set_bit() to set a bit in an integer is not a good idea, since
the function expects an unsigned long as argument, which can be 64bit wide.
Coverity reports this problem as

High:Out-of-bounds access(INCOMPATIBLE_CAST)
CWE119: Out-of-bounds access to a scalar
Pointer "&vcpu->arch.regs_avail" points to an object whose effective
type is "unsigned int" (32 bits, unsigned) but is dereferenced as a
wider "unsigned long" (64 bits, unsigned). This may lead to memory
corruption.

/home/heyuan.shy/git-repo/linux/arch/x86/kvm/kvm_cache_regs.h:
kvm_register_is_available

Just use BIT instead.

Reported-by: Abaci Robot <abaci@...ux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@...ux.alibaba.com>
---
 arch/x86/kvm/kvm_cache_regs.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h
index 2e11da2..cfa45d88 100644
--- a/arch/x86/kvm/kvm_cache_regs.h
+++ b/arch/x86/kvm/kvm_cache_regs.h
@@ -52,14 +52,14 @@ static inline bool kvm_register_is_dirty(struct kvm_vcpu *vcpu,
 static inline void kvm_register_mark_available(struct kvm_vcpu *vcpu,
 					       enum kvm_reg reg)
 {
-	__set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
+	vcpu->arch.regs_avail |= BIT(reg);
 }
 
 static inline void kvm_register_mark_dirty(struct kvm_vcpu *vcpu,
 					   enum kvm_reg reg)
 {
-	__set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
-	__set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
+	vcpu->arch.regs_avail |= BIT(reg);
+	vcpu->arch.regs_dirty |= BIT(reg);
 }
 
 static inline unsigned long kvm_register_read(struct kvm_vcpu *vcpu, int reg)
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ