From: Yonghong Song <yhs@meta.com>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCHv3 bpf-next 1/2] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program
Date: Tue, 17 Jan 2023 07:43:44 -0800 [thread overview]
Message-ID: <5ea1c791-eac4-b984-d0c1-1740d0a79ff6@meta.com> (raw)
In-Reply-To: <Y8ZoVLIkqKeP3DnX@krava>
On 1/17/23 1:20 AM, Jiri Olsa wrote:
> On Mon, Jan 16, 2023 at 11:17:56PM -0800, Yonghong Song wrote:
>>
>>
>> On 1/16/23 5:29 AM, Jiri Olsa 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.
>>>
>>> Acked-by: Song Liu <song@kernel.org>
>>> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>>
>> Ack with a minor comment below.
>>
>> Acked-by: Yonghong Song <yhs@fb.com>
>>
>>> ---
>>> v3 changes:
>>> - use switch in can_be_sleepable [Alexei]
>>> - added acks [Song]
>>>
>>> kernel/bpf/verifier.c | 22 +++++++++++++++++++---
>>> 1 file changed, 19 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>>> index fa4c911603e9..966dbfc14288 100644
>>> --- a/kernel/bpf/verifier.c
>>> +++ b/kernel/bpf/verifier.c
>>> @@ -16743,6 +16743,23 @@ BTF_ID(func, rcu_read_unlock_strict)
>>> #endif
>>> BTF_SET_END(btf_id_deny)
>>> +static bool can_be_sleepable(struct bpf_prog *prog)
>>> +{
>>> + if (prog->type == BPF_PROG_TYPE_TRACING) {
>>> + switch (prog->expected_attach_type) {
>>> + case BPF_TRACE_FENTRY:
>>> + case BPF_TRACE_FEXIT:
>>> + case BPF_MODIFY_RETURN:
>>> + case BPF_TRACE_ITER:
>>> + return true;
>>> + default:
>>> + return false;
>>> + }
>>> + }
>>> + 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 +16778,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");
>>
>> actually kprobe programs cannot be sleepable. See kernel/events/core.c.
>> perf_event_set_bpf_prog(...)
>> ...
>>
>> if (prog->type == BPF_PROG_TYPE_KPROBE && prog->aux->sleepable &&
>> !is_uprobe)
>> /* only uprobe programs are allowed to be sleepable */
>> return -EINVAL;
>>
>> So I suggest to add a comment and remove the above 'kprobe' from error
>> message.
>
> ok, is comment below ok?
Thanks! Sounds good to me.
>
> jirka
>
>
> ---
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index fa4c911603e9..ca7db2ce70b9 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -16743,6 +16743,23 @@ BTF_ID(func, rcu_read_unlock_strict)
> #endif
> BTF_SET_END(btf_id_deny)
>
> +static bool can_be_sleepable(struct bpf_prog *prog)
> +{
> + if (prog->type == BPF_PROG_TYPE_TRACING) {
> + switch (prog->expected_attach_type) {
> + case BPF_TRACE_FENTRY:
> + case BPF_TRACE_FEXIT:
> + case BPF_MODIFY_RETURN:
> + case BPF_TRACE_ITER:
> + return true;
> + default:
> + return false;
> + }
> + }
> + return prog->type == BPF_PROG_TYPE_LSM ||
> + prog->type == BPF_PROG_TYPE_KPROBE; /* only for uprobes */
> +}
> +
> static int check_attach_btf_id(struct bpf_verifier_env *env)
> {
> struct bpf_prog *prog = env->prog;
> @@ -16761,9 +16778,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 uprobe programs can be sleepable\n");
> return -EINVAL;
> }
>
prev parent reply other threads:[~2023-01-17 15:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-16 13:29 [PATCHv3 bpf-next 1/2] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program Jiri Olsa
2023-01-16 13:29 ` [PATCHv3 bpf-next 2/2] bpf/selftests: Add verifier tests for loading sleepable programs Jiri Olsa
2023-01-17 7:17 ` [PATCHv3 bpf-next 1/2] bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program Yonghong Song
2023-01-17 9:20 ` Jiri Olsa
2023-01-17 15:43 ` Yonghong Song [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5ea1c791-eac4-b984-d0c1-1740d0a79ff6@meta.com \
--to=yhs@meta.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=olsajiri@gmail.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.