Skip to content

Commit bd721ec

Browse files
Darrick J. Wongcmaiolino
authored andcommitted
xfs: don't set bt_nr_sectors to a negative number
xfs_daddr_t is a signed type, which means that xfs_buf_map_verify is using a signed comparison. This causes problems if bt_nr_sectors is never overridden (e.g. in the case of an xfbtree for rmap btree repairs) because even daddr 0 can't pass the verifier test in that case. Define an explicit max constant and set the initial bt_nr_sectors to a positive value. Found by xfs/422. Cc: [email protected] # v6.18-rc1 Fixes: 42852fe ("xfs: track the number of blocks in each buftarg") Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 0f41997 commit bd721ec

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

fs/xfs/xfs_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ xfs_init_buftarg(
17511751
const char *descr)
17521752
{
17531753
/* The maximum size of the buftarg is only known once the sb is read. */
1754-
btp->bt_nr_sectors = (xfs_daddr_t)-1;
1754+
btp->bt_nr_sectors = XFS_BUF_DADDR_MAX;
17551755

17561756
/* Set up device logical sector size mask */
17571757
btp->bt_logical_sectorsize = logical_sectorsize;

fs/xfs/xfs_buf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extern struct kmem_cache *xfs_buf_cache;
2222
*/
2323
struct xfs_buf;
2424

25+
#define XFS_BUF_DADDR_MAX ((xfs_daddr_t) S64_MAX)
2526
#define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL))
2627

2728
#define XBF_READ (1u << 0) /* buffer intended for reading from device */

0 commit comments

Comments
 (0)