]> git.baikalelectronics.ru Git - kernel.git/commitdiff
cgroup: cgroup_get_from_id() must check the looked-up kn is a directory
authorMing Lei <ming.lei@redhat.com>
Fri, 23 Sep 2022 11:51:19 +0000 (19:51 +0800)
committerTejun Heo <tj@kernel.org>
Fri, 23 Sep 2022 17:18:45 +0000 (07:18 -1000)
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: 6b658c4863c1 ("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>
kernel/cgroup/cgroup.c

index e4bb5d57f4d1d46cd0f1309765134c17410cf1cd..5f2090d051acba2fd4718c07ffc193d21ac40777 100644 (file)
@@ -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;