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 1/2] exec: don't honor PT_GNU_STACK PF_X under MDWE
Date: Sat, 5 Dec 2026 10:55:46 +0000 [thread overview]
Message-ID: <20261205105547.1251214-2-hang.zhengyang1010@gmail.com> (raw)
In-Reply-To: <20261205105547.1251214-1-hang.zhengyang1010@gmail.com>
With MDWE (PR_MDWE_REFUSE_EXEC_GAIN), mmap() and mprotect() refuse to
make memory writable and executable, and MDWE is inherited across
execve() by default. But a program whose PT_GNU_STACK has PF_X still
gets a writable and executable stack: setup_arg_pages() adds VM_EXEC
with mprotect_fixup(), which doesn't check map_deny_write_exec().
Under MDWE, clear VM_EXEC for EXSTACK_ENABLE_X as for EXSTACK_DISABLE_X,
and warn once. Don't fail the exec: the marking can be an accident, as
in the first example of commit 47a2ebb7f505 ("execve: warn if process
starts with executable stack"). A marked program that runs code from
its stack gets SIGSEGV instead.
Fixes: b507808ebce2 ("mm: implement memory-deny-write-execute as a prctl")
Cc: <stable+noautosel@kernel.org> # code run from the stack gets SIGSEGV under MDWE
Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
---
fs/exec.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 8d2b14e1d455..d23f87301abf 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -660,12 +660,21 @@ int setup_arg_pages(struct linux_binprm *bprm,
/*
* Adjust stack execute permissions; explicitly enable for
* EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
- * (arch default) otherwise.
+ * (arch default) otherwise. MDWE refuses writable and executable
+ * memory, so under MDWE treat EXSTACK_ENABLE_X as EXSTACK_DISABLE_X.
+ * The marking can be an accident, so don't fail the exec.
*/
- if (unlikely(executable_stack == EXSTACK_ENABLE_X))
- vm_flags |= VM_EXEC;
- else if (executable_stack == EXSTACK_DISABLE_X)
+ if (unlikely(executable_stack == EXSTACK_ENABLE_X)) {
+ if (mm_flags_test(MMF_HAS_MDWE, mm)) {
+ pr_warn_once("process '%pD4' asked for an executable stack, not granted under MDWE\n",
+ bprm->file);
+ vm_flags &= ~VM_EXEC;
+ } else {
+ vm_flags |= VM_EXEC;
+ }
+ } else if (executable_stack == EXSTACK_DISABLE_X) {
vm_flags &= ~VM_EXEC;
+ }
vm_flags |= mm->def_flags;
vm_flags |= VM_STACK_INCOMPLETE_SETUP;
--
2.53.0
next prev parent reply other threads:[~2026-12-05 10:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Hang Zhengyang [this message]
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-2-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