From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795941961; b=EMOHxF0TKfjA9ZGp7/Mz+fM6eSD5aWOVHYqe7Dy23V3MWIhWGydekL42cStXwVemy78R yDVMSVKO3kre9+DnEEkQT8tiPiVG7Jrq8zP9UnTkvMbf5xlYV6WHVHPYJiGfnFJbVNdek NONTTH3lC7+jhHWa2gR40AQ+wyWsQyaxd/yc27WZMh5v8DnjF70XyGAvh0J3F5QcLzIpS J53H2aAIrCm/RgEQJ/6CMJQtAli2XM/LtaOqHYkVLDYYlBUmexqhQGN8PZG5gtMYnfmA2 MhBeI3z8wO91+YDG+k/UVAi6A1MTKSj4JKrSCkcE15RVkYODOQwHkHpj9hhH+emIcrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795941961; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=eo7U2FbnxS53nD69A1zV7ucNbyAlXOqAqRxbzjv8iNU=; b=PEPzuiEGDUA3walPBW8b1T7lFjtdbx2SzUh573FTUvzwaW34US/c3mSTJ2FEOes95Xgp 1eaDHU+8cAEk0ArbQo1TSvfX15+pBLaUD+xFGU/l2MuT89/+vkUizgu1QqpW/8KrxT+VP qnqyytx9mWhY1OjQsp+qGEdg/E0ZfGiWwiOL+ISlcX186X354HuSaa2LwbmrALvjkVCIr JT77KAcJpCVFYkcaMzl3GThL9XjzYSxSJYMTkGJNxsPoYfknLiYxsdke5zYeCSz5fHzOs nArwEzR5kqUwpfyrzaRxd5TzVBcc15Df3aUf+TsQp3m0kCv+iqcHyRt5fAKOR7aOIkw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VGACdhW4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A54F606A31C; Sun, 29 Nov 2026 08:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=VGACdhW4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D6BF1F00898; Sun, 29 Nov 2026 08:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795941961; bh=eo7U2FbnxS53nD69A1zV7ucNbyAlXOqAqRxbzjv8iNU=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=VGACdhW4CUkzvGLctZCduKKCNHrzq3vEElABCOoWu2OvGq49ISNd4dgEqcbYCjoVf Vj8o6VfFNn8LG0QDZ+jGqHQizHfYEUHI6rvS4NeTFYpiPsiD5k9Nk7Ee6wLzsqFEXP HkUM1mkHvo1lAAN69FoegMVc/zOW3g7spTY1XdReKjuGYpSNbf/DjuAZZwNf/EQoAx An6Kyj35hvFJslpgDYkaitfbaky86k8Cy5o2W7PNIo9sK+7CcEhkh1oS7RT8JjFK2B BpWqEwlS3X+QwF9P3yRzTJQErdLvxImsDBYF6aouNmy3A8Xb+67pXK3WU28kWTiqff W5IBYc5t4kEvQ== Message-ID: Date: Sun, 29 Nov 2026 09:45:53 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] mm/util: don't let get_cmdline() stall on file-backed arguments To: Chris Down , Andrew Morton Cc: Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Mason , Paul Moore , Kees Cook , Willy Tarreau , audit@vger.kernel.org References: <3b7ddf9df487575f1fafa7c35d8653ba0181329e.1795891579.git.chris@chrisdown.name> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzS5EYXZpZCBIaWxk ZW5icmFuZCAoQ3VycmVudCkgPGRhdmlkQGtlcm5lbC5vcmc+wsGQBBMBCAA6AhsDBQkmWAik AgsJBB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8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <3b7ddf9df487575f1fafa7c35d8653ba0181329e.1795891579.git.chris@chrisdown.name> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 > --- > 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 Date: Wed Nov 18 22:16:20 2026 +0100 mm: read only anonymous memory in get_cmdline() get_cmdline() returns internally what /proc//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//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 [ david: simplify description, drop comment ] Signed-off-by: David Hildenbrand (Arm) 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