Files
linux/fs
Christian Brauner 186aaff0d1 binfmt_misc: let a bpf handler choose the invocation flags per exec
The 'P', 'C' and 'O' flags of a binfmt_misc entry - preserve argv[0],
compute credentials from the binary, and pass the binary as an open file
descriptor - are fixed at registration and apply to every binary the entry
matches. A bpf handler matches, selects the interpreter and reads the
binary per exec, so the flags should be its per-exec decision too: one
handler may match both setuid and non-setuid binaries, argv[0]-sensitive
ones and not.

Honor the flags the load program stages in bprm->bpf_flags through the
bpf_binprm_set_flags() kfunc: BPF_BINPRM_PRESERVE_ARGV0,
BPF_BINPRM_CREDENTIALS and BPF_BINPRM_EXECFD map to 'P', 'C' and 'O' and
keep the semantics of their static counterparts, credentials implying the
open file descriptor included.

Flags staged by a load program that then fails are dropped on the way out
so they cannot leak into a later handler's exec, and the argv[0] decision
acts on the entry's own choice instead of testing the accumulated
bprm->interp_flags bit, which an earlier chain level may have left set and
binfmt_misc never clears.

Since a 'B' entry's flags come from the program, it carries none in the
register string: 'P', 'C' and 'O' are rejected there alongside 'F', which
was already meaningless for it. load_misc_binary() takes the flags from
the entry for a static handler and from bprm->bpf_flags for a bpf one.

Link: https://patch.msgid.link/20260714-work-bpf-binfmt_misc-v2-7-57b7529c002c@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-03 10:08:42 +02:00
..
2026-05-21 13:39:35 +02:00
2026-07-28 09:20:44 +02:00
2026-05-21 13:39:35 +02:00
2026-06-11 11:42:21 -07:00
2026-07-27 12:31:11 +08:00
2026-07-01 15:26:47 +02:00
2026-07-09 15:48:55 -07:00
2026-01-02 13:43:41 -05:00
2026-07-01 15:26:47 +02:00
2026-05-21 13:39:36 +02:00
2026-05-21 13:39:35 +02:00
2026-01-12 16:52:09 +01:00
2026-07-24 10:30:58 +02:00