From: Lee Jones Date: Mon, 12 Sep 2022 13:38:55 +0000 (+0100) Subject: bpf: Ensure correct locking around vulnerable function find_vpid() X-Git-Tag: v6.1-rc5~319^2~1^2~2^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83c10cc362d91c0d8d25e60779ee52fdbbf3894d;p=platform%2Fkernel%2Flinux-starfive.git 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 for find_vpid() instance in bpf_task_fd_query(). Add proper rcu_read_lock/unlock() to fix the issue. Fixes: 41bdc4b40ed6f ("bpf: introduce bpf subcommand BPF_TASK_FD_QUERY") Signed-off-by: Lee Jones Signed-off-by: Daniel Borkmann Acked-by: Yonghong Song Link: https://lore.kernel.org/bpf/20220912133855.1218900-1-lee@kernel.org --- diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 2776062..1bd18af 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4395,7 +4395,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;