Skip to content

Commit 5adcee1

Browse files
author
Nick Piggin
committed
cgroup fs: avoid switching ->d_op on live dentry
Switching d_op on a live dentry is racy in general, so avoid it. In this case it is a negative dentry, which is safer, but there are still concurrent ops which may be called on d_op in that case (eg. d_revalidate). So in general a filesystem may not do this. Fix cgroupfs so as not to do this. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent 3e880fb commit 5adcee1

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

‎kernel/cgroup.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ EXPORT_SYMBOL_GPL(cgroup_unlock);
763763
* -> cgroup_mkdir.
764764
*/
765765

766+
static struct dentry *cgroup_lookup(struct inode *dir,
767+
struct dentry *dentry, struct nameidata *nd);
766768
static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, int mode);
767769
static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
768770
static int cgroup_populate_dir(struct cgroup *cgrp);
@@ -2180,7 +2182,7 @@ static const struct file_operations cgroup_file_operations = {
21802182
};
21812183

21822184
static const struct inode_operations cgroup_dir_inode_operations = {
2183-
.lookup = simple_lookup,
2185+
.lookup = cgroup_lookup,
21842186
.mkdir = cgroup_mkdir,
21852187
.rmdir = cgroup_rmdir,
21862188
.rename = cgroup_rename,
@@ -2196,13 +2198,29 @@ static inline struct cftype *__file_cft(struct file *file)
21962198
return __d_cft(file->f_dentry);
21972199
}
21982200

2199-
static int cgroup_create_file(struct dentry *dentry, mode_t mode,
2200-
struct super_block *sb)
2201+
static int cgroup_delete_dentry(struct dentry *dentry)
2202+
{
2203+
return 1;
2204+
}
2205+
2206+
static struct dentry *cgroup_lookup(struct inode *dir,
2207+
struct dentry *dentry, struct nameidata *nd)
22012208
{
2202-
static const struct dentry_operations cgroup_dops = {
2209+
static const struct dentry_operations cgroup_dentry_operations = {
2210+
.d_delete = cgroup_delete_dentry,
22032211
.d_iput = cgroup_diput,
22042212
};
22052213

2214+
if (dentry->d_name.len > NAME_MAX)
2215+
return ERR_PTR(-ENAMETOOLONG);
2216+
dentry->d_op = &cgroup_dentry_operations;
2217+
d_add(dentry, NULL);
2218+
return NULL;
2219+
}
2220+
2221+
static int cgroup_create_file(struct dentry *dentry, mode_t mode,
2222+
struct super_block *sb)
2223+
{
22062224
struct inode *inode;
22072225

22082226
if (!dentry)
@@ -2228,7 +2246,6 @@ static int cgroup_create_file(struct dentry *dentry, mode_t mode,
22282246
inode->i_size = 0;
22292247
inode->i_fop = &cgroup_file_operations;
22302248
}
2231-
dentry->d_op = &cgroup_dops;
22322249
d_instantiate(dentry, inode);
22332250
dget(dentry); /* Extra count - pin the dentry in core */
22342251
return 0;

0 commit comments

Comments
 (0)