From patchwork Mon Oct 24 11:30:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp432926wru; Mon, 24 Oct 2022 05:48:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6TWxuC+dbfrdBJ4lLXx1dBlSE6pC5JWbvMzES1pYZsJH5nUd/ZpuQZj4RhJU/CxCESvWf7 X-Received: by 2002:a17:90a:2cc7:b0:212:f074:cf4d with SMTP id n65-20020a17090a2cc700b00212f074cf4dmr11445486pjd.70.1666615686291; Mon, 24 Oct 2022 05:48:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615686; cv=none; d=google.com; s=arc-20160816; b=iZ1SQ/OnLcGZgOuwWdfPJGV2M9hHe6bWFo8ZPBvKdqheFocSOuTGHzJRjbvxw9sUJg ZRUvjuAryDrOKkBJG1J5uVfRs8FTnVSrXGGe6gglCmbRNB+WlSlhPbsXhn/1bbHu/wm2 fwmRrDRvezAAbd+5kx660RqtIVaf8c2z2G/v2Cp6j2U1+KWeltmrVq+QyMpsD75vRyzn DoyGddj6mhp6K5fCIqYoY4cQVqBaIYpKK6XQSahPoqAKiCsyRbfSd6RPTREpyi5jx6CO X85uEqxpbbJifQ5rAwBlVWeYoS0n/ub4UgJerX4KMnPPSjGrTeEfyHcZpHRFQPVxqxws 4IdQ== 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=W7zlw4081QrFjukqTmJhn52l7eozjl+3YuIqSz1vBSQ=; b=eMgg89GWmCthqJFZz7Zy5VAuK1AljSocwZXTf7OFghfYxPPL9PPCHh/vf/v1VNmfPa JSK1f6+OOQCmaMXzkCnuRi6QHbTgDz8Bi4/61SLYh8Lmfz+tmvXqqWTeYbknc1O8da1Z fQlD6ZwVFRn+2Uu8ZVmN3OU3RV39Z6ycSxP6KVwwHnJp7vKgO9t946sc5bSRiWLKNzOq NhVdNcih4YYwsxTw48/mVUqI5Iwc+3A4HYUKft7RWrGKzTb+gHyrU45X/4wYzko7H904 ZpXOARFL3s6uB/GK0MSzEZsSqZ3geHywWdZDi7EOapUqSgSK4nqolUsY2RqMvxVIdjIl idsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sOMUvPi7; 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 a11-20020a056a000c8b00b0053e1d872a91si37362941pfv.83.2022.10.24.05.47.49; Mon, 24 Oct 2022 05:48:06 -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=sOMUvPi7; 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 S234027AbiJXMig (ORCPT + 99 others); Mon, 24 Oct 2022 08:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233888AbiJXM2e (ORCPT ); Mon, 24 Oct 2022 08:28:34 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E93386FBB; Mon, 24 Oct 2022 05:02:18 -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 ams.source.kernel.org (Postfix) with ESMTPS id 64C12B81150; Mon, 24 Oct 2022 11:58:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAF06C433D6; Mon, 24 Oct 2022 11:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612709; bh=KXBQ6MdwJlojy74YROK74a4S4l8XmysUHJstxMTskFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sOMUvPi7gmYmooroz3cYA+glwU2WBlIVqGb5BM2bdUbdIyEWTkw5T8hJXOebmrHPr 4a5kWokoGWJKP9zChRZNuou0aMjigxDgWTRUVHe+Ev5fyBn/3dtZmrvTTD0Jl7b368 QI2zItdFX31ytmr7rgF1gN6rbjAkdTLbwSCwXTsI= 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 4.19 082/229] bpf: Ensure correct locking around vulnerable function find_vpid() Date: Mon, 24 Oct 2022 13:30:01 +0200 Message-Id: <20221024113001.724483738@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747573210042252706?= X-GMAIL-MSGID: =?utf-8?q?1747573210042252706?= 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 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;