bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] um: Fix some error handling in uml_vector_user_bpf()
@ 2020-01-24 10:14 Dan Carpenter
  2020-01-24 12:52 ` Anton Ivanov
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2020-01-24 10:14 UTC (permalink / raw)
  To: Jeff Dike, Anton Ivanov
  Cc: Richard Weinberger, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	Alex Dewar, linux-um, bpf, kernel-janitors

1) The uml_vector_user_bpf() returns pointers so it should return NULL
   instead of false.
2) If the "bpf_prog" allocation failed, it would have eventually lead to
   a crash.  We can't succeed after the error happens so it should just
   return.

Fixes: 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 arch/um/drivers/vector_user.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/um/drivers/vector_user.c b/arch/um/drivers/vector_user.c
index ddcd917be0af..88483f5b034c 100644
--- a/arch/um/drivers/vector_user.c
+++ b/arch/um/drivers/vector_user.c
@@ -732,13 +732,13 @@ void *uml_vector_user_bpf(char *filename)
 
 	if (stat(filename, &statbuf) < 0) {
 		printk(KERN_ERR "Error %d reading bpf file", -errno);
-		return false;
+		return NULL;
 	}
 	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 (!pfg_prog)
+		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);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-02-10 14:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 10:14 [PATCH] um: Fix some error handling in uml_vector_user_bpf() Dan Carpenter
2020-01-24 12:52 ` Anton Ivanov
2020-01-24 16:44   ` Dan Carpenter
2020-01-24 16:48     ` Anton Ivanov
2020-01-25  6:01       ` Dan Carpenter
2020-01-28 15:10       ` [PATCH] um: Dan Carpenter
2020-01-28 15:27         ` [PATCH v3] um: Fix some error handling in uml_vector_user_bpf() Dan Carpenter
2020-02-10 14:17         ` Anton Ivanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).