Re: [PATCH] tracepoint: don't make assumptions about length of string on task rename

From: Steven Rostedt
Date: Fri Aug 28 2015 - 11:02:58 EST


On Fri, 28 Aug 2015 07:06:58 -0400
Sasha Levin <sasha.levin@xxxxxxxxxx> wrote:

> 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.
>
> Signed-off-by: Sasha Levin <sasha.levin@xxxxxxxxxx>

Acked-by: Steven Rostedt <rostedt@xxxxxxxxxxx>

Should this go to stable as well?

Also, as the memcpy was just faster than a strcpy, the static length
was used. Perhaps we should convert that to a dynamic length string.
But that should be a separate patch as this one fixes a possible bug,
and the conversion to a dynamic string is just an enhancement.

-- Steve


> ---
> include/trace/events/task.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/trace/events/task.h b/include/trace/events/task.h
> index dee3bb1..2cca6cd 100644
> --- a/include/trace/events/task.h
> +++ b/include/trace/events/task.h
> @@ -46,7 +46,7 @@ TRACE_EVENT(task_rename,
> TP_fast_assign(
> __entry->pid = task->pid;
> memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN);
> - memcpy(entry->newcomm, comm, TASK_COMM_LEN);
> + strlcpy(entry->newcomm, comm, TASK_COMM_LEN);
> __entry->oom_score_adj = task->signal->oom_score_adj;
> ),
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/