Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline
@ 2026-11-29  5:51 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 ` [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
  0 siblings, 2 replies; 5+ 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 for audit's proctitle record,
Yama's ptrace reports, loadpin and the msm and etnaviv GPU hang
messages. Unlike /proc/pid/cmdline, which has only read anonymous
memory since 7f7ccc2ccc2e ("proc: do not access cmdline nor environ
from file-backed areas"), it still reads whatever the task has mapped
at arg_start. That includes a file on a FUSE filesystem whose server
can take as long as it likes to answer, and some of those readers are
other tasks, or msm's hang recovery with gpu->lock held.

Patch 1 passes FOLL_ANON, so get_cmdline() reads the same memory as
/proc. This is the one for stable.

Patch 2 drops FOLL_FORCE, which get_cmdline() only has because it was
missed when 272ddc8b3735 ("proc: don't use FOLL_FORCE for reading
cmdline and environment") dropped it from /proc.

For device mappings, patch 1 relies on "mm: do not call vm_ops->access
with FOLL_ANON" from David's vm_ops->access series [1], but it doesn't
need it to apply or build.

[1] https://lore.kernel.org/r/20261122-access_shite-v2-1-808d8d2aa700@kernel.org

Chris Down (2):
  mm/util: don't let get_cmdline() stall on file-backed arguments
  mm/util: drop FOLL_FORCE from get_cmdline()

 mm/util.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)


base-commit: c6f53520f32302ea64cbcfd7cc25a31081e34548
-- 
2.56.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [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  8:45   ` David Hildenbrand (Arm)
  2026-11-29  5:51 ` [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
  1 sibling, 1 reply; 5+ 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 related	[flat|nested] 5+ 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
  2026-11-29  9:44   ` David Hildenbrand (Arm)
  1 sibling, 1 reply; 5+ 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 related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] mm/util: don't let get_cmdline() stall on file-backed arguments
  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  8:45   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-29  8:45 UTC (permalink / raw)
  To: Chris Down, Andrew Morton
  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

On 11/29/26 06:51, Chris Down wrote:
> 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);
>  		}
>  	}

I was about to send out the following in a bigger batch I was preparing:

commit 43092c5d9f6e0f10eb8ad761436dcbc14b043743
Author: Chris Mason <mason@kernel.org>
Date:   Wed Nov 18 22:16:20 2026 +0100

    mm: read only anonymous memory in get_cmdline()

    get_cmdline() returns internally what /proc/<pid>/cmdline would expose
    to user space. Both implementations are separate (which should probably
    be cleaned up at some point). Commit 7f7ccc2ccc2e ("proc: do not access
    cmdline nor environ from file-backed areas") restricted only the procfs
    implementation to anonymous memory, and missed get_cmdline().

    Consequently, other subsystems that read the command line of another
    task through get_cmdline(), such as Yama, can get stuck in an
    uninterruptible sleep if the command line is backed by a file, for
    example on FUSE.

    Let's fix it by passing FOLL_ANON in get_cmdline() as well.

    This can change the command line reported by various subsystems,
    primarily in audit records or logs. /proc/<pid>/cmdline has behaved
    like this since v4.17, and the task controls its command line anyway, so
    it's not really bad if this interface fails in more (uncommon) scenarios.

    This has medium urgency, as unprivileged users can trigger it using FUSE.

    Fixes: a90902531a06 ("mm: Create utility function for accessing a tasks commandline value")
    Cc: stable@vger.kernel.org
    Signed-off-by: Chris Mason <mason@kernel.org>
    [ david: simplify description, drop comment ]
    Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>

diff --git a/mm/util.c b/mm/util.c
index 338f259b00351..c250aa088046d 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);
                }
        }


Guess which commit description I prefer ;)

-- 
Cheers,

David


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline()
  2026-11-29  5:51 ` [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
@ 2026-11-29  9:44   ` David Hildenbrand (Arm)
  0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-29  9:44 UTC (permalink / raw)
  To: Chris Down, Andrew Morton
  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

On 11/29/26 06:51, Chris Down wrote:
> 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.

That will now match what we do in get_mm_cmdline(), and I think not using
FOLL_FORCE would be great. Thanks!

Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>


I do wonder if there would be a way to have both functions share a common core
helper. Not completely trivial I guess.


-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-29  9:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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  8:45   ` David Hildenbrand (Arm)
2026-11-29  5:51 ` [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
2026-11-29  9:44   ` David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox