xfs: AGI length should be bounds checked
authorDarrick J. Wong <djwong@kernel.org>
Thu, 29 Jun 2023 17:15:45 +0000 (10:15 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 3 Jul 2023 16:48:17 +0000 (09:48 -0700)
commit2d7d1e7ea321b0b2810eb00183e21332ee9c4b6f
treee00f7799bc0b522fc99e9d3371d0e9f5d83c5475
parent5cf32f63b0f4c520460c1a5dd915dc4f09085f29
xfs: AGI length should be bounds checked

Similar to the recent patch strengthening the AGF agf_length
verification, the AGI verifier does not check that the AGI length field
is within known good bounds.  This isn't currently checked by runtime
kernel code, yet we assume in many places that it is correct and verify
other metadata against it.

Add length verification to the AGI verifier.  Just like the AGF length
checking, the length of the AGI must be equal to the size of the AG
specified in the superblock, unless it is the last AG in the filesystem.
In that case, it must be less than or equal to sb->sb_agblocks and
greater than XFS_MIN_AG_BLOCKS, which is the smallest AG a growfs
operation will allow to exist.

There's only one place in the filesystem that actually uses agi_length,
but let's not leave it vulnerable to the same weird nonsense that
generates syzbot bugs, eh?

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_alloc.h
fs/xfs/libxfs/xfs_ialloc.c