bpf: Do not allow to load sleepable BPF_TRACE_RAW_TP program
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> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20230117223705.440975-1-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Родитель
c1177979af
Коммит
700e6f853e
|
@ -16743,6 +16743,23 @@ BTF_ID(func, rcu_read_unlock_strict)
|
||||||
#endif
|
#endif
|
||||||
BTF_SET_END(btf_id_deny)
|
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)
|
static int check_attach_btf_id(struct bpf_verifier_env *env)
|
||||||
{
|
{
|
||||||
struct bpf_prog *prog = env->prog;
|
struct bpf_prog *prog = env->prog;
|
||||||
|
@ -16761,9 +16778,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prog->aux->sleepable && prog->type != BPF_PROG_TYPE_TRACING &&
|
if (prog->aux->sleepable && !can_be_sleepable(prog)) {
|
||||||
prog->type != BPF_PROG_TYPE_LSM && prog->type != BPF_PROG_TYPE_KPROBE) {
|
verbose(env, "Only fentry/fexit/fmod_ret, lsm, iter and uprobe programs can be sleepable\n");
|
||||||
verbose(env, "Only fentry/fexit/fmod_ret, lsm, and kprobe/uprobe programs can be sleepable\n");
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче