Commit e7fd37ba authored by Ma Shimiao's avatar Ma Shimiao Committed by Tejun Heo

cgroup: avoid copying strings longer than the buffers

cgroup root name and file name have max length limit, we should
avoid copying longer name than that to the name.

tj: minor update to $SUBJ.
Signed-off-by: default avatarMa Shimiao <mashimiao.fnst@cn.fujitsu.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent c2f31b79
...@@ -1397,7 +1397,7 @@ static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft, ...@@ -1397,7 +1397,7 @@ static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft,
cgroup_on_dfl(cgrp) ? ss->name : ss->legacy_name, cgroup_on_dfl(cgrp) ? ss->name : ss->legacy_name,
cft->name); cft->name);
else else
strncpy(buf, cft->name, CGROUP_FILE_NAME_MAX); strscpy(buf, cft->name, CGROUP_FILE_NAME_MAX);
return buf; return buf;
} }
...@@ -1864,9 +1864,9 @@ void init_cgroup_root(struct cgroup_root *root, struct cgroup_sb_opts *opts) ...@@ -1864,9 +1864,9 @@ void init_cgroup_root(struct cgroup_root *root, struct cgroup_sb_opts *opts)
root->flags = opts->flags; root->flags = opts->flags;
if (opts->release_agent) if (opts->release_agent)
strcpy(root->release_agent_path, opts->release_agent); strscpy(root->release_agent_path, opts->release_agent, PATH_MAX);
if (opts->name) if (opts->name)
strcpy(root->name, opts->name); strscpy(root->name, opts->name, MAX_CGROUP_ROOT_NAMELEN);
if (opts->cpuset_clone_children) if (opts->cpuset_clone_children)
set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags); set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment