linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] tracing: Fix out of bounds write in get_trace_buf
@ 2020-10-29 15:57 Qiujun Huang
  2020-10-29 18:30 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Qiujun Huang @ 2020-10-29 15:57 UTC (permalink / raw)
  To: rostedt, mingo, linux-kernel; +Cc: Qiujun Huang

The subscript should be nesting - 1, as nesting had self-added.

Fixes: e2ace001176dc ("tracing: Choose static tp_printk buffer by explicit nesting count")
Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
---
v3:
Modify the way of array reference instead.
v2:
Fix a typo in the title.
---
 kernel/trace/trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 528971714fc6..daa96215e294 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3132,7 +3132,7 @@ static char *get_trace_buf(void)
 
 	/* Interrupts must see nesting incremented before we use the buffer */
 	barrier();
-	return &buffer->buffer[buffer->nesting][0];
+	return &buffer->buffer[buffer->nesting - 1][0];
 }
 
 static void put_trace_buf(void)
-- 
2.17.1


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

* Re: [PATCH v3] tracing: Fix out of bounds write in get_trace_buf
  2020-10-29 15:57 [PATCH v3] tracing: Fix out of bounds write in get_trace_buf Qiujun Huang
@ 2020-10-29 18:30 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2020-10-29 18:30 UTC (permalink / raw)
  To: Qiujun Huang; +Cc: mingo, linux-kernel, Andy Lutomirski

On Thu, 29 Oct 2020 23:57:14 +0800
Qiujun Huang <hqjagain@gmail.com> wrote:

> The subscript should be nesting - 1, as nesting had self-added.

Thanks Qiujun! I'll add this to my urgent queue, and mark it for stable.

I'll update the change log to state:

"The nesting count of trace_printk allows for 4 levels of nesting. The
nesting counter starts at zero and is incremented before being used to
retrieve the current context's buffer. But the index to the buffer uses the
nesting counter after it was incremented, and not its original number,
which in needs to do."

-- Steve

> 
> Fixes: e2ace001176dc ("tracing: Choose static tp_printk buffer by explicit nesting count")
> Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
> ---
> v3:
> Modify the way of array reference instead.
> v2:
> Fix a typo in the title.
> ---
>  kernel/trace/trace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 528971714fc6..daa96215e294 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -3132,7 +3132,7 @@ static char *get_trace_buf(void)
>  
>  	/* Interrupts must see nesting incremented before we use the buffer */
>  	barrier();
> -	return &buffer->buffer[buffer->nesting][0];
> +	return &buffer->buffer[buffer->nesting - 1][0];
>  }
>  
>  static void put_trace_buf(void)


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

end of thread, other threads:[~2020-10-29 18:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 15:57 [PATCH v3] tracing: Fix out of bounds write in get_trace_buf Qiujun Huang
2020-10-29 18:30 ` 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).