]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib: bpf_legacy: avoid to pass invalid argument to close()
authorAndrea Claudi <aclaudi@redhat.com>
Sat, 1 May 2021 17:05:45 +0000 (19:05 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 6 May 2021 14:43:54 +0000 (14:43 +0000)
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>
Signed-off-by: David Ahern <dsahern@kernel.org>
lib/bpf_legacy.c

index 7ec9ce9d6122f02d4554d923b4025e6a23fc098c..d57d2635932d06a2928f9b9659a1f818ff1d565c 100644 (file)
@@ -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;
        }