[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <a401273d9c2e965d11c07cab76016d350b4f0b2c.1619887571.git.aclaudi@redhat.com>
Date: Sat, 1 May 2021 19:05:45 +0200
From: Andrea Claudi <aclaudi@...hat.com>
To: netdev@...r.kernel.org
Cc: stephen@...workplumber.org, dsahern@...il.com
Subject: [PATCH iproute2] 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 <aclaudi@...hat.com>
---
lib/bpf_legacy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 7ec9ce9d..d57d2635 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;
}
--
2.30.2
Powered by blists - more mailing lists