Skip to content

Commit 85f726a

Browse files
tzanussirostedt
authored andcommitted
tracing: Use strncpy instead of memcpy when copying comm in trace.c
Because there may be random garbage beyond a string's null terminator, code that might use the entire comm array e.g. histogram keys, can give unexpected results if that garbage is copied in too, so avoid that possibility by using strncpy instead of memcpy. Link: http://lkml.kernel.org/r/1d6ebac26570c2a29ce9fb575379f17ef5c8b81b.1551802084.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 27242c6 commit 85f726a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/trace/trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu)
14971497
max_data->critical_start = data->critical_start;
14981498
max_data->critical_end = data->critical_end;
14991499

1500-
memcpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
1500+
strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN);
15011501
max_data->pid = tsk->pid;
15021502
/*
15031503
* If tsk == current, then use current_uid(), as that does not use
@@ -1923,7 +1923,7 @@ static inline char *get_saved_cmdlines(int idx)
19231923

19241924
static inline void set_cmdline(int idx, const char *cmdline)
19251925
{
1926-
memcpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
1926+
strncpy(get_saved_cmdlines(idx), cmdline, TASK_COMM_LEN);
19271927
}
19281928

19291929
static int allocate_cmdlines_buffer(unsigned int val,

0 commit comments

Comments
 (0)