Commit 6d4e4c4fca5be806b888d606894d914847e82d78
1 parent
76c35c6e99
Exists in
master
and in
7 other branches
KVM: Disallow fork() and similar games when using a VM
We don't want the meaning of guest userspace changing under our feet. Signed-off-by: Avi Kivity <avi@qumranet.com>
Showing 3 changed files with 11 additions and 0 deletions Side-by-side Diff
drivers/kvm/kvm.h
drivers/kvm/kvm_main.c
... | ... | @@ -165,6 +165,8 @@ |
165 | 165 | if (IS_ERR(kvm)) |
166 | 166 | goto out; |
167 | 167 | |
168 | + kvm->mm = current->mm; | |
169 | + atomic_inc(&kvm->mm->mm_count); | |
168 | 170 | kvm_io_bus_init(&kvm->pio_bus); |
169 | 171 | mutex_init(&kvm->lock); |
170 | 172 | kvm_io_bus_init(&kvm->mmio_bus); |
171 | 173 | |
... | ... | @@ -202,12 +204,15 @@ |
202 | 204 | |
203 | 205 | static void kvm_destroy_vm(struct kvm *kvm) |
204 | 206 | { |
207 | + struct mm_struct *mm = kvm->mm; | |
208 | + | |
205 | 209 | spin_lock(&kvm_lock); |
206 | 210 | list_del(&kvm->vm_list); |
207 | 211 | spin_unlock(&kvm_lock); |
208 | 212 | kvm_io_bus_destroy(&kvm->pio_bus); |
209 | 213 | kvm_io_bus_destroy(&kvm->mmio_bus); |
210 | 214 | kvm_arch_destroy_vm(kvm); |
215 | + mmdrop(mm); | |
211 | 216 | } |
212 | 217 | |
213 | 218 | static int kvm_vm_release(struct inode *inode, struct file *filp) |
... | ... | @@ -818,6 +823,8 @@ |
818 | 823 | void __user *argp = (void __user *)arg; |
819 | 824 | int r; |
820 | 825 | |
826 | + if (vcpu->kvm->mm != current->mm) | |
827 | + return -EIO; | |
821 | 828 | switch (ioctl) { |
822 | 829 | case KVM_RUN: |
823 | 830 | r = -EINVAL; |
... | ... | @@ -976,6 +983,8 @@ |
976 | 983 | void __user *argp = (void __user *)arg; |
977 | 984 | int r; |
978 | 985 | |
986 | + if (kvm->mm != current->mm) | |
987 | + return -EIO; | |
979 | 988 | switch (ioctl) { |
980 | 989 | case KVM_CREATE_VCPU: |
981 | 990 | r = kvm_vm_ioctl_create_vcpu(kvm, arg); |