Skip to content

Commit bdcaef7

Browse files
charmitroborkmann
authored andcommitted
net, bpf: Fix RCU usage in task_cls_state() for BPF programs
The commit ee97163 ("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_trace_held() as a valid RCU context in the task_cls_state() function. This is safe because BPF programs are non-sleepable and task_cls_state() is only doing an RCU dereference to get the classid. Fixes: ee97163 ("bpf: Allow some trace helpers for all prog types") Reported-by: [email protected] Signed-off-by: Charalampos Mitrodimas <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Link: https://lore.kernel.org/bpf/[email protected] Closes: https://syzkaller.appspot.com/bug?extid=b4169a1cfb945d2ed0ec
1 parent f1c0257 commit bdcaef7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/netclassid_cgroup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ static inline struct cgroup_cls_state *css_cls_state(struct cgroup_subsys_state
2121
struct cgroup_cls_state *task_cls_state(struct task_struct *p)
2222
{
2323
return css_cls_state(task_css_check(p, net_cls_cgrp_id,
24-
rcu_read_lock_bh_held()));
24+
rcu_read_lock_bh_held() ||
25+
rcu_read_lock_trace_held()));
2526
}
2627
EXPORT_SYMBOL_GPL(task_cls_state);
2728

0 commit comments

Comments
 (0)