Linux userland API discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] exec: don't honor PT_GNU_STACK PF_X under MDWE
@ 2026-12-05 10:55 Hang Zhengyang
  2026-12-05 10:55 ` [PATCH 1/2] " Hang Zhengyang
  2026-12-05 10:55 ` [PATCH 2/2] selftests/mm: test exec of a PT_GNU_STACK PF_X program " Hang Zhengyang
  0 siblings, 2 replies; 4+ messages in thread
From: Hang Zhengyang @ 2026-12-05 10:55 UTC (permalink / raw)
  To: Andrew Morton, Kees Cook
  Cc: Lorenzo Stoakes, Chris Mason, Catalin Marinas, Joey Gouly,
	Christian Brauner, Alexander Viro, Jan Kara, David Hildenbrand,
	Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
	Suren Baghdasaryan, Shuah Khan, Gregory Price, Jann Horn,
	Pedro Falcato, Florent Revest, linux-mm, linux-fsdevel,
	linux-kselftest, linux-hardening, linux-api, linux-kernel

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@kernel.org

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-05 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 10:55 [PATCH 0/2] exec: don't honor PT_GNU_STACK PF_X under MDWE Hang Zhengyang
2026-12-05 10:55 ` [PATCH 1/2] " Hang Zhengyang
2026-12-05 10:55 ` [PATCH 2/2] selftests/mm: test exec of a PT_GNU_STACK PF_X program " Hang Zhengyang
2026-12-05 11:27   ` Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox