]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Check rcu_read_lock_trace_held() in bpf_map_lookup_percpu_elem()
authorHou Tao <houtao1@huawei.com>
Mon, 26 May 2025 06:25:34 +0000 (14:25 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 27 May 2025 17:45:59 +0000 (10:45 -0700)
bpf_map_lookup_percpu_elem() helper is also available for sleepable bpf
program. When BPF JIT is disabled or under 32-bit host,
bpf_map_lookup_percpu_elem() will not be inlined. Using it in a
sleepable bpf program will trigger the warning in
bpf_map_lookup_percpu_elem(), because the bpf program only holds
rcu_read_lock_trace lock. Therefore, add the missed check.

Reported-by: syzbot+dce5aae19ae4d6399986@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/bpf/000000000000176a130617420310@google.com/
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20250526062534.1105938-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c

index 376403707a85e179c35c815efbb1aef46f558375..b71e428ad9360fde0fc6aa2c0833a285ae6688dc 100644 (file)
@@ -130,7 +130,8 @@ const struct bpf_func_proto bpf_map_peek_elem_proto = {
 
 BPF_CALL_3(bpf_map_lookup_percpu_elem, struct bpf_map *, map, void *, key, u32, cpu)
 {
-       WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_bh_held());
+       WARN_ON_ONCE(!rcu_read_lock_held() && !rcu_read_lock_trace_held() &&
+                    !rcu_read_lock_bh_held());
        return (unsigned long) map->ops->map_lookup_percpu_elem(map, key, cpu);
 }