]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: fix integer overflow in bmap intent sort comparator
authorLong Li <leo.lilong@huawei.com>
Tue, 10 Mar 2026 12:32:33 +0000 (20:32 +0800)
committerCarlos Maiolino <cem@kernel.org>
Wed, 11 Mar 2026 12:21:42 +0000 (13:21 +0100)
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: 9f3afb57d5f1 ("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>
fs/xfs/xfs_bmap_item.c

index e8775f254c89c9603d799e3f178faa880c793e2b..b237a25d6045d3bdde59fd5462044c4dd61e9483 100644 (file)
@@ -245,7 +245,7 @@ xfs_bmap_update_diff_items(
        struct xfs_bmap_intent          *ba = bi_entry(a);
        struct xfs_bmap_intent          *bb = bi_entry(b);
 
-       return ba->bi_owner->i_ino - bb->bi_owner->i_ino;
+       return cmp_int(ba->bi_owner->i_ino, bb->bi_owner->i_ino);
 }
 
 /* Log bmap updates in the intent item. */