libbpf: set close-on-exec flag on gzopen
PATCH 1/1 libbpf: set close-on-exec flag on gzopen
From: Marco Vedovati <[email protected]>
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.
--- tools/lib/bpf/libbpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
@@ -1978,9 +1978,9 @@ static int bpf_object__read_kconfig_file(struct bpf_object *obj, void *data)return -ENAMETOOLONG ;/* gzopen also accepts uncompressed files. */ - file =gzopen (buf,"r" ); + file =gzopen (buf,"re" );if (!file) - file =gzopen ("/proc/config.gz" ,"r" ); + file =gzopen ("/proc/config.gz" ,"re" );if (!file) {pr_warn ("failed to open system Kconfig\n" );
Signature · 1 line
2.34.1
Quoted 7 lines · Martin Kelly
From: Marco Vedovati <[email protected]>
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.
We do have fopen(, "re") all over the place; gzopen seem to pass mode to fopen.
For fixes, not sure whether anybody actually builds libbpf from the kernel tree...