diff mbox series

[bpf-next,v2,2/2] bpf: Warn on non-preallocated case for missed trace types

Message ID 20220706155848.4939-3-laoar.shao@gmail.com (mailing list archive)
State New
Headers show
Series bpf: Minor fixes for non-preallocated memory | expand

Commit Message

Yafang Shao July 6, 2022, 3:58 p.m. UTC
BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE and BPF_PROG_TYPE_TRACING are
trace type as well, which may also cause unexpected memory allocation if
we set BPF_F_NO_PREALLOC.
Let's also warn on both of them.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 kernel/bpf/verifier.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alexei Starovoitov July 6, 2022, 4:50 p.m. UTC | #1
On Wed, Jul 6, 2022 at 8:59 AM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE and BPF_PROG_TYPE_TRACING are
> trace type as well, which may also cause unexpected memory allocation if
> we set BPF_F_NO_PREALLOC.
> Let's also warn on both of them.
>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  kernel/bpf/verifier.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index df3ec6b05f05..f9c0f4889a3a 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -12570,6 +12570,8 @@ static bool is_tracing_prog_type(enum bpf_prog_type type)
>         case BPF_PROG_TYPE_TRACEPOINT:
>         case BPF_PROG_TYPE_PERF_EVENT:
>         case BPF_PROG_TYPE_RAW_TRACEPOINT:
> +       case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
> +       case BPF_PROG_TYPE_TRACING:

BPF_TRACE_ITER should probably be excluded.
Yafang Shao July 7, 2022, 10:29 a.m. UTC | #2
On Thu, Jul 7, 2022 at 12:50 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Wed, Jul 6, 2022 at 8:59 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE and BPF_PROG_TYPE_TRACING are
> > trace type as well, which may also cause unexpected memory allocation if
> > we set BPF_F_NO_PREALLOC.
> > Let's also warn on both of them.
> >
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > ---
> >  kernel/bpf/verifier.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index df3ec6b05f05..f9c0f4889a3a 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -12570,6 +12570,8 @@ static bool is_tracing_prog_type(enum bpf_prog_type type)
> >         case BPF_PROG_TYPE_TRACEPOINT:
> >         case BPF_PROG_TYPE_PERF_EVENT:
> >         case BPF_PROG_TYPE_RAW_TRACEPOINT:
> > +       case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
> > +       case BPF_PROG_TYPE_TRACING:
>
> BPF_TRACE_ITER should probably be excluded.

Right, I have verified that BPF_TRACE_ITER can be excluded.
Will change it.
Alexei Starovoitov July 7, 2022, 3:45 p.m. UTC | #3
On Thu, Jul 7, 2022 at 3:30 AM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> On Thu, Jul 7, 2022 at 12:50 AM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Wed, Jul 6, 2022 at 8:59 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> > >
> > > BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE and BPF_PROG_TYPE_TRACING are
> > > trace type as well, which may also cause unexpected memory allocation if
> > > we set BPF_F_NO_PREALLOC.
> > > Let's also warn on both of them.
> > >
> > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > > ---
> > >  kernel/bpf/verifier.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > > index df3ec6b05f05..f9c0f4889a3a 100644
> > > --- a/kernel/bpf/verifier.c
> > > +++ b/kernel/bpf/verifier.c
> > > @@ -12570,6 +12570,8 @@ static bool is_tracing_prog_type(enum bpf_prog_type type)
> > >         case BPF_PROG_TYPE_TRACEPOINT:
> > >         case BPF_PROG_TYPE_PERF_EVENT:
> > >         case BPF_PROG_TYPE_RAW_TRACEPOINT:
> > > +       case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
> > > +       case BPF_PROG_TYPE_TRACING:
> >
> > BPF_TRACE_ITER should probably be excluded.
>
> Right, I have verified that BPF_TRACE_ITER can be excluded.
> Will change it.

Probably more than that. See that your change broke BPF CI
and selftests are failing.
Which means it breaks existing bpf programs.
Yafang Shao July 7, 2022, 4:22 p.m. UTC | #4
On Thu, Jul 7, 2022 at 11:45 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Thu, Jul 7, 2022 at 3:30 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > On Thu, Jul 7, 2022 at 12:50 AM Alexei Starovoitov
> > <alexei.starovoitov@gmail.com> wrote:
> > >
> > > On Wed, Jul 6, 2022 at 8:59 AM Yafang Shao <laoar.shao@gmail.com> wrote:
> > > >
> > > > BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE and BPF_PROG_TYPE_TRACING are
> > > > trace type as well, which may also cause unexpected memory allocation if
> > > > we set BPF_F_NO_PREALLOC.
> > > > Let's also warn on both of them.
> > > >
> > > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > > > ---
> > > >  kernel/bpf/verifier.c | 2 ++
> > > >  1 file changed, 2 insertions(+)
> > > >
> > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > > > index df3ec6b05f05..f9c0f4889a3a 100644
> > > > --- a/kernel/bpf/verifier.c
> > > > +++ b/kernel/bpf/verifier.c
> > > > @@ -12570,6 +12570,8 @@ static bool is_tracing_prog_type(enum bpf_prog_type type)
> > > >         case BPF_PROG_TYPE_TRACEPOINT:
> > > >         case BPF_PROG_TYPE_PERF_EVENT:
> > > >         case BPF_PROG_TYPE_RAW_TRACEPOINT:
> > > > +       case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
> > > > +       case BPF_PROG_TYPE_TRACING:
> > >
> > > BPF_TRACE_ITER should probably be excluded.
> >
> > Right, I have verified that BPF_TRACE_ITER can be excluded.
> > Will change it.
>
> Probably more than that. See that your change broke BPF CI
> and selftests are failing.
> Which means it breaks existing bpf programs.

Ah, yes, "#194 timer:FAIL" which is caused by this change.
I will be more careful here.
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index df3ec6b05f05..f9c0f4889a3a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -12570,6 +12570,8 @@  static bool is_tracing_prog_type(enum bpf_prog_type type)
 	case BPF_PROG_TYPE_TRACEPOINT:
 	case BPF_PROG_TYPE_PERF_EVENT:
 	case BPF_PROG_TYPE_RAW_TRACEPOINT:
+	case BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE:
+	case BPF_PROG_TYPE_TRACING:
 		return true;
 	default:
 		return false;