From patchwork Mon Oct 24 11:29:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9189 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp458611wru; Mon, 24 Oct 2022 06:37:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4PBqxxYH8Iwop1ahx6p7Cr94pRWdG2oqRXYAJHH5ihdsWk5TtWqzYtxn8vwrMcrsukvTxj X-Received: by 2002:aa7:c61a:0:b0:461:c48d:effe with SMTP id h26-20020aa7c61a000000b00461c48deffemr4909080edq.7.1666618673808; Mon, 24 Oct 2022 06:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618673; cv=none; d=google.com; s=arc-20160816; b=eSOFMwkydJJXjXRUiPo+cNCzI9F4hXhprwEj0bvvLcrO52P0YCbtMlY2/f8VZrtJij KZAg49RO7owSqZI3if/R9y4mpLTzIeX16gp7PVKrSv4+GTeuItAJSJlbtfYO6N1gsc4W hLPuJZ07FSFRwETwTmtDhMSjJQUB4FuH68orut4qdupJHQu9JfRQX4H2r4+xsc0gcIVc mdWF82Za7Fpi6ntc3UJkuR6Q7B1rAtswpnU45H5tEI+wuvEJYxYhNqABftmv6Gg8P56f FFUNjnKkIF5q7qoqSByYfvwz2BEXX9nM20hZ+0OkEOGcBeHMakOPqIldc33Uhrp2rukk 08Ig== 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=zFdcedCp7xw6WbFIwvZdgu59CP54udLeIEvJzVCmhEE=; b=ySKK35amA2/ncokTOc8THiELBK96Diz3GUqAuj93LPvbi0TOS0x45LXw1vg6fgMw1+ OXBcWWXXbVRB9KCSiIeLsBNkrcLZXg0I6/hZib0JpOP5sS2iLGtmHWUhchxVQDoROwIZ w8OtjVz4DyK0VzHkgnG6cdi/4/SrVSDqdsILLxGDAgELRKRb9xetx2SQA4jMd4EV/xxt S6xTJ9ySil+O8h+/70nTlrVpsei55xATP4uPjk8PUOMq9T/PMX1cxAaA+13dC8VpdeOi dk32oDg6KWVw6BunZ25RXIcwJG8vNl9OoD514XcteBH8UNhxWSGDVXH6IqvZJ83bqwo2 KgjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WqGN/J9a"; 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 dp21-20020a170906c15500b0078df1c345dcsi34222474ejc.535.2022.10.24.06.37.10; Mon, 24 Oct 2022 06:37:53 -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="WqGN/J9a"; 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 S230188AbiJXNcS (ORCPT + 99 others); Mon, 24 Oct 2022 09:32:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235975AbiJXN3R (ORCPT ); Mon, 24 Oct 2022 09:29:17 -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 AE49E12A9A; Mon, 24 Oct 2022 05:32:31 -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 F34C5B81212; Mon, 24 Oct 2022 12:07:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E0D6C4314E; Mon, 24 Oct 2022 12:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613271; bh=eu3dHn2Lu/ALN7PdPni6DW2q/Erc6p8YdVQGodhk4OA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WqGN/J9aNfxZggqej0WeCfHpFcT0YIFJ6Tg4/Ck09XW0zlt57UVyJWu1wmTHubJt9 GDRECsKBVPKeLr0/JDgCUu1yP3lL1h/WHoDPTdSyS7yjYXMCEm2ynaGZsvGUvY3GIf bJTvK+t4IfyVP1fc+pMOvd+tOxW9xafjVWMo54NU= 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.4 074/255] bpf: Ensure correct locking around vulnerable function find_vpid() Date: Mon, 24 Oct 2022 13:29:44 +0200 Message-Id: <20221024113004.972494500@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747576342584046292?= X-GMAIL-MSGID: =?utf-8?q?1747576342584046292?= 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 9ebdcdaa5f16..de788761b708 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2787,7 +2787,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;