]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86: Copy filter arg outside kvm_vm_ioctl_set_msr_filter()
authorAlexander Graf <graf@amazon.com>
Mon, 17 Oct 2022 18:45:40 +0000 (20:45 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Sat, 22 Oct 2022 09:15:56 +0000 (05:15 -0400)
In the next patch we want to introduce a second caller to
set_msr_filter() which constructs its own filter list on the stack.
Refactor the original function so it takes it as argument instead of
reading it through copy_from_user().

Signed-off-by: Alexander Graf <graf@amazon.com>
Message-Id: <20221017184541.2658-3-graf@amazon.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index 4bd5f8a751de91ffeb666e1be9c5db8ae3b65f36..78f779f0264b9f7c4e9f29d1b8fa5a9d18f4bc06 100644 (file)
@@ -6442,26 +6442,22 @@ static int kvm_add_msr_filter(struct kvm_x86_msr_filter *msr_filter,
        return 0;
 }
 
-static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp)
+static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm,
+                                      struct kvm_msr_filter *filter)
 {
-       struct kvm_msr_filter __user *user_msr_filter = argp;
        struct kvm_x86_msr_filter *new_filter, *old_filter;
-       struct kvm_msr_filter filter;
        bool default_allow;
        bool empty = true;
        int r = 0;
        u32 i;
 
-       if (copy_from_user(&filter, user_msr_filter, sizeof(filter)))
-               return -EFAULT;
-
-       if (filter.flags & ~KVM_MSR_FILTER_DEFAULT_DENY)
+       if (filter->flags & ~KVM_MSR_FILTER_DEFAULT_DENY)
                return -EINVAL;
 
-       for (i = 0; i < ARRAY_SIZE(filter.ranges); i++)
-               empty &= !filter.ranges[i].nmsrs;
+       for (i = 0; i < ARRAY_SIZE(filter->ranges); i++)
+               empty &= !filter->ranges[i].nmsrs;
 
-       default_allow = !(filter.flags & KVM_MSR_FILTER_DEFAULT_DENY);
+       default_allow = !(filter->flags & KVM_MSR_FILTER_DEFAULT_DENY);
        if (empty && !default_allow)
                return -EINVAL;
 
@@ -6469,8 +6465,8 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp)
        if (!new_filter)
                return -ENOMEM;
 
-       for (i = 0; i < ARRAY_SIZE(filter.ranges); i++) {
-               r = kvm_add_msr_filter(new_filter, &filter.ranges[i]);
+       for (i = 0; i < ARRAY_SIZE(filter->ranges); i++) {
+               r = kvm_add_msr_filter(new_filter, &filter->ranges[i]);
                if (r) {
                        kvm_free_msr_filter(new_filter);
                        return r;
@@ -6915,9 +6911,16 @@ set_pit2_out:
        case KVM_SET_PMU_EVENT_FILTER:
                r = kvm_vm_ioctl_set_pmu_event_filter(kvm, argp);
                break;
-       case KVM_X86_SET_MSR_FILTER:
-               r = kvm_vm_ioctl_set_msr_filter(kvm, argp);
+       case KVM_X86_SET_MSR_FILTER: {
+               struct kvm_msr_filter __user *user_msr_filter = argp;
+               struct kvm_msr_filter filter;
+
+               if (copy_from_user(&filter, user_msr_filter, sizeof(filter)))
+                       return -EFAULT;
+
+               r = kvm_vm_ioctl_set_msr_filter(kvm, &filter);
                break;
+       }
        default:
                r = -ENOTTY;
        }