]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
binfmt_elf_fdpic: consume a stashed PT_INTERP substitute
authorChristian Brauner <brauner@kernel.org>
Tue, 21 Jul 2026 14:13:59 +0000 (16:13 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 3 Aug 2026 08:08:46 +0000 (10:08 +0200)
Do what binfmt_elf does. When a binfmt_misc loader entry stashed
bprm->loader use it in place of the path named in PT_INTERP, and drop the
override when the binary names no interpreter at all.

Without this 'L' is unusable on nommu, where fdpic is the only ELF
loader. On ARM with an MMU both loaders are registered but split the ELF
space between them along elf_check_fdpic(), so an fdpic binary is never
picked up by binfmt_elf either.

Declining is what fdpic did so far, but it declined late. The pending
override was only caught in begin_new_exec(), by which point the segment
scan had opened the interpreter the binary itself names and overwritten
bprm->buf with its header, leaving the next format in the round to
inspect a buffer that no longer describes the file it is offered. The
scan consumes the override now, so of the in-tree formats only
binfmt_flat still relies on the refusal, and it reads bprm->buf without
writing it.

Transparent dispatch needs nothing on top of the AT_FLAGS translation
both loaders already share. The binary travels in AT_EXECFD, which
create_elf_fdpic_tables() emits, and the exe and comm labelling is done
in exec.c for every format.

Link: https://patch.msgid.link/20260721-work-bpf-binfmt_misc-ptinterp-v2-17-e57866e4ae0f@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/binfmt_elf_fdpic.c

index 0a3cdf28030738bd9930e63fc99b4335640300c5..068c46875c74423a1ee6f56cdd1a855820b092e9 100644 (file)
@@ -263,7 +263,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
                        kdebug("Using ELF interpreter %s", interpreter_name);
 
                        /* replace the program with the interpreter */
-                       interpreter = open_exec(interpreter_name);
+                       interpreter = bprm_open_interpreter(bprm,
+                                                           interpreter_name);
                        retval = PTR_ERR(interpreter);
                        if (IS_ERR(interpreter)) {
                                interpreter = NULL;
@@ -299,6 +300,9 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
 
        }
 
+       /* No PT_INTERP to substitute for: the override does not apply. */
+       bprm_drop_loader(bprm);
+
        if (is_constdisp(&exec_params.hdr))
                exec_params.flags |= ELF_FDPIC_FLAG_CONSTDISP;