]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exec: use strnlen() in __set_task_comm
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 1 Apr 2026 15:20:40 +0000 (17:20 +0200)
committerKees Cook <kees@kernel.org>
Wed, 1 Apr 2026 19:26:07 +0000 (12:26 -0700)
Use strnlen() to limit source string scanning to 'TASK_COMM_LEN - 1'
bytes.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20260401152039.724811-3-thorsten.blum@linux.dev
Signed-off-by: Kees Cook <kees@kernel.org>
fs/exec.c

index 9ea3a775d51e9b40fe999e5b833cbe15d528d760..ba12b4c466f6daf48cdc898e59c062341e400e36 100644 (file)
--- 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);