mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-08 09:39:07 +08:00
libbpf: Use O_CLOEXEC uniformly when opening fds
There are some instances where we don't use O_CLOEXEC when opening an fd, fix these up. Otherwise, it is possible that a parallel fork causes these fds to leak into a child process on execve. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20211028063501.2239335-6-memxor@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
bedab00b50
commit
a0195b3078
@@ -300,7 +300,7 @@ int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
|
||||
if (!umem)
|
||||
return -ENOMEM;
|
||||
|
||||
umem->fd = socket(AF_XDP, SOCK_RAW, 0);
|
||||
umem->fd = socket(AF_XDP, SOCK_RAW | SOCK_CLOEXEC, 0);
|
||||
if (umem->fd < 0) {
|
||||
err = -errno;
|
||||
goto out_umem_alloc;
|
||||
@@ -549,7 +549,7 @@ static int xsk_get_max_queues(struct xsk_socket *xsk)
|
||||
struct ifreq ifr = {};
|
||||
int fd, err, ret;
|
||||
|
||||
fd = socket(AF_LOCAL, SOCK_DGRAM, 0);
|
||||
fd = socket(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
@@ -1046,7 +1046,7 @@ int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
|
||||
}
|
||||
|
||||
if (umem->refcount++ > 0) {
|
||||
xsk->fd = socket(AF_XDP, SOCK_RAW, 0);
|
||||
xsk->fd = socket(AF_XDP, SOCK_RAW | SOCK_CLOEXEC, 0);
|
||||
if (xsk->fd < 0) {
|
||||
err = -errno;
|
||||
goto out_xsk_alloc;
|
||||
|
||||
Reference in New Issue
Block a user