cgroup: reject cgroup names with '
authorAlban Crequy <alban.crequy@collabora.co.uk>
Mon, 18 Aug 2014 11:20:20 +0000 (12:20 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 5 Nov 2014 20:27:39 +0000 (20:27 +0000)
'

commit 71b1fb5c4473a5b1e601d41b109bdfe001ec82e0 upstream.

/proc/<pid>/cgroup contains one cgroup path on each line. If cgroup names are
allowed to contain "\n", applications cannot parse /proc/<pid>/cgroup safely.

Signed-off-by: Alban Crequy <alban.crequy@collabora.co.uk>
Signed-off-by: Tejun Heo <tj@kernel.org>
[bwh: Backported to 3.2:
 - Adjust context
 - We have to get the name from the dentry pointer]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
kernel/cgroup.c

index 93fc15e..ffcf896 100644 (file)
@@ -3871,6 +3871,11 @@ static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, int mode)
 {
        struct cgroup *c_parent = dentry->d_parent->d_fsdata;
 
+       /* Do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable.
+        */
+       if (strchr(dentry->d_name.name, '\n'))
+               return -EINVAL;
+
        /* the vfs holds inode->i_mutex already */
        return cgroup_create(c_parent, dentry, mode | S_IFDIR);
 }