Skip to content

Commit f212599

Browse files
committed
Merge tag 'xfs-4.17-fixes-1' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull xfs fixes from Darrick Wong: "Here are a few more bug fixes for xfs for 4.17-rc4. Most of them are fixes for bad behavior. This series has been run through a full xfstests run during LSF and through a quick xfstests run against this morning's master, with no major failures reported. Summary: - Enhance inode fork verifiers to prevent loading of corrupted metadata. - Fix a crash when we try to convert extents format inodes to btree format, we run out of space, but forget to revert the in-core state changes. - Fix file size checks when doing INSERT_RANGE that could cause files to end up negative size if there previously was an extent mapped at s_maxbytes. - Fix a bug when doing a remove-then-add ATTR_REPLACE xattr update where we forget to clear ATTR_REPLACE after the remove, which causes the attr to be lost and the fs to shut down due to (what it thinks is) inconsistent in-core state" * tag 'xfs-4.17-fixes-1' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: xfs: don't fail when converting shortform attr to long form during ATTR_REPLACE xfs: prevent creating negative-sized file via INSERT_RANGE xfs: set format back to extents if xfs_bmap_extents_to_btree xfs: enhance dinode verifier
2 parents fff75eb + 7b38460 commit f212599

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

‎fs/xfs/libxfs/xfs_attr.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,14 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
511511
if (args->flags & ATTR_CREATE)
512512
return retval;
513513
retval = xfs_attr_shortform_remove(args);
514-
ASSERT(retval == 0);
514+
if (retval)
515+
return retval;
516+
/*
517+
* Since we have removed the old attr, clear ATTR_REPLACE so
518+
* that the leaf format add routine won't trip over the attr
519+
* not being around.
520+
*/
521+
args->flags &= ~ATTR_REPLACE;
515522
}
516523

517524
if (args->namelen >= XFS_ATTR_SF_ENTSIZE_MAX ||

‎fs/xfs/libxfs/xfs_bmap.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,16 @@ xfs_bmap_extents_to_btree(
725725
*logflagsp = 0;
726726
if ((error = xfs_alloc_vextent(&args))) {
727727
xfs_iroot_realloc(ip, -1, whichfork);
728+
ASSERT(ifp->if_broot == NULL);
729+
XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
728730
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
729731
return error;
730732
}
731733

732734
if (WARN_ON_ONCE(args.fsbno == NULLFSBLOCK)) {
733735
xfs_iroot_realloc(ip, -1, whichfork);
736+
ASSERT(ifp->if_broot == NULL);
737+
XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
734738
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
735739
return -ENOSPC;
736740
}

‎fs/xfs/libxfs/xfs_inode_buf.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ xfs_dinode_verify(
466466
return __this_address;
467467
if (di_size > XFS_DFORK_DSIZE(dip, mp))
468468
return __this_address;
469+
if (dip->di_nextents)
470+
return __this_address;
469471
/* fall through */
470472
case XFS_DINODE_FMT_EXTENTS:
471473
case XFS_DINODE_FMT_BTREE:
@@ -484,12 +486,31 @@ xfs_dinode_verify(
484486
if (XFS_DFORK_Q(dip)) {
485487
switch (dip->di_aformat) {
486488
case XFS_DINODE_FMT_LOCAL:
489+
if (dip->di_anextents)
490+
return __this_address;
491+
/* fall through */
487492
case XFS_DINODE_FMT_EXTENTS:
488493
case XFS_DINODE_FMT_BTREE:
489494
break;
490495
default:
491496
return __this_address;
492497
}
498+
} else {
499+
/*
500+
* If there is no fork offset, this may be a freshly-made inode
501+
* in a new disk cluster, in which case di_aformat is zeroed.
502+
* Otherwise, such an inode must be in EXTENTS format; this goes
503+
* for freed inodes as well.
504+
*/
505+
switch (dip->di_aformat) {
506+
case 0:
507+
case XFS_DINODE_FMT_EXTENTS:
508+
break;
509+
default:
510+
return __this_address;
511+
}
512+
if (dip->di_anextents)
513+
return __this_address;
493514
}
494515

495516
/* only version 3 or greater inodes are extensively verified here */

‎fs/xfs/xfs_file.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,22 +778,26 @@ xfs_file_fallocate(
778778
if (error)
779779
goto out_unlock;
780780
} else if (mode & FALLOC_FL_INSERT_RANGE) {
781-
unsigned int blksize_mask = i_blocksize(inode) - 1;
781+
unsigned int blksize_mask = i_blocksize(inode) - 1;
782+
loff_t isize = i_size_read(inode);
782783

783-
new_size = i_size_read(inode) + len;
784784
if (offset & blksize_mask || len & blksize_mask) {
785785
error = -EINVAL;
786786
goto out_unlock;
787787
}
788788

789-
/* check the new inode size does not wrap through zero */
790-
if (new_size > inode->i_sb->s_maxbytes) {
789+
/*
790+
* New inode size must not exceed ->s_maxbytes, accounting for
791+
* possible signed overflow.
792+
*/
793+
if (inode->i_sb->s_maxbytes - isize < len) {
791794
error = -EFBIG;
792795
goto out_unlock;
793796
}
797+
new_size = isize + len;
794798

795799
/* Offset should be less than i_size */
796-
if (offset >= i_size_read(inode)) {
800+
if (offset >= isize) {
797801
error = -EINVAL;
798802
goto out_unlock;
799803
}

0 commit comments

Comments
 (0)