Skip to content

Commit 362c490

Browse files
Long Licmaiolino
authored andcommitted
xfs: fix integer overflow in bmap intent sort comparator
xfs_bmap_update_diff_items() sorts bmap intents by inode number using a subtraction of two xfs_ino_t (uint64_t) values, with the result truncated to int. This is incorrect when two inode numbers differ by more than INT_MAX (2^31 - 1), which is entirely possible on large XFS filesystems. Fix this by replacing the subtraction with cmp_int(). Cc: <stable@vger.kernel.org> # v4.9 Fixes: 9f3afb5 ("xfs: implement deferred bmbt map/unmap operations") Signed-off-by: Long Li <leo.lilong@huawei.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 52a8a1b commit 362c490

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/xfs/xfs_bmap_item.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ xfs_bmap_update_diff_items(
245245
struct xfs_bmap_intent *ba = bi_entry(a);
246246
struct xfs_bmap_intent *bb = bi_entry(b);
247247

248-
return ba->bi_owner->i_ino - bb->bi_owner->i_ino;
248+
return cmp_int(ba->bi_owner->i_ino, bb->bi_owner->i_ino);
249249
}
250250

251251
/* Log bmap updates in the intent item. */

0 commit comments

Comments
 (0)