Skip to content

Commit

Permalink
cgroup: cgroup_get_from_id() must check the looked-up kn is a directory
Browse files Browse the repository at this point in the history
commit df02452 upstream.

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

Reported-by: Marco Patalano <mpatalan@redhat.com>
Fixes: 6b658c4 ("scsi: cgroup: Add cgroup_get_from_id()")
Cc: Muneendra <muneendra.kumar@broadcom.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Mukesh Ojha <quic_mojha@quicinc.com>
Cc: stable@vger.kernel.org # v5.14+
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ming Lei authored and gregkh committed Sep 28, 2022
1 parent a899ba6 commit 1e95718
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernel/cgroup/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -6026,14 +6026,17 @@ 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);
if (cgrp && !cgroup_tryget(cgrp))
cgrp = NULL;

rcu_read_unlock();

put:
kernfs_put(kn);
out:
return cgrp;
Expand Down

0 comments on commit 1e95718

Please sign in to comment.