KVM: x86: Fix off-by-one error in kvm_vcpu_ioctl_x86_setup_mce
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.
--- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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;
Signature · 1 line
2.26.2.645.ge9eca65c58-goog
Quoted 27 lines · Jim Mattson
Bank_numis a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater thanKVM_MAX_MCE_BANKS.Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")Signed-off-by Jue Wang <[email protected]>Signed-off-by Jim Mattson <[email protected]>Reviewed-by Peter Shier <[email protected]>--- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/x86.c +1
-2@@ -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?
Quoted 17 lines · Jim Mattson
Bank_numis a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater thanKVM_MAX_MCE_BANKS.Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")Signed-off-by Jue Wang <[email protected]>Signed-off-by Jim Mattson <[email protected]>Reviewed-by Peter Shier <[email protected]>--- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-0
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
-1r = -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
Quoted 18 lines · Jim Mattson
Bank_numis a one-based count of banks, not a zero-based index. It overflows the allocated space only when strictly greater thanKVM_MAX_MCE_BANKS.Fixes a9e38c3e01ad ("KVM: x86: Catch potential overrun in MCE setup")Signed-off-by Jue Wang <[email protected]>Signed-off-by Jim Mattson <[email protected]>Reviewed-by Peter Shier <[email protected]>--- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-0
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