This is a note to let you know that I've just added the patch titled cgroup: cgroup_get_from_id() must check the looked-up kn is a directory to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: cgroup-cgroup_get_from_id-must-check-the-looked-up-k.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 3da6a620885c933439c7c8ec5cc789f9e4018058 Author: Ming Lei <ming.lei@xxxxxxxxxx> Date: Fri Sep 23 19:51:19 2022 +0800 cgroup: cgroup_get_from_id() must check the looked-up kn is a directory [ 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 <mpatalan@xxxxxxxxxx> Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()") Cc: Muneendra <muneendra.kumar@xxxxxxxxxxxx> Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> Acked-by: Mukesh Ojha <quic_mojha@xxxxxxxxxxx> Cc: stable@xxxxxxxxxxxxxxx # v5.14+ Signed-off-by: Tejun Heo <tj@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> 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;