]> git.ipfire.org Git - thirdparty/linux.git/commit
net, bpf: Fix RCU usage in task_cls_state() for BPF programs
authorCharalampos Mitrodimas <charmitro@posteo.net>
Wed, 11 Jun 2025 17:20:43 +0000 (17:20 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 11 Jun 2025 19:30:29 +0000 (21:30 +0200)
commit7f12c33850482521c961c5c15a50ebe9b9a88d1e
tree5d21fc3909fed1d9702e08c13e533797b4c36559
parentf1c025773f257b534f6fa77dca29b0967dfed459
net, bpf: Fix RCU usage in task_cls_state() for BPF programs

The commit ee971630f20f ("bpf: Allow some trace helpers for all prog
types") made bpf_get_cgroup_classid_curr helper available to all BPF
program types, not just networking programs.

This helper calls __task_get_classid() which internally calls
task_cls_state() requiring rcu_read_lock_bh_held(). This works
in networking/tc context where RCU BH is held, but triggers an RCU
warning when called from other contexts like BPF syscall programs
that run under rcu_read_lock_trace():

  WARNING: suspicious RCU usage
  6.15.0-rc4-syzkaller-g079e5c56a5c4 #0 Not tainted
  -----------------------------
  net/core/netclassid_cgroup.c:24 suspicious rcu_dereference_check() usage!

Fix this by also accepting rcu_read_lock_held() and
rcu_read_lock_trace_held() as valid RCU contexts in the
task_cls_state() function. This ensures the helper works correctly
in all needed RCU contexts where it might be called, regular RCU,
RCU BH (for networking), and RCU trace (for BPF syscall programs).

Fixes: ee971630f20f ("bpf: Allow some trace helpers for all prog types")
Reported-by: syzbot+b4169a1cfb945d2ed0ec@syzkaller.appspotmail.com
Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20250611-rcu-fix-task_cls_state-v3-1-3d30e1de753f@posteo.net
Closes: https://syzkaller.appspot.com/bug?extid=b4169a1cfb945d2ed0ec
net/core/netclassid_cgroup.c