diff mbox series

[iproute2] lib: bpf_legacy: avoid to pass invalid argument to close()

Message ID a401273d9c2e965d11c07cab76016d350b4f0b2c.1619887571.git.aclaudi@redhat.com (mailing list archive)
State Accepted
Delegated to: David Ahern
Headers show
Series [iproute2] lib: bpf_legacy: avoid to pass invalid argument to close() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Andrea Claudi May 1, 2021, 5:05 p.m. UTC
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@redhat.com>
---
 lib/bpf_legacy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Ahern May 6, 2021, 2:46 p.m. UTC | #1
On 5/1/21 11:05 AM, Andrea Claudi wrote:
> 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@redhat.com>
> ---
>  lib/bpf_legacy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

applied
diff mbox series

Patch

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;
 	}