Skip to content

Commit

Permalink
Merge tag 'for-5.4-rc7-tag' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/git/kdave/linux

Pull btrfs fix from David Sterba:
 "A fix for an older bug that has started to show up during testing
  (because of an updated test for rename exchange).

  It's an in-memory corruption caused by local variable leaking out of
  the function scope"

* tag 'for-5.4-rc7-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
  Btrfs: fix log context list corruption after rename exchange operation
  • Loading branch information
Linus Torvalds committed Nov 13, 2019
2 parents 0e3f1ad + e6c6171 commit afd7a71
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -9744,6 +9744,18 @@ static int btrfs_rename_exchange(struct inode *old_dir,
commit_transaction = true;
}
if (commit_transaction) {
/*
* We may have set commit_transaction when logging the new name
* in the destination root, in which case we left the source
* root context in the list of log contextes. So make sure we
* remove it to avoid invalid memory accesses, since the context
* was allocated in our stack frame.
*/
if (sync_log_root) {
mutex_lock(&root->log_mutex);
list_del_init(&ctx_root.list);
mutex_unlock(&root->log_mutex);
}
ret = btrfs_commit_transaction(trans);
} else {
int ret2;
Expand All @@ -9757,6 +9769,9 @@ static int btrfs_rename_exchange(struct inode *old_dir,
if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
up_read(&fs_info->subvol_sem);

ASSERT(list_empty(&ctx_root.list));
ASSERT(list_empty(&ctx_dest.list));

return ret;
}

Expand Down

0 comments on commit afd7a71

Please sign in to comment.