Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2515022rwb; Mon, 3 Oct 2022 01:44:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7G/QpYKlhtvtQZIQBHlPFd56VrEG7fJea0FNQUrZ2kivzlLKKQrobuD7YkvqyEGsKILaMO X-Received: by 2002:a17:902:d2c3:b0:179:ff70:2a15 with SMTP id n3-20020a170902d2c300b00179ff702a15mr20888303plc.77.1664786642491; Mon, 03 Oct 2022 01:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664786642; cv=none; d=google.com; s=arc-20160816; b=EJWi6DX/92E0NxNCahgSmTs2ypHrA6Q1O31/LXh/chVfs9WupeR3dvSfasPWkvVXRM m9DRwHPwKnqdE4XcgB4NSfk3May1BwpUCit1xOogcb89/9paUdp8m4PFwLJcJy4Ma5IX DyjmCyDeOoNhlazw05M1VK4C+y8S5v87V+2CbDO7oOpUXKPMl5el4GmGgTmHtuqkWq3T bNyfZ4G93FneV6FfofpnPyHrxXRRIRvRrifb6YTGrBRno0VZdGzJzyZBuEmgY/xElzJt 9/XEE7fUy3bqmXi2eW6gakNK4tBOImv5HWEtKaPGJf3xY0RpGm1HCHbq+jbb5csppBZq bxLQ== 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=6/cWOUJN1oDElk6F58Vf9YmcHoL68Ma7Pn+2N1jCbcI=; b=JYPIPNvwdd0lkjiXtWpbcwObZmGriyduJ4BVAfTl3TP7vvy2vn5tVbZV1LNjY8WcP0 S2vPSXR5XJj3WYFbEV2GglDqGPQxKOu2WFDQj11loIBWgodcpNZ/ov5bpedFcCkEOFsU ncKTIeGhoVC7NdgjweaZ/1ei3wCvI65xTx3ULwWOZnbO+xOgnHwdQYGnjpQdcPrmfA0e b3aa2QlDecans4bNFvSKOTMn5l4YIqQ4GwXZ2BHyx+dUKcC8etxpydOHTzQJzTAhbx1l tjEyGCJM0YVh9aFCIVcy/BbcNlS0vRU5ocs3ai8IUcyOgcDXFW/5GlxkwMx0JyRZ3egx 7V4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iQ070zOK; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c16-20020a170903235000b0017c9ffbab0fsi9217503plh.152.2022.10.03.01.43.51; Mon, 03 Oct 2022 01:44:02 -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=iQ070zOK; 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 S231216AbiJCH3b (ORCPT + 99 others); Mon, 3 Oct 2022 03:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbiJCH2J (ORCPT ); Mon, 3 Oct 2022 03:28:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCB6C6B; Mon, 3 Oct 2022 00:19:36 -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 8275860FA2; Mon, 3 Oct 2022 07:17:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95C15C433D7; Mon, 3 Oct 2022 07:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781467; bh=vS+9SYW7kd6xHNsujI0Rd9vRK7JVdZ14PAQh+RhulaA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iQ070zOKIM4feWa8DR4Y79aszH2PFJaRglkatPwdZ8Sk3ioCryB1AT4KFTF6lqyH0 mukx5OyqURxhA8Hg4aodM6saM11W2qcfFvBUNQO3VDKY0/9Q2EUkeMNrozs0+nUZ51 Y9S5mutjB07gQuikLwkpSjCrB1RIClFDG52Xvoq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marco Patalano , Muneendra , Ming Lei , Mukesh Ojha , Tejun Heo , Sasha Levin Subject: [PATCH 5.15 06/83] cgroup: cgroup_get_from_id() must check the looked-up kn is a directory Date: Mon, 3 Oct 2022 09:10:31 +0200 Message-Id: <20221003070722.143782710@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 From: Ming Lei [ Upstream commit df02452f3df069a59bc9e69c84435bf115cb6e37 ] cgroup has to be one kernfs dir, otherwise kernel panic is caused, especially cgroup id is provide from userspace. Reported-by: Marco Patalano Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()") Cc: Muneendra Signed-off-by: Ming Lei Acked-by: Mukesh Ojha Cc: stable@vger.kernel.org # v5.14+ Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin --- kernel/cgroup/cgroup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 97282d6b5d18..4b19f7fc4deb 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6025,6 +6025,9 @@ struct cgroup *cgroup_get_from_id(u64 id) if (!kn) goto out; + if (kernfs_type(kn) != KERNFS_DIR) + goto put; + rcu_read_lock(); cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv); @@ -6032,7 +6035,7 @@ struct cgroup *cgroup_get_from_id(u64 id) cgrp = NULL; rcu_read_unlock(); - +put: kernfs_put(kn); out: return cgrp; -- 2.35.1