Skip to content

Commit c74eb98

Browse files
Al Virosashalevin
authored andcommitted
debugfs: leave freeing a symlink body until inode eviction
commit 0db59e5 upstream. As it is, we have debugfs_remove() racing with symlink traversals. Supply ->evict_inode() and do freeing there - inode will remain pinned until we are done with the symlink body. And rip the idiocy with checking if dentry is positive right after we'd verified debugfs_positive(), which is a stronger check... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent be9eb99 commit c74eb98

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

‎fs/debugfs/inode.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,19 @@ static int debugfs_show_options(struct seq_file *m, struct dentry *root)
246246
return 0;
247247
}
248248

249+
static void debugfs_evict_inode(struct inode *inode)
250+
{
251+
truncate_inode_pages_final(&inode->i_data);
252+
clear_inode(inode);
253+
if (S_ISLNK(inode->i_mode))
254+
kfree(inode->i_private);
255+
}
256+
249257
static const struct super_operations debugfs_super_operations = {
250258
.statfs = simple_statfs,
251259
.remount_fs = debugfs_remount,
252260
.show_options = debugfs_show_options,
261+
.evict_inode = debugfs_evict_inode,
253262
};
254263

255264
static int debug_fill_super(struct super_block *sb, void *data, int silent)
@@ -466,23 +475,14 @@ static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
466475
int ret = 0;
467476

468477
if (debugfs_positive(dentry)) {
469-
if (dentry->d_inode) {
470-
dget(dentry);
471-
switch (dentry->d_inode->i_mode & S_IFMT) {
472-
case S_IFDIR:
473-
ret = simple_rmdir(parent->d_inode, dentry);
474-
break;
475-
case S_IFLNK:
476-
kfree(dentry->d_inode->i_private);
477-
/* fall through */
478-
default:
479-
simple_unlink(parent->d_inode, dentry);
480-
break;
481-
}
482-
if (!ret)
483-
d_delete(dentry);
484-
dput(dentry);
485-
}
478+
dget(dentry);
479+
if (S_ISDIR(dentry->d_inode->i_mode))
480+
ret = simple_rmdir(parent->d_inode, dentry);
481+
else
482+
simple_unlink(parent->d_inode, dentry);
483+
if (!ret)
484+
d_delete(dentry);
485+
dput(dentry);
486486
}
487487
return ret;
488488
}

0 commit comments

Comments
 (0)