Patch "libbpf: keep FD_CLOEXEC flag when dup()'ing FD" has been added to the 6.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    libbpf: keep FD_CLOEXEC flag when dup()'ing FD

to the 6.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     libbpf-keep-fd_cloexec-flag-when-dup-ing-fd.patch
and it can be found in the queue-6.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 63ec4cc8f50326c5a9c6e7fa1df26a8284e8b956
Author: Andrii Nakryiko <andrii@xxxxxxxxxx>
Date:   Wed May 29 15:32:39 2024 -0700

    libbpf: keep FD_CLOEXEC flag when dup()'ing FD
    
    [ Upstream commit 531876c80004ecff7bfdbd8ba6c6b48835ef5e22 ]
    
    Make sure to preserve and/or enforce FD_CLOEXEC flag on duped FDs.
    Use dup3() with O_CLOEXEC flag for that.
    
    Without this fix libbpf effectively clears FD_CLOEXEC flag on each of BPF
    map/prog FD, which is definitely not the right or expected behavior.
    
    Reported-by: Lennart Poettering <lennart@xxxxxxxxxxxxxx>
    Fixes: bc308d011ab8 ("libbpf: call dup2() syscall directly")
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240529223239.504241-1-andrii@xxxxxxxxxx
    Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index a0dcfb82e455d..7e7e686008c62 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -597,13 +597,9 @@ static inline int ensure_good_fd(int fd)
 	return fd;
 }
 
-static inline int sys_dup2(int oldfd, int newfd)
+static inline int sys_dup3(int oldfd, int newfd, int flags)
 {
-#ifdef __NR_dup2
-	return syscall(__NR_dup2, oldfd, newfd);
-#else
-	return syscall(__NR_dup3, oldfd, newfd, 0);
-#endif
+	return syscall(__NR_dup3, oldfd, newfd, flags);
 }
 
 /* Point *fixed_fd* to the same file that *tmp_fd* points to.
@@ -614,7 +610,7 @@ static inline int reuse_fd(int fixed_fd, int tmp_fd)
 {
 	int err;
 
-	err = sys_dup2(tmp_fd, fixed_fd);
+	err = sys_dup3(tmp_fd, fixed_fd, O_CLOEXEC);
 	err = err < 0 ? -errno : 0;
 	close(tmp_fd); /* clean up temporary FD */
 	return err;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux