From nobody Fri Sep 25 16:04:37 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 EF8AB4AB1CB; Thu, 10 Sep 2026 16:49:43 +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=1789058992; cv=none; b=LPRgJfckJuoYSR3WoUBKnvdYktRuNqO0w1BGvrRIs6WioaJELWXW1+5HlHvVIrtdz/gwl0VZ5zB1UJDz+TbU000dAn2azU1LFXTMGu3atF9BGrPgwT4ZFMDuHh1Mi3ZqiFxTq8SE5lYvb72jDhcl539l5TvCXDK1UF152mLfQDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789058992; c=relaxed/simple; bh=xUz3Vps7MiWiAh/87LeCjZsAWobb6z4TEK3EDhENwp0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y5bo8sxXKjKgAqFuKIaw/J6Z8jgfTH4UEUS6L1N6B9/HV2cYbbqMtAHBa0eFvv8ubAg0MXd8XY5rR9/4o5vYT0DjpR15i2gB+L34Zzrzsd0KdpibGGRkQDWMx+OMxjPa89QJ2TZzh6zRDHl3/cExpQEJ7bTpbYeFkHVuIq2unuk= 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=dG8+nXoj; 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="dG8+nXoj" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=54N1HLMogpGOh+fD9wT6RVMPM6GzrKR7V/ciKH8F8s0=; b=dG8+nXojxsResarmT8dzG4EQY3 GhrfAnhk2ZHxKU/Wc8x1NSHoXSqS2Ym/EuDzzMq1Hk5DB5Eg0s8GJySsQR1zvkTc7d9AFE4cNIQU0 oERaBgHYTjCbR9ZPt6rX7P67+q25s96FZPp4PZSuOfnZs4wdUgfmXijoZ1TkWGC5QDSwoTRuxs0H4 urYyAI5OAKpLUSiClLrteXu7xz2sGZdM15BnX0iEijEDdWitVC8xO5sqll3AuiT3NjRL/l8cTrjyR qcHyY+jY2qhHYu1pbua22dL7hfBCjEA2dyiEjRdseXzeSXBx/ge0TSANZ8sg2tT0Jzx65SXc9dxLN Gl9m2Atg==; Received: from [177.172.123.122] (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 1x4hxw-000GV1-Mv; Thu, 10 Sep 2026 18:49:36 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Sep 2026 13:49:23 -0300 Subject: [PATCH v6 1/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: <20260910-tonyk-long_name-v6-1-d70afbf194c5@igalia.com> References: <20260910-tonyk-long_name-v6-0-d70afbf194c5@igalia.com> In-Reply-To: <20260910-tonyk-long_name-v6-0-d70afbf194c5@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, linux-trace-kernel@vger.kernel.org, =?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/ Signed-off-by: Andr=C3=A9 Almeida --- Changes from v1: - Fix for security/ipe/audit.c and net/netfilter/nf_tables_api.c --- 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 | 4 +++- security/integrity/integrity_audit.c | 3 ++- security/ipe/audit.c | 3 ++- security/landlock/domain.c | 2 +- security/lsm_audit.c | 7 ++++--- security/smack/smack_access.c | 4 ++-- security/smack/smack_lsm.c | 4 +++- 31 files changed, 47 insertions(+), 55 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 9b10d015671c..2c92bb12c269 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c @@ -73,7 +73,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->context_id =3D context_id; dma_fence_init(&fence->base, &amdkfd_fence_ops, &fence->lock, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c b/drivers/g= pu/drm/amd/amdgpu/amdgpu_eviction_fence.c index f6b7522c3c82..046243e3a3cd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c @@ -128,7 +128,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 35eb87591740..6f140025a5f3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c @@ -3687,7 +3687,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 743b41db5b7c..12cae9bb6eed 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 bb04101b0fb5..bedb5fdf285d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -2573,10 +2573,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 249f07f30951..d6f32bc44aef 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -565,7 +565,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 72908be5e144..3dfcd4b77f81 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -54,7 +54,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 5778e23e20a0..1702b12ee395 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -3617,7 +3617,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 3d8e4ccdb7c1..b10a0e1cb1ed 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 06d0df105382..a47d393a10b5 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1554,7 +1554,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 068c46875c74..76333fa2f949 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1376,7 +1376,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 f6f75d206762..8ebb7cf1a7b0 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 705970d07614..d7d3bbb205c9 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2036,25 +2036,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 strscpy_pad() in __set_task_comm() can ensure 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 9412af9144bc..75bcc0d43c55 100644 --- a/kernel/audit.c +++ b/kernel/audit.c @@ -1667,7 +1667,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); @@ -2483,7 +2484,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 2b9ce0b52511..79e2aae80685 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2878,7 +2878,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); @@ -2901,7 +2902,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 6d3d18a50da7..7e94704d9a2b 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 35b538ba843c..97df708c11a0 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 070ca388f9ac..4e66cb2d9549 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -104,7 +104,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 31fbd5a28937..97e79fda9eaf 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -9735,9 +9735,11 @@ static int nf_tables_fill_gen_info(struct sk_buff *s= kb, struct net *net, if (!nlh) goto nla_put_failure; =20 + strscpy_pad(buf, current->comm); + 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, buf)) 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..90a6acfb7cdf 100644 --- a/security/ipe/audit.c +++ b/security/ipe/audit.c @@ -145,7 +145,8 @@ 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)); + strscpy_pad(comm, current->comm); + audit_log_untrustedstring(ab, 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 4031b581be07..e259a5d6a9c6 100644 --- a/security/landlock/domain.c +++ b/security/landlock/domain.c @@ -563,7 +563,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 diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c index fb85356266e5..0e7b2edcc3d6 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c @@ -335,10 +335,10 @@ static void smack_log_callback(struct audit_buffer *a= b, void *a) if (sad->subj_tsk) { char comm[TASK_COMM_LEN]; =20 + strscpy_pad(comm, sad->subj_tsk->comm); audit_log_format(ab, " subj_pid=3D%d subj_comm=3D", task_tgid_nr(sad->subj_tsk)); - audit_log_untrustedstring(ab, - get_task_comm(comm, sad->subj_tsk)); + audit_log_untrustedstring(ab, comm); } } =20 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 8e88ac65fd7f..0e1aa2bb4a7c 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -138,6 +138,8 @@ smk_bu_tsk_to_obj(struct task_struct *tsk, const struct= task_smack *tsp, char acc[SMK_NUM_ACCESS_TYPE + 1]; char comm[TASK_COMM_LEN]; =20 + strscpy_pad(comm, tsk); + if (rc <=3D 0) return rc; if (rc > SMACK_UNCONFINED_OBJECT) @@ -147,7 +149,7 @@ smk_bu_tsk_to_obj(struct task_struct *tsk, const struct= task_smack *tsp, =20 pr_info("Smack %s: (%s %s %s) %s %s\n", smk_bu_mess[rc], smk_of_task(tsp)->smk_known, oskp->smk_known, - acc, get_task_comm(comm, tsk), note); + acc, comm, note); return 0; #else return rc; --=20 2.55.0 From nobody Fri Sep 25 16:04:37 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 57CC6519905; Thu, 10 Sep 2026 16:49:49 +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=1789058993; cv=none; b=n48ilPYCriWaSCxv+KTsnU8RctwCAz7bdv/hy4LGjF4KlGcFxMaDwV3cFWi7ZrqDw8zN1fwG3hatDu0DsQUUN1EXNoXJEmYRKe8kwrGx9CRppcEHY1HMjyE8ugjC9V/8//D80UNR2faOpw52dw1nmKncRZBg3vMPrOC6op/VHQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789058993; c=relaxed/simple; bh=1Eh79kG2dm9aU7YG7Rx2URM3X6dXi2f/AbfRl0RUrX0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KkolWAHDXAPSA6k+mvN0SKBG7wH1+SD98Vk42wa3ZxnFGW3ctNbM67jmFmv82xyEyRWhIj73ZhxOo/BThcVC2FA4azT8WutND8MggIjKCU/+ssPjm7B5W1opT+I9THq9Z+B+m4u8bsYR+RG43/7u3FfPflzYXftsLZBhsg00JD4= 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=KCaarpJ+; 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="KCaarpJ+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=8CooP9O6Zd+Z0+YmlrfGudXXPI99XIVgVv6tCFXXz0E=; b=KCaarpJ+Wrd02t7QFtyxe9RJ9K 8029D+xgUnb6/ce1Wy7n/yTp9jmqFAe/POH4KA7VBtQ1c8ICAw/sh+I1HfI3aJUMkKxic+cb2CP4z fmA5BVxNFoIwcYN/H5YUl2wuI85RPgws3e3FB/P3HuAqrwV+GwOxWj7rOAHivjBQwHbwi8m2gY+rq OFQZUjfd6wKUVBSkBrjjEwTIdBoO1hO71To0b7Ajx8U2mPWEkUSg1m6trWiTFu4gpc3S8eWiIk2Iv 62LkHfyq060R5HrapS1MPYvgY2FEUap+Vct/nvp7XqRYWdkoImDHzUOhazA8QKL9qoMDA87By0H7A sGQ1uC5Q==; Received: from [177.172.123.122] (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 1x4hy2-000GV1-9L; Thu, 10 Sep 2026 18:49:42 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Sep 2026 13:49:24 -0300 Subject: [PATCH v6 2/6] treewide: Replace memcpy(..., current->comm) with copy_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: <20260910-tonyk-long_name-v6-2-d70afbf194c5@igalia.com> References: <20260910-tonyk-long_name-v6-0-d70afbf194c5@igalia.com> In-Reply-To: <20260910-tonyk-long_name-v6-0-d70afbf194c5@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, linux-trace-kernel@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 In order to increase the size of current->comm[] and to avoid breaking any existing code, replace memcpy() with copy_task_comm(). This new function makes sure that the copy is NUL terminated. This is crucial given that the source buffer might be larger than the destination buffer and could truncate the NUL character out of it. Signed-off-by: Andr=C3=A9 Almeida --- Changes from v4: - Remove copy_task_comm() calls for structs other than struct task_struct - Add checks for len > TASK_COMM_LEN and len < 0 Changes from v3: - Simplify copy_task_comm() to a memcpy + NUL char at the end of buffer Changes from v2: - Bring back custom function. Changes from v1: - New patch, dropped strtostr() from last version --- include/linux/coredump.h | 2 +- include/linux/sched.h | 15 +++++++++++= ++++ 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 ++-- .../testing/selftests/bpf/test_kmods/bpf_testmod-events.h | 2 +- 12 files changed, 37 insertions(+), 22 deletions(-) diff --git a/include/linux/coredump.h b/include/linux/coredump.h index 7b38ee2e7913..dee82e3c350a 100644 --- a/include/linux/coredump.h +++ b/include/linux/coredump.h @@ -58,7 +58,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)); \ + copy_task_comm(comm, current, sizeof(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/sched.h b/include/linux/sched.h index d7d3bbb205c9..ba2040566424 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2036,6 +2036,21 @@ extern void __set_task_comm(struct task_struct *tsk,= const char *from, bool exec __set_task_comm(tsk, from, false); \ }) =20 +/* + * Copy task name to a buffer. Final result is always a NUL-terminated str= ing. + */ +static __always_inline void copy_task_comm(char *dst, struct task_struct *= tsk, size_t len) +{ + const char *_src =3D tsk->comm; + size_t _len =3D min(len, TASK_COMM_LEN); + + if (!_len) + return; + + memcpy(dst, _src, _len); + dst[_len - 1] =3D '\0'; +} + static __always_inline void scheduler_ipi(void) { /* diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index e0d838c9ce93..9b0094fa44c6 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -637,10 +637,10 @@ static inline struct tracepoint *tracepoint_ptr_deref= (tracepoint_ptr_t *p) * * * * TP_fast_assign( - * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); + * copy_task_comm(__entry->next_comm, next, TASK_COMM_LEN); * __entry->prev_pid =3D prev->pid; * __entry->prev_prio =3D prev->prio; - * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); + * copy_task_comm(__entry->prev_comm, prev, TASK_COMM_LEN); * __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 9c97a16850b9..1e3a9ded03bd 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); + copy_task_comm(__entry->comm, current, TASK_COMM_LEN); ), =20 TP_printk("%d,%d %s %u (%s) %llu + %u %s,%u,%u [%s]", @@ -410,7 +410,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); + copy_task_comm(__entry->comm, current, TASK_COMM_LEN); ), =20 TP_printk("%d,%d %s %llu + %u [%s]", @@ -493,7 +493,7 @@ TRACE_EVENT(block_plug, ), =20 TP_fast_assign( - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + copy_task_comm(__entry->comm, current, TASK_COMM_LEN); ), =20 TP_printk("[%s]", __entry->comm) @@ -512,7 +512,7 @@ DECLARE_EVENT_CLASS(block_unplug, =20 TP_fast_assign( __entry->nr_rq =3D depth; - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + copy_task_comm(__entry->comm, current, TASK_COMM_LEN); ), =20 TP_printk("[%s] %d", __entry->comm, __entry->nr_rq) @@ -563,7 +563,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); + copy_task_comm(__entry->comm, current, TASK_COMM_LEN); ), =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..fdd20bc46bb0 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); + copy_task_comm(__entry->comm, current, TASK_COMM_LEN); ), =20 TP_printk("sig=3D%d comm=3D%s", diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h index d53be932df01..faabc15b4a11 100644 --- a/include/trace/events/f2fs.h +++ b/include/trace/events/f2fs.h @@ -2518,7 +2518,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); + copy_task_comm(__entry->comm, p, TASK_COMM_LEN); __entry->pid =3D p->pid; __entry->prio =3D p->prio; __entry->ioprio_class =3D IOPRIO_PRIO_CLASS(ioprio); @@ -2571,7 +2571,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); + copy_task_comm(__entry->comm, p, TASK_COMM_LEN); __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..8bcdc4ffc8d3 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); + copy_task_comm(__entry->comm, task, TASK_COMM_LEN); __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..2cf047bb9fb7 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); + copy_task_comm(__entry->comm, t, TASK_COMM_LEN); __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..afb24e9dac91 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); + copy_task_comm(__entry->comm, p, TASK_COMM_LEN); __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); + copy_task_comm(__entry->prev_comm, prev, TASK_COMM_LEN); __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); + copy_task_comm(__entry->next_comm, next, TASK_COMM_LEN); __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); + copy_task_comm(__entry->comm, p, TASK_COMM_LEN); __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); + copy_task_comm(__entry->comm, tsk, TASK_COMM_LEN); __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..8fffe6d9bdcc 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); + copy_task_comm(__entry->comm, task, TASK_COMM_LEN); __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..e3faaeb997ef 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); + copy_task_comm(__entry->comm, task, TASK_COMM_LEN); __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); + copy_task_comm(entry->oldcomm, task, TASK_COMM_LEN); strscpy(entry->newcomm, comm, TASK_COMM_LEN); __entry->oom_score_adj =3D task->signal->oom_score_adj; ), 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..27a1c12799cf 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); + copy_task_comm(__entry->comm, task->comm, TASK_COMM_LEN); __entry->off =3D ctx->off; __entry->len =3D ctx->len; ), --=20 2.55.0 From nobody Fri Sep 25 16:04:37 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 2800553CA61; Thu, 10 Sep 2026 16:49:53 +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=1789058996; cv=none; b=gvnTjpN/f1Gkv2xcKGtUchXHgC3ut/omhtGBbhgLktG+Yjw+HQmH6APA/RtMT4KGmPqInTaMliQN0wv7nkHWzMHcQR9gfyYNl0jTm7zQDGpmzAOX59ryui01Tu+Wy2XhG61G12qsBcMqHbBCk3QwWTmdFHz7EBHfnMROikW7ig0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789058996; c=relaxed/simple; bh=uho5UQ0Az37K2IRerC1Luwb5Pg6lv4RnKyjZ+YPmkrE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OKlb+WXUnO5oUVlOoVz6ck1wfhDcyvJCTgms87DFGwuXLi9udAc9ZLWYETj+T73GTO2Yz0sx6+WYhsDZ8pPfjxHhYYt9JcecPmgtCyHAe19/kKpI5gWINjtbcguDVbKN7CiembiKFnOQB8rotVlPnoIEjshFEBjUKFopRDS/My4= 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=a2D6raGc; 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="a2D6raGc" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=eoYcCAglewCWVwj2AVy806Wq+FVmxIJYd36pevZhoXY=; b=a2D6raGcP0RCTpXl67nSvb7R2V WFSa5ujCHs+5dcnspyYfejXwX3G7uZ8rNxsr6Mix0RGlxLGLPAArBNxVk52pKrj7wR0Rlxrr5iYuw QNf3W75SxuKSxCHEWANzBEWi9d2vs85lUo2YTf3I57UEIBg+Fd/i/jNxzQT7TqY4AKS58lanYXX8K b64TzEvq58AA+nBv+eSDmHUY1uewglcotnI9aZG6z9MqvqGSVoOlVBs/JRO5pIeXnI1otx4xKX88d a1egSIaIIiC3736hlO/wHdOX43P6i7MMbnPE6hKQ0R7IC0QrbTdAg5p/5Usi/HgT0Yr1yZjhHmkBj FlLdxsmg==; Received: from [177.172.123.122] (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 1x4hy7-000GV1-LH; Thu, 10 Sep 2026 18:49:47 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Sep 2026 13:49:25 -0300 Subject: [PATCH v6 3/6] lib/string_kunit: Add test for copy_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: <20260910-tonyk-long_name-v6-3-d70afbf194c5@igalia.com> References: <20260910-tonyk-long_name-v6-0-d70afbf194c5@igalia.com> In-Reply-To: <20260910-tonyk-long_name-v6-0-d70afbf194c5@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, linux-trace-kernel@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.15.2 Add a new test for copy_task_comm(). Check if a copy from a task_struct works, and special cases when the size of source and destination buffer mismatches. Signed-off-by: Andr=C3=A9 Almeida --- lib/tests/string_kunit.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/tests/string_kunit.c b/lib/tests/string_kunit.c index 0819ace5b027..66c3398f2317 100644 --- a/lib/tests/string_kunit.c +++ b/lib/tests/string_kunit.c @@ -881,6 +881,43 @@ static void string_bench_strrchr(struct kunit *test) STRING_BENCH_BUF(test, buf, len, strrchr, buf, '\0'); } =20 +#define TASK_NAME "task_name" +#define TASK_NAME_LEN 9 +#define TASK_MAX_LEN TASK_COMM_LEN +#define SMALLER_LEN (TASK_NAME_LEN - 3) +#define BIGGER_LEN (TASK_MAX_LEN + 3) + +static void string_copy_task_comm(struct kunit *test) +{ + char str[TASK_MAX_LEN] =3D TASK_NAME, copy[TASK_MAX_LEN], + smaller_buf[SMALLER_LEN], bigger_buf[BIGGER_LEN]; + static struct task_struct task, *tsk =3D &task; + int len1, len2, i; + + /* set and get task name */ + strscpy_pad(tsk->comm, str); + copy_task_comm(copy, tsk, TASK_COMM_LEN); + + len1 =3D strlen(str); + len2 =3D strlen(copy); + + KUNIT_ASSERT_EQ(test, len1, len2); + KUNIT_ASSERT_EQ(test, len2, TASK_NAME_LEN); + KUNIT_ASSERT_EQ(test, copy[len2], '\0'); + KUNIT_ASSERT_TRUE(test, !strcmp(str, copy)); + + /* copy to a smaller dst buffer */ + copy_task_comm(smaller_buf, tsk, sizeof(smaller_buf)); + KUNIT_ASSERT_TRUE(test, !strncmp(str, smaller_buf, SMALLER_LEN - 1)); + KUNIT_ASSERT_EQ(test, smaller_buf[SMALLER_LEN - 1], '\0'); + + /* copy to a bigger dst buffer */ + copy_task_comm(bigger_buf, tsk, sizeof(bigger_buf)); + KUNIT_ASSERT_TRUE(test, !strncmp(str, bigger_buf, TASK_NAME_LEN)); + for (i =3D TASK_NAME_LEN; i < BIGGER_LEN; i++) + KUNIT_ASSERT_EQ(test, bigger_buf[i], '\0'); +} + static struct kunit_case string_test_cases[] =3D { KUNIT_CASE(string_test_memset16), KUNIT_CASE(string_test_memset32), @@ -910,6 +947,7 @@ static struct kunit_case string_test_cases[] =3D { KUNIT_CASE(string_bench_strnlen), KUNIT_CASE(string_bench_strchr), KUNIT_CASE(string_bench_strrchr), + KUNIT_CASE(string_copy_task_comm), {} }; =20 --=20 2.55.0 From nobody Fri Sep 25 16:04:37 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 D91F253A893; Thu, 10 Sep 2026 16:49:58 +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=1789059002; cv=none; b=XTCC2F6U5Ry2Axs5I8HZKimuvP+6uL9wjp45ITWgnPhs7cgiAUF3mN9OYXLMdjnOsRj2i6l1/wf8uvzBKvfoPidrLvMOgYAuGYe/WZhTp2qsjpYYip1eVTnEw6iH1LAJjP5yBOwsGbh/vXkDmHdS4kg2y9OrfJx6WLYHc8MfSus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789059002; c=relaxed/simple; bh=46inCMZBKL4Dn2MYeOCdxLCzeD1FLycLRZASs/WYhuo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PESbpWEiMbNCAI3A3AQLNNnkVkPvQRkmpWiYnXki7WoAzI2go02blyutT11rjQjhaL9DPh6eZ2dAvXTN0s7qJQr70icP62i2b4ObGRbgX9S4OJUb9TukrEjCJ1IoDZP8B1W8tZHfCD1L/1H3hiK92KfGNPqe4qF1qbE88JnX/h8= 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=pQz1zxlQ; 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="pQz1zxlQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=1MfA022lMI6eopMpnYm97azulYzjdx+Jco4w94leDiw=; b=pQz1zxlQD+em6o0ikC/F+rt/mg 8NXjQxCOgce50tHZiWLUMta/2epDzYxoQ8oVrtmJTr8D/LBx2bQYxbayey2kXk0hAs2ZyzQAZi5pJ eT6J4LeHoemYJKnzgdPh1KeJO0kJ6cPN3zp7IRbSwgcKs5zWku+BdzcTz+8NT4qdUZsovN/FafTPe 6w6azMQNwkXTKzFbumEdbrBgLH8QOzcPK+SasJENgwxOMfgRNUk8SofwCzUaHydkVhPn1OL0yLhEJ /gFNjqk+BhSaEQW8drUOWuE9EVZ41ZthDrbmqi+0Nz6uxle+TACTUwvSemat8D6jqTc7F+KuNDZjH 4UScT3Ag==; Received: from [177.172.123.122] (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 1x4hyD-000GV1-0v; Thu, 10 Sep 2026 18:49:52 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Sep 2026 13:49:26 -0300 Subject: [PATCH v6 4/6] sched: Extend task command name with TASK_COMM_EXT_LEN 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: <20260910-tonyk-long_name-v6-4-d70afbf194c5@igalia.com> References: <20260910-tonyk-long_name-v6-0-d70afbf194c5@igalia.com> In-Reply-To: <20260910-tonyk-long_name-v6-0-d70afbf194c5@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, linux-trace-kernel@vger.kernel.org, =?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. Signed-off-by: Andr=C3=A9 Almeida --- Changes from v5: - Fix blktrace buffer size - Fix i915 buffer size --- drivers/gpu/drm/i915/display/intel_display_driver.c | 4 ++-- drivers/gpu/drm/i915/gem/i915_gem_context.c | 4 ++-- fs/proc/array.c | 2 +- include/linux/sched.h | 5 +++-- kernel/sys.c | 10 +++++----- kernel/trace/blktrace.c | 6 ++++-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.c b/drivers/= gpu/drm/i915/display/intel_display_driver.c index 70d112fd4287..e2b19b064722 100644 --- a/drivers/gpu/drm/i915/display/intel_display_driver.c +++ b/drivers/gpu/drm/i915/display/intel_display_driver.c @@ -435,8 +435,8 @@ void intel_display_driver_resume_access(struct intel_di= splay *display) */ bool intel_display_driver_check_access(struct intel_display *display) { - char current_task[TASK_COMM_LEN + 16]; - char allowed_task[TASK_COMM_LEN + 16] =3D "none"; + char current_task[TASK_COMM_EXT_LEN + 16]; + char allowed_task[TASK_COMM_EXT_LEN + 16] =3D "none"; =20 if (display->access.any_task_allowed || display->access.allowed_task =3D=3D current) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/= i915/gem/i915_gem_context.c index c58ffa5a8fa6..b62b82c6de04 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1730,8 +1730,8 @@ static void gem_context_register(struct i915_gem_cont= ext *ctx, ctx->pid =3D get_task_pid(current, PIDTYPE_PID); ctx->client =3D i915_drm_client_get(fpriv->client); =20 - snprintf(ctx->name, sizeof(ctx->name), "%s[%d]", - current->comm, pid_nr(ctx->pid)); + snprintf(ctx->name, sizeof(ctx->name), "%.*s[%d]", + TASK_COMM_LEN - 1, current->comm, pid_nr(ctx->pid)); =20 spin_lock(&ctx->client->ctx_lock); list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list); diff --git a/fs/proc/array.c b/fs/proc/array.c index 8ebb7cf1a7b0..0d70b21c803c 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 ba2040566424..c4e0104e7ae9 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); @@ -1187,7 +1188,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 @@ -2042,7 +2043,7 @@ extern void __set_task_comm(struct task_struct *tsk, = const char *from, bool exec static __always_inline void copy_task_comm(char *dst, struct task_struct *= tsk, size_t len) { const char *_src =3D tsk->comm; - size_t _len =3D min(len, TASK_COMM_LEN); + size_t _len =3D min(len, TASK_COMM_EXT_LEN); =20 if (!_len) return; diff --git a/kernel/sys.c b/kernel/sys.c index 97df708c11a0..5ebd3c1dfddf 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: diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index 8cd2520b4c99..edc1377c3e3c 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -214,12 +214,14 @@ static void trace_note_tsk(struct task_struct *tsk) { unsigned long flags; struct blk_trace *bt; + char comm[TASK_COMM_LEN]; =20 tsk->btrace_seq =3D blktrace_seq; raw_spin_lock_irqsave(&running_trace_lock, flags); list_for_each_entry(bt, &running_trace_list, running_list) { - trace_note(bt, tsk->pid, BLK_TN_PROCESS, tsk->comm, - sizeof(tsk->comm), 0); + strscpy_pad(comm, tsk->comm); + trace_note(bt, tsk->pid, BLK_TN_PROCESS, comm, + sizeof(comm), 0); } raw_spin_unlock_irqrestore(&running_trace_lock, flags); } --=20 2.55.0 From nobody Fri Sep 25 16:04:37 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 203805476E3; Thu, 10 Sep 2026 16:50:03 +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=1789059006; cv=none; b=aFM7jq+DBWOM+CC9BjtyCD65rnAnonm42/qv0a4tORc+2P65e9lBPZiM/LxZ/Z7cKg7XKCVE67hmkkZEz1RKR9aLV8JAVTeSgKbsCKJ83PqBNI2BKJ5XQAsx4QFvMiq83rUCdGf5MpeCl1POx6G0b5Pl/i5C3pFaGiaG5Iw4p7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789059006; c=relaxed/simple; bh=9wKMGMxKPDnJkzoBxj/pTuJdtocxN5isJ4nxpGIBtXo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=etISCZvKBBuswuOCWM+wp+4N9zWXK01wUxuRg6mMuxONEiNzvEwvN6UTARus5QgmyHXw1ep8E9ZF06HuVL4tPg+NEy7csk0dYqvfcqaaD1d4zbj6L/2aGfwaM7MbNkvffRdzszXC4ROC2+fyUxmmxTpaONXMYZmFf27vfefFxW0= 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=NOS02qo5; 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="NOS02qo5" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=NPPKZAStI7N6lxDqkkzLK3v+X0s+kCzQt7K1E1LT7Z8=; b=NOS02qo5QoJ2/caZC+vrUIs2JQ wybjBGhaqXXHawkEH2ysTp0aKM1CNs6PKbZaIQPAoW58s7WEIu73mwrYy1lmKg3IhvoPsNjLrKQSN Of4UVkBJli7fxLOtnG+ojslanmfsLVTnaDi1Ed2FHCkQczJ1/L9tmvhFgfDzeKPwwQZMcus0lr0Ex LCtkev9jotmG0Y5tItHSiDE6X0akwZaXwQ19XN7FH/wt1A1cwDu0S6eRVlr1jk557quKJaeRS9xmm Beuhq7GtmGcpqPU60QV701d/K++akGAdqkdp/SM7UYlsCSoC2n5rBn4WfQH3FjHR47WZtFLTzmsol 34M7L4jQ==; Received: from [177.172.123.122] (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 1x4hyI-000GV1-CL; Thu, 10 Sep 2026 18:49:58 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Sep 2026 13:49:27 -0300 Subject: [PATCH v6 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: <20260910-tonyk-long_name-v6-5-d70afbf194c5@igalia.com> References: <20260910-tonyk-long_name-v6-0-d70afbf194c5@igalia.com> In-Reply-To: <20260910-tonyk-long_name-v6-0-d70afbf194c5@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, linux-trace-kernel@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 c4e0104e7ae9..0736b6a32dcf 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2033,7 +2033,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 5ebd3c1dfddf..4caf6ef836f1 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.55.0 From nobody Fri Sep 25 16:04:37 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 0221653ECE9; Thu, 10 Sep 2026 16:50:08 +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=1789059011; cv=none; b=RtOAISAYBb9/gUvyf0VpSkPh+MzVhJpAlWA3i6qevdaeptN5zoIqHRkC82NpH2mulIwZwxODCsP1rGRLDPAJlyaPOCel7N9GRo/2+Zh625z+fDfzyeYGAdqD23xGmtrJMpC4NMKqdaAkusPa3Lx2DzJdVSQ4W9AB8d6vbQ1LBjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789059011; c=relaxed/simple; bh=ZobS2slsYgymP728EIsS1ZZzI/jDqEeK66f+TXlhRLQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BmoxuR/l2deJbXkIN+z/32Zw/BWWaaENGHfspAS9VG0/T06XvJU8l3D+yQIYJFfBUQcW1zEs8UnW5goU95N3y7cqwL/agb88f20jqdGVGrf9HEDZNUI4HpL+yG98vi98AbWAckUaiiCLBHrGA3vrP95mabo7aH0ujPVf3fIoqys= 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=XgKzfBTS; 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="XgKzfBTS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:Message-Id:Content-Transfer-Encoding:Content-Type: MIME-Version:Subject:Date:From:From:Reply-To; bh=yEhMQLJIbP2So5XydAfHqKEdD7p0FcLEoTOB/mDNo2A=; b=XgKzfBTStCdsvTd4feuEEWqHBK c/YwChzbakcux2jWKS3mVcP+hlWrxBcSNl/EVcm00WoyINZpyl/SeI4nEuyx5DsmOucg1tMizMSGb LBeMHFiIOYEr2CiZzoZ7PzWHVf5oPqHZl0aOFd57yS85eZnXBtuatz2Nfp8hWrat3q6gWSDANou5I I7jg8gh6x+fMNGt/JCcDsE0v2O9PqD6qzkcQbGVpGMw6vs7e4BOC/Rzln9WoQnu6rRaCfgsTFp0rB L4l6ALJSYgBKN8NlGgKV2scyyU7lyMVA9T7XGnOFCeGJFMGh1OR/J2GGuk17HZnzW6vfSddk0a49r DdETPr0w==; Received: from [177.172.123.122] (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 1x4hyO-000GV1-5R; Thu, 10 Sep 2026 18:50:04 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Sep 2026 13:49:28 -0300 Subject: [PATCH v6 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: <20260910-tonyk-long_name-v6-6-d70afbf194c5@igalia.com> References: <20260910-tonyk-long_name-v6-0-d70afbf194c5@igalia.com> In-Reply-To: <20260910-tonyk-long_name-v6-0-d70afbf194c5@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, linux-trace-kernel@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. While here, fix the check_is_name_correct() logic. It currently returns 1 for success, or a negative number for error. EXPECT_TRUE() evaluates any non-zero value as true, so the error will be evaluated as a success. Make the logic more robust and straightforward by returning the results of strcmp() and expecting zero as success. Signed-off-by: Andr=C3=A9 Almeida --- Changes in v5: - fix check_is_name_correct() return logic --- tools/testing/selftests/prctl/set-process-name.c | 53 ++++++++++++++++++++= +--- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testi= ng/selftests/prctl/set-process-name.c index 3f7b146d36df..27a0dbbce4db 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,20 @@ 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; + return res; +} + +/* + * Return 0 if strings match + */ int check_is_name_correct(char *check_name) { char name[TASK_COMM_LEN]; @@ -35,7 +57,23 @@ int check_is_name_correct(char *check_name) if (res < 0) return -errno; =20 - return !strcmp(name, check_name); + return strcmp(name, check_name); +} + +/* + * Return 0 if strings match + */ +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); } =20 int check_null_pointer(char *check_name) @@ -56,8 +94,8 @@ int check_name(void) pid =3D getpid(); FILE *fptr =3D NULL; char path[MAX_PATH_LEN] =3D {}; - char name[TASK_COMM_LEN] =3D {}; - char output[TASK_COMM_LEN] =3D {}; + char name[TASK_COMM_EXT_LEN] =3D {}; + char output[TASK_COMM_EXT_LEN] =3D {}; int j; =20 j =3D snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid); @@ -80,10 +118,15 @@ int check_name(void) TEST(rename_process) { =20 EXPECT_GE(set_name(CHANGE_NAME), 0); - EXPECT_TRUE(check_is_name_correct(CHANGE_NAME)); + EXPECT_FALSE(check_is_name_correct(CHANGE_NAME)); + + EXPECT_GE(set_ext_name(LONG_NAME), 0); + EXPECT_FALSE(check_is_ext_name_correct(LONG_NAME)); + EXPECT_FALSE(check_is_name_correct(LONG_NAME_CAP)); + EXPECT_TRUE(check_name()); =20 EXPECT_GE(set_name(EMPTY_NAME), 0); - EXPECT_TRUE(check_is_name_correct(EMPTY_NAME)); + EXPECT_FALSE(check_is_name_correct(EMPTY_NAME)); =20 EXPECT_GE(set_name(CHANGE_NAME), 0); EXPECT_LT(check_null_pointer(CHANGE_NAME), 0); --=20 2.55.0