Skip to content

Commit

Permalink
Merge tag 'xfs-4.13-fixes-2' of git://git.kernel.org/pub/scm/fs/xfs/x…
Browse files Browse the repository at this point in the history
…fs-linux

Pull xfs fixes from Darrick Wong:

 - fix firstfsb variables that we left uninitialized, which could lead
   to locking problems.

 - check for NULL metadata buffer pointers before using them.

 - don't allow btree cursor manipulation if the btree block is corrupt.
   Better to just shut down.

 - fix infinite loop problems in quotacheck.

 - fix buffer overrun when validating directory blocks.

 - fix deadlock problem in bunmapi.

* tag 'xfs-4.13-fixes-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux:
  xfs: fix multi-AG deadlock in xfs_bunmapi
  xfs: check that dir block entries don't off the end of the buffer
  xfs: fix quotacheck dquot id overflow infinite loop
  xfs: check _alloc_read_agf buffer pointer before using
  xfs: set firstfsb to NULLFSBLOCK before feeding it to _bmapi_write
  xfs: check _btree_check_block value
  • Loading branch information
Linus Torvalds committed Jul 28, 2017
2 parents 8155469 + 5b094d6 commit 19993e7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
21 changes: 21 additions & 0 deletions fs/xfs/libxfs/xfs_bmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5435,6 +5435,7 @@ __xfs_bunmapi(
xfs_fsblock_t sum;
xfs_filblks_t len = *rlen; /* length to unmap in file */
xfs_fileoff_t max_len;
xfs_agnumber_t prev_agno = NULLAGNUMBER, agno;

trace_xfs_bunmap(ip, bno, len, flags, _RET_IP_);

Expand Down Expand Up @@ -5534,6 +5535,17 @@ __xfs_bunmapi(
*/
del = got;
wasdel = isnullstartblock(del.br_startblock);

/*
* Make sure we don't touch multiple AGF headers out of order
* in a single transaction, as that could cause AB-BA deadlocks.
*/
if (!wasdel) {
agno = XFS_FSB_TO_AGNO(mp, del.br_startblock);
if (prev_agno != NULLAGNUMBER && prev_agno > agno)
break;
prev_agno = agno;
}
if (got.br_startoff < start) {
del.br_startoff = start;
del.br_blockcount -= start - got.br_startoff;
Expand Down Expand Up @@ -6499,6 +6511,15 @@ xfs_bmap_finish_one(
xfs_fsblock_t firstfsb;
int error = 0;

/*
* firstfsb is tied to the transaction lifetime and is used to
* ensure correct AG locking order and schedule work item
* continuations. XFS_BUI_MAX_FAST_EXTENTS (== 1) restricts us
* to only making one bmap call per transaction, so it should
* be safe to have it as a local variable here.
*/
firstfsb = NULLFSBLOCK;

trace_xfs_bmap_deferred(tp->t_mountp,
XFS_FSB_TO_AGNO(tp->t_mountp, startblock), type,
XFS_FSB_TO_AGBNO(tp->t_mountp, startblock),
Expand Down
6 changes: 4 additions & 2 deletions fs/xfs/libxfs/xfs_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ xfs_btree_firstrec(
* Get the block pointer for this level.
*/
block = xfs_btree_get_block(cur, level, &bp);
xfs_btree_check_block(cur, block, level, bp);
if (xfs_btree_check_block(cur, block, level, bp))
return 0;
/*
* It's empty, there is no such record.
*/
Expand Down Expand Up @@ -757,7 +758,8 @@ xfs_btree_lastrec(
* Get the block pointer for this level.
*/
block = xfs_btree_get_block(cur, level, &bp);
xfs_btree_check_block(cur, block, level, bp);
if (xfs_btree_check_block(cur, block, level, bp))
return 0;
/*
* It's empty, there is no such record.
*/
Expand Down
4 changes: 4 additions & 0 deletions fs/xfs/libxfs/xfs_dir2_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ __xfs_dir3_data_check(
*/
if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
XFS_WANT_CORRUPTED_RETURN(mp, lastfree == 0);
XFS_WANT_CORRUPTED_RETURN(mp, endp >=
p + be16_to_cpu(dup->length));
XFS_WANT_CORRUPTED_RETURN(mp,
be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) ==
(char *)dup - (char *)hdr);
Expand Down Expand Up @@ -164,6 +166,8 @@ __xfs_dir3_data_check(
XFS_WANT_CORRUPTED_RETURN(mp, dep->namelen != 0);
XFS_WANT_CORRUPTED_RETURN(mp,
!xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)));
XFS_WANT_CORRUPTED_RETURN(mp, endp >=
p + ops->data_entsize(dep->namelen));
XFS_WANT_CORRUPTED_RETURN(mp,
be16_to_cpu(*ops->data_entry_tag_p(dep)) ==
(char *)dep - (char *)hdr);
Expand Down
4 changes: 4 additions & 0 deletions fs/xfs/libxfs/xfs_refcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,10 @@ xfs_refcount_recover_cow_leftovers(
error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
if (error)
goto out_trans;
if (!agbp) {
error = -ENOMEM;
goto out_trans;
}
cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno, NULL);

/* Find all the leftover CoW staging extents. */
Expand Down
3 changes: 3 additions & 0 deletions fs/xfs/xfs_qm.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ xfs_qm_dquot_walk(
skipped = 0;
break;
}
/* we're done if id overflows back to zero */
if (!next_index)
break;
}

if (skipped) {
Expand Down
4 changes: 3 additions & 1 deletion fs/xfs/xfs_reflink.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ xfs_reflink_find_shared(
error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
if (error)
return error;
if (!agbp)
return -ENOMEM;

cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno, NULL);

Expand Down Expand Up @@ -329,7 +331,7 @@ xfs_reflink_convert_cow_extent(
xfs_filblks_t count_fsb,
struct xfs_defer_ops *dfops)
{
xfs_fsblock_t first_block;
xfs_fsblock_t first_block = NULLFSBLOCK;
int nimaps = 1;

if (imap->br_state == XFS_EXT_NORM)
Expand Down

0 comments on commit 19993e7

Please sign in to comment.