Skip to contentSkip to conversation

Revert "bpf: remove unnecessary rcu_read_{lock,unlock}() in multi-uprobe attach logic"

PATCH Applied Xuewen Yan 4 participants 4 messages May 20, 2025 – May 22, 2025

Subsystems (4)
lore
Share & tools
lore

Xuewen Yan

author
#0 lore raw

PATCH 1/1 Revert "bpf: remove unnecessary rcu_read_{lock,unlock}() in multi-uprobe attach logic"

From: Di Shen <[email protected]>

This reverts commit 4a8f635a60540888dab3804992e86410360339c8.

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().

---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +2 -0
index 187dc37d61d4..0c4b6af10601 100644
@@ -3417,7 +3417,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;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 25 lines · Xuewen Yan

From: Di Shen <[email protected]>

This reverts commit 4a8f635a60540888dab3804992e86410360339c8.

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().

---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +0 -0
index 187dc37d61d4..0c4b6af10601 100644

kernel/trace/bpf_trace.c int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr · line 3425

Quoted 9 lines
kernel/trace/bpf_trace.c +2 -0
@@ -3417,7 +3417,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;

hmm. indeed.

Jiri ?

#2 lore raw
Quoted 29 lines · Alexei Starovoitov
Quoted 27 lines · Xuewen Yan

From: Di Shen <[email protected]>

This reverts commit 4a8f635a60540888dab3804992e86410360339c8.

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().

---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +0 -0
index 187dc37d61d4..0c4b6af10601 100644
@@ -3417,7 +3417,9 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
        }
 
Quoted 10 lines

kernel/trace/bpf_trace.c int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr · line 3425

Quoted 7 lines
kernel/trace/bpf_trace.c +2 -0
        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;

hmm. indeed.

yep, my bad, missed find_vpid() restrictions. revert LGTM

Quoted 1 line

Jiri ?

#3 lore raw
In reply to Xuewen Yan
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Tue, 20 May 2025 13:49:43 +0800 you wrote:

From: Di Shen <[email protected]>

This reverts commit 4a8f635a60540888dab3804992e86410360339c8.

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

[...]

Here is the summary with links:
- Revert "bpf: remove unnecessary rcu_read_{lock,unlock}() in multi-uprobe attach logic"

    https://git.kernel.org/bpf/bpf-next/c/4e2e6841ff76

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html