[PATCH bpf-next v2] libbpf: use SOCK_CLOEXEC when opening the netlink socket

Subsystems: bpf [general] (safe dynamic programs and tools), bpf [library] (libbpf), the rest

STALE1963d LANDED

Landed in mainline as 58bfd95b554f on 2021-03-17.

3 messages, 3 authors, 2021-03-18 · open the first message on its own page

[PATCH bpf-next v2] libbpf: use SOCK_CLOEXEC when opening the netlink socket

From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date: 2021-03-17 12:01:02

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>
---
Changelog:

v1 -> v2
Tag the bpf-next tree (Toke)
Add a Fixes: tag (Toke)
---
 tools/lib/bpf/netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c
index 4dd73de00..d2cb28e9e 100644
--- a/tools/lib/bpf/netlink.c
+++ b/tools/lib/bpf/netlink.c
@@ -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;
 
-- 
2.30.2

Re: [PATCH bpf-next v2] libbpf: use SOCK_CLOEXEC when opening the netlink socket

From: Toke Høiland-Jørgensen <hidden>
Date: 2021-03-17 13:05:48

Kumar Kartikeya Dwivedi [off-list ref] writes:
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>
Acked-by: Toke Høiland-Jørgensen <redacted>

Re: [PATCH bpf-next v2] libbpf: use SOCK_CLOEXEC when opening the netlink socket

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-03-18 00:00:56

Hello:

This patch was applied to bpf/bpf.git (refs/heads/master):

On Wed, 17 Mar 2021 17:28:58 +0530 you wrote:
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>

[...]
Here is the summary with links:
  - [bpf-next,v2] libbpf: use SOCK_CLOEXEC when opening the netlink socket
    https://git.kernel.org/bpf/bpf/c/58bfd95b554f

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help