Skip to content

Commit b7e24eb

Browse files
Alexander Kuznetsovhtejun
authored andcommitted
cgroup1: don't allow '\n' in renaming
cgroup_mkdir() have restriction on newline usage in names: $ mkdir $'/sys/fs/cgroup/cpu/test\ntest2' mkdir: cannot create directory '/sys/fs/cgroup/cpu/test\ntest2': Invalid argument But in cgroup1_rename() such check is missed. This allows us to make /proc/<pid>/cgroup unparsable: $ mkdir /sys/fs/cgroup/cpu/test $ mv /sys/fs/cgroup/cpu/test $'/sys/fs/cgroup/cpu/test\ntest2' $ echo $$ > $'/sys/fs/cgroup/cpu/test\ntest2' $ cat /proc/self/cgroup 11:pids:/ 10:freezer:/ 9:hugetlb:/ 8:cpuset:/ 7:blkio:/user.slice 6:memory:/user.slice 5:net_cls,net_prio:/ 4:perf_event:/ 3:devices:/user.slice 2:cpu,cpuacct:/test test2 1:name=systemd:/ 0::/ Signed-off-by: Alexander Kuznetsov <[email protected]> Reported-by: Andrey Krasichkov <[email protected]> Acked-by: Dmitry Yakunin <[email protected]> Cc: [email protected] Signed-off-by: Tejun Heo <[email protected]>
1 parent 08b2b6f commit b7e24eb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/cgroup/cgroup-v1.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,10 @@ static int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent
820820
struct cgroup *cgrp = kn->priv;
821821
int ret;
822822

823+
/* do not accept '\n' to prevent making /proc/<pid>/cgroup unparsable */
824+
if (strchr(new_name_str, '\n'))
825+
return -EINVAL;
826+
823827
if (kernfs_type(kn) != KERNFS_DIR)
824828
return -ENOTDIR;
825829
if (kn->parent != new_parent)

0 commit comments

Comments
 (0)