From: Thorsten Blum Date: Wed, 1 Apr 2026 15:20:40 +0000 (+0200) Subject: exec: use strnlen() in __set_task_comm X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10cd6758e054e4002ccb409fef7dd2c6b7bbd549;p=thirdparty%2Fkernel%2Flinux.git exec: use strnlen() in __set_task_comm Use strnlen() to limit source string scanning to 'TASK_COMM_LEN - 1' bytes. Signed-off-by: Thorsten Blum Reviewed-by: Jan Kara Link: https://patch.msgid.link/20260401152039.724811-3-thorsten.blum@linux.dev Signed-off-by: Kees Cook --- diff --git a/fs/exec.c b/fs/exec.c index 9ea3a775d51e9..ba12b4c466f6d 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);