xfs: fix potential integer overflow in sort comparators
cover xfs: fix potential integer overflow in sort comparators
Several sort comparators in XFS subtract two uint32_t values and return the result as int, which can overflow when the difference exceeds INT_MAX.
Use cmp_int() instead, as was done in commit 362c49098086 ("xfs: fix integer overflow in bmap intent sort comparator").
Patch 1 fixes the deferred intent comparators (rmap, extfree, refcount). Patch 2 fixes the busy extent comparator.
Yuto Ohnuki (2):
xfs: fix integer overflow in deferred intent sort comparators
xfs: fix integer overflow in busy extent sort comparator
fs/xfs/xfs_extent_busy.c | 4 ++-- fs/xfs/xfs_extfree_item.c | 2 +- fs/xfs/xfs_refcount_item.c | 2 +- fs/xfs/xfs_rmap_item.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 8 lines
2.50.1 Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284 Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705
PATCH 1/2 xfs: fix integer overflow in deferred intent sort comparators
xfs_extent_free_diff_items(), xfs_refcount_update_diff_items(), and xfs_rmap_update_diff_items() subtract two uint32_t group numbers and return the result as int, which can overflow when the difference exceeds INT_MAX.
Use cmp_int() instead, as was done in commit 362c49098086 ("xfs:
fix integer overflow in bmap intent sort comparator").
--- fs/xfs/xfs_extfree_item.c | 2 +- fs/xfs/xfs_refcount_item.c | 2 +- fs/xfs/xfs_rmap_item.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/xfs/xfs_extfree_item.c +1 -1
@@ -387,7 +387,7 @@ xfs_extent_free_diff_items(struct xfs_extent_free_item *ra =xefi_entry (a);struct xfs_extent_free_item *rb =xefi_entry (b); -return ra->xefi_group->xg_gno - rb->xefi_group->xg_gno; +return cmp_int (ra->xefi_group->xg_gno, rb->xefi_group->xg_gno); }/* Log a free extent to the intent item. */
fs/xfs/xfs_refcount_item.c +1 -1
@@ -266,7 +266,7 @@ xfs_refcount_update_diff_items(struct xfs_refcount_intent *ra =ci_entry (a);struct xfs_refcount_intent *rb =ci_entry (b); -return ra->ri_group->xg_gno - rb->ri_group->xg_gno; +return cmp_int (ra->ri_group->xg_gno, rb->ri_group->xg_gno); }/* Log refcount updates in the intent item. */
fs/xfs/xfs_rmap_item.c +1 -1
@@ -267,7 +267,7 @@ xfs_rmap_update_diff_items(struct xfs_rmap_intent *ra =ri_entry (a);struct xfs_rmap_intent *rb =ri_entry (b); -return ra->ri_group->xg_gno - rb->ri_group->xg_gno; +return cmp_int (ra->ri_group->xg_gno, rb->ri_group->xg_gno); }/* Log rmap updates in the intent item. */
Signature · 8 lines
2.50.1 Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284 Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705
Re: [PATCH 1/2] xfs: fix integer overflow in deferred intent sort comparators
Quoted 7 lines · Yuto Ohnuki
xfs_extent_free_diff_items(),xfs_refcount_update_diff_items(), andxfs_rmap_update_diff_items()subtract twouint32_tgroup numbers and return the result as int, which can overflow when the difference exceedsINT_MAX.Use
cmp_int()instead, as was done in commit362c49098086("xfs:
fix integer overflow in bmap intent sort comparator").
Looks good:
PATCH 2/2 xfs: fix integer overflow in busy extent sort comparator
In reply to Yuto Ohnukixfs_extent_busy_ag_cmp() subtracts two uint32_t values (group numbers and block numbers) and returns the result as s32. When the difference exceeds INT_MAX, the result overflows and the sort order is corrupted.
Use cmp_int() instead, as was done in commit 362c49098086 ("xfs:
fix integer overflow in bmap intent sort comparator").
--- fs/xfs/xfs_extent_busy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_extent_busy.c +2 -2
@@ -690,9 +690,9 @@ xfs_extent_busy_ag_cmp( container_of(l2, struct xfs_extent_busy, list);s32 diff; - diff = b1->group->xg_gno - b2->group->xg_gno; + diff =cmp_int (b1->group->xg_gno, b2->group->xg_gno);if (!diff) - diff = b1->bno - b2->bno; + diff =cmp_int (b1->bno, b2->bno);return diff; }
Signature · 8 lines
2.50.1 Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284 Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705
Re: [PATCH 2/2] xfs: fix integer overflow in busy extent sort comparator
Quoted 7 lines · Yuto Ohnuki
xfs_extent_busy_ag_cmp()subtracts twouint32_tvalues (group numbers and block numbers) and returns the result as s32. When the difference exceedsINT_MAX, the result overflows and the sort order is corrupted.Use
cmp_int()instead, as was done in commit362c49098086("xfs:
fix integer overflow in bmap intent sort comparator").
Looks good:
Quoted 14 lines · Yuto Ohnuki
Several sort comparators in XFS subtract two
uint32_tvalues and return the result as int, which can overflow when the difference exceedsINT_MAX.Use
cmp_int()instead, as was done in commit362c49098086("xfs: fix integer overflow in bmap intent sort comparator").Patch 1 fixes the deferred intent comparators (rmap, extfree, refcount). Patch 2 fixes the busy extent comparator.
Yuto Ohnuki (2):
xfs: fix integer overflow in deferred intent sort comparators
xfs: fix integer overflow in busy extent sort comparator
Quoted 6 lines
fs/xfs/xfs_extent_busy.c | 4 ++-- fs/xfs/xfs_extfree_item.c | 2 +- fs/xfs/xfs_refcount_item.c | 2 +- fs/xfs/xfs_rmap_item.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
For the series:
Quoted 13 lines
Signature · 8 lines
2.50.1 Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284 Amazon Web Services EMEA SARL, Irish Branch, One Burlington Plaza, Burlington Road, Dublin 4, Ireland, branch registration number 908705
Quoted 8 lines · Yuto Ohnuki
Several sort comparators in XFS subtract two
uint32_tvalues and return the result as int, which can overflow when the difference exceedsINT_MAX.Use
cmp_int()instead, as was done in commit362c49098086("xfs: fix integer overflow in bmap intent sort comparator").[...]
Applied to for-next, thanks!
[1/2] xfs: fix integer overflow in deferred intent sort comparators
commit: 59e586d7dc7813910abe20a8281bbc3f1360e08e
[2/2] xfs: fix integer overflow in busy extent sort comparator
commit: 553a13e2076d64774910d597977a17022625763dBest regards,
Signature · 1 line
Carlos Maiolino <[email protected]>