Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1411139 > unrolled thread

[PATCH 5/7] KVM: x86: avoid vmalloc(0) in the KVM_SET_CPUID

Started byPaolo Bonzini <pbonzini@redhat.com>
First post2016-06-01 14:20 +0200
Last post2016-06-05 02:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 5/7] KVM: x86: avoid vmalloc(0) in the KVM_SET_CPUID Paolo Bonzini <pbonzini@redhat.com> - 2016-06-01 14:20 +0200
    Re: [PATCH 5/7] KVM: x86: avoid vmalloc(0) in the KVM_SET_CPUID Wanpeng Li <kernellwp@gmail.com> - 2016-06-05 02:00 +0200

#1411139 — [PATCH 5/7] KVM: x86: avoid vmalloc(0) in the KVM_SET_CPUID

FromPaolo Bonzini <pbonzini@redhat.com>
Date2016-06-01 14:20 +0200
Subject[PATCH 5/7] KVM: x86: avoid vmalloc(0) in the KVM_SET_CPUID
Message-ID<rFdhT-8iE-1@gated-at.bofh.it>
This causes an ugly dmesg splat.  Beautified syzkaller testcase:

    #include <unistd.h>
    #include <sys/syscall.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    #include <linux/kvm.h>

    long r[8];

    int main()
    {
        struct kvm_irq_routing ir = { 0 };
        r[2] = open("/dev/kvm", O_RDWR);
        r[3] = ioctl(r[2], KVM_CREATE_VM, 0);
        r[4] = ioctl(r[3], KVM_SET_GSI_ROUTING, &ir);
        return 0;
    }

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 virt/kvm/kvm_main.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 37af23052470..02e98f3131bd 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2935,7 +2935,7 @@ static long kvm_vm_ioctl(struct file *filp,
 	case KVM_SET_GSI_ROUTING: {
 		struct kvm_irq_routing routing;
 		struct kvm_irq_routing __user *urouting;
-		struct kvm_irq_routing_entry *entries;
+		struct kvm_irq_routing_entry *entries = NULL;
 
 		r = -EFAULT;
 		if (copy_from_user(&routing, argp, sizeof(routing)))
@@ -2945,15 +2945,17 @@ static long kvm_vm_ioctl(struct file *filp,
 			goto out;
 		if (routing.flags)
 			goto out;
-		r = -ENOMEM;
-		entries = vmalloc(routing.nr * sizeof(*entries));
-		if (!entries)
-			goto out;
-		r = -EFAULT;
-		urouting = argp;
-		if (copy_from_user(entries, urouting->entries,
-				   routing.nr * sizeof(*entries)))
-			goto out_free_irq_routing;
+		if (routing.nr) {
+			r = -ENOMEM;
+			entries = vmalloc(routing.nr * sizeof(*entries));
+			if (!entries)
+				goto out;
+			r = -EFAULT;
+			urouting = argp;
+			if (copy_from_user(entries, urouting->entries,
+					   routing.nr * sizeof(*entries)))
+				goto out_free_irq_routing;
+		}
 		r = kvm_set_irq_routing(kvm, entries, routing.nr,
 					routing.flags);
 out_free_irq_routing:
-- 
1.8.3.1

[toc] | [next] | [standalone]


#1413900

FromWanpeng Li <kernellwp@gmail.com>
Date2016-06-05 02:00 +0200
Message-ID<rGtDX-7xl-9@gated-at.bofh.it>
In reply to#1411139
2016-06-01 20:09 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
> This causes an ugly dmesg splat.  Beautified syzkaller testcase:
>
>     #include <unistd.h>
>     #include <sys/syscall.h>
>     #include <sys/ioctl.h>
>     #include <fcntl.h>
>     #include <linux/kvm.h>
>
>     long r[8];
>
>     int main()
>     {
>         struct kvm_irq_routing ir = { 0 };
>         r[2] = open("/dev/kvm", O_RDWR);
>         r[3] = ioctl(r[2], KVM_CREATE_VM, 0);
>         r[4] = ioctl(r[3], KVM_SET_GSI_ROUTING, &ir);
>         return 0;
>     }
>

The patch subject is not correct.

Regards,
Wanpeng Li

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web