All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Lock bpf_trace_printk's tmp buf before it is written to
@ 2021-04-27 11:29 Florent Revest
  2021-04-27 15:07 ` Alexei Starovoitov
  0 siblings, 1 reply; 4+ messages in thread
From: Florent Revest @ 2021-04-27 11:29 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, kpsingh, jackmanb, linux, linux-kernel,
	Florent Revest

bpf_trace_printk uses a shared static buffer to hold strings before they
are printed. A recent refactoring moved the locking of that buffer after
it gets filled by mistake.

Fixes: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf")
Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Florent Revest <revest@chromium.org>
---
 kernel/trace/bpf_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 2a8bcdc927c7..0e67d12a8f40 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -391,13 +391,13 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
 	if (ret < 0)
 		return ret;
 
+	raw_spin_lock_irqsave(&trace_printk_lock, flags);
 	ret = snprintf(buf, sizeof(buf), fmt, BPF_CAST_FMT_ARG(0, args, mod),
 		BPF_CAST_FMT_ARG(1, args, mod), BPF_CAST_FMT_ARG(2, args, mod));
 	/* snprintf() will not append null for zero-length strings */
 	if (ret == 0)
 		buf[0] = '\0';
 
-	raw_spin_lock_irqsave(&trace_printk_lock, flags);
 	trace_bpf_trace_printk(buf);
 	raw_spin_unlock_irqrestore(&trace_printk_lock, flags);
 
-- 
2.31.1.498.g6c1eba8ee3d-goog


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

* Re: [PATCH bpf-next] bpf: Lock bpf_trace_printk's tmp buf before it is written to
  2021-04-27 11:29 [PATCH bpf-next] bpf: Lock bpf_trace_printk's tmp buf before it is written to Florent Revest
@ 2021-04-27 15:07 ` Alexei Starovoitov
  2021-04-27 15:20   ` Florent Revest
  0 siblings, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2021-04-27 15:07 UTC (permalink / raw)
  To: Florent Revest
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	KP Singh, Brendan Jackman, Rasmus Villemoes, LKML

On Tue, Apr 27, 2021 at 4:30 AM Florent Revest <revest@chromium.org> wrote:
>
> bpf_trace_printk uses a shared static buffer to hold strings before they
> are printed. A recent refactoring moved the locking of that buffer after
> it gets filled by mistake.
>
> Fixes: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf")
> Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Signed-off-by: Florent Revest <revest@chromium.org>

Applied.

Pls send v2 of bstr_printf series as soon as possible. Thanks!

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

* Re: [PATCH bpf-next] bpf: Lock bpf_trace_printk's tmp buf before it is written to
  2021-04-27 15:07 ` Alexei Starovoitov
@ 2021-04-27 15:20   ` Florent Revest
  2021-04-27 15:23     ` Alexei Starovoitov
  0 siblings, 1 reply; 4+ messages in thread
From: Florent Revest @ 2021-04-27 15:20 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	KP Singh, Brendan Jackman, Rasmus Villemoes, LKML

On Tue, Apr 27, 2021 at 5:08 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Tue, Apr 27, 2021 at 4:30 AM Florent Revest <revest@chromium.org> wrote:
> >
> > bpf_trace_printk uses a shared static buffer to hold strings before they
> > are printed. A recent refactoring moved the locking of that buffer after
> > it gets filled by mistake.
> >
> > Fixes: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf")
> > Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > Signed-off-by: Florent Revest <revest@chromium.org>
>
> Applied.

Thanks!

> Pls send v2 of bstr_printf series as soon as possible. Thanks!

Sure, I just assumed there would be more reviews on v1. The feedback
I'll address is only about the commit description wording but I can
send a v2 today.

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

* Re: [PATCH bpf-next] bpf: Lock bpf_trace_printk's tmp buf before it is written to
  2021-04-27 15:20   ` Florent Revest
@ 2021-04-27 15:23     ` Alexei Starovoitov
  0 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2021-04-27 15:23 UTC (permalink / raw)
  To: Florent Revest
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	KP Singh, Brendan Jackman, Rasmus Villemoes, LKML

On Tue, Apr 27, 2021 at 8:20 AM Florent Revest <revest@chromium.org> wrote:
>
> On Tue, Apr 27, 2021 at 5:08 PM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Tue, Apr 27, 2021 at 4:30 AM Florent Revest <revest@chromium.org> wrote:
> > >
> > > bpf_trace_printk uses a shared static buffer to hold strings before they
> > > are printed. A recent refactoring moved the locking of that buffer after
> > > it gets filled by mistake.
> > >
> > > Fixes: d9c9e4db186a ("bpf: Factorize bpf_trace_printk and bpf_seq_printf")
> > > Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > > Signed-off-by: Florent Revest <revest@chromium.org>
> >
> > Applied.
>
> Thanks!
>
> > Pls send v2 of bstr_printf series as soon as possible. Thanks!
>
> Sure, I just assumed there would be more reviews on v1. The feedback
> I'll address is only about the commit description wording but I can
> send a v2 today.

Yes. Please.

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

end of thread, other threads:[~2021-04-27 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 11:29 [PATCH bpf-next] bpf: Lock bpf_trace_printk's tmp buf before it is written to Florent Revest
2021-04-27 15:07 ` Alexei Starovoitov
2021-04-27 15:20   ` Florent Revest
2021-04-27 15:23     ` Alexei Starovoitov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.