Skip to content

RFC Introduce a way to expose the interpreted file with binfmt_misc

Guilherme G. Piccoli linux-fsdevel linux-mm lkml oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2binfmt_misc, fork, proc: Introduce flag to expose the interpreted binary in procfsDocumentation/admin-guide/binfmt-misc.rst arch/arc/kernel/troubleshoot.c fs/binfmt_elf.c +14 more+173 -370 replies
2/2fork, procfs: Introduce /proc/self/interpreter symlinkfs/exec.c fs/proc/base.c include/linux/binfmts.h +3 more+69 -160 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by.

PatchRyan Houdek
1/2T-b
2/2T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/2] Introduce a way to expose the interpreted file with binfmt_misc

Currently the kernel provides a symlink to the executable binary, in the form of procfs file exe_file (/proc/self/exe_file for example). But what happens in interpreted scenarios (like binfmt_misc) is that such link always points to the *interpreter*. For cases of Linux binary emulators, like FEX [0] for example, it's then necessary to somehow mask that and emulate the true binary path.

We hereby propose a way to expose such interpreted binary as exe_file if the flag 'I' is selected on binfmt_misc. When that flag is set, the file /proc/self/exe_file points to the *interpreted* file, be it ELF or not. In order to allow users to distinguish if such flag is used or not without checking the binfmt_misc filesystem, we propose also the /proc/self/interpreter file, which always points to the *interpreter* in scenarios where interpretation is set, like binfmt_misc. This file is empty / points to nothing in the case of regular ELF execution, though we could consider implementing a way to point to the LD preloader if that makes sense...

This was sent as RFC because of course it's a very core change, affecting multiple areas and there are design choices (and questions) in each patch so we could discuss and check the best way to implement the solution as well as the corner cases handling. This is a very useful feature for emulators and such, like FEX and Wine, which usually need to circumvent this kernel limitation in order to expose the true emulated file name (more examples at [1][2][3]).

This patchset is based on the currently v6.6-rc1 candidate (Linus tree from yesterday) and was tested under QEMU as well as using FEX. Thanks in advance for comments, any feedback is greatly appreciated! Cheers,

Guilherme

[0] https://github.com/FEX-Emu/FEX

[1] Using an environment variable trick to override exe_file:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/util/u_process.c#L209

[2] https://github.com/baldurk/renderdoc/pull/2694

[3] FEX handling of the exe_file parsing:
https://github.com/FEX-Emu/FEX/blob/main/Source/Tools/FEXLoader/LinuxSyscalls/FileManagement.cpp#L499

Guilherme G. Piccoli (2):
binfmt_misc, fork, proc: Introduce flag to expose the interpreted binary in procfs fork, procfs: Introduce /proc/self/interpreter symlink

 Documentation/admin-guide/binfmt-misc.rst |  11 ++
 arch/arc/kernel/troubleshoot.c            |   5 +
 fs/binfmt_elf.c                           |   7 ++
 fs/binfmt_misc.c                          |  11 ++
 fs/coredump.c                             |   5 +
 fs/exec.c                                 |  26 ++++-
 fs/proc/base.c                            |  48 +++++---
 include/linux/binfmts.h                   |   4 +
 include/linux/mm.h                        |   7 +-
 include/linux/mm_types.h                  |   2 +
 kernel/audit.c                            |   5 +
 kernel/audit_watch.c                      |   7 +-
 kernel/fork.c                             | 131 +++++++++++++++++-----
 kernel/signal.c                           |   7 +-
 kernel/sys.c                              |   5 +
 kernel/taskstats.c                        |   7 +-
 security/tomoyo/util.c                    |   5 +
 17 files changed, 241 insertions(+), 52 deletions(-)
Signature · 1 line
2.42.0