Skip to contentSkip to conversation

bpf: Ensure correct locking around vulnerable function find_vpid()

PATCH Applied Lee Jones 3 participants 5 messages Sep 12, 2022 – Sep 16, 2022

Subsystems (2)
lore
Share & tools
lore

Lee Jones

author
#0 lore raw

PATCH v3 1/1 bpf: Ensure correct locking around vulnerable function find_vpid()

The documentation for find_vpid() clearly states:

"Must be called with the tasklist_lock or rcu_read_lock() held."

Presently we do neither.

Cc Jiri Olsa <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Fixes 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY")

---

v2 => v3:
* Changed strategy from find_get_pid() to rcu_read_{un}lock()
* Removed Jiri's Ack

v1 => v2:
* Commit log update - no code differences

 kernel/bpf/syscall.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/bpf/syscall.c +2 -0
index 69be1c612daa5..d5c77c021c043 100644
@@ -4399,7 +4399,9 @@ static int bpf_task_fd_query(const union bpf_attr *attr,
 	if (attr->task_fd_query.flags != 0)
 		return -EINVAL;
 
+	rcu_read_lock();
 	task = get_pid_task(find_vpid(pid), PIDTYPE_PID);
+	rcu_read_unlock();
 	if (!task)
 		return -ENOENT;
 
Signature · 1 line
2.37.2.789.g6183377224-goog
Acked-by on v3 1/1
#1 lore raw
Quoted 2 lines · Lee Jones

The documentation for find_vpid() clearly states:

No need for the above extra line.

Quoted 3 lines

"Must be called with the tasklist_lock or rcu_read_lock() held."

Presently we do neither.

Presently we do neither for find_vpid() instance in bpf_task_fd_query(). Add proper rcu_read_lock/unlock() to fix the issue.

Quoted 15 lines
Cc Jiri Olsa <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Fixes 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY")

Ack with above a few suggestions for the commit message.

author
#2 lore raw
Quoted 5 lines · Yonghong Song
Quoted 2 lines · Lee Jones

The documentation for find_vpid() clearly states:

No need for the above extra line.

The intentional blank formatting line?

The commit message would look worse without it.

Is this really a blocker?

Quoted 6 lines
Quoted 3 lines

"Must be called with the tasklist_lock or rcu_read_lock() held."

Presently we do neither.

Presently we do neither for find_vpid() instance in bpf_task_fd_query(). Add proper rcu_read_lock/unlock() to fix the issue.

I can expand this.

Quoted 18 lines
Quoted 6 lines
Cc Jiri Olsa <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Quoted 8 lines
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Fixes 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY")

Ack with above a few suggestions for the commit message.

Signature · 1 line
Lee Jones [李琼斯]
#3 lore raw
Quoted 5 lines · Lee Jones
Quoted 4 lines · Yonghong Song
Quoted 2 lines · Lee Jones

The documentation for find_vpid() clearly states:

Quoted 7 lines
Quoted 1 line

No need for the above extra line.

The intentional blank formatting line?

The commit message would look worse without it.

Is this really a blocker?

Not a blocker. Just a suggestion. I won't enforce it if you do have this extra line.

Quoted 29 lines
Quoted 7 lines
Quoted 4 lines

"Must be called with the tasklist_lock or rcu_read_lock() held."

Presently we do neither.

Presently we do neither for find_vpid() instance in bpf_task_fd_query(). Add proper rcu_read_lock/unlock() to fix the issue.

I can expand this.

Quoted 18 lines
Quoted 6 lines
Cc Jiri Olsa <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Quoted 8 lines
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Fixes 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY")

Ack with above a few suggestions for the commit message.

#4 lore raw
In reply to Lee Jones
This patch was applied to bpf/bpf.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <[email protected]>:

Quoted 21 lines · On Mon, 12 Sep 2022 14:38:55 +0100 you wrote:

The documentation for find_vpid() clearly states:

"Must be called with the tasklist_lock or rcu_read_lock() held."

Presently we do neither.

Cc Jiri Olsa <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Fixes 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY")
Quoted 1 line

[...]

Here is the summary with links:
- [v3,1/1] bpf: Ensure correct locking around vulnerable function find_vpid()

    https://git.kernel.org/bpf/bpf/c/83c10cc362d9

You are awesome, thank you!

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