OSDN Git Service

xfs: AGF length has never been bounds checked
authorDave Chinner <dchinner@redhat.com>
Thu, 29 Jun 2023 02:43:55 +0000 (19:43 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 29 Jun 2023 16:28:24 +0000 (09:28 -0700)
commitedd8276dd70279c29d412d99b99c2c0cac1b2cdd
tree48eacb20da8ccc735ed23e17514309ba98a0ab1f
parentf1e1765aad7de7a8b8102044fc6a44684bc36180
xfs: AGF length has never been bounds checked

The AGF verifier does not check that the AGF length field is within
known good bounds. This has never been checked by runtime kernel
code (i.e. the lack of verification goes back to 1993) yet we assume
in many places that it is correct and verify other metdata against
it.

Add length verification to the AGF verifier. The length of the AGF
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.

This requires a bit of rework of the verifier function. We want to
verify metadata before we use it to verify other metadata. Hence
we need to verify the AGF sequence numbers before using them to
verify the length of the AGF. Then we can verify the AGF length
before we verify AGFL fields. Then we can verifier other fields that
are bounds limited by the AGF length.

And, finally, by calculating agf_length only once into a local
variable, we can collapse repeated "if (xfs_has_foo() &&"
conditionaly checks into single checks. This makes the code much
easier to follow as all the checks for a given feature are obviously
in the same place.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_alloc.c