From nobody Mon Dec 15 15:12:38 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B37EDC07E9D for ; Mon, 26 Sep 2022 11:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238826AbiIZL4a (ORCPT ); Mon, 26 Sep 2022 07:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238813AbiIZLxu (ORCPT ); Mon, 26 Sep 2022 07:53:50 -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 2015D48CAF; Mon, 26 Sep 2022 03:49:53 -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 1DDF1B80921; Mon, 26 Sep 2022 10:49:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FA2FC433C1; Mon, 26 Sep 2022 10:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189372; bh=5Wecxc0YtwM+6k5gpDHuu2iI+A5vqPhrYMOoNyICU3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cT+qI3IyPIsyPDE6BHWc0YO4bKH4AMAts3Fh4BYuCmm0hSV6A1YPXJE0tJLD1tOLw dF7yl9atS8vlnYe7Tll1EjHyFZYLUWrJ8nuh8UUDd0d4uY5cDUKrek5YjVXeKcYLyC qUwR1GTF1Dx8/jVCJ/bqo1AvWp5HZeUDvcBDXjys= 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 Subject: [PATCH 5.19 164/207] cgroup: cgroup_get_from_id() must check the looked-up kn is a directory Date: Mon, 26 Sep 2022 12:12:33 +0200 Message-Id: <20220926100814.011227446@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ming Lei commit df02452f3df069a59bc9e69c84435bf115cb6e37 upstream. 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: Greg Kroah-Hartman --- kernel/cgroup/cgroup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6026,6 +6026,9 @@ struct cgroup *cgroup_get_from_id(u64 id if (!kn) goto out; =20 + if (kernfs_type(kn) !=3D KERNFS_DIR) + goto put; + rcu_read_lock(); =20 cgrp =3D rcu_dereference(*(void __rcu __force **)&kn->priv); @@ -6033,7 +6036,7 @@ struct cgroup *cgroup_get_from_id(u64 id cgrp =3D NULL; =20 rcu_read_unlock(); - +put: kernfs_put(kn); out: return cgrp;