Re: [PATCH bpf-next] libbpf: set close-on-exec flag on gzopen

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

 



On 8/10/23 14:43, Martin Kelly wrote:
From: Marco Vedovati <marco.vedovati@xxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxx>
---
  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");

Sorry for double-sending the patch; the first was missing the bpf-next prefix and I wasn't sure if that would be an issue. Feel free to ignore this patch, as the other already got a reply.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux