Skip to contentSkip to conversation

Fix null pointer dereference in vector_user_bpf

PATCH In review Gaurav Singh 2 participants 2 messages Jun 14, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 arch/um/drivers/vector_user.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/um/drivers/vector_user.c +5 -3
index c4a0f26b2824..0e6d6717bf73 100644
@@ -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);
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Gaurav Singh

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.

---
  arch/um/drivers/vector_user.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
arch/um/drivers/vector_user.c +0 -2
index c4a0f26b2824..0e6d6717bf73 100644
@@ -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);

arch/um/drivers/vector_user.c void *uml_vector_user_bpf(char *filename) · line 800

Quoted 10 lines
arch/um/drivers/vector_user.c +5 -1
-		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);
Signature · 8 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um