From: Kyle Zeng <kylebot@openai.com>
To: linux-mm@kvack.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
kees@kernel.org, outbounddisclosures@openai.com,
Kyle Zeng <kylebot@openai.com>,
stable@vger.kernel.org
Subject: [PATCH] exec: snapshot the dentry name before setting task comm
Date: Tue, 6 Oct 2026 15:15:11 -0700 [thread overview]
Message-ID: <20261006221511.35798-1-kylebot@openai.com> (raw)
For an empty execveat() pathname, begin_new_exec() passes a live dentry
name to __set_task_comm(). RCU keeps the name allocation alive, but does
not prevent a concurrent rename from changing an inline name.
__set_task_comm() measures the source before copying it. If a rename
replaces a long inline name with a shorter one in between, the copy can
include stale slab bytes after the new NUL. The subsequent padding starts
at the old length, leaving those bytes in task->comm. An unprivileged
task can observe the suffix through a count-only syscall tracepoint
filter such as COMM ~ "*pattern*".
Take a dentry name snapshot before setting comm and release it afterwards.
The snapshot retries concurrent renames and either copies the inline name
or holds a reference to an immutable external name. This gives both the
tracepoint and the length/copy sequence a stable source while preserving
the selected executable and the existing comm truncation and padding.
Fixes: 543841d18060 ("exec: fix up /proc/pid/comm in the execveat(AT_EMPTY_PATH) case")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
fs/exec.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 819643408e6d..34cf557a17f7 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1279,19 +1279,16 @@ int begin_new_exec(struct linux_binprm * bprm)
*/
if (bprm->comm_from_dentry) {
struct file *comm_file = bprm_identity_file(bprm);
+ struct name_snapshot name;
/*
- * Hold RCU lock to keep the name from being freed behind our back.
- * Use acquire semantics to make sure the terminating NUL from
- * __d_alloc() is seen.
- *
- * Note, we're deliberately sloppy here. We don't need to care about
- * detecting a concurrent rename and just want a terminated name.
+ * __set_task_comm() measures the name before copying it. Keep
+ * a rename from shortening the name and exposing stale bytes
+ * in the inline name buffer.
*/
- rcu_read_lock();
- __set_task_comm(me, smp_load_acquire(&comm_file->f_path.dentry->d_name.name),
- true);
- rcu_read_unlock();
+ take_dentry_name_snapshot(&name, comm_file->f_path.dentry);
+ __set_task_comm(me, name.name.name, true);
+ release_dentry_name_snapshot(&name);
} else {
__set_task_comm(me, kbasename(bprm->filename), true);
}
base-commit: fd179f8a05be3ccae366b9b96e176b51fbe54aab
--
2.53.0
reply other threads:[~2026-10-06 22:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261006221511.35798-1-kylebot@openai.com \
--to=kylebot@openai.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=outbounddisclosures@openai.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®