public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] exec: use strnlen() in __set_task_comm
@ 2026-04-01 15:20 Thorsten Blum
  2026-04-01 15:20 ` [PATCH 2/2] sched: update task_struct->comm comment Thorsten Blum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-01 15:20 UTC (permalink / raw)
  To: Kees Cook, Alexander Viro, Christian Brauner, Jan Kara
  Cc: Thorsten Blum, linux-mm, linux-fsdevel, linux-kernel

Use strnlen() to limit source string scanning to 'TASK_COMM_LEN - 1'
bytes.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 fs/exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/exec.c b/fs/exec.c
index 9ea3a775d51e..ba12b4c466f6 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1074,7 +1074,7 @@ static int unshare_sighand(struct task_struct *me)
  */
 void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)
 {
-	size_t len = min(strlen(buf), sizeof(tsk->comm) - 1);
+	size_t len = strnlen(buf, sizeof(tsk->comm) - 1);
 
 	trace_task_rename(tsk, buf);
 	memcpy(tsk->comm, buf, len);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] sched: update task_struct->comm comment
  2026-04-01 15:20 [PATCH 1/2] exec: use strnlen() in __set_task_comm Thorsten Blum
@ 2026-04-01 15:20 ` Thorsten Blum
  2026-04-01 16:30 ` [PATCH 1/2] exec: use strnlen() in __set_task_comm Jan Kara
  2026-04-01 19:28 ` Kees Cook
  2 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2026-04-01 15:20 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
	Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, K Prateek Nayak
  Cc: Thorsten Blum, linux-kernel

Since commit 3a3f61ce5e0b ("exec: Make sure task->comm is always
NUL-terminated"), __set_task_comm() is unlocked and no longer uses
strscpy_pad() - update the stale comment accordingly.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 include/linux/sched.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 5a5d3dbc9cdf..f510b465db04 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1159,12 +1159,9 @@ struct task_struct {
 	/*
 	 * executable name, excluding path.
 	 *
-	 * - normally initialized begin_new_exec()
-	 * - set it with set_task_comm()
-	 *   - strscpy_pad() to ensure it is always NUL-terminated and
-	 *     zero-padded
-	 *   - task_lock() to ensure the operation is atomic and the name is
-	 *     fully updated.
+	 * - normally initialized by begin_new_exec()
+	 * - set it with set_task_comm() to ensure it is always
+	 *   NUL-terminated and zero-padded
 	 */
 	char				comm[TASK_COMM_LEN];
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] exec: use strnlen() in __set_task_comm
  2026-04-01 15:20 [PATCH 1/2] exec: use strnlen() in __set_task_comm Thorsten Blum
  2026-04-01 15:20 ` [PATCH 2/2] sched: update task_struct->comm comment Thorsten Blum
@ 2026-04-01 16:30 ` Jan Kara
  2026-04-01 19:28 ` Kees Cook
  2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2026-04-01 16:30 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Kees Cook, Alexander Viro, Christian Brauner, Jan Kara, linux-mm,
	linux-fsdevel, linux-kernel

On Wed 01-04-26 17:20:40, Thorsten Blum wrote:
> Use strnlen() to limit source string scanning to 'TASK_COMM_LEN - 1'
> bytes.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/exec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/exec.c b/fs/exec.c
> index 9ea3a775d51e..ba12b4c466f6 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1074,7 +1074,7 @@ static int unshare_sighand(struct task_struct *me)
>   */
>  void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)
>  {
> -	size_t len = min(strlen(buf), sizeof(tsk->comm) - 1);
> +	size_t len = strnlen(buf, sizeof(tsk->comm) - 1);
>  
>  	trace_task_rename(tsk, buf);
>  	memcpy(tsk->comm, buf, len);
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] exec: use strnlen() in __set_task_comm
  2026-04-01 15:20 [PATCH 1/2] exec: use strnlen() in __set_task_comm Thorsten Blum
  2026-04-01 15:20 ` [PATCH 2/2] sched: update task_struct->comm comment Thorsten Blum
  2026-04-01 16:30 ` [PATCH 1/2] exec: use strnlen() in __set_task_comm Jan Kara
@ 2026-04-01 19:28 ` Kees Cook
  2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2026-04-01 19:28 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Jan Kara, Thorsten Blum
  Cc: Kees Cook, linux-mm, linux-fsdevel, linux-kernel

On Wed, 01 Apr 2026 17:20:40 +0200, Thorsten Blum wrote:
> Use strnlen() to limit source string scanning to 'TASK_COMM_LEN - 1'
> bytes.
> 
> 

Applied to for-next/execve, thanks!

[1/2] exec: use strnlen() in __set_task_comm
      https://git.kernel.org/kees/c/10cd6758e054
[2/2] sched: update task_struct->comm comment
      https://git.kernel.org/kees/c/9bf092c97b86

Take care,

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-01 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 15:20 [PATCH 1/2] exec: use strnlen() in __set_task_comm Thorsten Blum
2026-04-01 15:20 ` [PATCH 2/2] sched: update task_struct->comm comment Thorsten Blum
2026-04-01 16:30 ` [PATCH 1/2] exec: use strnlen() in __set_task_comm Jan Kara
2026-04-01 19:28 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox