Skip to content

Commit 4edc2ca

Browse files
Dave Joneschrismason-xx
authored andcommitted
Btrfs: fix use-after-free in __btrfs_end_transaction
49b25e0 introduced a use-after-free bug that caused spurious -EIO's to be returned. Do the check before we free the transaction. Cc: David Sterba <[email protected]> Cc: Jeff Mahoney <[email protected]> Signed-off-by: Dave Jones <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent e627ee7 commit 4edc2ca

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

fs/btrfs/transaction.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
480480
struct btrfs_transaction *cur_trans = trans->transaction;
481481
struct btrfs_fs_info *info = root->fs_info;
482482
int count = 0;
483+
int err = 0;
483484

484485
if (--trans->use_count) {
485486
trans->block_rsv = trans->orig_rsv;
@@ -532,18 +533,18 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
532533

533534
if (current->journal_info == trans)
534535
current->journal_info = NULL;
535-
memset(trans, 0, sizeof(*trans));
536-
kmem_cache_free(btrfs_trans_handle_cachep, trans);
537536

538537
if (throttle)
539538
btrfs_run_delayed_iputs(root);
540539

541540
if (trans->aborted ||
542541
root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
543-
return -EIO;
542+
err = -EIO;
544543
}
545544

546-
return 0;
545+
memset(trans, 0, sizeof(*trans));
546+
kmem_cache_free(btrfs_trans_handle_cachep, trans);
547+
return err;
547548
}
548549

549550
int btrfs_end_transaction(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)