[PATCH 0/2] exec: don't honor PT_GNU_STACK PF_X under MDWE

From: Hang Zhengyang

Date: Sat Dec 05 2026 - 05:56:05 EST


Under MDWE, a program whose PT_GNU_STACK has PF_X still gets a writable
and executable stack at execve(). Patch 1 drops VM_EXEC there, and
patch 2 adds a test.

Failing the exec is the other choice, and the one Kees Cook suggested
for such programs on the RFC that led to MDWE [1]. I chose to drop
VM_EXEC because the marking can be an accident, and today such a
program runs under MDWE unless it creates threads with glibc. The cost
is that a program that runs code from its stack gets SIGSEGV instead of
failing to start. I can switch to failing the exec.

Patch 1 leaves the arch default alone, so a program without
PT_GNU_STACK can still get an executable stack where that is the
default. "mm/vma: make brk mappings non-executable under MDWE" [2] in
mm-unstable drops VM_EXEC for brk() in that case too. I can do the same
for the stack.

Tested on mm-unstable in an x86_64 KVM guest: under MDWE, the stack of
a -z execstack program goes from rwxp to rw-p, and the new test cases
under MDWE fail without patch 1 and pass with it.

[1] https://lore.kernel.org/all/202204200952.F2B1F58D6B@keescook/
[2] https://patch.msgid.link/20261121-some-more-ai-fixes-v1-7-236e925d9b64@xxxxxxxxxx

I used Claude Code to find the issue, write the patches and run the
tests. I reviewed the patches.

Hang Zhengyang (2):
exec: don't honor PT_GNU_STACK PF_X under MDWE
selftests/mm: test exec of a PT_GNU_STACK PF_X program under MDWE

fs/exec.c | 17 ++++++--
tools/testing/selftests/mm/Makefile | 3 ++
tools/testing/selftests/mm/mdwe_execstack.c | 44 +++++++++++++++++++++
tools/testing/selftests/mm/mdwe_test.c | 43 ++++++++++++++++++++
4 files changed, 103 insertions(+), 4 deletions(-)
create mode 100644 tools/testing/selftests/mm/mdwe_execstack.c


base-commit: 2d2d9f22c9c7ae457ba93480ba82ebf57cbf0df8
--
2.53.0