um: Fix null pointer dereference in vector_user_bpf
authorGaurav Singh <gaurav1086@gmail.com>
Sun, 14 Jun 2020 01:19:40 +0000 (21:19 -0400)
committerRichard Weinberger <richard@nod.at>
Sun, 11 Oct 2020 21:12:51 +0000 (23:12 +0200)
The bpf_prog is being checked for !NULL after uml_kmalloc
but later its used directly for example:
bpf_prog->filter = bpf and is also later returned upon
success. Fix this, do a NULL check and return right away.

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
arch/um/drivers/vector_user.c

index c4a0f26..0e6d671 100644 (file)
@@ -789,10 +789,12 @@ void *uml_vector_user_bpf(char *filename)
                return false;
        }
        bpf_prog = uml_kmalloc(sizeof(struct sock_fprog), UM_GFP_KERNEL);
-       if (bpf_prog != NULL) {
-               bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
-               bpf_prog->filter = NULL;
+       if (bpf_prog == NULL) {
+               printk(KERN_ERR "Failed to allocate bpf prog buffer");
+               return NULL;
        }
+       bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
+       bpf_prog->filter = NULL;
        ffd = os_open_file(filename, of_read(OPENFLAGS()), 0);
        if (ffd < 0) {
                printk(KERN_ERR "Error %d opening bpf file", -errno);