summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-11-06 21:40:59 -0800
committerDaniel Borkmann <daniel@iogearbox.net>2019-11-07 16:15:27 +0100
commit9656b346b280c3e49c8a116c3a715f966633b161 (patch)
tree67930b0a4a9a805df41fb87b1905806f69db7f8d
parentdab2e9eb187cb53c951c0c556172a73ac7f0e834 (diff)
downloadblackbird-op-linux-9656b346b280c3e49c8a116c3a715f966633b161.tar.gz
blackbird-op-linux-9656b346b280c3e49c8a116c3a715f966633b161.zip
libbpf: Fix negative FD close() in xsk_setup_xdp_prog()
Fix issue reported by static analysis (Coverity). If bpf_prog_get_fd_by_id() fails, xsk_lookup_bpf_maps() will fail as well and clean-up code will attempt close() with fd=-1. Fix by checking bpf_prog_get_fd_by_id() return result and exiting early. Fixes: 10a13bb40e54 ("libbpf: remove qidconf and better support external bpf programs.") Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20191107054059.313884-1-andriin@fb.com
-rw-r--r--tools/lib/bpf/xsk.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 74d84f36a5b2..86c1b61017f6 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -553,6 +553,8 @@ static int xsk_setup_xdp_prog(struct xsk_socket *xsk)
}
} else {
xsk->prog_fd = bpf_prog_get_fd_by_id(prog_id);
+ if (xsk->prog_fd < 0)
+ return -errno;
err = xsk_lookup_bpf_maps(xsk);
if (err) {
close(xsk->prog_fd);
OpenPOWER on IntegriCloud