From nobody Mon May 25 06:43:07 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AD673CF049; Sun, 17 May 2026 18:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043042; cv=none; b=aQEtuDVriMJ0M/svaOOS8wfu7/4tVI8d8sAg1FX986j/m6ZmD1azfe5KdmyISvvz2add4VLqAdsQcFIO9MamrcowIrjFCYsE3ZTkjhv3c7oq0WOeoosOqlIRF73P546v3CXOmqV0L26LOxiQrt/9vel2Xo6a+RhtIFeomfN2sAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043042; c=relaxed/simple; bh=IzfWb3FIR60iFfSyvP7+1f4VtR+EYtoEKOgTcB72TyY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=exdXCfDBu+C5kYFO9xwsKuvxLfzj2zRLXK/2PI3gHrtbo1/QL0pSLJuwgsqGGGeO/+9pRUpapwHPKcStaXVO8hhZ1a8kk9co5cHa5qazbCrv+WBfXUGGVoDftPEKrgW/QNYvb1DBi3vj/QdBXj1dHppqThOTftZJSzO4f1aNyFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=O/JinnuG; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="O/JinnuG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jA0jwO8NqAbbwvetC+CA7ZxVTwLGbB+JAjjbDxxkNIo=; b=O/JinnuGiGhzy01uMYkZrNHAid FNpw8ojhEVNvS+5fkDEuqe13fStMmXjCP1zAqPkX1GysQki04I7mUOlpTPAWoPQVzxytJbnDsRDVl qoXhNizkQ/9oUU/Fva8KtP8IWVfDgmWd2L1ZjwUTFJYXnXQk04jDGYFs1M1Jq0iBnRrf0pNlIDaT3 GxOSd8vsxkawJaYOF+ghOJ5bTeBb8MssDeCnDH3Y5xl0tifUZp6OoiXngzHMX1QaiY6MvDiF8oCKo nUOFbCIJXM3eD0wcpdtcbkz3Cb4/GJPnwimZLAT3dycZpadsU75Zbki6rX+mj2m83z5daWnCM/Zrx wj3gLUAg==; Received: from [179.193.2.40] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wOgM8-001cLz-Sf; Sun, 17 May 2026 20:36:53 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 17 May 2026 15:36:11 -0300 Subject: [PATCH 1/6] sched: Update get_task_comm() comment Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-tonyk-long_name-v1-1-3c282eaa91e2@igalia.com> References: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> In-Reply-To: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> To: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, David Laight , Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org, Bhupesh , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Since commit 3a3f61ce5e0b ("exec: Make sure task->comm is always NUL-terminated"), __set_task_comm() no longer uses strscpy_pad(). Update the stale comment accordingly. Co-developed-by: Bhupesh Signed-off-by: Bhupesh Signed-off-by: Andr=C3=A9 Almeida --- include/linux/sched.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 368c7b4d7cb5..60d004a49a27 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2005,7 +2005,7 @@ extern void __set_task_comm(struct task_struct *tsk, = const char *from, bool exec * User space can randomly change their names anyway, so locking for rea= ders * doesn't make sense. For writers, locking is probably necessary, as a = race * condition could lead to long-term mixed results. - * The strscpy_pad() in __set_task_comm() can ensure that the task comm = is + * The logic inside __set_task_comm() ensures that the task comm is * always NUL-terminated and zero-padded. Therefore the race condition b= etween * reader and writer is not an issue. * --=20 2.54.0 From nobody Mon May 25 06:43:07 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67A0D3CEBBB; Sun, 17 May 2026 18:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043043; cv=none; b=Ni3X4IrvNmu9OmUIztsX1uwtNwdBR2NF+EF/mvqb4aa/WDAepUwxlOmIHELL0X/Wi8ZVZeJf6NIbu8z7GnSmi1Eplv0VTNMt+phfkmeJp39oteLq/LcrpKBD+Jquib2i+b3nsJ7xIH+vahtNuffQrt4SGGmwtvGsSD3qsGty3fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043043; c=relaxed/simple; bh=mIENcpgWYZdJyFUjos5wRPSiJnbTL+awczLAF8Eprvs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f3FiR8N1GkeO/nHwNWvN4WzE7Jw+S2x/8uqlq6KDwg7RvdrfcIizzK+qL8aMJsQEUheFzkOQHnm2ZM98SWAqedVCRYDq8nUPvkw10FarlCFz7rWVGAaubsOCetxKDYtjmb49uIyQLi/WiJOyWrnYAezPPXw9pjg/Ko9Xw1ie2pI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=jwdfCr1n; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="jwdfCr1n" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yuo9ZBEeU6JatQxAD5qGTp8gG9D/rBQJB1zd4jdqZnQ=; b=jwdfCr1naca0+SgNY7Fg6nzwJ/ ZRQJSEbbDbbmNMAKTqPq2VKnwKg9paRsZzpLquf1QLKtwWShG6RJO6qP7W5lr9Rp52XYu47Sb39pD 2m7SXOyCQMJEFEmBwjLtBsxDDoy6yp7WCVAkKukBd6aVzSFCT0aDSeaazYvvQIVq2kfYdBtFcSfg0 jL0keziT5QhEHoMbhUlneScxpXeG0XcN8hSRgVf6SYzYd+a8hT75igcTBIbM1hR7/c6Pyv+IRuIaZ oacU0fbvlhWyqitJrt54+7WiP/yJKLPW2EsQMBXGCVXkHVR64uZm0A43uWmke5alhSHoTYtZUbhgH rZBeSYCw==; Received: from [179.193.2.40] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wOgME-001cLz-8l; Sun, 17 May 2026 20:36:58 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 17 May 2026 15:36:12 -0300 Subject: [PATCH 2/6] treewide: Get rid of get_task_comm() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-tonyk-long_name-v1-2-3c282eaa91e2@igalia.com> References: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> In-Reply-To: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> To: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, David Laight , Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org, Bhupesh , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Since commit 4cc0473d7754 ("get rid of __get_task_comm()"), get_task_comm() does just a redundant check for the buffer size and call strscpy_pad(). Replace get_task_comm() calls with strscpy_pad(), that will do the right thing if the buffers sizes doesn't match: zero-pad if it's bigger, and truncate if it's smaller. Link: https://lore.kernel.org/lkml/CAHk-=3Dwi5c=3D_-FBGo_88CowJd_F-Gi6Ud9d= =3DTALm65ReN7YjrMw@mail.gmail.com/ Co-developed-by: Bhupesh Signed-off-by: Bhupesh Signed-off-by: Andr=C3=A9 Almeida --- drivers/connector/cn_proc.c | 2 +- drivers/dma-buf/sw_sync.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 2 +- drivers/gpu/drm/lima/lima_ctx.c | 2 +- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 2 +- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 2 +- drivers/hwtracing/stm/core.c | 2 +- drivers/tty/tty_audit.c | 2 +- fs/binfmt_elf.c | 2 +- fs/binfmt_elf_fdpic.c | 2 +- fs/proc/array.c | 2 +- include/linux/sched.h | 19 ------------------- kernel/audit.c | 6 ++++-- kernel/auditsc.c | 6 ++++-- kernel/printk/printk.c | 2 +- kernel/sys.c | 2 +- net/bluetooth/hci_sock.c | 2 +- net/netfilter/nf_tables_api.c | 2 +- security/integrity/integrity_audit.c | 3 ++- security/ipe/audit.c | 2 +- security/landlock/domain.c | 2 +- security/lsm_audit.c | 7 ++++--- 29 files changed, 39 insertions(+), 52 deletions(-) diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c index 0056ab81fbc3..c78243ed3c2a 100644 --- a/drivers/connector/cn_proc.c +++ b/drivers/connector/cn_proc.c @@ -278,7 +278,7 @@ void proc_comm_connector(struct task_struct *task) ev->what =3D PROC_EVENT_COMM; ev->event_data.comm.process_pid =3D task->pid; ev->event_data.comm.process_tgid =3D task->tgid; - get_task_comm(ev->event_data.comm.comm, task); + strscpy_pad(ev->event_data.comm.comm, task->comm); =20 memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack =3D 0; /* not used */ diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index 8df20b0218a9..d501657ad801 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -312,7 +312,7 @@ static int sw_sync_debugfs_open(struct inode *inode, st= ruct file *file) struct sync_timeline *obj; char task_comm[TASK_COMM_LEN]; =20 - get_task_comm(task_comm, current); + strscpy_pad(task_comm, current->comm); =20 obj =3D sync_timeline_create(task_comm); if (!obj) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c b/drivers/gpu= /drm/amd/amdgpu/amdgpu_amdkfd_fence.c index 6a364357522b..13c8857e4ffb 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c @@ -74,7 +74,7 @@ struct amdgpu_amdkfd_fence *amdgpu_amdkfd_fence_create(u6= 4 context, /* This reference gets released in amdkfd_fence_release */ mmgrab(mm); fence->mm =3D mm; - get_task_comm(fence->timeline_name, current); + strscpy_pad(fence->timeline_name, current->comm); spin_lock_init(&fence->lock); fence->svm_bo =3D svm_bo; fence->context_id =3D context_id; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c b/drivers/g= pu/drm/amd/amdgpu/amdgpu_eviction_fence.c index 4c5e38dea4c2..faf0f36d8328 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c @@ -129,7 +129,7 @@ int amdgpu_evf_mgr_rearm(struct amdgpu_eviction_fence_m= gr *evf_mgr, return -ENOMEM; =20 ev_fence->evf_mgr =3D evf_mgr; - get_task_comm(ev_fence->timeline_name, current); + strscpy_pad(ev_fence->timeline_name, current->comm); spin_lock_init(&ev_fence->lock); dma_fence_init64(&ev_fence->base, &amdgpu_eviction_fence_ops, &ev_fence->lock, evf_mgr->ev_fence_ctx, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/= amdgpu/amdgpu_ras.c index 6c644cfe6695..c45630457155 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -4419,7 +4419,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev) } =20 con->init_task_pid =3D task_pid_nr(current); - get_task_comm(con->init_task_comm, current); + strscpy_pad(con->init_task_comm, current->comm); =20 mutex_init(&con->critical_region_lock); INIT_LIST_HEAD(&con->critical_region_head); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/= drm/amd/amdgpu/amdgpu_userq_fence.c index e2d5f04296e1..8fdc38d8d64d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c @@ -85,7 +85,7 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device = *adev, =20 fence_drv->adev =3D adev; fence_drv->context =3D dma_fence_context_alloc(1); - get_task_comm(fence_drv->timeline_name, current); + strscpy_pad(fence_drv->timeline_name, current->comm); =20 *fence_drv_req =3D fence_drv; =20 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/a= mdgpu/amdgpu_vm.c index 9ba9de16a27a..de80d0ace905 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -2571,10 +2571,10 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) return; =20 vm->task_info->task.pid =3D current->pid; - get_task_comm(vm->task_info->task.comm, current); + strscpy_pad(vm->task_info->task.comm, current->comm); =20 vm->task_info->tgid =3D current->tgid; - get_task_comm(vm->task_info->process_name, current->group_leader); + strscpy_pad(vm->task_info->process_name, current->group_leader->comm); } =20 /** diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm= /amd/amdgpu/amdgpu_vram_mgr.c index 2a241a5b12c4..f8ce59d8587a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -563,7 +563,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_mana= ger *man, } =20 vres->task.pid =3D task_pid_nr(current); - get_task_comm(vres->task.comm, current); + strscpy_pad(vres->task.comm, current->comm); list_add_tail(&vres->vres_node, &mgr->allocated_vres_list); =20 if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && adjust_dcc_size) { diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ct= x.c index 68ede7a725e2..e8c5c3601bf1 100644 --- a/drivers/gpu/drm/lima/lima_ctx.c +++ b/drivers/gpu/drm/lima/lima_ctx.c @@ -29,7 +29,7 @@ int lima_ctx_create(struct lima_device *dev, struct lima_= ctx_mgr *mgr, u32 *id) goto err_out0; =20 ctx->pid =3D task_pid_nr(current); - get_task_comm(ctx->pname, current); + strscpy_pad(ctx->pname, current->comm); =20 return 0; =20 diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panf= rost/panfrost_gem.c index 3a7fce428898..11936c4d3573 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -36,7 +36,7 @@ static void panfrost_gem_debugfs_bo_add(struct panfrost_d= evice *pfdev, struct panfrost_gem_object *bo) { bo->debugfs.creator.tgid =3D current->tgid; - get_task_comm(bo->debugfs.creator.process_name, current->group_leader); + strscpy_pad(bo->debugfs.creator.process_name, current->group_leader->comm= ); =20 mutex_lock(&pfdev->debugfs.gems_lock); list_add_tail(&bo->debugfs.node, &pfdev->debugfs.gems_list); diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/pantho= r/panthor_gem.c index cd49859da89b..b44fd715c17e 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -46,7 +46,7 @@ static void panthor_gem_debugfs_bo_add(struct panthor_gem= _object *bo) struct panthor_device, base); =20 bo->debugfs.creator.tgid =3D current->tgid; - get_task_comm(bo->debugfs.creator.process_name, current->group_leader); + strscpy_pad(bo->debugfs.creator.process_name, current->group_leader->comm= ); =20 mutex_lock(&ptdev->gems.lock); list_add_tail(&bo->debugfs.node, &ptdev->gems.node); diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/pant= hor/panthor_sched.c index 2fe04d0f0e3a..8ee9de96acf6 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -3603,7 +3603,7 @@ static void group_init_task_info(struct panthor_group= *group) struct task_struct *task =3D current->group_leader; =20 group->task_info.pid =3D task->pid; - get_task_comm(group->task_info.comm, task); + strscpy_pad(group->task_info.comm, task->comm); } =20 static void add_group_kbo_sizes(struct panthor_device *ptdev, diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virti= o/virtgpu_ioctl.c index c33c057365f8..d2bf221e8f01 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -50,7 +50,7 @@ static void virtio_gpu_create_context_locked(struct virti= o_gpu_device *vgdev, } else { char dbgname[TASK_COMM_LEN]; =20 - get_task_comm(dbgname, current); + strscpy_pad(dbgname, current->comm); virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, vfpriv->context_init, strlen(dbgname), dbgname); diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index f48c6a8a0654..c7715439964e 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -634,7 +634,7 @@ static ssize_t stm_char_write(struct file *file, const = char __user *buf, char comm[sizeof(current->comm)]; char *ids[] =3D { comm, "default", NULL }; =20 - get_task_comm(comm, current); + strscpy_pad(comm, current->comm); =20 err =3D stm_assign_first_policy(stmf->stm, &stmf->output, ids, 1); /* diff --git a/drivers/tty/tty_audit.c b/drivers/tty/tty_audit.c index d014af6ab060..d514a81d0a5c 100644 --- a/drivers/tty/tty_audit.c +++ b/drivers/tty/tty_audit.c @@ -77,7 +77,7 @@ static void tty_audit_log(const char *description, dev_t = dev, audit_log_format(ab, "%s pid=3D%u uid=3D%u auid=3D%u ses=3D%u major=3D%d = minor=3D%d comm=3D", description, pid, uid, loginuid, sessionid, MAJOR(dev), MINOR(dev)); - get_task_comm(name, current); + strscpy_pad(name, current->comm); audit_log_untrustedstring(ab, name); audit_log_format(ab, " data=3D"); audit_log_n_hex(ab, data, size); diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 16a56b6b3f6c..d25922460b63 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1557,7 +1557,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, s= truct task_struct *p, SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); rcu_read_unlock(); - get_task_comm(psinfo->pr_fname, p); + strscpy_pad(psinfo->pr_fname, p->comm); =20 return 0; } diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 7e3108489c83..c4d4e59ff34d 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1371,7 +1371,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, s= truct task_struct *p, SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); rcu_read_unlock(); - get_task_comm(psinfo->pr_fname, p); + strscpy_pad(psinfo->pr_fname, p->comm); =20 return 0; } diff --git a/fs/proc/array.c b/fs/proc/array.c index 90fb0c6b5f99..c8c3fbd9bfa9 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -110,7 +110,7 @@ void proc_task_name(struct seq_file *m, struct task_str= uct *p, bool escape) else if (p->flags & PF_KTHREAD) get_kthread_comm(tcomm, sizeof(tcomm), p); else - get_task_comm(tcomm, p); + strscpy_pad(tcomm, p->comm); =20 if (escape) seq_escape_str(m, tcomm, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\"); diff --git a/include/linux/sched.h b/include/linux/sched.h index 60d004a49a27..b6de742b1155 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2000,25 +2000,6 @@ extern void __set_task_comm(struct task_struct *tsk,= const char *from, bool exec __set_task_comm(tsk, from, false); \ }) =20 -/* - * - Why not use task_lock()? - * User space can randomly change their names anyway, so locking for rea= ders - * doesn't make sense. For writers, locking is probably necessary, as a = race - * condition could lead to long-term mixed results. - * The logic inside __set_task_comm() ensures that the task comm is - * always NUL-terminated and zero-padded. Therefore the race condition b= etween - * reader and writer is not an issue. - * - * - BUILD_BUG_ON() can help prevent the buf from being truncated. - * Since the callers don't perform any return value checks, this safegua= rd is - * necessary. - */ -#define get_task_comm(buf, tsk) ({ \ - BUILD_BUG_ON(sizeof(buf) < TASK_COMM_LEN); \ - strscpy_pad(buf, (tsk)->comm); \ - buf; \ -}) - static __always_inline void scheduler_ipi(void) { /* diff --git a/kernel/audit.c b/kernel/audit.c index e1d489bc2dff..6fc867adbf3d 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1662,7 +1662,8 @@ static void audit_log_multicast(int group, const char= *op, int err) audit_put_tty(tty); audit_log_task_context(ab); /* subj=3D */ audit_log_format(ab, " comm=3D"); - audit_log_untrustedstring(ab, get_task_comm(comm, current)); + strscpy_pad(comm, current->comm); + audit_log_untrustedstring(ab, comm); audit_log_d_path_exe(ab, current->mm); /* exe=3D */ audit_log_format(ab, " nl-mcgrp=3D%d op=3D%s res=3D%d", group, op, !err); audit_log_end(ab); @@ -2465,7 +2466,8 @@ void audit_log_task_info(struct audit_buffer *ab) audit_get_sessionid(current)); audit_put_tty(tty); audit_log_format(ab, " comm=3D"); - audit_log_untrustedstring(ab, get_task_comm(comm, current)); + strscpy_pad(comm, current->comm); + audit_log_untrustedstring(ab, comm); audit_log_d_path_exe(ab, current->mm); audit_log_task_context(ab); } diff --git a/kernel/auditsc.c b/kernel/auditsc.c index ab54fccba215..8e4f70105a13 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2877,7 +2877,8 @@ void __audit_log_nfcfg(const char *name, u8 af, unsig= ned int nentries, audit_log_format(ab, " pid=3D%u", task_tgid_nr(current)); audit_log_task_context(ab); /* subj=3D */ audit_log_format(ab, " comm=3D"); - audit_log_untrustedstring(ab, get_task_comm(comm, current)); + strscpy_pad(comm, current->comm); + audit_log_untrustedstring(ab, comm); audit_log_end(ab); } EXPORT_SYMBOL_GPL(__audit_log_nfcfg); @@ -2900,7 +2901,8 @@ static void audit_log_task(struct audit_buffer *ab) sessionid); audit_log_task_context(ab); audit_log_format(ab, " pid=3D%d comm=3D", task_tgid_nr(current)); - audit_log_untrustedstring(ab, get_task_comm(comm, current)); + strscpy_pad(comm, current->comm); + audit_log_untrustedstring(ab, comm); audit_log_d_path_exe(ab, current->mm); } =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0323149548f6..1f04e753ca02 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2247,7 +2247,7 @@ static u16 printk_sprint(char *text, u16 size, int fa= cility, static void printk_store_execution_ctx(struct printk_info *info) { info->caller_id2 =3D printk_caller_id2(); - get_task_comm(info->comm, current); + strscpy_pad(info->comm, current->comm); } =20 static void pmsg_load_execution_ctx(struct printk_message *pmsg, diff --git a/kernel/sys.c b/kernel/sys.c index 62e842055cc9..1d5152d2395e 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2609,7 +2609,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, ar= g2, unsigned long, arg3, proc_comm_connector(me); break; case PR_GET_NAME: - get_task_comm(comm, me); + strscpy_pad(comm, me->comm); if (copy_to_user((char __user *)arg2, comm, sizeof(comm))) return -EFAULT; break; diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 0290dea081f6..38e16ba2de38 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -106,7 +106,7 @@ static bool hci_sock_gen_cookie(struct sock *sk) id =3D 0xffffffff; =20 hci_pi(sk)->cookie =3D id; - get_task_comm(hci_pi(sk)->comm, current); + strscpy_pad(hci_pi(sk)->comm, current->comm); return true; } =20 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 87387adbca65..d859ffa2874c 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -9711,7 +9711,7 @@ static int nf_tables_fill_gen_info(struct sk_buff *sk= b, struct net *net, =20 if (nla_put_be32(skb, NFTA_GEN_ID, htonl(nft_base_seq(net))) || nla_put_be32(skb, NFTA_GEN_PROC_PID, htonl(task_pid_nr(current))) || - nla_put_string(skb, NFTA_GEN_PROC_NAME, get_task_comm(buf, current))) + nla_put_string(skb, NFTA_GEN_PROC_NAME, strscpy_pad(buf, current->com= m))) goto nla_put_failure; =20 nlmsg_end(skb, nlh); diff --git a/security/integrity/integrity_audit.c b/security/integrity/inte= grity_audit.c index d8d9e5ff1cd2..98060060929d 100644 --- a/security/integrity/integrity_audit.c +++ b/security/integrity/integrity_audit.c @@ -54,7 +54,8 @@ void integrity_audit_message(int audit_msgno, struct inod= e *inode, audit_get_sessionid(current)); audit_log_task_context(ab); audit_log_format(ab, " op=3D%s cause=3D%s comm=3D", op, cause); - audit_log_untrustedstring(ab, get_task_comm(name, current)); + strscpy_pad(name, current->comm); + audit_log_untrustedstring(ab, name); if (fname) { audit_log_format(ab, " name=3D"); audit_log_untrustedstring(ab, fname); diff --git a/security/ipe/audit.c b/security/ipe/audit.c index 93fb59fbddd6..c04901baed73 100644 --- a/security/ipe/audit.c +++ b/security/ipe/audit.c @@ -145,7 +145,7 @@ void ipe_audit_match(const struct ipe_eval_ctx *const c= tx, audit_log_format(ab, "ipe_op=3D%s ipe_hook=3D%s enforcing=3D%d pid=3D%d c= omm=3D", op, audit_hook_names[ctx->hook], READ_ONCE(enforce), task_tgid_nr(current)); - audit_log_untrustedstring(ab, get_task_comm(comm, current)); + audit_log_untrustedstring(ab, strscpy_pad(comm, current->comm)); =20 if (ctx->file) { audit_log_d_path(ab, " path=3D", &ctx->file->f_path); diff --git a/security/landlock/domain.c b/security/landlock/domain.c index 06b6bd845060..a35a27f523e6 100644 --- a/security/landlock/domain.c +++ b/security/landlock/domain.c @@ -101,7 +101,7 @@ static struct landlock_details *get_current_details(voi= d) memcpy(details->exe_path, path_str, path_size); details->pid =3D get_pid(task_tgid(current)); details->uid =3D from_kuid(&init_user_ns, current_uid()); - get_task_comm(details->comm, current); + strscpy_pad(details->comm, current->comm); return details; } =20 diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 737f5a263a8f..a587ffecd985 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -276,8 +276,8 @@ void audit_log_lsm_data(struct audit_buffer *ab, if (pid) { char tskcomm[sizeof(tsk->comm)]; audit_log_format(ab, " opid=3D%d ocomm=3D", pid); - audit_log_untrustedstring(ab, - get_task_comm(tskcomm, tsk)); + strscpy_pad(tskcomm, tsk->comm); + audit_log_untrustedstring(ab, tskcomm); } } break; @@ -417,7 +417,8 @@ static void dump_common_audit_data(struct audit_buffer = *ab, char comm[sizeof(current->comm)]; =20 audit_log_format(ab, " pid=3D%d comm=3D", task_tgid_nr(current)); - audit_log_untrustedstring(ab, get_task_comm(comm, current)); + strscpy_pad(comm, current->comm); + audit_log_untrustedstring(ab, comm); audit_log_lsm_data(ab, a); } =20 --=20 2.54.0 From nobody Mon May 25 06:43:07 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFA313B52E2; Sun, 17 May 2026 18:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043044; cv=none; b=ttZTkltvAEL3sb0QDITmXlZku8pE76Z9XQN0q1mFPFf4cTXqZmYTUF209hHVYlbZLysAKfo10JXk7CtBBn2bCjwrxqI09KjVfM7AiUiO55J5i2udYgJwNeKtRAhVPeCgVaaJdyXRDa8Kr5BMuvKYUUzeFLRs4JuHpJShUajCcR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043044; c=relaxed/simple; bh=kVodm9LMpgNVXUQFAY7Q3oZjOCA1cRri8mhLSWd3dyM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QZ/bOz+usgGznJHSPOyRAw9VJKaQ75MZvmKxBixwRcKQ3qHEfRkzBnk6cWpf4s6j5BzhzlBMc0ltSOyKQeWKq0K8gOrlFOsgeRWFXHPuMNL2WWtRcWTosOBwiztm4Oe8Lb3Jl6XzuL+C1B9Nrz6ndXBE1NKkT5X/K+vtsP4igYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=VOnrAJZI; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="VOnrAJZI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FlZNLnmdjy9yDSd4c5nakFinf3LBKF7+LBofFSSFz3c=; b=VOnrAJZIgoRLkq2fAPAElAvtiJ JeJ6mawddx1kS/5cPoKOGKqIGPwEU7FEqDzbRA6QuA5rXEEhIglPbneNMiCJcRl12izuzUPtPmvYg uMwSm5hniWPk5YG9ReKCtWrMBVQbp9C6PWBOFfJx+3rujwocoKc2g06QFth0yWIN5xWBrKH7YG5Af gta3qWW401sVs6tMH+HUT9mL/peYi+jSBbwHKiDLfMZyeFP4fCp2iA19jlRRlmgZK93iDKGMbYDyv ZfUsscH9L8XOyNqdvoLWDoaMCmvj+4YWnrdPDfbnz1Kp5YpV5jbxyVe2xJmDldy1xlJBhqtMI8iaJ YZTA2Hkg==; Received: from [179.193.2.40] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wOgMJ-001cLz-Kp; Sun, 17 May 2026 20:37:03 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 17 May 2026 15:36:13 -0300 Subject: [PATCH 3/6] string: Introduce strtostr() for safe and performance string copies Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-tonyk-long_name-v1-3-3c282eaa91e2@igalia.com> References: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> In-Reply-To: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> To: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, David Laight , Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Some parts of the kernel uses memcpy() instead of strscpy() because they are performance sensitive and doesn't care about the return value of strscpy(). One such common case is to copy current->comm to a different buffer. As the command name is guaranteed to be NUL-terminated in the range of TASK_COMM_LEN, this is safe enough and doesn't create unterminated strings. However, in order to expand the size of current->comm, this expectation will be broken and those memcpy() could create such strings without trailing NUL byte. In order to support a fast and safe string copy, create strtostr(), to copy a NUL-terminated string to a new string buffer. If the destination buffer is bigger than the source, no pad is applied, but the string is NUL-terminated. If the destination buffer is smaller, the string is truncated. The last byte of the destination is always set to NUL for safety. Signed-off-by: Andr=C3=A9 Almeida --- include/linux/coredump.h | 2 +- include/linux/string.h | 28 ++++++++++++++++++= ++++ include/linux/tracepoint.h | 4 ++-- include/trace/events/block.h | 10 ++++---- include/trace/events/coredump.h | 2 +- include/trace/events/f2fs.h | 4 ++-- include/trace/events/oom.h | 2 +- include/trace/events/osnoise.h | 2 +- include/trace/events/sched.h | 10 ++++---- include/trace/events/signal.h | 2 +- include/trace/events/task.h | 4 ++-- kernel/printk/nbcon.c | 2 +- kernel/printk/printk.c | 2 +- tools/bpf/bpftool/pids.c | 4 ++-- .../selftests/bpf/test_kmods/bpf_testmod-events.h | 2 +- 15 files changed, 54 insertions(+), 26 deletions(-) diff --git a/include/linux/coredump.h b/include/linux/coredump.h index 68861da4cf7c..b370ef69f673 100644 --- a/include/linux/coredump.h +++ b/include/linux/coredump.h @@ -54,7 +54,7 @@ extern void vfs_coredump(const kernel_siginfo_t *siginfo); do { \ char comm[TASK_COMM_LEN]; \ /* This will always be NUL terminated. */ \ - memcpy(comm, current->comm, sizeof(comm)); \ + strtostr(comm, current->comm); \ printk_ratelimited(Level "coredump: %d(%*pE): " Format "\n", \ task_tgid_vnr(current), (int)strlen(comm), comm, ##__VA_ARGS__); \ } while (0) \ diff --git a/include/linux/string.h b/include/linux/string.h index b850bd91b3d8..ff1f59f4139c 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -445,6 +445,34 @@ void memcpy_and_pad(void *dest, size_t dest_len, const= void *src, size_t count, memcpy(dest, src, strnlen(src, min(_src_len, _dest_len))); \ } while (0) =20 +/** + * strtostr - Copy NUL-terminanted string to NUL-terminate string + * + * @dest: Pointer of destination string + * @src: Pointer to NUL-terminates string + * + * This is a replacement for strcpy() where the caller doesn't care about = the + * return value and if the string is going to be truncated, albeit it needs + * to mark sure that it will be NUL-terminated. Intended for performance + * sensitive cases, such as tracing. + * + * If the destination is bigger than the source, no padding happens. It it= 's + * smaller the strings gets truncated. + * + * Both arguments needs to be arrays with lengths discoverable by the comp= iler. + */ +#define strtostr(dest, src) do { \ + const size_t _dest_len =3D __must_be_cstr(dest) + \ + ARRAY_SIZE(dest); \ + const size_t _src_len =3D __must_be_cstr(src) + \ + __builtin_object_size(src, 1); \ + \ + BUILD_BUG_ON(!__builtin_constant_p(_dest_len) || \ + _dest_len =3D=3D (size_t)-1); \ + memcpy(dest, src, strnlen(src, min(_src_len, _dest_len))); \ + dest[_dest_len - 1] =3D '\0'; \ +} while (0) + /** * memtostr - Copy a possibly non-NUL-term string to a NUL-term string * @dest: Pointer to destination NUL-terminates string diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 763eea4d80d8..19e3cb4ca487 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -615,10 +615,10 @@ static inline struct tracepoint *tracepoint_ptr_deref= (tracepoint_ptr_t *p) * * * * TP_fast_assign( - * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); + * strtostr(__entry->next_comm, next->comm); * __entry->prev_pid =3D prev->pid; * __entry->prev_prio =3D prev->prio; - * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); + * strtostr(__entry->prev_comm, prev->comm); * __entry->next_pid =3D next->pid; * __entry->next_prio =3D next->prio; * ), diff --git a/include/trace/events/block.h b/include/trace/events/block.h index 6aa79e2d799c..779622cadee3 100644 --- a/include/trace/events/block.h +++ b/include/trace/events/block.h @@ -213,7 +213,7 @@ DECLARE_EVENT_CLASS(block_rq, =20 blk_fill_rwbs(__entry->rwbs, rq->cmd_flags); __get_str(cmd)[0] =3D '\0'; - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + strtostr(__entry->comm, current->comm); ), =20 TP_printk("%d,%d %s %u (%s) %llu + %u %s,%u,%u [%s]", @@ -351,7 +351,7 @@ DECLARE_EVENT_CLASS(block_bio, __entry->sector =3D bio->bi_iter.bi_sector; __entry->nr_sector =3D bio_sectors(bio); blk_fill_rwbs(__entry->rwbs, bio->bi_opf); - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + strtostr(__entry->comm, current->comm); ), =20 TP_printk("%d,%d %s %llu + %u [%s]", @@ -434,7 +434,7 @@ TRACE_EVENT(block_plug, ), =20 TP_fast_assign( - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + strtostr(__entry->comm, current->comm); ), =20 TP_printk("[%s]", __entry->comm) @@ -453,7 +453,7 @@ DECLARE_EVENT_CLASS(block_unplug, =20 TP_fast_assign( __entry->nr_rq =3D depth; - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + strtostr(__entry->comm, current->comm); ), =20 TP_printk("[%s] %d", __entry->comm, __entry->nr_rq) @@ -504,7 +504,7 @@ TRACE_EVENT(block_split, __entry->sector =3D bio->bi_iter.bi_sector; __entry->new_sector =3D new_sector; blk_fill_rwbs(__entry->rwbs, bio->bi_opf); - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + strtostr(__entry->comm, current->comm); ), =20 TP_printk("%d,%d %s %llu / %llu [%s]", diff --git a/include/trace/events/coredump.h b/include/trace/events/coredum= p.h index c7b9c53fc498..581768a122f8 100644 --- a/include/trace/events/coredump.h +++ b/include/trace/events/coredump.h @@ -32,7 +32,7 @@ TRACE_EVENT(coredump, =20 TP_fast_assign( __entry->sig =3D sig; - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + strtostr(__entry->comm, current->comm); ), =20 TP_printk("sig=3D%d comm=3D%s", diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h index b5188d2671d7..cc1fd1e01541 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h @@ -2505,7 +2505,7 @@ TRACE_EVENT(f2fs_lock_elapsed_time, =20 TP_fast_assign( __entry->dev =3D sbi->sb->s_dev; - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + strtostr(__entry->comm, p->comm); __entry->pid =3D p->pid; __entry->prio =3D p->prio; __entry->ioprio_class =3D IOPRIO_PRIO_CLASS(ioprio); @@ -2558,7 +2558,7 @@ DECLARE_EVENT_CLASS(f2fs_priority_update, =20 TP_fast_assign( __entry->dev =3D sbi->sb->s_dev; - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + strtostr(__entry->comm, p->comm); __entry->pid =3D p->pid; __entry->lock_name =3D lock_name; __entry->is_write =3D is_write; diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h index 9f0a5d1482c4..61b66928de4d 100644 --- a/include/trace/events/oom.h +++ b/include/trace/events/oom.h @@ -23,7 +23,7 @@ TRACE_EVENT(oom_score_adj_update, =20 TP_fast_assign( __entry->pid =3D task->pid; - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + strtostr(__entry->comm, task->comm); __entry->oom_score_adj =3D task->signal->oom_score_adj; ), =20 diff --git a/include/trace/events/osnoise.h b/include/trace/events/osnoise.h index 3f4273623801..26e42fd1a084 100644 --- a/include/trace/events/osnoise.h +++ b/include/trace/events/osnoise.h @@ -116,7 +116,7 @@ TRACE_EVENT(thread_noise, ), =20 TP_fast_assign( - memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + strtostr(__entry->comm, t->comm); __entry->pid =3D t->pid; __entry->start =3D start; __entry->duration =3D duration; diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 535860581f15..91bc5931e2a3 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -152,7 +152,7 @@ DECLARE_EVENT_CLASS(sched_wakeup_template, ), =20 TP_fast_assign( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + strtostr(__entry->comm, p->comm); __entry->pid =3D p->pid; __entry->prio =3D p->prio; /* XXX SCHED_DEADLINE */ __entry->target_cpu =3D task_cpu(p); @@ -237,11 +237,11 @@ TRACE_EVENT(sched_switch, ), =20 TP_fast_assign( - memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); + strtostr(__entry->prev_comm, prev->comm); __entry->prev_pid =3D prev->pid; __entry->prev_prio =3D prev->prio; __entry->prev_state =3D __trace_sched_switch_state(preempt, prev_state, = prev); - memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); + strtostr(__entry->next_comm, next->comm); __entry->next_pid =3D next->pid; __entry->next_prio =3D next->prio; /* XXX SCHED_DEADLINE */ @@ -346,7 +346,7 @@ TRACE_EVENT(sched_process_exit, ), =20 TP_fast_assign( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + strtostr(__entry->comm, p->comm); __entry->pid =3D p->pid; __entry->prio =3D p->prio; /* XXX SCHED_DEADLINE */ __entry->group_dead =3D group_dead; @@ -787,7 +787,7 @@ TRACE_EVENT(sched_skip_cpuset_numa, ), =20 TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + strtostr(__entry->comm, tsk->comm); __entry->pid =3D task_pid_nr(tsk); __entry->tgid =3D task_tgid_nr(tsk); __entry->ngid =3D task_numa_group_id(tsk); diff --git a/include/trace/events/signal.h b/include/trace/events/signal.h index 1db7e4b07c01..8759078b0da9 100644 --- a/include/trace/events/signal.h +++ b/include/trace/events/signal.h @@ -67,7 +67,7 @@ TRACE_EVENT(signal_generate, TP_fast_assign( __entry->sig =3D sig; TP_STORE_SIGINFO(__entry, info); - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + strtostr(__entry->comm, task->comm); __entry->pid =3D task->pid; __entry->group =3D group; __entry->result =3D result; diff --git a/include/trace/events/task.h b/include/trace/events/task.h index b9a129eb54d9..8636ead17cd8 100644 --- a/include/trace/events/task.h +++ b/include/trace/events/task.h @@ -21,7 +21,7 @@ TRACE_EVENT(task_newtask, =20 TP_fast_assign( __entry->pid =3D task->pid; - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + strtostr(__entry->comm, task->comm); __entry->clone_flags =3D clone_flags; __entry->oom_score_adj =3D task->signal->oom_score_adj; ), @@ -46,7 +46,7 @@ TRACE_EVENT(task_rename, =20 TP_fast_assign( __entry->pid =3D task->pid; - memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN); + strtostr(entry->oldcomm, task->comm); strscpy(entry->newcomm, comm, TASK_COMM_LEN); __entry->oom_score_adj =3D task->signal->oom_score_adj; ), diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index d7044a7a214b..5b0c54082876 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -952,7 +952,7 @@ static void wctxt_load_execution_ctx(struct nbcon_write= _context *wctxt, { wctxt->cpu =3D pmsg->cpu; wctxt->pid =3D pmsg->pid; - memcpy(wctxt->comm, pmsg->comm, sizeof(wctxt->comm)); + strtostr(wctxt->comm, pmsg->comm); static_assert(sizeof(wctxt->comm) =3D=3D sizeof(pmsg->comm)); } #else diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1f04e753ca02..231c4d7c3580 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2255,7 +2255,7 @@ static void pmsg_load_execution_ctx(struct printk_mes= sage *pmsg, { pmsg->cpu =3D printk_info_get_cpu(info); pmsg->pid =3D printk_info_get_pid(info); - memcpy(pmsg->comm, info->comm, sizeof(pmsg->comm)); + strtostr(pmsg->comm, info->comm); static_assert(sizeof(pmsg->comm) =3D=3D sizeof(info->comm)); } #else diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c index 23f488cf1740..46b62f65dc43 100644 --- a/tools/bpf/bpftool/pids.c +++ b/tools/bpf/bpftool/pids.c @@ -53,7 +53,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_= entry *e) refs->refs =3D tmp; ref =3D &refs->refs[refs->ref_cnt]; ref->pid =3D e->pid; - memcpy(ref->comm, e->comm, sizeof(ref->comm)); + strtostr(ref->comm, e->comm); ref->comm[sizeof(ref->comm) - 1] =3D '\0'; refs->ref_cnt++; =20 @@ -77,7 +77,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_= entry *e) } ref =3D &refs->refs[0]; ref->pid =3D e->pid; - memcpy(ref->comm, e->comm, sizeof(ref->comm)); + strtostr(ref->comm, e->comm); ref->comm[sizeof(ref->comm) - 1] =3D '\0'; refs->ref_cnt =3D 1; refs->has_bpf_cookie =3D e->has_bpf_cookie; diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod-events.h b/= tools/testing/selftests/bpf/test_kmods/bpf_testmod-events.h index 45a5e41f3a92..72c865ccf1b5 100644 --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod-events.h +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod-events.h @@ -20,7 +20,7 @@ TRACE_EVENT(bpf_testmod_test_read, ), TP_fast_assign( __entry->pid =3D task->pid; - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + strtostr(__entry->comm, task->comm); __entry->off =3D ctx->off; __entry->len =3D ctx->len; ), --=20 2.54.0 From nobody Mon May 25 06:43:07 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 657563CEB84; Sun, 17 May 2026 18:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043043; cv=none; b=lQVE0xQTunFX/N3SgRk89jwMgBZxPFs76sXORfojKqxgEn6+hUQSoo8PSCjwnV5ymjfz2CM0/3ltUGBGKBJAgB0i9FMHiU2AHiC9SIvtVRXNDYFmJDTVxySsw+17QNAfXJI8q5FqeBVXPn7kbV6QE9hsDa9pFgmYoYwLKx1LuWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043043; c=relaxed/simple; bh=wTGET38CD6COu11C+GfxiQLuwWdWIja53YJgU+fO9Ug=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VhLZCM0sxbWZTSkt737Wp0KxlH0JHYjUfBu1UXLQl5ACIpt0o+2TMVRzMNhsShCnKAnWTEc21ikv8ooCerOrbDQGXC/XCbalB6Nj0NZ8kp8ytv9oxBbAgXvArhFYlxGpainAm4+r2SsE1cR73vigv0qg6MMubHFF/ecVgHsXE5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=jYvt3RcS; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="jYvt3RcS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=mTm1itVUL5+eVJJJDMx7jNDUCkEzXL7A51fiJoig9I0=; b=jYvt3RcSvTnOoaO46YZIWqLtZF Jcaxk+Y3HCUWarNvWwQkb8inBe04XwyaEGiIfRRWaixV2Dx3bB1jMlqZ9U51R0GMy34P+je5ttt1K VeJfYi+cko+AAe3cf0tyRHwknRu/DoL0gkfGbJETg5b0uY6UK+YS77bswwr8MHXhBmYLMh32NJ0Hg fzg+1dHm0WfdsBWDjKvKNUlodpVKNPmBy35FgnxDAdU2dkIJ49doxNfgZrS0/drvfaAVqw/qq5uUs 7kcAV2HUdxLB5bIWuk2olWe+etvVOG2We+PCCQ+1OoOHjsRzOsFkSIinTPmLfJRlga5TSwI24TG4n LOUus7LQ==; Received: from [179.193.2.40] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wOgMP-001cLz-0b; Sun, 17 May 2026 20:37:09 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 17 May 2026 15:36:14 -0300 Subject: [PATCH 4/6] sched: Extend task command name to 64 bytes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-tonyk-long_name-v1-4-3c282eaa91e2@igalia.com> References: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> In-Reply-To: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> To: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, David Laight , Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org, Bhupesh , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Command name has been restrict to only 16 bytes, which is too limiting, specially when debugging and tracing complex software with thousands of threads and the need to differentiate them. Just as it was done with kthreads in commit 6b59808bfe48 ("workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status}"), support long names for userspace threads as well. To avoid buffer overflows, cap all existing userspace APIs to TASK_COMM_LEN, and leave the full extended name for a new interface. Co-developed-by: Bhupesh Signed-off-by: Bhupesh Signed-off-by: Andr=C3=A9 Almeida --- fs/proc/array.c | 2 +- include/linux/sched.h | 3 ++- kernel/sys.c | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index c8c3fbd9bfa9..312371eddc7f 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -110,7 +110,7 @@ void proc_task_name(struct seq_file *m, struct task_str= uct *p, bool escape) else if (p->flags & PF_KTHREAD) get_kthread_comm(tcomm, sizeof(tcomm), p); else - strscpy_pad(tcomm, p->comm); + strscpy_pad(tcomm, p->comm, TASK_COMM_LEN); =20 if (escape) seq_escape_str(m, tcomm, ESCAPE_SPACE | ESCAPE_SPECIAL, "\n\\"); diff --git a/include/linux/sched.h b/include/linux/sched.h index b6de742b1155..f7fd2b7d131d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -323,6 +323,7 @@ struct user_event_mm; */ enum { TASK_COMM_LEN =3D 16, + TASK_COMM_EXT_LEN =3D 64, }; =20 extern void sched_tick(void); @@ -1167,7 +1168,7 @@ struct task_struct { * - set it with set_task_comm() to ensure it is always * NUL-terminated and zero-padded */ - char comm[TASK_COMM_LEN]; + char comm[TASK_COMM_EXT_LEN]; =20 struct nameidata *nameidata; =20 diff --git a/kernel/sys.c b/kernel/sys.c index 1d5152d2395e..76d77218ab19 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2535,7 +2535,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, ar= g2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5) { struct task_struct *me =3D current; - unsigned char comm[sizeof(me->comm)]; + unsigned char comm[TASK_COMM_LEN]; long error; =20 error =3D security_task_prctl(option, arg2, arg3, arg4, arg5); @@ -2601,16 +2601,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, = arg2, unsigned long, arg3, error =3D -EINVAL; break; case PR_SET_NAME: - comm[sizeof(me->comm) - 1] =3D 0; + comm[TASK_COMM_LEN - 1] =3D 0; if (strncpy_from_user(comm, (char __user *)arg2, - sizeof(me->comm) - 1) < 0) + TASK_COMM_LEN - 1) < 0) return -EFAULT; set_task_comm(me, comm); proc_comm_connector(me); break; case PR_GET_NAME: - strscpy_pad(comm, me->comm); - if (copy_to_user((char __user *)arg2, comm, sizeof(comm))) + strscpy_pad(comm, me->comm, TASK_COMM_LEN); + if (copy_to_user((char __user *)arg2, comm, TASK_COMM_LEN)) return -EFAULT; break; case PR_GET_ENDIAN: --=20 2.54.0 From nobody Mon May 25 06:43:07 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6EE43CFF62; Sun, 17 May 2026 18:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043046; cv=none; b=f4HqJGDRPOuOPQM+tuLg6+L1wEpDE9ao/3cvKhrLbnEbONlJIwcL+oTjisv6iaz9wcXxtibZFEHrf+vgt4f0E4p1/1qo729U6SO2fVu/axL7ybP7/M+/6nfxREpams25gGNYjoT6EkSXr3tTrPT9WHqigc3qx7zIKpJhzf6uOiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043046; c=relaxed/simple; bh=HOpRwiLSWog/jJRLeZlc2u1UKRPV1E7lSpFIgWK67n0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YxlCNvg/9PXZg0cSZbbXSUXNSEbuFXcWPSgj35P/JA/fcnnC+6ltNqFnC4UQ85ADlOS1tuQu3y7owtpa/9dAM+jke22mJcGYWkJFcYwSafO1mlDBM2tRs2skSccngDDzn1fCZqwwZboNxM/XTZm+jH7vzfXF3Kj416A7X5vzfkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Iebe6Qz7; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Iebe6Qz7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lgKKOAKtBLHbCbNFX0Fho8kvN0dZzv79V8RbAyegXZw=; b=Iebe6Qz7co4TTXTHE6u55ZMsqi nz+6V71obbR9JQjbaVz6iUoGis1PHIB9/M9+AjovPfIzhzmZTeZ/GKw3PRSrZ/nNk4/Tjbn6X/Vz3 RJOfprpK9lp7UCkMK6VkoLQV+uw0iZlC/yDCA+NHdVzUlD3ZnjrLwsaaQv+8MbfCtZS7skvAGXyzj TnV2sn8gRBZJP79ROEnw4/h2kRpdTpCcjbVlDZ/7MGOGXhNiqDNIIyLXDTroRCfMv9EUkXT9NbjZq CzBuinbHpuUhbkNVYl+9wqViLvK+OjlkTbzbZ939b4BMvjjzX09Tl64br4rWy71lFKXiFt+SxFsS4 Z8AuH2kA==; Received: from [179.193.2.40] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wOgMU-001cLz-5c; Sun, 17 May 2026 20:37:14 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 17 May 2026 15:36:15 -0300 Subject: [PATCH 5/6] prctl: Add support for long user thread names Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-tonyk-long_name-v1-5-3c282eaa91e2@igalia.com> References: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> In-Reply-To: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> To: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, David Laight , Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Add support for getting and setting long user thread names with PR_{SET,GET}_EXT_NAME. Signed-off-by: Andr=C3=A9 Almeida --- include/linux/sched.h | 2 +- include/uapi/linux/prctl.h | 3 +++ kernel/sys.c | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index f7fd2b7d131d..fd4256c8627b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1997,7 +1997,7 @@ extern void kick_process(struct task_struct *tsk); =20 extern void __set_task_comm(struct task_struct *tsk, const char *from, boo= l exec); #define set_task_comm(tsk, from) ({ \ - BUILD_BUG_ON(sizeof(from) !=3D TASK_COMM_LEN); \ + BUILD_BUG_ON(sizeof(from) < TASK_COMM_LEN); \ __set_task_comm(tsk, from, false); \ }) =20 diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index b6ec6f693719..a07f8edadd65 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -56,6 +56,9 @@ #define PR_SET_NAME 15 /* Set process name */ #define PR_GET_NAME 16 /* Get process name */ =20 +#define PR_SET_EXT_NAME 17 /* Set extended process name */ +#define PR_GET_EXT_NAME 18 /* Get extended process name */ + /* Get/set process endian */ #define PR_GET_ENDIAN 19 #define PR_SET_ENDIAN 20 diff --git a/kernel/sys.c b/kernel/sys.c index 76d77218ab19..1b70d53da998 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2535,7 +2535,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, ar= g2, unsigned long, arg3, unsigned long, arg4, unsigned long, arg5) { struct task_struct *me =3D current; - unsigned char comm[TASK_COMM_LEN]; + unsigned char comm[TASK_COMM_EXT_LEN]; long error; =20 error =3D security_task_prctl(option, arg2, arg3, arg4, arg5); @@ -2613,6 +2613,19 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, a= rg2, unsigned long, arg3, if (copy_to_user((char __user *)arg2, comm, TASK_COMM_LEN)) return -EFAULT; break; + case PR_SET_EXT_NAME: + comm[TASK_COMM_EXT_LEN - 1] =3D 0; + if (strncpy_from_user(comm, (char __user *)arg2, + TASK_COMM_EXT_LEN - 1) < 0) + return -EFAULT; + set_task_comm(me, comm); + proc_comm_connector(me); + break; + case PR_GET_EXT_NAME: + strscpy_pad(comm, me->comm, TASK_COMM_EXT_LEN); + if (copy_to_user((char __user *)arg2, comm, TASK_COMM_EXT_LEN)) + return -EFAULT; + break; case PR_GET_ENDIAN: error =3D GET_ENDIAN(me, arg2); break; --=20 2.54.0 From nobody Mon May 25 06:43:07 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA6533C661D; Sun, 17 May 2026 18:37:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043053; cv=none; b=khEFE49gjOiLgFH0J3uD4uURO4SddjEqT4IqDmKIpJ762R/ri+V/9r8X05ovBmstZQMyjW1785ZH+AEghgK9/K0xEiBjPvA5jmTBUiqFqtXD53yrbiK6jAv+XlWQPPauICkSVAkgSEEVvMFhBgpa/4GaQBi3Uk6Qy8IXaEKb9/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779043053; c=relaxed/simple; bh=DQGECCu54qCFjAJEEwdPLsPC8heYQxz75RhXI6ITvYw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nYvVdX6Lxvzz1QPiltRCWghRlmyZM5L6MRrFr9Cjs8EbkpWu48FMfwFacw/gDfZYB6zXS7CgfiF/KpJT55DVOOPXWKHwCy1DplHl5NM10xwlqsYwDg3IhNRtDHMCW6EC7OamB6DHbuFheOW8h6kTg7po3DJRZpMCctZpsgeLLDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=YxMlzr1y; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="YxMlzr1y" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=EOUkvSr2Gn8JmW0nio1LgmkdjEeAiY0SGNTncIeyo40=; b=YxMlzr1yiCTDLGXptBuFAfeJ66 XjsFGuUOgWIYgOLTqm+BE+ZO1r6FWcQiUQQ0xFUGcHxM9wtrgLxuMsGfS2Hrov+Y4bkihsDDzzc/h EwUVoBbm0MieEY5918taB0Wt/FjpA5RVIGYv0JwrqjJvhN1Sl/4GmMrrSnFumMpYfYnCwxF4ZQ71D jjX/LxSEB9GawNVgAGpgtViIk8GqKSM9YzCZJaMk6bSPWB1xIVrL0iDL6ItOS4iT7j8o71hFnnZTb maq+TuRY0OGQsxx5Yt6zIwYjfb40XeWbgrWtOIphV9tdc1CZF+oZbGDTbvtzNbEPSURvl34I4SQFs 6Jxmx+6g==; Received: from [179.193.2.40] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wOgMZ-001cLz-Ae; Sun, 17 May 2026 20:37:19 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Sun, 17 May 2026 15:36:16 -0300 Subject: [PATCH 6/6] selftests: prctl: Add test for long thread names Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260517-tonyk-long_name-v1-6-3c282eaa91e2@igalia.com> References: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> In-Reply-To: <20260517-tonyk-long_name-v1-0-3c282eaa91e2@igalia.com> To: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, David Laight , Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Add tests for the new interface to set and get long thread names. The kernel should accept the LONG_NAME and returning it accordingly. For the old PR_GET_NAME interface, the kernel should truncate the name up to 16 chars. /proc//comm should return the same string ad PR_GET_NAME. Signed-off-by: Andr=C3=A9 Almeida --- tools/testing/selftests/prctl/set-process-name.c | 36 ++++++++++++++++++++= ++++ 1 file changed, 36 insertions(+) diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testi= ng/selftests/prctl/set-process-name.c index 3f7b146d36df..0f20f7deac67 100644 --- a/tools/testing/selftests/prctl/set-process-name.c +++ b/tools/testing/selftests/prctl/set-process-name.c @@ -9,9 +9,17 @@ =20 #include "kselftest_harness.h" =20 +#ifndef PR_SET_EXT_NAME +# define PR_SET_EXT_NAME 17 +# define PR_GET_EXT_NAME 18 +#endif + #define CHANGE_NAME "changename" +#define LONG_NAME "change_to_very_long_extended_name" +#define LONG_NAME_CAP "change_to_very_" #define EMPTY_NAME "" #define TASK_COMM_LEN 16 +#define TASK_COMM_EXT_LEN 64 #define MAX_PATH_LEN 50 =20 int set_name(char *name) @@ -25,6 +33,16 @@ int set_name(char *name) return res; } =20 +int set_ext_name(char *name) +{ + int res; + + res =3D prctl(PR_SET_EXT_NAME, name, NULL, NULL, NULL); + + if (res < 0) + return -errno; +} + int check_is_name_correct(char *check_name) { char name[TASK_COMM_LEN]; @@ -38,6 +56,19 @@ int check_is_name_correct(char *check_name) return !strcmp(name, check_name); } =20 +int check_is_ext_name_correct(char *check_name) +{ + char name[TASK_COMM_EXT_LEN]; + int res; + + res =3D prctl(PR_GET_EXT_NAME, name, NULL, NULL, NULL); + + if (res < 0) + return -errno; + + return !strcmp(name, check_name); +} + int check_null_pointer(char *check_name) { char *name =3D NULL; @@ -82,6 +113,11 @@ TEST(rename_process) { EXPECT_GE(set_name(CHANGE_NAME), 0); EXPECT_TRUE(check_is_name_correct(CHANGE_NAME)); =20 + EXPECT_GE(set_ext_name(LONG_NAME), 0); + EXPECT_TRUE(check_is_ext_name_correct(LONG_NAME)); + EXPECT_TRUE(check_is_name_correct(LONG_NAME_CAP)); + EXPECT_TRUE(check_name()); + EXPECT_GE(set_name(EMPTY_NAME), 0); EXPECT_TRUE(check_is_name_correct(EMPTY_NAME)); =20 --=20 2.54.0