]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tools, bpftool: Add missing close before bpftool net attach exit
authorWang Hai <wanghai38@huawei.com>
Fri, 13 Nov 2020 11:51:52 +0000 (19:51 +0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 13 Nov 2020 14:59:13 +0000 (15:59 +0100)
progfd is created by prog_parse_fd() in do_attach() and before the latter
returns in case of success, the file descriptor should be closed.

Fixes: 377cdd23c244 ("tools: bpftool: add net attach command to attach XDP on interface")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20201113115152.53178-1-wanghai38@huawei.com
tools/bpf/bpftool/net.c

index 910e7bac6e9ec6223e86e873c65272adbbf35ab5..3fae61ef63396dad501e1b65bf326ff7728c5522 100644 (file)
@@ -578,8 +578,8 @@ static int do_attach(int argc, char **argv)
 
        ifindex = net_parse_dev(&argc, &argv);
        if (ifindex < 1) {
-               close(progfd);
-               return -EINVAL;
+               err = -EINVAL;
+               goto cleanup;
        }
 
        if (argc) {
@@ -587,8 +587,8 @@ static int do_attach(int argc, char **argv)
                        overwrite = true;
                } else {
                        p_err("expected 'overwrite', got: '%s'?", *argv);
-                       close(progfd);
-                       return -EINVAL;
+                       err = -EINVAL;
+                       goto cleanup;
                }
        }
 
@@ -596,17 +596,17 @@ static int do_attach(int argc, char **argv)
        if (is_prefix("xdp", attach_type_strings[attach_type]))
                err = do_attach_detach_xdp(progfd, attach_type, ifindex,
                                           overwrite);
-
-       if (err < 0) {
+       if (err) {
                p_err("interface %s attach failed: %s",
                      attach_type_strings[attach_type], strerror(-err));
-               return err;
+               goto cleanup;
        }
 
        if (json_output)
                jsonw_null(json_wtr);
-
-       return 0;
+cleanup:
+       close(progfd);
+       return err;
 }
 
 static int do_detach(int argc, char **argv)