Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Chris Down <chris@chrisdown.name>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Chris Mason <mason@kernel.org>, Paul Moore <paul@paul-moore.com>,
	Kees Cook <kees@kernel.org>, Willy Tarreau <w@1wt.eu>,
	audit@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/util: don't let get_cmdline() stall on file-backed arguments
Date: Sun, 29 Nov 2026 09:45:53 +0100	[thread overview]
Message-ID: <c182f78c-49b7-4526-a3ef-fd56c1b12c0e@kernel.org> (raw)
In-Reply-To: <3b7ddf9df487575f1fafa7c35d8653ba0181329e.1795891579.git.chris@chrisdown.name>

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


  reply	other threads:[~2026-11-29  8:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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) [this message]
2026-11-29  5:51 ` [PATCH 2/2] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down

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=c182f78c-49b7-4526-a3ef-fd56c1b12c0e@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=audit@vger.kernel.org \
    --cc=chris@chrisdown.name \
    --cc=kees@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mason@kernel.org \
    --cc=mhocko@suse.com \
    --cc=paul@paul-moore.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=w@1wt.eu \
    /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