lkml.org 
[lkml]   [2019]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 5.4 242/350] libbpf: Fix negative FD close() in xsk_setup_xdp_prog()
    Date
    From: Andrii Nakryiko <andriin@fb.com>

    [ Upstream commit 9656b346b280c3e49c8a116c3a715f966633b161 ]

    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>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20191107054059.313884-1-andriin@fb.com
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    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 9d53480862030..a73b79d293337 100644
    --- a/tools/lib/bpf/xsk.c
    +++ b/tools/lib/bpf/xsk.c
    @@ -466,6 +466,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.20.1
    \
     
     \ /
      Last update: 2019-12-10 22:22    [W:4.079 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site