From 47f6bc4ce1ff70d7ba0924c2f1c218c96cd585fb Mon Sep 17 00:00:00 2001 From: Brett Mastbergen Date: Tue, 9 Jun 2020 17:35:06 -0400 Subject: tools, bpf: Do not force gcc as CC This allows transparent cross-compilation with CROSS_COMPILE by relying on 7ed1c1901fe5 ("tools: fix cross-compile var clobbering"). Same change was applied to tools/bpf/bpftool/Makefile in 9e88b9312acb ("tools: bpftool: do not force gcc as CC"). Signed-off-by: Brett Mastbergen Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20200609213506.3299-1-brett.mastbergen@gmail.com --- tools/bpf/Makefile | 1 - 1 file changed, 1 deletion(-) (limited to 'tools/bpf') diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile index 77472e28c8fd..6df1850f8353 100644 --- a/tools/bpf/Makefile +++ b/tools/bpf/Makefile @@ -3,7 +3,6 @@ include ../scripts/Makefile.include prefix ?= /usr/local -CC = gcc LEX = flex YACC = bison MAKE = make -- cgit v1.2.3 From d4060ac969563113101c79433f2ae005feca1c29 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 10 Jun 2020 15:08:04 +0200 Subject: tools, bpftool: Fix memory leak in codegen error cases Free the memory allocated for the template on error paths in function codegen. Signed-off-by: Tobias Klauser Signed-off-by: Daniel Borkmann Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20200610130804.21423-1-tklauser@distanz.ch --- tools/bpf/bpftool/gen.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools/bpf') diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index a3c4bb86c05a..ecbae47e66b8 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -224,6 +224,7 @@ static int codegen(const char *template, ...) } else { p_err("unrecognized character at pos %td in template '%s'", src - template - 1, template); + free(s); return -EINVAL; } } @@ -234,6 +235,7 @@ static int codegen(const char *template, ...) if (*src != '\t') { p_err("not enough tabs at pos %td in template '%s'", src - template - 1, template); + free(s); return -EINVAL; } } -- cgit v1.2.3 From 2c4779eff837f1035f6f9650d246905daadd9528 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 11 Jun 2020 12:33:41 +0200 Subject: tools, bpftool: Exit on error in function codegen Currently, the codegen function might fail and return an error. But its callers continue without checking its return value. Since codegen can fail only in the unlikely case of the system running out of memory or the static template being malformed, just exit(-1) directly from codegen and make it void-returning. Suggested-by: Andrii Nakryiko Signed-off-by: Tobias Klauser Signed-off-by: Daniel Borkmann Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20200611103341.21532-1-tklauser@distanz.ch --- tools/bpf/bpftool/gen.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tools/bpf') diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index ecbae47e66b8..7443879e87af 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -200,7 +200,7 @@ out: return err; } -static int codegen(const char *template, ...) +static void codegen(const char *template, ...) { const char *src, *end; int skip_tabs = 0, n; @@ -211,7 +211,7 @@ static int codegen(const char *template, ...) n = strlen(template); s = malloc(n + 1); if (!s) - return -ENOMEM; + exit(-1); src = template; dst = s; @@ -225,7 +225,7 @@ static int codegen(const char *template, ...) p_err("unrecognized character at pos %td in template '%s'", src - template - 1, template); free(s); - return -EINVAL; + exit(-1); } } @@ -236,7 +236,7 @@ static int codegen(const char *template, ...) p_err("not enough tabs at pos %td in template '%s'", src - template - 1, template); free(s); - return -EINVAL; + exit(-1); } } /* trim trailing whitespace */ @@ -257,7 +257,8 @@ static int codegen(const char *template, ...) va_end(args); free(s); - return n; + if (n) + exit(-1); } static int do_skeleton(int argc, char **argv) -- cgit v1.2.3 From 22eb78792e07a4dfb63c85f34950d4e58eb90326 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Fri, 12 Jun 2020 13:16:03 -0700 Subject: tools/bpftool: Fix skeleton codegen Remove unnecessary check at the end of codegen() routine which makes codegen() to always fail and exit bpftool with error code. Positive value of variable n is not an indicator of a failure. Fixes: 2c4779eff837 ("tools, bpftool: Exit on error in function codegen") Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Reviewed-by: Tobias Klauser Link: https://lore.kernel.org/bpf/20200612201603.680852-1-andriin@fb.com --- tools/bpf/bpftool/gen.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools/bpf') diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index 7443879e87af..10de76b296ba 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -257,8 +257,6 @@ static void codegen(const char *template, ...) va_end(args); free(s); - if (n) - exit(-1); } static int do_skeleton(int argc, char **argv) -- cgit v1.2.3