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 --- 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