Files
linux/tools/testing/selftests/exec/binfmt_bind_interp.c
Christian Brauner 7404b1472b selftests/exec: test interpreters bound to a 'B' entry
One handler, one entry registered disabled, an interpreter per guest
architecture bound to a file one write at a time. The load program picks
one by name per exec:

- an aarch64 binary runs the interpreter bound as "first" and a riscv one
  the interpreter bound as "second", from a single entry and a single
  handler

- unlinking a bound interpreter and putting a different binary in its
  place changes nothing, which is what the binding exists for

- the entry reports what it bound, under the names it bound them as

- a name the entry did not bind fails the exec with -ENOENT rather than
  falling back to anything

- activating the entry refuses further binding with -EBUSY, a later
  disable does not undo that, and an entry registered without 'D' never
  accepted a '+' write to begin with

- a name binds one interpreter, and control characters are refused

- the command has to end at the write, bytes past an embedded nul are
  refused

- an entry binds at most 100 interpreters, the next one is refused with
  -ENOSPC

The test interpreter prints its argv[0], which is the path the kernel ran
that copy under, so one binary installed at two paths tells the harness
which of them the program picked.

Link: https://patch.msgid.link/20260730-work-binfmt_misc-preopen-v1-8-4a0b0da71f16@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-08-03 19:15:44 +02:00

15 lines
462 B
C

// SPDX-License-Identifier: GPL-2.0
/*
* Test interpreter for the bound-interpreter case of the binfmt_misc_bpf
* selftest. Two copies are installed at different paths and bound to one
* entry under different names; printing argv[0] - the path the kernel ran
* this copy under - tells the harness which of them the load program picked.
*/
#include <stdio.h>
int main(int argc, char **argv)
{
printf("BIND_RAN %s\n", argc > 0 ? argv[0] : "");
return 0;
}