From: Andrea Claudi Date: Sat, 1 May 2021 17:05:45 +0000 (+0200) Subject: lib: bpf_legacy: avoid to pass invalid argument to close() X-Git-Tag: v5.14.0~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3296d4fe773107e52f2e5a7b9244ad7073f36f5a;p=thirdparty%2Fiproute2.git lib: bpf_legacy: avoid to pass invalid argument to close() In function bpf_obj_open, if bpf_fetch_prog_arg() return an error, we end up in the out: path with a negative value for fd, and pass it to close. Avoid this checking for fd to be positive. Fixes: 32e93fb7f66d ("{f,m}_bpf: allow for sharing maps") Signed-off-by: Andrea Claudi Signed-off-by: David Ahern --- diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c index 7ec9ce9d6..d57d26359 100644 --- a/lib/bpf_legacy.c +++ b/lib/bpf_legacy.c @@ -2992,7 +2992,7 @@ static int bpf_obj_open(const char *pathname, enum bpf_prog_type type, out: bpf_elf_ctx_destroy(ctx, ret < 0); if (ret < 0) { - if (fd) + if (fd >= 0) close(fd); return ret; }