History

cgroup: cgroup_get_from_id() must check the looked-up kn is a directory

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

Ming Lei committed 4 years ago

Commit df024521 parent a81e18e1 file · +4 −1Browse files

Unified · Split

kernel/cgroup/cgroup.c+4−1
@@ -6049,6 +6049,9 @@ struct cgroup *cgroup_get_from_id(u64 id) · 6048 unmodified lines
60496049 if (!kn)
60506050 goto out;
60516051
6052+ if (kernfs_type(kn) != KERNFS_DIR)
6053+ goto put;
6054+
60526055 rcu_read_lock();
60536056
60546057 cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv);
@@ -6056,7 +6059,7 @@ struct cgroup *cgroup_get_from_id(u64 id) · 1 unmodified line
60566059 cgrp = NULL;
60576060
60586061 rcu_read_unlock();
6059−
6062+put:
60606063 kernfs_put(kn);
60616064 out:
60626065 return cgrp;