Skip to content

Commit

Permalink
tools, bpftool: Add missing close before bpftool net attach exit
Browse files Browse the repository at this point in the history
[ Upstream commit 50431b4 ]

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: 04949cc ("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
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Wang Hai authored and gregkh committed Nov 24, 2020
1 parent 012e9e7 commit 089a92d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tools/bpf/bpftool/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,35 +313,35 @@ 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) {
if (is_prefix(*argv, "overwrite")) {
overwrite = true;
} else {
p_err("expected 'overwrite', got: '%s'?", *argv);
close(progfd);
return -EINVAL;
err = -EINVAL;
goto cleanup;
}
}

/* attach xdp prog */
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)
Expand Down

0 comments on commit 089a92d

Please sign in to comment.