Skip to content

Commit

Permalink
debugfs: Fix filesystem reference counting on debugfs_remove() failure
Browse files Browse the repository at this point in the history
When __debugfs_remove() fails (because simple_rmdir() fails e.g. when a
directory is not empty), we must not decrement use count of the filesystem
as nothing was in fact deleted.

This fixes use after free caused by debugfs in some cases.

Signed-off-by: Jan Kara <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
jankara authored and gregkh committed Feb 18, 2011
1 parent b38360a commit 25d41d8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fs/debugfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
}
EXPORT_SYMBOL_GPL(debugfs_create_symlink);

static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
{
int ret = 0;

Expand All @@ -330,6 +330,7 @@ static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
dput(dentry);
}
}
return ret;
}

/**
Expand All @@ -348,7 +349,8 @@ static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
void debugfs_remove(struct dentry *dentry)
{
struct dentry *parent;

int ret;

if (!dentry)
return;

Expand All @@ -357,9 +359,10 @@ void debugfs_remove(struct dentry *dentry)
return;

mutex_lock(&parent->d_inode->i_mutex);
__debugfs_remove(dentry, parent);
ret = __debugfs_remove(dentry, parent);
mutex_unlock(&parent->d_inode->i_mutex);
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
if (!ret)
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
}
EXPORT_SYMBOL_GPL(debugfs_remove);

Expand Down

0 comments on commit 25d41d8

Please sign in to comment.