Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Don't make assumptions about length of string on task rename

While the dest comm string size is assured to be at least TASK_COMM_LEN long,
doing a memcpy() also adds the assumption that the source is at least that
long as well, which isn't assured, and isn't true in cases such as:

set_task_comm(worker->task, "kworker/dying");

This leads to accessing invalid memory.

Link: http://lkml.kernel.org/r/1440760018-1557-1-git-send-email-sasha.levin@oracle.com

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Sasha Levin and committed by
Steven Rostedt
f0a51578 9f616680

+1 -1
+1 -1
include/trace/events/task.h
··· 46 46 TP_fast_assign( 47 47 __entry->pid = task->pid; 48 48 memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN); 49 - memcpy(entry->newcomm, comm, TASK_COMM_LEN); 49 + strlcpy(entry->newcomm, comm, TASK_COMM_LEN); 50 50 __entry->oom_score_adj = task->signal->oom_score_adj; 51 51 ), 52 52