* [PATCH bpf-next] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program
@ 2023-01-09 14:37 Jiri Olsa
2023-01-09 16:19 ` Song Liu
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2023-01-09 14:37 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: bpf, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo
Currently we allow to load any tracing program as sleepable,
but BPF_TRACE_RAW_TP can't sleep. Making the check explicit
for tracing programs attach types, so sleepable BPF_TRACE_RAW_TP
will fail to load.
Updating the verifier error to mention iter programs as well.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
kernel/bpf/verifier.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index fa4c911603e9..121a64ee841a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -16743,6 +16743,18 @@ BTF_ID(func, rcu_read_unlock_strict)
#endif
BTF_SET_END(btf_id_deny)
+static int can_be_sleepable(struct bpf_prog *prog)
+{
+ if (prog->type == BPF_PROG_TYPE_TRACING) {
+ return prog->expected_attach_type == BPF_TRACE_FENTRY ||
+ prog->expected_attach_type == BPF_TRACE_FEXIT ||
+ prog->expected_attach_type == BPF_MODIFY_RETURN ||
+ prog->expected_attach_type == BPF_TRACE_ITER;
+ }
+ return prog->type == BPF_PROG_TYPE_LSM ||
+ prog->type == BPF_PROG_TYPE_KPROBE;
+}
+
static int check_attach_btf_id(struct bpf_verifier_env *env)
{
struct bpf_prog *prog = env->prog;
@@ -16761,9 +16773,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
return -EINVAL;
}
- if (prog->aux->sleepable && prog->type != BPF_PROG_TYPE_TRACING &&
- prog->type != BPF_PROG_TYPE_LSM && prog->type != BPF_PROG_TYPE_KPROBE) {
- verbose(env, "Only fentry/fexit/fmod_ret, lsm, and kprobe/uprobe programs can be sleepable\n");
+ if (prog->aux->sleepable && !can_be_sleepable(prog)) {
+ verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and kprobe/uprobe programs can be sleepable\n");
return -EINVAL;
}
--
2.39.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program
2023-01-09 14:37 [PATCH bpf-next] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program Jiri Olsa
@ 2023-01-09 16:19 ` Song Liu
2023-01-09 16:55 ` Jiri Olsa
0 siblings, 1 reply; 3+ messages in thread
From: Song Liu @ 2023-01-09 16:19 UTC (permalink / raw)
To: Jiri Olsa
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo
On Mon, Jan 9, 2023 at 6:37 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Currently we allow to load any tracing program as sleepable,
> but BPF_TRACE_RAW_TP can't sleep. Making the check explicit
> for tracing programs attach types, so sleepable BPF_TRACE_RAW_TP
> will fail to load.
>
> Updating the verifier error to mention iter programs as well.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> kernel/bpf/verifier.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index fa4c911603e9..121a64ee841a 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -16743,6 +16743,18 @@ BTF_ID(func, rcu_read_unlock_strict)
> #endif
> BTF_SET_END(btf_id_deny)
>
> +static int can_be_sleepable(struct bpf_prog *prog)
Shall we return bool?
> +{
> + if (prog->type == BPF_PROG_TYPE_TRACING) {
> + return prog->expected_attach_type == BPF_TRACE_FENTRY ||
> + prog->expected_attach_type == BPF_TRACE_FEXIT ||
> + prog->expected_attach_type == BPF_MODIFY_RETURN ||
> + prog->expected_attach_type == BPF_TRACE_ITER;
> + }
> + return prog->type == BPF_PROG_TYPE_LSM ||
> + prog->type == BPF_PROG_TYPE_KPROBE;
> +}
> +
> static int check_attach_btf_id(struct bpf_verifier_env *env)
> {
> struct bpf_prog *prog = env->prog;
> @@ -16761,9 +16773,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
> return -EINVAL;
> }
>
> - if (prog->aux->sleepable && prog->type != BPF_PROG_TYPE_TRACING &&
> - prog->type != BPF_PROG_TYPE_LSM && prog->type != BPF_PROG_TYPE_KPROBE) {
> - verbose(env, "Only fentry/fexit/fmod_ret, lsm, and kprobe/uprobe programs can be sleepable\n");
> + if (prog->aux->sleepable && !can_be_sleepable(prog)) {
> + verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and kprobe/uprobe programs can be sleepable\n");
> return -EINVAL;
> }
Maybe add a verifier test for this?
Thanks,
Song
>
> --
> 2.39.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program
2023-01-09 16:19 ` Song Liu
@ 2023-01-09 16:55 ` Jiri Olsa
0 siblings, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2023-01-09 16:55 UTC (permalink / raw)
To: Song Liu
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo
On Mon, Jan 09, 2023 at 08:19:31AM -0800, Song Liu wrote:
> On Mon, Jan 9, 2023 at 6:37 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Currently we allow to load any tracing program as sleepable,
> > but BPF_TRACE_RAW_TP can't sleep. Making the check explicit
> > for tracing programs attach types, so sleepable BPF_TRACE_RAW_TP
> > will fail to load.
> >
> > Updating the verifier error to mention iter programs as well.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > kernel/bpf/verifier.c | 17 ++++++++++++++---
> > 1 file changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index fa4c911603e9..121a64ee841a 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -16743,6 +16743,18 @@ BTF_ID(func, rcu_read_unlock_strict)
> > #endif
> > BTF_SET_END(btf_id_deny)
> >
> > +static int can_be_sleepable(struct bpf_prog *prog)
>
> Shall we return bool?
ok
>
> > +{
> > + if (prog->type == BPF_PROG_TYPE_TRACING) {
> > + return prog->expected_attach_type == BPF_TRACE_FENTRY ||
> > + prog->expected_attach_type == BPF_TRACE_FEXIT ||
> > + prog->expected_attach_type == BPF_MODIFY_RETURN ||
> > + prog->expected_attach_type == BPF_TRACE_ITER;
> > + }
> > + return prog->type == BPF_PROG_TYPE_LSM ||
> > + prog->type == BPF_PROG_TYPE_KPROBE;
> > +}
> > +
> > static int check_attach_btf_id(struct bpf_verifier_env *env)
> > {
> > struct bpf_prog *prog = env->prog;
> > @@ -16761,9 +16773,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
> > return -EINVAL;
> > }
> >
> > - if (prog->aux->sleepable && prog->type != BPF_PROG_TYPE_TRACING &&
> > - prog->type != BPF_PROG_TYPE_LSM && prog->type != BPF_PROG_TYPE_KPROBE) {
> > - verbose(env, "Only fentry/fexit/fmod_ret, lsm, and kprobe/uprobe programs can be sleepable\n");
> > + if (prog->aux->sleepable && !can_be_sleepable(prog)) {
> > + verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and kprobe/uprobe programs can be sleepable\n");
> > return -EINVAL;
> > }
>
> Maybe add a verifier test for this?
ok, will add
thanks,
jirka
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-09 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-09 14:37 [PATCH bpf-next] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program Jiri Olsa
2023-01-09 16:19 ` Song Liu
2023-01-09 16:55 ` Jiri Olsa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox