summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorLee Jones <lee@kernel.org>2022-09-12 14:38:55 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-10-26 13:19:25 +0200
commite4b17b461c992c30e594d24357a44951cf3cdc18 (patch)
treea0dae2a4b42ae0afdb244fdef6032d7a31581af2 /kernel
parentaed374b4729b37dd6a6280b69f1277d9494b15d2 (diff)
downloadlinux-stable-e4b17b461c992c30e594d24357a44951cf3cdc18.tar.gz
linux-stable-e4b17b461c992c30e594d24357a44951cf3cdc18.tar.bz2
linux-stable-e4b17b461c992c30e594d24357a44951cf3cdc18.zip
bpf: Ensure correct locking around vulnerable function find_vpid()
[ Upstream commit 83c10cc362d91c0d8d25e60779ee52fdbbf3894d ] 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 <lee@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220912133855.1218900-1-lee@kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/syscall.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index e940c1f65938..02e5bdb82a9a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2325,7 +2325,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;