* [PATCH 5.4] tracing/ring-buffer: Only do full wait when cpu != RING_BUFFER_ALL_CPUS
@ 2022-12-16 13:42 Pratyush Yadav
2022-12-16 14:15 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Pratyush Yadav @ 2022-12-16 13:42 UTC (permalink / raw)
To: stable
Cc: Pratyush Yadav, Greg Kroah-Hartman, patches, Linux Trace Kernel,
Masami Hiramatsu, Mathieu Desnoyers, Primiano Tucci,
Steven Rostedt (Google)
full_hit() directly uses cpu as an array index. Since
RING_BUFFER_ALL_CPUS == -1, calling full_hit() with cpu ==
RING_BUFFER_ALL_CPUS will cause an invalid memory access.
The upstream commit 42fb0a1e84ff ("tracing/ring-buffer: Have polling
block on watermark") already does this. This was missed when backporting
to v5.4.y.
This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.
Fixes: e65ac2bdda54 ("tracing/ring-buffer: Have polling block on watermark")
Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
---
I am not familiar with this code. This was just pointed out by our
static analysis tool and I wrote a quick patch fixing this. Only
compile-tested.
kernel/trace/ring_buffer.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 176d858903bd..11e8189dd8ae 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -727,6 +727,7 @@ __poll_t ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
if (cpu == RING_BUFFER_ALL_CPUS) {
work = &buffer->irq_work;
+ full = 0;
} else {
if (!cpumask_test_cpu(cpu, buffer->cpumask))
return -EINVAL;
--
2.38.1
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 5.4] tracing/ring-buffer: Only do full wait when cpu != RING_BUFFER_ALL_CPUS
2022-12-16 13:42 [PATCH 5.4] tracing/ring-buffer: Only do full wait when cpu != RING_BUFFER_ALL_CPUS Pratyush Yadav
@ 2022-12-16 14:15 ` Steven Rostedt
2022-12-19 12:21 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2022-12-16 14:15 UTC (permalink / raw)
To: Pratyush Yadav
Cc: stable, Greg Kroah-Hartman, patches, Linux Trace Kernel,
Masami Hiramatsu, Mathieu Desnoyers, Primiano Tucci
On Fri, 16 Dec 2022 14:42:41 +0100
Pratyush Yadav <ptyadav@amazon.de> wrote:
> full_hit() directly uses cpu as an array index. Since
> RING_BUFFER_ALL_CPUS == -1, calling full_hit() with cpu ==
> RING_BUFFER_ALL_CPUS will cause an invalid memory access.
>
> The upstream commit 42fb0a1e84ff ("tracing/ring-buffer: Have polling
> block on watermark") already does this. This was missed when backporting
> to v5.4.y.
>
> This bug was discovered and resolved using Coverity Static Analysis
> Security Testing (SAST) by Synopsys, Inc.
Nice.
>
> Fixes: e65ac2bdda54 ("tracing/ring-buffer: Have polling block on watermark")
> Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
> ---
>
> I am not familiar with this code. This was just pointed out by our
> static analysis tool and I wrote a quick patch fixing this. Only
> compile-tested.
>
> kernel/trace/ring_buffer.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 176d858903bd..11e8189dd8ae 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -727,6 +727,7 @@ __poll_t ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
>
> if (cpu == RING_BUFFER_ALL_CPUS) {
> work = &buffer->irq_work;
> + full = 0;
Good catch. This was indeed missed in the backport. The backported patch
even added the comment:
* @full: wait until the percentage of pages are available, if @cpu != RING_BUFFER_ALL_CPUS
Greg, please take this patch.
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Thanks,
-- Steve
> } else {
> if (!cpumask_test_cpu(cpu, buffer->cpumask))
> return -EINVAL;
> --
> 2.38.1
>
>
>
>
> Amazon Development Center Germany GmbH
> Krausenstr. 38
> 10117 Berlin
> Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
> Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
> Sitz: Berlin
> Ust-ID: DE 289 237 879
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 5.4] tracing/ring-buffer: Only do full wait when cpu != RING_BUFFER_ALL_CPUS
2022-12-16 14:15 ` Steven Rostedt
@ 2022-12-19 12:21 ` Greg KH
0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2022-12-19 12:21 UTC (permalink / raw)
To: Steven Rostedt
Cc: Pratyush Yadav, stable, patches, Linux Trace Kernel,
Masami Hiramatsu, Mathieu Desnoyers, Primiano Tucci
On Fri, Dec 16, 2022 at 09:15:33AM -0500, Steven Rostedt wrote:
> On Fri, 16 Dec 2022 14:42:41 +0100
> Pratyush Yadav <ptyadav@amazon.de> wrote:
>
> > full_hit() directly uses cpu as an array index. Since
> > RING_BUFFER_ALL_CPUS == -1, calling full_hit() with cpu ==
> > RING_BUFFER_ALL_CPUS will cause an invalid memory access.
> >
> > The upstream commit 42fb0a1e84ff ("tracing/ring-buffer: Have polling
> > block on watermark") already does this. This was missed when backporting
> > to v5.4.y.
> >
> > This bug was discovered and resolved using Coverity Static Analysis
> > Security Testing (SAST) by Synopsys, Inc.
>
> Nice.
>
> >
> > Fixes: e65ac2bdda54 ("tracing/ring-buffer: Have polling block on watermark")
> > Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
> > ---
> >
> > I am not familiar with this code. This was just pointed out by our
> > static analysis tool and I wrote a quick patch fixing this. Only
> > compile-tested.
> >
> > kernel/trace/ring_buffer.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> > index 176d858903bd..11e8189dd8ae 100644
> > --- a/kernel/trace/ring_buffer.c
> > +++ b/kernel/trace/ring_buffer.c
> > @@ -727,6 +727,7 @@ __poll_t ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
> >
> > if (cpu == RING_BUFFER_ALL_CPUS) {
> > work = &buffer->irq_work;
> > + full = 0;
>
> Good catch. This was indeed missed in the backport. The backported patch
> even added the comment:
>
> * @full: wait until the percentage of pages are available, if @cpu != RING_BUFFER_ALL_CPUS
>
> Greg, please take this patch.
>
> Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Now queued up, thanks.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-19 12:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-16 13:42 [PATCH 5.4] tracing/ring-buffer: Only do full wait when cpu != RING_BUFFER_ALL_CPUS Pratyush Yadav
2022-12-16 14:15 ` Steven Rostedt
2022-12-19 12:21 ` Greg KH
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).