diff options
| author | Kumar Kartikeya Dwivedi <[email protected]> | 2021-10-28 06:34:58 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <[email protected]> | 2021-10-28 23:30:07 +0000 |
| commit | 92274e24b01b331ef7a4227135933e6163fe94aa (patch) | |
| tree | e7fc60b8c4b80def6d9a9c74cd4b811589ad55ee /tools/lib/bpf/linker.c | |
| parent | libbpf: Ensure that BPF syscall fds are never 0, 1, or 2 (diff) | |
| download | kernel-92274e24b01b331ef7a4227135933e6163fe94aa.tar.gz kernel-92274e24b01b331ef7a4227135933e6163fe94aa.zip | |
libbpf: Use O_CLOEXEC uniformly when opening fds
There are some instances where we don't use O_CLOEXEC when opening an
fd, fix these up. Otherwise, it is possible that a parallel fork causes
these fds to leak into a child process on execve.
Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/lib/bpf/linker.c')
| -rw-r--r-- | tools/lib/bpf/linker.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index ce0800e61dc7..f677dccdeae4 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -301,7 +301,7 @@ static int init_output_elf(struct bpf_linker *linker, const char *file) if (!linker->filename) return -ENOMEM; - linker->fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0644); + linker->fd = open(file, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); if (linker->fd < 0) { err = -errno; pr_warn("failed to create '%s': %d\n", file, err); @@ -556,7 +556,7 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, obj->filename = filename; - obj->fd = open(filename, O_RDONLY); + obj->fd = open(filename, O_RDONLY | O_CLOEXEC); if (obj->fd < 0) { err = -errno; pr_warn("failed to open file '%s': %d\n", filename, err); |
