Linux userland API discussions
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@igalia.com>
To: 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,
	David Laight <david.laight.linux@gmail.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>
Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
	linux-mm@kvack.org, linux-api@vger.kernel.org,
	"André Almeida" <andrealmeid@igalia.com>
Subject: [PATCH v4 5/6] prctl: Add support for long user thread names
Date: Fri, 17 Jul 2026 10:54:38 -0300	[thread overview]
Message-ID: <20260717-tonyk-long_name-v4-5-1fedfc870d21@igalia.com> (raw)
In-Reply-To: <20260717-tonyk-long_name-v4-0-1fedfc870d21@igalia.com>

Add support for getting and setting long user thread names with
PR_{SET,GET}_EXT_NAME.

Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
 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 6a48517f01cc..0f1b40a5dbc6 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2018,7 +2018,7 @@ extern void kick_process(struct task_struct *tsk);
 
 extern void __set_task_comm(struct task_struct *tsk, const char *from, bool exec);
 #define set_task_comm(tsk, from) ({			\
-	BUILD_BUG_ON(sizeof(from) != TASK_COMM_LEN);	\
+	BUILD_BUG_ON(sizeof(from) < TASK_COMM_LEN);	\
 	__set_task_comm(tsk, from, false);		\
 })
 
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 */
 
+#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 3c37b5c1c072..26d5026f9590 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[TASK_COMM_LEN];
+	unsigned char comm[TASK_COMM_EXT_LEN];
 	long error;
 
 	error = security_task_prctl(option, arg2, arg3, arg4, arg5);
@@ -2613,6 +2613,19 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, 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] = 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 = GET_ENDIAN(me, arg2);
 		break;

-- 
2.55.0


  parent reply	other threads:[~2026-07-17 13:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 13:54 [PATCH v4 0/6] sched: Add support for long task name André Almeida
2026-07-17 13:54 ` [PATCH v4 1/6] treewide: Get rid of get_task_comm() André Almeida
2026-07-17 13:54 ` [PATCH v4 2/6] treewide: Replace memcpy(..., current->comm) with copy_task_comm() André Almeida
2026-07-17 13:54 ` [PATCH v4 3/6] lib/string_kunit: Add test for copy_task_comm() André Almeida
2026-07-17 13:54 ` [PATCH v4 4/6] sched: Extend task command name with TASK_COMM_EXT_LEN André Almeida
2026-07-17 13:54 ` André Almeida [this message]
2026-07-17 13:54 ` [PATCH v4 6/6] selftests: prctl: Add test for long thread names 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=20260717-tonyk-long_name-v4-5-1fedfc870d21@igalia.com \
    --to=andrealmeid@igalia.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=arnaldo.melo@gmail.com \
    --cc=brauner@kernel.org \
    --cc=david.laight.linux@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox