Skip to content

Commit 8b8e57e

Browse files
minipli-osssean-jc
authored andcommitted
KVM: Reject overly excessive IDs in KVM_CREATE_VCPU
If, on a 64 bit system, a vCPU ID is provided that has the upper 32 bits set to a non-zero value, it may get accepted if the truncated to 32 bits integer value is below KVM_MAX_VCPU_IDS and 'max_vcpus'. This feels very wrong and triggered the reporting logic of PaX's SIZE_OVERFLOW plugin. Instead of silently truncating and accepting such values, pass the full value to kvm_vm_ioctl_create_vcpu() and make the existing limit checks return an error. Even if this is a userland ABI breaking change, no sane userland could have ever relied on that behaviour. Reported-by: PaX's SIZE_OVERFLOW plugin running on grsecurity's syzkaller Fixes: 6aa8b73 ("[PATCH] kvm: userspace interface") Cc: Emese Revfy <[email protected]> Cc: PaX Team <[email protected]> Signed-off-by: Mathias Krause <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: tweak comment about INT_MAX assertion] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 5c1f50a commit 8b8e57e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

virt/kvm/kvm_main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4207,12 +4207,21 @@ static void kvm_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
42074207
/*
42084208
* Creates some virtual cpus. Good luck creating more than one.
42094209
*/
4210-
static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
4210+
static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
42114211
{
42124212
int r;
42134213
struct kvm_vcpu *vcpu;
42144214
struct page *page;
42154215

4216+
/*
4217+
* KVM tracks vCPU IDs as 'int', be kind to userspace and reject
4218+
* too-large values instead of silently truncating.
4219+
*
4220+
* Ensure KVM_MAX_VCPU_IDS isn't pushed above INT_MAX without first
4221+
* changing the storage type (at the very least, IDs should be tracked
4222+
* as unsigned ints).
4223+
*/
4224+
BUILD_BUG_ON(KVM_MAX_VCPU_IDS > INT_MAX);
42164225
if (id >= KVM_MAX_VCPU_IDS)
42174226
return -EINVAL;
42184227

0 commit comments

Comments
 (0)