Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Set close-on-exec flag on gzopen

Enable the close-on-exec flag when using gzopen. This is especially important
for multithreaded programs making use of libbpf, where a fork + exec could
race with libbpf library calls, potentially resulting in a file descriptor
leaked to the new process. This got missed in 59842c5451fe ("libbpf: Ensure
libbpf always opens files with O_CLOEXEC").

Fixes: 59842c5451fe ("libbpf: Ensure libbpf always opens files with O_CLOEXEC")
Signed-off-by: Marco Vedovati <marco.vedovati@crowdstrike.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20230810214350.106301-1-martin.kelly@crowdstrike.com

authored by

Marco Vedovati and committed by
Daniel Borkmann
8e50750f 6da4fea8

+2 -2
+2 -2
tools/lib/bpf/libbpf.c
··· 1978 1978 return -ENAMETOOLONG; 1979 1979 1980 1980 /* gzopen also accepts uncompressed files. */ 1981 - file = gzopen(buf, "r"); 1981 + file = gzopen(buf, "re"); 1982 1982 if (!file) 1983 - file = gzopen("/proc/config.gz", "r"); 1983 + file = gzopen("/proc/config.gz", "re"); 1984 1984 1985 1985 if (!file) { 1986 1986 pr_warn("failed to open system Kconfig\n");