Message ID | 20231007135945.4306-1-laoar.shao@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 29a7e00ffadddd8d68eff311de1bf12ae10687bb |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next,v2,1/2] bpf: Fix missed rcu read lock in bpf_task_under_cgroup() | expand |
Hello: This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <daniel@iogearbox.net>: On Sat, 7 Oct 2023 13:59:44 +0000 you wrote: > When employed within a sleepable program not under RCU protection, the use > of 'bpf_task_under_cgroup()' may trigger a warning in the kernel log, > particularly when CONFIG_PROVE_RCU is enabled. > > [ 1259.662354] ============================= > [ 1259.662357] WARNING: suspicious RCU usage > [ 1259.662358] 6.5.0+ #33 Not tainted > [ 1259.662360] ----------------------------- > [ 1259.662361] include/linux/cgroup.h:423 suspicious rcu_dereference_check() usage! > [ 1259.662364] > other info that might help us debug this: > > [...] Here is the summary with links: - [bpf-next,v2,1/2] bpf: Fix missed rcu read lock in bpf_task_under_cgroup() https://git.kernel.org/bpf/bpf-next/c/29a7e00ffadd - [bpf-next,v2,2/2] selftests/bpf: Add selftest for bpf_task_under_cgroup() in sleepable prog https://git.kernel.org/bpf/bpf-next/c/44cb03f19b38 You are awesome, thank you!
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index dd1c69ee3375..bb521b181cc3 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2212,7 +2212,12 @@ __bpf_kfunc struct cgroup *bpf_cgroup_from_id(u64 cgid) __bpf_kfunc long bpf_task_under_cgroup(struct task_struct *task, struct cgroup *ancestor) { - return task_under_cgroup_hierarchy(task, ancestor); + long ret; + + rcu_read_lock(); + ret = task_under_cgroup_hierarchy(task, ancestor); + rcu_read_unlock(); + return ret; } #endif /* CONFIG_CGROUPS */