[v4] tracing: Fix out of bounds write in get_trace_buf
diff mbox series

Message ID 20201029161905.4269-1-hqjagain@gmail.com
State Accepted
Commit c1acb4ac1a892cf08d27efcb964ad281728b0545
Headers show
Series
  • [v4] tracing: Fix out of bounds write in get_trace_buf
Related show

Commit Message

Qiujun Huang Oct. 29, 2020, 4:19 p.m. UTC
The subscript should be nesting - 1, as nesting had self-added.

Fixes: 3d9622c12c887 ("tracing: Add barrier to trace_printk() buffer nesting modification")
Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
---
v4:
Find the right patch which cause the problem.
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(-)

Comments

Steven Rostedt Oct. 29, 2020, 6:49 p.m. UTC | #1
On Fri, 30 Oct 2020 00:19:05 +0800
Qiujun Huang <hqjagain@gmail.com> wrote:

> The subscript should be nesting - 1, as nesting had self-added.
> 
> Fixes: 3d9622c12c887 ("tracing: Add barrier to trace_printk() buffer nesting modification")

Thanks, I'll still use the updated change log.

-- Steve

> Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
> ---
> v4:
> Find the right patch which cause the problem.
> 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)

Patch
diff mbox series

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)