Skip to content

Commit 01239d7

Browse files
Shan Haidjwong
Shan Hai
authored andcommitted
xfs: fix a null pointer dereference in xfs_bmap_extents_to_btree
Fuzzing tool reports a write to null pointer error in the xfs_bmap_extents_to_btree, fix it by bailing out on encountering a null pointer. Signed-off-by: Shan Hai <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent fa6c668 commit 01239d7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

fs/xfs/libxfs/xfs_bmap.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -712,19 +712,14 @@ xfs_bmap_extents_to_btree(
712712
args.wasdel = wasdel;
713713
*logflagsp = 0;
714714
if ((error = xfs_alloc_vextent(&args))) {
715-
xfs_iroot_realloc(ip, -1, whichfork);
716715
ASSERT(ifp->if_broot == NULL);
717-
XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
718-
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
719-
return error;
716+
goto err1;
720717
}
721718

722719
if (WARN_ON_ONCE(args.fsbno == NULLFSBLOCK)) {
723-
xfs_iroot_realloc(ip, -1, whichfork);
724720
ASSERT(ifp->if_broot == NULL);
725-
XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
726-
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
727-
return -ENOSPC;
721+
error = -ENOSPC;
722+
goto err1;
728723
}
729724
/*
730725
* Allocation can't fail, the space was reserved.
@@ -736,6 +731,10 @@ xfs_bmap_extents_to_btree(
736731
ip->i_d.di_nblocks++;
737732
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
738733
abp = xfs_btree_get_bufl(mp, tp, args.fsbno, 0);
734+
if (!abp) {
735+
error = -ENOSPC;
736+
goto err2;
737+
}
739738
/*
740739
* Fill in the child block.
741740
*/
@@ -775,6 +774,15 @@ xfs_bmap_extents_to_btree(
775774
*curp = cur;
776775
*logflagsp = XFS_ILOG_CORE | xfs_ilog_fbroot(whichfork);
777776
return 0;
777+
778+
err2:
779+
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L);
780+
err1:
781+
xfs_iroot_realloc(ip, -1, whichfork);
782+
XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
783+
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
784+
785+
return error;
778786
}
779787

780788
/*

0 commit comments

Comments
 (0)