From patchwork Sat Oct 22 07:22:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093430wrr; Sat, 22 Oct 2022 00:57:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5dFJesW3q032gYCVWG2o12J3RhlGxHA3JCg0MJH7/LweQWoedO37XqycfOPd2Nuc3s8DCD X-Received: by 2002:a63:5761:0:b0:43c:5940:9176 with SMTP id h33-20020a635761000000b0043c59409176mr19351043pgm.65.1666425433856; Sat, 22 Oct 2022 00:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425433; cv=none; d=google.com; s=arc-20160816; b=yZFlB+Ob5Ud0yrdjXBlImohE2t1BFbvykHm0aoSr3t7cgRJVNi5VKo28jIU2bCOKoO spKvizsJfXYGFtxpG3bIoXtsPON/S50EVA3x+K608szgH3B2M8UKzA448tnvvF6uor4u s3uLnPB231oCj1vFvW0gSS5eaV70ne5l1636b6biU48CdHW3How6Er96t/04wB+7ruQF PaJQ2ozXU5XWZKLsum2hZa7TmxcbgtagqTdryFzRWKzgMKIZvNXIGPiC6V91Ldatd0Ct 1qkX0n1HuGuWnMCZCA6X9jtAAShqh9nPh+Ce6LVwKVJFEdt5e272P7bAbDhdRgkkxjmM va5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Yz4Bd+NSZmKkn1Ll22znpWa7yzAkQdmD+xL2GFyPjoQ=; b=ivKmthCsS/RzgiNoh9iznyOanF+ImSamPnfoPiQvI4LCyVWpRKDtvmKr6O1dvgdo63 X8RtFJzrzZh/8PlxpZ2PO4dk82fUBtB6bM1spdHJy2dzZRklkIOoQ66ainmjZNB77u/w +ZJJ0WXfe4yOEik72K1ph+SsXCjmF/PHYcF29t+t9grwK5VBqdSrVIEBJSZNyMcVDF3B 2QoZQaD+Ccg5cOaqkTLXtoAyFHTE0d7F1dpRPP7HWL1RT1P2W5xUSFEsOTD7Y3EDAZ69 HeasaykLoT51nSzzLbORo+6JMZtxCT4u/HkfTo1EPt4hvp4gCbs7ug/n1tfmjDsEeWn/ N32w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SAkJz2rF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il11-20020a17090b164b00b001fb3040753fsi10730389pjb.64.2022.10.22.00.57.01; Sat, 22 Oct 2022 00:57:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SAkJz2rF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232161AbiJVH4o (ORCPT + 99 others); Sat, 22 Oct 2022 03:56:44 -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 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373715655510359?= X-GMAIL-MSGID: =?utf-8?q?1747373715655510359?= 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 *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;