public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: fix cgroup_get_from_id
@ 2022-09-23 11:51 Ming Lei
  2022-09-23 15:43 ` Mukesh Ojha
       [not found] ` <20220923115119.2035603-1-ming.lei-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 2 replies; 5+ messages in thread
From: Ming Lei @ 2022-09-23 11:51 UTC (permalink / raw)
  To: Tejun Heo, linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: cgroups-u79uwXL29TY76Z2rM5mHXA, Ming Lei, Marco Patalano,
	Muneendra

cgroup has to be one kernfs dir, otherwise kernel panic is caused,
especially cgroup id is provide from userspace.

Reported-by: Marco Patalano <mpatalan-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()")
Cc: Muneendra <muneendra.kumar-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
Signed-off-by: Ming Lei <ming.lei-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 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 e4bb5d57f4d1..5f2090d051ac 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -6049,6 +6049,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);
@@ -6056,7 +6059,7 @@ struct cgroup *cgroup_get_from_id(u64 id)
 		cgrp = NULL;
 
 	rcu_read_unlock();
-
+put:
 	kernfs_put(kn);
 out:
 	return cgrp;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-28 11:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-23 11:51 [PATCH] cgroup: fix cgroup_get_from_id Ming Lei
2022-09-23 15:43 ` Mukesh Ojha
     [not found] ` <20220923115119.2035603-1-ming.lei-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-09-23 17:29   ` Tejun Heo
     [not found]     ` <Yy3tEKSV+vg6swOd-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-09-23 17:31       ` [PATCH cgroup/for-6.1] cgroup: Make cgroup_get_from_id() prettier Tejun Heo
     [not found]         ` <Yy3tjvIGd2j4wnSw-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-09-28 11:38           ` Michal Koutný

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox