From nobody Fri Dec 19 16:01:35 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB5E4C433FE for ; Sat, 22 Oct 2022 07:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232196AbiJVH4q (ORCPT ); Sat, 22 Oct 2022 03:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231873AbiJVHwv (ORCPT ); Sat, 22 Oct 2022 03:52:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 068042CA7D1; Sat, 22 Oct 2022 00:46:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7BC0460B1B; Sat, 22 Oct 2022 07:45:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9334DC433D6; Sat, 22 Oct 2022 07:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424726; bh=HiG51sHsMxzHVedBNQE+5UlO3SgRy+hGjnxhkYctKZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SAkJz2rF0MLx3D+TcCVHce3fpLksAVq04ESX+07XTU8zGonEa3zblzQ7RLaYlo8S8 QiiHRycYFPadX5KPDAS1DKza27bo4SWRSb0ErLH7WttiYin+ZnV59GdJmajtUgOJS8 hrEl/5unbHY1OffR7tF27lKgcuOSEzlLOoOM+/AI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lee Jones , Daniel Borkmann , Yonghong Song , Sasha Levin Subject: [PATCH 5.19 253/717] bpf: Ensure correct locking around vulnerable function find_vpid() Date: Sat, 22 Oct 2022 09:22:12 +0200 Message-Id: <20221022072459.614445182@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lee Jones [ 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 Signed-off-by: Daniel Borkmann Acked-by: Yonghong Song Link: https://lore.kernel.org/bpf/20220912133855.1218900-1-lee@kernel.org Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 7a3444988c84..494ba88054e8 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4361,7 +4361,9 @@ static int bpf_task_fd_query(const union bpf_attr *at= tr, if (attr->task_fd_query.flags !=3D 0) return -EINVAL; =20 + rcu_read_lock(); task =3D get_pid_task(find_vpid(pid), PIDTYPE_PID); + rcu_read_unlock(); if (!task) return -ENOENT; =20 --=20 2.35.1