KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right
PATCH v2 1/1 KVM: Don't fail KVM_GET_SUPPORTED_CPUID if nent is just right
If we pass just enough entries to KVM_GET_SUPPORTED_CPUID, we would still fail with -E2BIG due to wrong comparisons.
--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/x86.c +1 -1
@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, cpuid->nent); r = -E2BIG ; -if (nent >= cpuid->nent) +if (nent > cpuid->nent) goto out_free; r = -EFAULT ;
Signature · 1 line
1.7.8.rc3
Quoted 15 lines · Sasha Levin
If we pass just enough entries to
KVM_GET_SUPPORTED_CPUID, we would still fail with-E2BIGdue to wrong comparisons.Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, · line 2716
Quoted 8 lines
arch/x86/kvm/x86.c +1
-1@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, cpuid->nent); r = -E2BIG ; -if (nent >= cpuid->nent) +if (nent > cpuid->nent) goto out_free;
This is just a landmine for the next entry to be added there; surely whoever adds it will forget to correct the > back to >=.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 18 lines · Avi Kivity
Quoted 17 lines · Sasha Levin
If we pass just enough entries to
KVM_GET_SUPPORTED_CPUID, we would still fail with-E2BIGdue to wrong comparisons.Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/kvm/x86.c +0
-0@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, cpuid->nent);
Quoted 10 lines
arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
Quoted 6 lines
arch/x86/kvm/x86.c +1
-1r = -E2BIG ; -if (nent >= cpuid->nent) +if (nent > cpuid->nent) goto out_free;This is just a landmine for the next entry to be added there; surely whoever adds it will forget to correct the > back to >=.
Slapping a big warning before that should do the trick? Or maybe add something similar to 'final_nent = nent - 1;'?
Signature · 1 line
Sasha.
Quoted 30 lines · Sasha Levin
Quoted 18 lines · Avi Kivity
Quoted 17 lines · Sasha Levin
If we pass just enough entries to
KVM_GET_SUPPORTED_CPUID, we would still fail with-E2BIGdue to wrong comparisons.Cc Avi Kivity <[email protected]>Cc Marcelo Tosatti <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/x86/kvm/x86.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/kvm/x86.c +0
-0@@ -2710,7 +2710,7 @@ static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, cpuid->nent);Quoted 10 lines
arch/x86/kvm/x86.c static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
Quoted 6 lines
arch/x86/kvm/x86.c +1
-1r = -E2BIG ; -if (nent >= cpuid->nent) +if (nent > cpuid->nent) goto out_free;This is just a landmine for the next entry to be added there; surely whoever adds it will forget to correct the > back to >=.
Quoted 2 lines
Slapping a big warning before that should do the trick? Or maybe add something similar to '
final_nent= nent - 1;'?
Refactor the whole thing so all the repetitive code goes away. Maybe make it table driven.
But after my cpuid.c patch please, I'd hate to redo it.
Signature · 1 line
error compiling committee.c: too many arguments to function