bpf: Relax allowlist for css_task iter
authorChuyi Zhou <zhouchuyi@bytedance.com>
Tue, 31 Oct 2023 05:04:36 +0000 (13:04 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 2 Nov 2023 05:49:20 +0000 (22:49 -0700)
commit3091b667498b0a212e760e1033e5f9b8c33a948f
tree64e1da0f69e939ed6c28ea8b5d32ee3b35033549
parent9af3775962afa8b5cd0cc30c1e454405a650c1f3
bpf: Relax allowlist for css_task iter

The newly added open-coded css_task iter would try to hold the global
css_set_lock in bpf_iter_css_task_new, so the bpf side has to be careful in
where it allows to use this iter. The mainly concern is dead locking on
css_set_lock. check_css_task_iter_allowlist() in verifier enforced css_task
can only be used in bpf_lsm hooks and sleepable bpf_iter.

This patch relax the allowlist for css_task iter. Any lsm and any iter
(even non-sleepable) and any sleepable are safe since they would not hold
the css_set_lock before entering BPF progs context.

This patch also fixes the misused BPF_TRACE_ITER in
check_css_task_iter_allowlist which compared bpf_prog_type with
bpf_attach_type.

Fixes: 9c66dc94b62ae ("bpf: Introduce css_task open-coded iterator kfuncs")
Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231031050438.93297-2-zhouchuyi@bytedance.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/verifier.c
tools/testing/selftests/bpf/progs/iters_task_failure.c