From patchwork Mon Oct 24 11:28:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp535117wru; Mon, 24 Oct 2022 09:12:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4hQKZ+fJ4F3BIuCFegaXqJTkhyD3mpkxZRoWtwm8nBYJNgvYmeCcmWllU/VQD09Qw7aQb5 X-Received: by 2002:a05:6a00:24d0:b0:563:6d36:eae8 with SMTP id d16-20020a056a0024d000b005636d36eae8mr34273524pfv.66.1666627944795; Mon, 24 Oct 2022 09:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666627944; cv=none; d=google.com; s=arc-20160816; b=BHOxJLgXLhJ1O9pIPJ5gMI5PIvb28kz1i+wkXuYK7gto6wnaRCcGdsCEW2xwCESmO+ 6QAkiNekAQYAAW8Xrg9ROiJK0NZZSPUVILgscqfjq6vMq5jxFqouHSyHLIO+LoB1yRhj 7a1t/0wUV39cIQ+NCnz+aCcTuzMLD7MX9vFdCrN0KGGJMsUWS0eFfBGuoZ/a1w3+2u3G aSo1/gk/6qLjjqDr9gH/kkVyratQRaTDOKKJ8HvwF5uG14liHcJvEazmIzw+X/NV1NcB FzDQUWuIVLioaGhizMzKHJ4o3+C0jCSazpxaEMCXQx/JaXrIfvht97k1ldQUtKgXPxns hDSw== 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=eSbpPGL3ojDNCDYvWP0bknzBDDVe0KhKpsTR4MFXtJc=; b=buvm5B85wODXk8wfZfd5InOlYR9pvb3E7NtwQLEEv9lR6/Iu51rFBqXe4ieUSVyfKI DLDDeVzHFRD6e68mygVKIE/AncvtnZnp0hUdGjFbdZ+oy8gJ+yQ2u3EF0lApBb5mmz3+ oA04pnVoHJrUc1BRKm8VL4TjuTs5VhafszGGs3YCvDwujEyHQWSXwGtDW5r9SrSZ3QFf ECHq5swMalo1+tOZuzewk+MHogpGSi5kkwsVseLUTYBUrtfVPEEZUPezoL4zqA1iKgxO FD5TsaSkP2fK+gPgDOKQ0J2moZyjr4ko3r9+xtJ11JeiU6AMe7wpsHlHnkEY4+Rc8ocL MrMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xO6vO4ka; 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 c10-20020aa78e0a000000b0056bc9b188c6si27210pfr.245.2022.10.24.09.12.10; Mon, 24 Oct 2022 09:12:24 -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=xO6vO4ka; 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 S233748AbiJXQLp (ORCPT + 99 others); Mon, 24 Oct 2022 12:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbiJXQFA (ORCPT ); Mon, 24 Oct 2022 12:05:00 -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 E8D8B22510; Mon, 24 Oct 2022 07:57:46 -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 942A9B8162B; Mon, 24 Oct 2022 12:22:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA29EC433D6; Mon, 24 Oct 2022 12:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614145; bh=dcsN3cYuMFF+AYHBJhPzQlBwMzkk1P7+S/W9/R6kMy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xO6vO4kavbJyacTK9+bE3XtZ0PZT06ha5V2WGrhmFTVnoOlqoSkye7jMwaiB/WDBF 06f9xz9WoANGMH8KVSiNMTitN8OswJ0uSjnhioIZDVW2c/maL9Yihnes7mGNJFl7Bj GPrZlTmAV/LNYjXL61WAMrWk1kbVyQQV1hSazMf8= 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.10 119/390] bpf: Ensure correct locking around vulnerable function find_vpid() Date: Mon, 24 Oct 2022 13:28:36 +0200 Message-Id: <20221024113027.745111211@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747586063700043547?= X-GMAIL-MSGID: =?utf-8?q?1747586063700043547?= 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 419dbc3d060e..aaad2dce2be6 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3915,7 +3915,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;