From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A579FC282EC for ; Tue, 18 Mar 2025 15:51:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C67F280002; Tue, 18 Mar 2025 11:51:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87449280001; Tue, 18 Mar 2025 11:51:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73CF7280002; Tue, 18 Mar 2025 11:51:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 518AD280001 for ; Tue, 18 Mar 2025 11:51:21 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 153851A0189 for ; Tue, 18 Mar 2025 15:51:21 +0000 (UTC) X-FDA: 83235111162.27.5707CF7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf10.hostedemail.com (Postfix) with ESMTP id 4AED4C000E for ; Tue, 18 Mar 2025 15:51:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZDRtp2xu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of kees@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742313079; a=rsa-sha256; cv=none; b=OGSkEsx7A+HSlhCHgq1r8MdQR1aSWfIjDdW6dnCt8UdjN1R9cJGdsBLRmtfURJm6W6jc6a uYsD3j7JbCKIaDVhEeI339249nojMCdLB1+dd/7lmG/pSuDLYwd6R6YmZcjYHT5D6FfSl7 IW4uBZxoicGw/4LsKavpxB6ImmfYIUE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZDRtp2xu; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of kees@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742313079; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iwONymIZLgIN4cjumNSEcbQTb3b/t7dQLIHriuB4mjI=; b=0Jj6XJ7LD+FiYzsN/6Q4Z29NF2C0PIVT5gUYi7DcypgcKOwKoR4fJ3pvCAtxB6595JqxMJ uLt1laldOThXC5NPnoFgAhKQ5ECOgo+oDrw2mx4QCz6dikRSBOwXKgeKafG7vCRCY8y6eM aV8t2owZZR+ohxwEbcfFXCez4Sdj2z4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E2A78A48ABC; Tue, 18 Mar 2025 15:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FB81C4CEDD; Tue, 18 Mar 2025 15:51:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742313078; bh=cUwvZQQ+NjakBpbZKcTfx3t1d3Z+pAZHSuUAZGVxDxE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZDRtp2xuLYROQzbQK0ZXRpd/eWbvAUBk+xosqGBpv4QyNuXbt5tWpBrOCCdXzKHRh dgnAXbktka2ZLS25yb09k+fyai7woE9wmk4uPzhKSYeDWFLAB2Du05CZBd0ujHnXOP GfRPFvWNYW0M+LiXAnL1PbpMA1haUl885t/s2xrFPKWfq6ns/MwHOuOMPmuQXZ0SwE x9RrEmMNgy4p6j5tyYwkvRHYyPj+T8oF68TqrXf5wNnDIgsKpLMCrmn4AiW7NgeitG IdNBoBHj/ri2USwpaTRwW2SaQ6fKw+AHJpm8PvrDfg9cWgqYq079CIUcfjUM8Uc3fr xW9pmgpkWQPOQ== Date: Tue, 18 Mar 2025 08:51:14 -0700 From: Kees Cook To: Bhupesh Sharma Cc: Andres Rodriguez , Bhupesh , akpm@linux-foundation.org, kernel-dev@igalia.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com, laoar.shao@gmail.com, pmladek@suse.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com, mirq-linux@rere.qmqm.pl, peterz@infradead.org, willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk, ebiederm@xmission.com, brauner@kernel.org, jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com Subject: Re: [PATCH RFC 0/2] Dynamically allocate memory to store task's full name Message-ID: <202503180846.EAB79290D@keescook> References: <20250314052715.610377-1-bhupesh@igalia.com> <202503141420.37D605B2@keescook> <8b11d5f6-bb16-7af6-8377-bb0951fcfb60@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8b11d5f6-bb16-7af6-8377-bb0951fcfb60@igalia.com> X-Stat-Signature: 6dhw6exqx6e53hyjp3sehqeiupq6d19p X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4AED4C000E X-Rspam-User: X-HE-Tag: 1742313079-628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H7ZQqs24T0IoAoYoSjavSaBdbGbsPMJIOUrloGWi/XcBQsR3NButao8M4D5ySZUQhvvdHwJYiuVLlpRfHXZlkxhBxhN0oYnmUqCeXjKJBjXz1ahoPOjkrhMCz1DuT8abOwAKeQ9TxodJ8Z1YjI4OC9o4KI0vb+g0K/44R23BkoimwNenADt6/0pX+s6mUvS7ZdpRfEzDqDHSwbjiAm7N6K6BqK1lKfXWaj4eUE98gZH3N3sQbVOj0U4Zz/LKYUBRriS4p9UFUDOCV9HWI12KrUgtd7EhVBZbLYIWT+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Mar 18, 2025 at 04:49:28PM +0530, Bhupesh Sharma wrote: > On 3/15/25 1:13 PM, Andres Rodriguez wrote: > > On 3/14/25 14:25, Kees Cook wrote: > > > On Fri, Mar 14, 2025 at 10:57:13AM +0530, Bhupesh wrote: > > > > While working with user-space debugging tools which work especially > > > > on linux gaming platforms, I found that the task name is truncated due > > > > to the limitation of TASK_COMM_LEN. > > > > > > > > For example, currently running 'ps', the task->comm value of a long > > > > task name is truncated due to the limitation of TASK_COMM_LEN. > > > >      create_very_lon > > > > > > > > This leads to the names passed from userland via pthread_setname_np() > > > > being truncated. > > > > > > So there have been long discussions about "comm", and it mainly boils > > > down to "leave it alone". For the /proc-scraping tools like "ps" and > > > "top", they check both "comm" and "cmdline", depending on mode. The more > > > useful (and already untruncated) stuff is in "cmdline", so I suspect it > > > may make more sense to have pthread_setname_np() interact with that > > > instead. Also TASK_COMM_LEN is basically considered userspace ABI at > > > this point and we can't sanely change its length without breaking the > > > world. > > > > > > > Completely agree that comm is best left untouched. TASK_COMM_LEN is > > embedded into the kernel and the pthread ABI changes here should be > > avoided. > > > > So, basically my approach _does not_ touch TASK_COMM_LEN at all. The normal > 'TASK_COMM_LEN' 16byte design remains untouched. > Which means that all the legacy / existing ABi which uses 'task->comm' and > hence are designed / written to handle 'TASK_COMM_LEN' 16-byte name, > continue to work as before using '/proc/$pid/task/$tid/comm'. > > This change-set only adds a _parallel_ dynamically allocated > 'task->full_name' which can be used by interested users via > '/proc/$pid/task/$tid/full_name'. I don't want to add this to all processes at exec time as the existing solution works for those processes: read /proc/$pid/cmdline. That said, adding another pointer to task_struct isn't to bad I guess, and it could be updated by later calls. Maybe by default it just points to "comm". > I am fine with adding either '/proc/$pid/task/$tid/full_name' or > '/proc/$pid/task/$tid/debug_name' (actually both of these achieve the same). > The new / modified users (especially the debug applications you listed > above) can switch easily to using '/proc/$pid/task/$tid/full_name' instead > of ''/proc/$pid/task/$tid/comm' > > AFAIK we already achieved for the kthreads using d6986ce24fc00 ("kthread: > dynamically allocate memory to store kthread's full name"), which adds > 'full_name' in parallel to 'comm' for kthread names. If we do this for task_struct, we should remove "full_name" from kthread and generalize it for all processes. -- Kees Cook