]> git.baikalelectronics.ru Git - kernel.git/commitdiff
libbpf: Use SOCK_CLOEXEC when opening the netlink socket
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Wed, 17 Mar 2021 11:58:58 +0000 (17:28 +0530)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 17 Mar 2021 23:50:21 +0000 (00:50 +0100)
Otherwise, there exists a small window between the opening and closing
of the socket fd where it may leak into processes launched by some other
thread.

Fixes: 949abbe88436 ("libbpf: add function to setup XDP")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210317115857.6536-1-memxor@gmail.com
tools/lib/bpf/netlink.c

index 4dd73de00b6f1c0a413ff01c15c5352f824f4167..d2cb28e9ef52ec2af43c8497732a8c40916c920d 100644 (file)
@@ -40,7 +40,7 @@ static int libbpf_netlink_open(__u32 *nl_pid)
        memset(&sa, 0, sizeof(sa));
        sa.nl_family = AF_NETLINK;
 
-       sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+       sock = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
        if (sock < 0)
                return -errno;