diff options
author | Tejun Heo <tj@kernel.org> | 2014-02-11 11:52:48 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-02-11 11:52:48 -0500 |
commit | 8d7e6fb0a1db970ac3589f87af0f2a20ef46654b (patch) | |
tree | f6b10b105575da92908db304722450511e9cdf23 /kernel/cgroup.c | |
parent | d427dfeb120b92c0c5e2ca9d1ec6952de67ebad9 (diff) |
cgroup: update cgroup name handling
Straightforward updates to cgroup name handling in preparation of
kernfs conversion.
* cgroup_alloc_name() is updated to take const char * isntead of
dentry * for name source.
* cgroup name formatting is separated out into cgroup_file_name().
While at it, buffer length protection is added.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r-- | kernel/cgroup.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 0a178cd1f836..3f204429d108 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -67,6 +67,9 @@ | |||
67 | */ | 67 | */ |
68 | #define CGROUP_PIDLIST_DESTROY_DELAY HZ | 68 | #define CGROUP_PIDLIST_DESTROY_DELAY HZ |
69 | 69 | ||
70 | #define CGROUP_FILE_NAME_MAX (MAX_CGROUP_TYPE_NAMELEN + \ | ||
71 | MAX_CFTYPE_NAME + 2) | ||
72 | |||
70 | /* | 73 | /* |
71 | * cgroup_tree_mutex nests above cgroup_mutex and protects cftypes, file | 74 | * cgroup_tree_mutex nests above cgroup_mutex and protects cftypes, file |
72 | * creation/removal and hierarchy changing operations including cgroup | 75 | * creation/removal and hierarchy changing operations including cgroup |
@@ -799,17 +802,29 @@ static struct inode *cgroup_new_inode(umode_t mode, struct super_block *sb) | |||
799 | return inode; | 802 | return inode; |
800 | } | 803 | } |
801 | 804 | ||
802 | static struct cgroup_name *cgroup_alloc_name(struct dentry *dentry) | 805 | static struct cgroup_name *cgroup_alloc_name(const char *name_str) |
803 | { | 806 | { |
804 | struct cgroup_name *name; | 807 | struct cgroup_name *name; |
805 | 808 | ||
806 | name = kmalloc(sizeof(*name) + dentry->d_name.len + 1, GFP_KERNEL); | 809 | name = kmalloc(sizeof(*name) + strlen(name_str) + 1, GFP_KERNEL); |
807 | if (!name) | 810 | if (!name) |
808 | return NULL; | 811 | return NULL; |
809 | strcpy(name->name, dentry->d_name.name); | 812 | strcpy(name->name, name_str); |
810 | return name; | 813 | return name; |
811 | } | 814 | } |
812 | 815 | ||
816 | static char *cgroup_file_name(struct cgroup *cgrp, const struct cftype *cft, | ||
817 | char *buf) | ||
818 | { | ||
819 | if (cft->ss && !(cft->flags & CFTYPE_NO_PREFIX) && | ||
820 | !(cgrp->root->flags & CGRP_ROOT_NOPREFIX)) | ||
821 | snprintf(buf, CGROUP_FILE_NAME_MAX, "%s.%s", | ||
822 | cft->ss->name, cft->name); | ||
823 | else | ||
824 | strncpy(buf, cft->name, CGROUP_FILE_NAME_MAX); | ||
825 | return buf; | ||
826 | } | ||
827 | |||
813 | static void cgroup_free_fn(struct work_struct *work) | 828 | static void cgroup_free_fn(struct work_struct *work) |
814 | { | 829 | { |
815 | struct cgroup *cgrp = container_of(work, struct cgroup, destroy_work); | 830 | struct cgroup *cgrp = container_of(work, struct cgroup, destroy_work); |
@@ -2437,7 +2452,7 @@ static int cgroup_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
2437 | if (cgroup_sane_behavior(cgrp)) | 2452 | if (cgroup_sane_behavior(cgrp)) |
2438 | return -EPERM; | 2453 | return -EPERM; |
2439 | 2454 | ||
2440 | name = cgroup_alloc_name(new_dentry); | 2455 | name = cgroup_alloc_name(new_dentry->d_name.name); |
2441 | if (!name) | 2456 | if (!name) |
2442 | return -ENOMEM; | 2457 | return -ENOMEM; |
2443 | 2458 | ||
@@ -2613,14 +2628,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft) | |||
2613 | struct cfent *cfe; | 2628 | struct cfent *cfe; |
2614 | int error; | 2629 | int error; |
2615 | umode_t mode; | 2630 | umode_t mode; |
2616 | char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 }; | 2631 | char name[CGROUP_FILE_NAME_MAX]; |
2617 | |||
2618 | if (cft->ss && !(cft->flags & CFTYPE_NO_PREFIX) && | ||
2619 | !(cgrp->root->flags & CGRP_ROOT_NOPREFIX)) { | ||
2620 | strcpy(name, cft->ss->name); | ||
2621 | strcat(name, "."); | ||
2622 | } | ||
2623 | strcat(name, cft->name); | ||
2624 | 2632 | ||
2625 | BUG_ON(!mutex_is_locked(&dir->d_inode->i_mutex)); | 2633 | BUG_ON(!mutex_is_locked(&dir->d_inode->i_mutex)); |
2626 | 2634 | ||
@@ -2628,6 +2636,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cftype *cft) | |||
2628 | if (!cfe) | 2636 | if (!cfe) |
2629 | return -ENOMEM; | 2637 | return -ENOMEM; |
2630 | 2638 | ||
2639 | cgroup_file_name(cgrp, cft, name); | ||
2631 | dentry = lookup_one_len(name, dir, strlen(name)); | 2640 | dentry = lookup_one_len(name, dir, strlen(name)); |
2632 | if (IS_ERR(dentry)) { | 2641 | if (IS_ERR(dentry)) { |
2633 | error = PTR_ERR(dentry); | 2642 | error = PTR_ERR(dentry); |
@@ -4135,7 +4144,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry, | |||
4135 | if (!cgrp) | 4144 | if (!cgrp) |
4136 | return -ENOMEM; | 4145 | return -ENOMEM; |
4137 | 4146 | ||
4138 | name = cgroup_alloc_name(dentry); | 4147 | name = cgroup_alloc_name(dentry->d_name.name); |
4139 | if (!name) { | 4148 | if (!name) { |
4140 | err = -ENOMEM; | 4149 | err = -ENOMEM; |
4141 | goto err_free_cgrp; | 4150 | goto err_free_cgrp; |