netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: fix negative FD close() in xsk_setup_xdp_prog()
@ 2019-11-07  5:40 Andrii Nakryiko
  2019-11-07 16:04 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2019-11-07  5:40 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel, jonathan.lemon
  Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko

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>
---
 tools/lib/bpf/xsk.c | 2 ++
 1 file changed, 2 insertions(+)

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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: fix negative FD close() in xsk_setup_xdp_prog()
  2019-11-07  5:40 [PATCH bpf-next] libbpf: fix negative FD close() in xsk_setup_xdp_prog() Andrii Nakryiko
@ 2019-11-07 16:04 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2019-11-07 16:04 UTC (permalink / raw)
  To: Andrii Nakryiko, bpf, netdev, ast, jonathan.lemon
  Cc: andrii.nakryiko, kernel-team

On 11/7/19 6:40 AM, Andrii Nakryiko wrote:
> 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>

Applied, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-07 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07  5:40 [PATCH bpf-next] libbpf: fix negative FD close() in xsk_setup_xdp_prog() Andrii Nakryiko
2019-11-07 16:04 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).