Skip to content

exec: randomize the argument block's in-page offset

Brian Witte linux-fsdevel linux-hardening linux-kselftest linux-mm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2exec: randomize the argument block's offset within its pagefs/exec.c+32 -00 replies
2/2selftests/exec: test the argument block's in-page offsettools/testing/selftests/exec/.gitignore tools/testing/selftests/exec/Makefile tools/testing/selftests/exec/argblock-offset.c +1 more+246 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] exec: randomize the argument block's in-page offset

Patch 1 randomizes where the argv, envp and execfn strings sit within the first stack page, as KSPP issue 283 asks; today their low address bits never change. Patch 2 adds a selftest.

Patch 1 repeats bprm_fill_uid()'s set-id checks; I can send a shared helper as a preparatory patch if preferred.

Tested in QEMU, compared with unpatched for-next/execve (b36b990c50b1), on x86_64 with ia32, arm64 (4K pages with AArch32, and 64K pages), and parisc 32-bit and 64-bit (STACK_GROWSUP):

- The selftest passes; unpatched, it fails.
- 10000 execs give 3709-3764 distinct offsets with 4K pages and 9259 with 64K, as a uniform draw predicts.
- Cost: about 0.5 more minor page faults per exec on average, and up to a page of RLIMIT_STACK; exec time is within noise.
- No change in LTP execve and execveat, CRIU dump and restore, or programs that rewrite argv[0] (setproctitle(), sshd, postgres), and no KASAN, UBSAN or lockdep reports under exec and chmod races.

The series is based on mainline (864c07de0c7d), which now includes for-next/execve and the const mnt_idmap conversion. On that base it adds no W=1 warnings with GCC 14 or clang 19 on x86_64 and arm64, and the selftest passes on x86_64.

Brian Witte (2):
exec: randomize the argument block's offset within its page selftests/exec: test the argument block's in-page offset

 fs/exec.c                                     |  32 +++
 tools/testing/selftests/exec/.gitignore       |   3 +
 tools/testing/selftests/exec/Makefile         |   5 +
 .../testing/selftests/exec/argblock-offset.c  | 214 ++++++++++++++++++
 .../testing/selftests/exec/argblock-report.c  |  24 ++
 5 files changed, 278 insertions(+)
 create mode 100644 tools/testing/selftests/exec/argblock-offset.c
 create mode 100644 tools/testing/selftests/exec/argblock-report.c

base-commit: 864c07de0c7dcbca58b61625dfa2e461ae63b242

Signature · 1 line
2.47.3