Skip to contentSkip to conversation

tracing: Fix out of bounds write in get_trace_buf

PATCH Superseded Qiujun Huang 2 participants 2 messages Oct 29, 2020 Tracing

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tracing: Fix out of bounds write in get_trace_buf

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

Fixes e2ace001176dc ("tracing: Choose static tp_printk buffer by explicit nesting count")

---
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(-)
kernel/trace/trace.c +1 -1
index 528971714fc6..daa96215e294 100644
@@ -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)
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 1 line · On Thu, 29 Oct 2020 23:57:14 +0800 Qiujun Huang <[email protected]> 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

Quoted 25 lines
Fixes e2ace001176dc ("tracing: Choose static tp_printk buffer by explicit nesting count")

---
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(-)
kernel/trace/trace.c +1 -1
index 528971714fc6..daa96215e294 100644
@@ -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)