aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2025-07-25 16:54:49 +0100
committerDavid Sterba <dsterba@suse.com>2025-08-22 00:58:27 +0200
commite87e953bb20629ca1f008f8146c38e313e5ed319 (patch)
treeb7587daa1d3df93797179f9ba03ff46e42b4ea84
parentbtrfs: abort transaction on failure to add link to inode (diff)
downloadwireguard-linux-e87e953bb20629ca1f008f8146c38e313e5ed319.tar.xz
wireguard-linux-e87e953bb20629ca1f008f8146c38e313e5ed319.zip
btrfs: fix inode leak on failure to add link to inode
If we fail to update the inode or delete the orphan item we leak the inode since we update its refcount with the ihold() call to account for the d_instantiate() call which never happens in case we fail those steps. Fix this by setting 'drop_inode' to true in case we fail those steps. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/inode.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index af2f9b2c8c85..4ed5ab5d3ac1 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -6854,6 +6854,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
ret = btrfs_update_inode(trans, BTRFS_I(inode));
if (ret) {
btrfs_abort_transaction(trans, ret);
+ drop_inode = 1;
goto fail;
}
if (inode->i_nlink == 1) {
@@ -6864,6 +6865,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
ret = btrfs_orphan_del(trans, BTRFS_I(inode));
if (ret) {
btrfs_abort_transaction(trans, ret);
+ drop_inode = 1;
goto fail;
}
}