From: Hang Zhengyang <hang.zhengyang1010@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>, Kees Cook <kees@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>, Chris Mason <mason@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Joey Gouly <joey.gouly@arm.com>,
Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
David Hildenbrand <david@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
Suren Baghdasaryan <surenb@google.com>,
Shuah Khan <shuah@kernel.org>, Gregory Price <gourry@gourry.net>,
Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
Florent Revest <revest@chromium.org>,
linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org,
linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 0/2] exec: don't honor PT_GNU_STACK PF_X under MDWE
Date: Sat, 5 Dec 2026 10:55:45 +0000 [thread overview]
Message-ID: <20261205105547.1251214-1-hang.zhengyang1010@gmail.com> (raw)
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
next reply other threads:[~2026-12-05 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 10:55 Hang Zhengyang [this message]
2026-12-05 10:55 ` [PATCH 1/2] exec: don't honor PT_GNU_STACK PF_X under MDWE 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205105547.1251214-1-hang.zhengyang1010@gmail.com \
--to=hang.zhengyang1010@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=joey.gouly@arm.com \
--cc=kees@kernel.org \
--cc=liam@infradead.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mason@kernel.org \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=revest@chromium.org \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox