Skip to content

Commit

Permalink
configfs: fix config_item refcnt leak in configfs_rmdir()
Browse files Browse the repository at this point in the history
configfs_rmdir() invokes configfs_get_config_item(), which returns a
reference of the specified config_item object to "parent_item" with
increased refcnt.

When configfs_rmdir() returns, local variable "parent_item" becomes
invalid, so the refcount should be decreased to keep refcount balanced.

The reference counting issue happens in one exception handling path of
configfs_rmdir(). When down_write_killable() fails, the function forgets
to decrease the refcnt increased by configfs_get_config_item(), causing
a refcnt leak.

Fix this issue by calling config_item_put() when down_write_killable()
fails.

Signed-off-by: Xiyu Yang <[email protected]>
Signed-off-by: Xin Tan <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
sherlly authored and Christoph Hellwig committed Apr 27, 2020
1 parent 6a8b55e commit 8aebfff
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions fs/configfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
spin_lock(&configfs_dirent_lock);
configfs_detach_rollback(dentry);
spin_unlock(&configfs_dirent_lock);
config_item_put(parent_item);
return -EINTR;
}
frag->frag_dead = true;
Expand Down

0 comments on commit 8aebfff

Please sign in to comment.