bpf: Revert "bpf: remove unnecessary rcu_read_{lock,unlock}() in multi-uprobe attach...
authorDi Shen <di.shen@unisoc.com>
Tue, 20 May 2025 05:49:43 +0000 (13:49 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 22 May 2025 14:49:32 +0000 (07:49 -0700)
This reverts commit 4a8f635a6054.

Althought get_pid_task() internally already calls rcu_read_lock() and
rcu_read_unlock(), the find_vpid() was not.

The documentation for find_vpid() clearly states:
"Must be called with the tasklist_lock or rcu_read_lock() held."

Add proper rcu_read_lock/unlock() to protect the find_vpid().

Fixes: 4a8f635a6054 ("bpf: remove unnecessary rcu_read_{lock,unlock}() in multi-uprobe attach logic")
Reported-by: Xuewen Yan <xuewen.yan@unisoc.com>
Signed-off-by: Di Shen <di.shen@unisoc.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20250520054943.5002-1-xuewen.yan@unisoc.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/trace/bpf_trace.c

index b0eb721..289ff0c 100644 (file)
@@ -3318,7 +3318,9 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
        }
 
        if (pid) {
+               rcu_read_lock();
                task = get_pid_task(find_vpid(pid), PIDTYPE_TGID);
+               rcu_read_unlock();
                if (!task) {
                        err = -ESRCH;
                        goto error_path_put;