Skip to content

Commit 4651573

Browse files
bonzinikees
authored andcommitted
kvm: whitelist struct kvm_vcpu_arch
On x86, ARM and s390, struct kvm_vcpu_arch has a usercopy region that is read and written by the KVM_GET/SET_CPUID2 ioctls (x86) or KVM_GET/SET_ONE_REG (ARM/s390). Without whitelisting the area, KVM is completely broken on those architectures with usercopy hardening enabled. For now, allow writing to the entire struct on all architectures. The KVM tree will not refine this to an architecture-specific subset of struct kvm_vcpu_arch. Cc: [email protected] Cc: Kees Cook <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Christoffer Dall <[email protected]> Cc: Radim Krčmář <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Acked-by: Christoffer Dall <[email protected]> Acked-by: Marc Zyngier <[email protected]> Acked-by: Christian Borntraeger <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 08626a6 commit 4651573

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

virt/kvm/kvm_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,8 +4029,12 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
40294029
/* A kmem cache lets us meet the alignment requirements of fx_save. */
40304030
if (!vcpu_align)
40314031
vcpu_align = __alignof__(struct kvm_vcpu);
4032-
kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
4033-
SLAB_ACCOUNT, NULL);
4032+
kvm_vcpu_cache =
4033+
kmem_cache_create_usercopy("kvm_vcpu", vcpu_size, vcpu_align,
4034+
SLAB_ACCOUNT,
4035+
offsetof(struct kvm_vcpu, arch),
4036+
sizeof_field(struct kvm_vcpu, arch),
4037+
NULL);
40344038
if (!kvm_vcpu_cache) {
40354039
r = -ENOMEM;
40364040
goto out_free_3;

0 commit comments

Comments
 (0)