Skip to content

Commit 27242c6

Browse files
tzanussirostedt
authored andcommitted
tracing: Use strncpy instead of memcpy when copying comm for hist triggers
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/1eb9f096a8086c3c82c7fc087c900005143cec54.1551802084.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 9f0bbf3 commit 27242c6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ static inline void save_comm(char *comm, struct task_struct *task)
21412141
return;
21422142
}
21432143

2144-
memcpy(comm, task->comm, TASK_COMM_LEN);
2144+
strncpy(comm, task->comm, TASK_COMM_LEN);
21452145
}
21462146

21472147
static void hist_elt_data_free(struct hist_elt_data *elt_data)
@@ -3557,7 +3557,7 @@ static bool cond_snapshot_update(struct trace_array *tr, void *cond_data)
35573557
elt_data = context->elt->private_data;
35583558
track_elt_data = track_data->elt.private_data;
35593559
if (elt_data->comm)
3560-
memcpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN);
3560+
strncpy(track_elt_data->comm, elt_data->comm, TASK_COMM_LEN);
35613561

35623562
track_data->updated = true;
35633563

0 commit comments

Comments
 (0)