Skip to content

Commit bab991c

Browse files
gaurav1086richardweinberger
authored andcommitted
um: Fix null pointer dereference in vector_user_bpf
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>
1 parent ba4f184 commit bab991c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎arch/um/drivers/vector_user.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,12 @@ void *uml_vector_user_bpf(char *filename)
789789
return false;
790790
}
791791
bpf_prog = uml_kmalloc(sizeof(struct sock_fprog), UM_GFP_KERNEL);
792-
if (bpf_prog != NULL) {
793-
bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
794-
bpf_prog->filter = NULL;
792+
if (bpf_prog == NULL) {
793+
printk(KERN_ERR "Failed to allocate bpf prog buffer");
794+
return NULL;
795795
}
796+
bpf_prog->len = statbuf.st_size / sizeof(struct sock_filter);
797+
bpf_prog->filter = NULL;
796798
ffd = os_open_file(filename, of_read(OPENFLAGS()), 0);
797799
if (ffd < 0) {
798800
printk(KERN_ERR "Error %d opening bpf file", -errno);

0 commit comments

Comments
 (0)