* [PATCH 1/2] mm/util: don't let get_cmdline() stall on file-backed arguments
2026-11-29 5:51 [PATCH 0/2] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
@ 2026-11-29 5:51 ` Chris Down
2026-11-29 5:51 ` [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
1 sibling, 0 replies; 3+ messages in thread
From: Chris Down @ 2026-11-29 5:51 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
Chris Mason, Paul Moore, Kees Cook, Willy Tarreau, audit
get_cmdline() reads a task's arguments with access_process_vm(), and
in the setproctitle() case reads on into its environment. Since
commit 7f7ccc2ccc2e ("proc: do not access cmdline nor environ from
file-backed areas"), /proc/pid/cmdline and /proc/pid/environ pass
FOLL_ANON so that they only read anonymous memory, but get_cmdline()
was left alone and still faults in whatever is mapped there.
The task decides what is mapped at arg_start. It can mmap() a file
over its arguments, or move arg_start with prctl(PR_SET_MM_MAP), which
needs no capability. If that file is on a FUSE filesystem whose server
the user runs, the read blocks for as long as the server holds back
the reply.
That matters when the reader is somebody else. Yama reads the target's
command line when it reports a denied ptrace attach, and the msm and
etnaviv drivers read the command line of the task whose job hung the
GPU from their hang recovery path, msm with gpu->lock held. So the
task that hung the GPU can also hold up the recovery.
For example, take a FUSE server that waits three seconds before it
answers a read, and an unprivileged task that maps a file from it and
points arg_start there. When another of the user's tasks tries to
attach to it and Yama denies the attach, ptrace() takes the full three
seconds to fail:
PTRACE_ATTACH returned -1 (Operation not permitted) after 3.002s
ptrace attach of "FUSEARGS x"[109] was attempted by "/tmp/cmdtest file /tmp/fm/f"[110]
Let's pass FOLL_ANON here too, so that get_cmdline() reads the same
memory as /proc/pid/cmdline. A task whose arguments are not in
anonymous memory gets an empty command line (audit logs
proctitle=(null)), as /proc already shows it. The task decides what
its arguments say anyway, so this doesn't let it hide anything from
audit. With this applied, the attach above fails straight away.
This doesn't help device mappings with a vm_ops->access handler. GUP
already refuses those, and __access_remote_vm() then falls back to
->access whatever the flags. [1] stops that fallback for FOLL_ANON,
and with both applied get_cmdline() no longer reaches device memory
either.
[1]: https://lore.kernel.org/r/20261122-access_shite-v2-1-808d8d2aa700@kernel.org
Fixes: 7f7ccc2ccc2e ("proc: do not access cmdline nor environ from file-backed areas")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Down <chris@chrisdown.name>
---
mm/util.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/util.c b/mm/util.c
index 338f259b0035..c250aa088046 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1048,7 +1048,8 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
if (len > buflen)
len = buflen;
- res = access_process_vm(task, arg_start, buffer, len, FOLL_FORCE);
+ res = access_process_vm(task, arg_start, buffer, len,
+ FOLL_FORCE | FOLL_ANON);
/*
* If the nul at the end of args has been overwritten, then
@@ -1064,7 +1065,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
len = buflen - res;
res += access_process_vm(task, env_start,
buffer+res, len,
- FOLL_FORCE);
+ FOLL_FORCE | FOLL_ANON);
res = strnlen(buffer, res);
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline()
2026-11-29 5:51 [PATCH 0/2] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
2026-11-29 5:51 ` [PATCH 1/2] mm/util: don't let get_cmdline() stall on file-backed arguments Chris Down
@ 2026-11-29 5:51 ` Chris Down
1 sibling, 0 replies; 3+ messages in thread
From: Chris Down @ 2026-11-29 5:51 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
Chris Mason, Paul Moore, Kees Cook, Willy Tarreau, audit
get_cmdline() passes FOLL_FORCE, so it reads a task's arguments even
after the task has made them unreadable with mprotect(PROT_NONE).
It has done that from the start, because access_process_vm() used to
imply force, and commit f307ab6dcea0 ("mm: replace access_process_vm()
write parameter with gup_flags") only made that explicit. Right after
that, commit 272ddc8b3735 ("proc: don't use FOLL_FORCE for reading
cmdline and environment") dropped it again for /proc/pid/cmdline and
/proc/pid/environ, but get_cmdline() was missed.
None of the callers of get_cmdline() are debuggers, and there is no
reason for audit or Yama to see arguments that the task itself can't
read. Let's drop FOLL_FORCE, which leaves get_cmdline() with the same
flags as /proc/pid/cmdline.
Signed-off-by: Chris Down <chris@chrisdown.name>
---
mm/util.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/mm/util.c b/mm/util.c
index c250aa088046..8073af6708fb 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1048,8 +1048,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
if (len > buflen)
len = buflen;
- res = access_process_vm(task, arg_start, buffer, len,
- FOLL_FORCE | FOLL_ANON);
+ res = access_process_vm(task, arg_start, buffer, len, FOLL_ANON);
/*
* If the nul at the end of args has been overwritten, then
@@ -1064,8 +1063,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
if (len > buflen - res)
len = buflen - res;
res += access_process_vm(task, env_start,
- buffer+res, len,
- FOLL_FORCE | FOLL_ANON);
+ buffer + res, len, FOLL_ANON);
res = strnlen(buffer, res);
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread