From: David Laight <david.laight.linux@gmail.com>
To: "André Almeida" <andrealmeid@igalia.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Steven Rostedt <rostedt@goodmis.org>,
Christian Brauner <brauner@kernel.org>,
Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>,
willy@infradead.org, mathieu.desnoyers@efficios.com,
Linus Torvalds <torvalds@linux-foundation.org>,
akpm@linux-foundation.org, Yafang Shao <laoar.shao@gmail.com>,
andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com,
Petr Mladek <pmladek@suse.com>,
linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
linux-mm@kvack.org, linux-api@vger.kernel.org,
Bhupesh <bhupesh@igalia.com>
Subject: Re: [PATCH v2 4/6] sched: Extend task command name to 64 bytes
Date: Mon, 25 May 2026 11:42:41 +0100 [thread overview]
Message-ID: <20260525114241.4b6f3050@pumpkin> (raw)
In-Reply-To: <20260525114107.7fa5b4c1@pumpkin>
On Mon, 25 May 2026 11:41:07 +0100
David Laight <david.laight.linux@gmail.com> wrote:
> On Sun, 24 May 2026 19:38:54 -0300
> André Almeida <andrealmeid@igalia.com> wrote:
>
> > 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 <bhupesh@igalia.com>
> > Signed-off-by: Bhupesh <bhupesh@igalia.com>
> > Signed-off-by: André Almeida <andrealmeid@igalia.com>
> > ---
> > 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_struct *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);
> >
> > 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 = 16,
> > + TASK_COMM_EXT_LEN = 64,
> > };
> >
> > 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];
> >
> > struct nameidata *nameidata;
> >
> > 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, arg2, unsigned long, arg3,
> > unsigned long, arg4, unsigned long, arg5)
> > {
> > struct task_struct *me = current;
> > - unsigned char comm[sizeof(me->comm)];
> > + unsigned char comm[TASK_COMM_LEN];
> > long error;
> >
> > error = security_task_prctl(option, arg2, arg3, arg4, arg5);
> > @@ -2601,16 +2601,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
> > error = -EINVAL;
> > break;
> > case PR_SET_NAME:
> > - comm[sizeof(me->comm) - 1] = 0;
> > + comm[TASK_COMM_LEN - 1] = 0;
> > if (strncpy_from_user(comm, (char __user *)arg2,
> > - sizeof(me->comm) - 1) < 0)
> > + TASK_COMM_LEN - 1) < 0)
>
> Nak - you can't do that.
> You are reading data that the application doesn't expect you to read.
Or have I got confused over the names...
-- David
>
> > 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))
>
> Double-nak - you are writing beyond the end of the applications buffer.
>
> You can't change the user memory that the syscalls access.
>
> You can support the longer name for read/write of /proc/self/comm.
>
> -- David
>
> > return -EFAULT;
> > break;
> > case PR_GET_ENDIAN:
> >
>
next prev parent reply other threads:[~2026-05-25 10:42 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-24 22:38 [PATCH v2 0/6] sched: Add support for long task name André Almeida
2026-05-24 22:38 ` [PATCH v2 1/6] sched: Update get_task_comm() comment André Almeida
2026-05-24 22:38 ` [PATCH v2 2/6] treewide: Get rid of get_task_comm() André Almeida
2026-05-25 10:34 ` David Laight
2026-05-24 22:38 ` [PATCH v2 3/6] treewide: Replace memcpy(..., current->comm) with strscpy() André Almeida
2026-05-26 23:06 ` Steven Rostedt
2026-05-27 9:18 ` David Laight
2026-05-29 16:46 ` André Almeida
2026-05-24 22:38 ` [PATCH v2 4/6] sched: Extend task command name to 64 bytes André Almeida
2026-05-25 10:41 ` David Laight
2026-05-25 10:42 ` David Laight [this message]
2026-05-26 16:31 ` Steven Rostedt
2026-05-27 8:42 ` David Laight
2026-05-29 16:43 ` André Almeida
2026-05-24 22:38 ` [PATCH v2 5/6] prctl: Add support for long user thread names André Almeida
2026-05-24 22:38 ` [PATCH v2 6/6] selftests: prctl: Add test for long " André Almeida
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260525114241.4b6f3050@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrealmeid@igalia.com \
--cc=andrii.nakryiko@gmail.com \
--cc=arnaldo.melo@gmail.com \
--cc=bhupesh@igalia.com \
--cc=brauner@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kernel-dev@igalia.com \
--cc=laoar.shao@gmail.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.