* [PATCH] libbpf: set close-on-exec flag on gzopen
@ 2023-08-10 21:09 Martin Kelly
2023-08-10 22:08 ` Stanislav Fomichev
0 siblings, 1 reply; 2+ messages in thread
From: Martin Kelly @ 2023-08-10 21:09 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Alexei Starovoitov, Marco Vedovati
From: Marco Vedovati <marco.vedovati@crowdstrike.com>
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.
Signed-off-by: Marco Vedovati <marco.vedovati@crowdstrike.com>
---
tools/lib/bpf/libbpf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 17883f5a44b9..b14a4376a86e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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");
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libbpf: set close-on-exec flag on gzopen
2023-08-10 21:09 [PATCH] libbpf: set close-on-exec flag on gzopen Martin Kelly
@ 2023-08-10 22:08 ` Stanislav Fomichev
0 siblings, 0 replies; 2+ messages in thread
From: Stanislav Fomichev @ 2023-08-10 22:08 UTC (permalink / raw)
To: Martin Kelly; +Cc: bpf, Andrii Nakryiko, Alexei Starovoitov, Marco Vedovati
On 08/10, Martin Kelly wrote:
> From: Marco Vedovati <marco.vedovati@crowdstrike.com>
>
> 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.
Acked-by: Stanislav Fomichev <sdf@google.com>
Fixes: 8601fd422148 ("libbpf: Allow to augment system Kconfig through extra optional config")
For fixes, not sure whether anybody actually builds libbpf from the kernel
tree...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-10 22:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 21:09 [PATCH] libbpf: set close-on-exec flag on gzopen Martin Kelly
2023-08-10 22:08 ` Stanislav Fomichev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox