Skip to contentSkip to conversation

KVM: x86: Fix off-by-one error in kvm_vcpu_ioctl_x86_setup_mce

PATCH Applied Jim Mattson 3 participants 4 messages May 11, 2020 – May 15, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Fix off-by-one error in kvm_vcpu_ioctl_x86_setup_mce

Bank_num is a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater than KVM_MAX_MCE_BANKS.

Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -1
index d786c7d27ce5..5bf45c9aa8e5 100644
@@ -3751,7 +3751,7 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu,
 	unsigned bank_num = mcg_cap & 0xff, bank;
 
 	r = -EINVAL;
-	if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS)
+	if (!bank_num || bank_num > KVM_MAX_MCE_BANKS)
 		goto out;
 	if (mcg_cap & ~(kvm_mce_cap_supported | 0xff | 0xff0000))
 		goto out;
Signature · 1 line
2.26.2.645.ge9eca65c58-goog
#1 lore raw
Quoted 27 lines · Jim Mattson

Bank_num is a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater than KVM_MAX_MCE_BANKS.

Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +1 -2
index d786c7d27ce5..5bf45c9aa8e5 100644
@@ -3751,7 +3751,7 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu,
        unsigned bank_num = mcg_cap & 0xff, bank;
 
        r = -EINVAL;
-       if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS)
+       if (!bank_num || bank_num > KVM_MAX_MCE_BANKS)
                goto out;
        if (mcg_cap & ~(kvm_mce_cap_supported | 0xff | 0xff0000))
                goto out;
--
Quoted 2 lines

2.26.2.645.ge9eca65c58-goog

Ping?

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jim Mattson
Quoted 17 lines · Jim Mattson

Bank_num is a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater than KVM_MAX_MCE_BANKS.

Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +0 -0
index d786c7d27ce5..5bf45c9aa8e5 100644

arch/x86/kvm/x86.c static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, · line 3751

Quoted 1 line
arch/x86/kvm/x86.c +0 -0
@@ -3751,7 +3751,7 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu,
 	unsigned bank_num = mcg_cap & 0xff, bank;

/* it would be great to get rid of bare unsigned-s in kvm_vcpu_ioctl_x86_setup_mce/kvm_vcpu_ioctl_x86_set_mce ... */

arch/x86/kvm/x86.c static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, · line 3757

Quoted 7 lines
arch/x86/kvm/x86.c +1 -1
 	r = -EINVAL;
-	if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS)
+	if (!bank_num || bank_num > KVM_MAX_MCE_BANKS)
 		goto out;
 	if (mcg_cap & ~(kvm_mce_cap_supported | 0xff | 0xff0000))
 		goto out;
Signature · 1 line
Vitaly
maintainer Applied
#3 lore raw
In reply to Jim Mattson
Quoted 18 lines · Jim Mattson

Bank_num is a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater than KVM_MAX_MCE_BANKS.

Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.c +0 -0
index d786c7d27ce5..5bf45c9aa8e5 100644

arch/x86/kvm/x86.c static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu, · line 3757

Quoted 8 lines
arch/x86/kvm/x86.c +1 -1
@@ -3751,7 +3751,7 @@ static int kvm_vcpu_ioctl_x86_setup_mce(struct kvm_vcpu *vcpu,
 	unsigned bank_num = mcg_cap & 0xff, bank;
 
 	r = -EINVAL;
-	if (!bank_num || bank_num >= KVM_MAX_MCE_BANKS)
+	if (!bank_num || bank_num > KVM_MAX_MCE_BANKS)
 		goto out;
 	if (mcg_cap & ~(kvm_mce_cap_supported | 0xff | 0xff0000))
 		goto out;

Queued, thanks.

Paolo