Skip to content

Commit 712317a

Browse files
lizf-oshtejun
authored andcommitted
cgroup: fix broken file xattrs
We should store file xattrs in struct cfent instead of struct cftype, because cftype is a type while cfent is object instance of cftype. For example each cgroup has a tasks file, and each tasks file is associated with a uniq cfent, but all those files share the same struct cftype. Alexey Kodanev reported a crash, which can be reproduced: # mount -t cgroup -o xattr /sys/fs/cgroup # mkdir /sys/fs/cgroup/test # setfattr -n trusted.value -v test_value /sys/fs/cgroup/tasks # rmdir /sys/fs/cgroup/test # umount /sys/fs/cgroup oops! In this case, simple_xattrs_free() will free the same struct simple_xattrs twice. tj: Dropped unused local variable @cft from cgroup_diput(). Cc: <stable@vger.kernel.org> # 3.8.x Reported-by: Alexey Kodanev <alexey.kodanev@oracle.com> Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent e57d5cf commit 712317a

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

include/linux/cgroup.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,6 @@ struct cftype {
422422
/* CFTYPE_* flags */
423423
unsigned int flags;
424424

425-
/* file xattrs */
426-
struct simple_xattrs xattrs;
427-
428425
int (*open)(struct inode *inode, struct file *file);
429426
ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
430427
struct file *file,

kernel/cgroup.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ struct cfent {
117117
struct list_head node;
118118
struct dentry *dentry;
119119
struct cftype *type;
120+
121+
/* file xattrs */
122+
struct simple_xattrs xattrs;
120123
};
121124

122125
/*
@@ -882,13 +885,12 @@ static void cgroup_diput(struct dentry *dentry, struct inode *inode)
882885
} else {
883886
struct cfent *cfe = __d_cfe(dentry);
884887
struct cgroup *cgrp = dentry->d_parent->d_fsdata;
885-
struct cftype *cft = cfe->type;
886888

887889
WARN_ONCE(!list_empty(&cfe->node) &&
888890
cgrp != &cgrp->root->top_cgroup,
889891
"cfe still linked for %s\n", cfe->type->name);
892+
simple_xattrs_free(&cfe->xattrs);
890893
kfree(cfe);
891-
simple_xattrs_free(&cft->xattrs);
892894
}
893895
iput(inode);
894896
}
@@ -2501,7 +2503,7 @@ static struct simple_xattrs *__d_xattrs(struct dentry *dentry)
25012503
if (S_ISDIR(dentry->d_inode->i_mode))
25022504
return &__d_cgrp(dentry)->xattrs;
25032505
else
2504-
return &__d_cft(dentry)->xattrs;
2506+
return &__d_cfe(dentry)->xattrs;
25052507
}
25062508

25072509
static inline int xattr_enabled(struct dentry *dentry)
@@ -2677,8 +2679,6 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
26772679
umode_t mode;
26782680
char name[MAX_CGROUP_TYPE_NAMELEN + MAX_CFTYPE_NAME + 2] = { 0 };
26792681

2680-
simple_xattrs_init(&cft->xattrs);
2681-
26822682
if (subsys && !(cgrp->root->flags & CGRP_ROOT_NOPREFIX)) {
26832683
strcpy(name, subsys->name);
26842684
strcat(name, ".");
@@ -2703,6 +2703,7 @@ static int cgroup_add_file(struct cgroup *cgrp, struct cgroup_subsys *subsys,
27032703
cfe->type = (void *)cft;
27042704
cfe->dentry = dentry;
27052705
dentry->d_fsdata = cfe;
2706+
simple_xattrs_init(&cfe->xattrs);
27062707
list_add_tail(&cfe->node, &parent->files);
27072708
cfe = NULL;
27082709
}

0 commit comments

Comments
 (0)