linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracepoint: don't make assumptions about length of string on task rename
@ 2015-08-28 11:06 Sasha Levin
  2015-08-28 15:02 ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2015-08-28 11:06 UTC (permalink / raw)
  To: rostedt, mingo; +Cc: linux-kernel, Sasha Levin

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@oracle.com>
---
 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;
 	),
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tracepoint: don't make assumptions about length of string on task rename
  2015-08-28 11:06 [PATCH] tracepoint: don't make assumptions about length of string on task rename Sasha Levin
@ 2015-08-28 15:02 ` Steven Rostedt
  2015-09-01 15:07   ` Sasha Levin
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2015-08-28 15:02 UTC (permalink / raw)
  To: Sasha Levin; +Cc: mingo, linux-kernel

On Fri, 28 Aug 2015 07:06:58 -0400
Sasha Levin <sasha.levin@oracle.com> 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@oracle.com>

Acked-by: Steven Rostedt <rostedt@goodmis.org>

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;
>  	),
>  


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tracepoint: don't make assumptions about length of string on task rename
  2015-08-28 15:02 ` Steven Rostedt
@ 2015-09-01 15:07   ` Sasha Levin
  2015-09-01 15:32     ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2015-09-01 15:07 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: mingo, linux-kernel

On 08/28/2015 11:02 AM, Steven Rostedt wrote:
> On Fri, 28 Aug 2015 07:06:58 -0400
> Sasha Levin <sasha.levin@oracle.com> 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@oracle.com>
> 
> Acked-by: Steven Rostedt <rostedt@goodmis.org>
> 
> Should this go to stable as well?

Yup.

> 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.

That'll slow things down for the common case, no?


Thanks,
Sasha


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tracepoint: don't make assumptions about length of string on task rename
  2015-09-01 15:07   ` Sasha Levin
@ 2015-09-01 15:32     ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2015-09-01 15:32 UTC (permalink / raw)
  To: Sasha Levin; +Cc: mingo, linux-kernel

On Tue, 01 Sep 2015 11:07:32 -0400
Sasha Levin <sasha.levin@oracle.com> wrote:

 
> > 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.
> 
> That'll slow things down for the common case, no?

Not really that much.

The comms should have been dynamic strings too, but the sched_switch
tracepoint (the one others have been copied from) was created before we
had dynamic strings for tracepoints.

-- Steve


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-01 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-28 11:06 [PATCH] tracepoint: don't make assumptions about length of string on task rename Sasha Levin
2015-08-28 15:02 ` Steven Rostedt
2015-09-01 15:07   ` Sasha Levin
2015-09-01 15:32     ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).