Skip to contentSkip to conversation

tools: bpftool: Add missing close before bpftool net attach exit

PATCH Superseded Wang Hai 4 participants 5 messages Nov 9, 2020 – Nov 10, 2020

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Wang Hai

author
#0 lore raw

PATCH 1/1 tools: bpftool: Add missing close before bpftool net attach exit

progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.

Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
---
 tools/bpf/bpftool/net.c | 2 ++
 1 file changed, 2 insertions(+)
tools/bpf/bpftool/net.c +2 -0
index 910e7bac6e9e..3e9b40e64fb0 100644
@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
 	if (err < 0) {
 		p_err("interface %s attach failed: %s",
 		      attach_type_strings[attach_type], strerror(-err));
+		close(progfd);
 		return err;
 	}
 
 	if (json_output)
 		jsonw_null(json_wtr);
 
+	close(progfd);
 	return 0;
 }
 
Signature · 1 line
2.17.1
#2 lore raw
In reply to Wang Hai
Quoted 18 lines · Wang Hai

progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.

Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
---
  tools/bpf/bpftool/net.c | 2 ++
  1 file changed, 2 insertions(+)
tools/bpf/bpftool/net.c +1 -0
index 910e7bac6e9e..3e9b40e64fb0 100644
@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
  	if (err < 0) {
  		p_err("interface %s attach failed: %s",
  		      attach_type_strings[attach_type], strerror(-err));
+		close(progfd);

tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 613

Quoted 10 lines
tools/bpf/bpftool/net.c +1 -0
  		return err;
  	}
 
  	if (json_output)
  		jsonw_null(json_wtr);
 
+	close(progfd);
  	return 0;
  }
 

Nit - wouldn't it be better to create a cleanup/out section before return and use goto, to avoid copying the close call?

#3 lore raw
Quoted 25 lines · Michal Rostecki
Quoted 24 lines · Wang Hai

progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.

Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
---
  tools/bpf/bpftool/net.c | 2 ++
  1 file changed, 2 insertions(+)
tools/bpf/bpftool/net.c +1 -0
index 910e7bac6e9e..3e9b40e64fb0 100644
@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
  	if (err < 0) {
  		p_err("interface %s attach failed: %s",
  		      attach_type_strings[attach_type], strerror(-err));
+		close(progfd);
  		return err;
  	}
 
  	if (json_output)
  		jsonw_null(json_wtr);
 
Quoted 7 lines

tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 613

Quoted 4 lines
tools/bpf/bpftool/net.c +1 -0
+	close(progfd);
  	return 0;
  }
 

Nit - wouldn't it be better to create a cleanup/out section before return and use goto, to avoid copying the close call?

I agree would be nicer.

#4 lore raw
In reply to Michal Rostecki
Quoted 21 lines · Michal Rostecki
Quoted 20 lines · Wang Hai

progfd is created by prog_parse_fd(), before 'bpftool net attach' exit, it should be closed.

Fixes 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")

---
  tools/bpf/bpftool/net.c | 2 ++

  1 file changed, 2 insertions(+)
tools/bpf/bpftool/net.c +1 -0
index 910e7bac6e9e..3e9b40e64fb0 100644
@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
       if (err < 0) {
           p_err("interface %s attach failed: %s",
                 attach_type_strings[attach_type], strerror(-err));
+        close(progfd);
           return err;
       }
Quoted 9 lines

tools/bpf/bpftool/net.c static int do_attach(int argc, char **argv) · line 612

Quoted 5 lines
tools/bpf/bpftool/net.c +0 -0
         if (json_output)
           jsonw_null(json_wtr);
   +    close(progfd);
       return 0;
   }

Nit - wouldn't it be better to create a cleanup/out section before return and use goto, to avoid copying the close call? .

Thanks for review. I just sent v2 patch

"[PATCH v2 bpf] tools: bpftool: Add missing close before bpftool net attach exit"