Skip to contentSkip to conversation

tools/bpftool: ignore build products

PATCH Superseded Taeung Song 2 participants 4 messages Jul 18, 2018 – Jul 19, 2018

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tools/bpftool: ignore build products

For untracked things of tools/bpf, add this.

---
 tools/bpf/.gitignore | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 tools/bpf/.gitignore
tools/bpf/.gitignore new file +5 -0
new file mode 100644
index 000000000000..dfe2bd5a4b95
@@ -0,0 +1,5 @@
+FEATURE-DUMP.bpf
+bpf_asm
+bpf_dbg
+bpf_exp.yacc.*
+bpf_jit_disasm
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 tools/bpftool: Fix segfault case regarding 'pin' arguments

Arguments of 'pin' subcommand should be checked at the very beginning of do_pin_any(). Otherwise segfault errors can occur when using 'map pin' or 'prog pin' commands, so fix it.

  # bpftool prog pin id
  Segmentation fault
Fixes 71bb428fe2c1 ("tools: bpf: add bpftool")
Cc Jakub Kicinski <[email protected]>
---
 tools/bpf/bpftool/common.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/bpf/bpftool/common.c +8 -3
index 32f9e397a6c0..b1e1ba9e1c90 100644
@@ -217,6 +217,14 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
 	int err;
 	int fd;
 
+	if (argc < 3) {
+		p_err("too few arguments, id PROG_ID and FILE path is required");
+		return -1;
+	} else if (argc > 3) {
+		p_err("too many arguments");
+		return -1;
+	}
+
 	if (!is_prefix(*argv, "id")) {
 		p_err("expected 'id' got %s", *argv);
 		return -1;
@@ -230,9 +238,6 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
 	}
 	NEXT_ARG();
 
-	if (argc != 1)
-		usage();
-
 	fd = get_fd_by_id(id);
 	if (fd < 0) {
 		p_err("can't get prog by id (%u): %s", id, strerror(errno));
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 2/2] tools/bpftool: Fix segfault case regarding 'pin' arguments

Quoted 21 lines · Taeung Song

Arguments of 'pin' subcommand should be checked at the very beginning of do_pin_any(). Otherwise segfault errors can occur when using 'map pin' or 'prog pin' commands, so fix it.

  # bpftool prog pin id
  Segmentation fault
Fixes 71bb428fe2c1 ("tools: bpf: add bpftool")
Cc Jakub Kicinski <[email protected]>
---
 tools/bpf/bpftool/common.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/bpf/bpftool/common.c +0 -0
index 32f9e397a6c0..b1e1ba9e1c90 100644

tools/bpf/bpftool/common.c int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32)) · line 221

Quoted 5 lines
tools/bpf/bpftool/common.c +2 -0
@@ -217,6 +217,14 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
 	int err;
 	int fd;
 
+	if (argc < 3) {
+		p_err("too few arguments, id PROG_ID and FILE path is required");

Thanks for the fix! You can't say PROG_ID here, because this function is also called by bpftool map pin id X. How about s/PROG_ID/ID/ ?

Quoted 19 lines
tools/bpf/bpftool/common.c +6 -3
+		return -1;
+	} else if (argc > 3) {
+		p_err("too many arguments");
+		return -1;
+	}
+
 	if (!is_prefix(*argv, "id")) {
 		p_err("expected 'id' got %s", *argv);
 		return -1;
@@ -230,9 +238,6 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
 	}
 	NEXT_ARG();
 
-	if (argc != 1)
-		usage();
-
 	fd = get_fd_by_id(id);
 	if (fd < 0) {
 		p_err("can't get prog by id (%u): %s", id, strerror(errno));
#3 lore raw

Re: [PATCH 2/2] tools/bpftool: Fix segfault case regarding 'pin' arguments

Quoted 25 lines · Jakub Kicinski
Quoted 24 lines · Taeung Song

Arguments of 'pin' subcommand should be checked at the very beginning of do_pin_any(). Otherwise segfault errors can occur when using 'map pin' or 'prog pin' commands, so fix it.

   # bpftool prog pin id
   Segmentation fault
Fixes 71bb428fe2c1 ("tools: bpf: add bpftool")
Cc Jakub Kicinski <[email protected]>
---
  tools/bpf/bpftool/common.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
tools/bpf/bpftool/common.c +0 -0
index 32f9e397a6c0..b1e1ba9e1c90 100644
@@ -217,6 +217,14 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
  	int err;
  	int fd;
 
Quoted 6 lines

tools/bpf/bpftool/common.c int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32)) · line 221

Quoted 2 lines
tools/bpf/bpftool/common.c +2 -0
+	if (argc < 3) {
+		p_err("too few arguments, id PROG_ID and FILE path is required");

Thanks for the fix! You can't say PROG_ID here, because this function is also called by bpftool map pin id X. How about s/PROG_ID/ID/ ?

Yep! will fix it :)

--
Thanks,
Taeung

Quoted 20 lines
Quoted 19 lines
tools/bpf/bpftool/common.c +6 -3
+		return -1;
+	} else if (argc > 3) {
+		p_err("too many arguments");
+		return -1;
+	}
+
  	if (!is_prefix(*argv, "id")) {
  		p_err("expected 'id' got %s", *argv);
  		return -1;
@@ -230,9 +238,6 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
  	}
  	NEXT_ARG();
 
-	if (argc != 1)
-		usage();
-
  	fd = get_fd_by_id(id);
  	if (fd < 0) {
  		p_err("can't get prog by id (%u): %s", id, strerror(errno));