exec: use strnlen() in __set_task_comm
Subsystems (4)
PATCH 1/2 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 <[email protected]>
--- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exec.c +1 -1
@@ -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);
PATCH 2/2 sched: update task_struct->comm comment
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 <[email protected]>
--- include/linux/sched.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
include/linux/sched.h +3 -6
@@ -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 ];
Quoted 4 lines · Thorsten Blum
Use
strnlen()to limit source string scanning to 'TASK_COMM_LEN- 1' bytes.Signed-off-by Thorsten Blum <[email protected]>
Looks good. Feel free to add:
Reviewed-by Jan Kara <[email protected]>
Honza
Quoted 17 lines
--- fs/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/exec.c +1
-1@@ -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);
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 4 lines · Thorsten Blum
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,
Signature · 1 line
Kees Cook