diff options
author | Darrick J. Wong <djwong@kernel.org> | 2022-10-10 09:06:24 -0700 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2022-10-31 08:58:21 -0700 |
commit | 9a50ee4f8db6e4dd0d8d757b7adaf0591776860a (patch) | |
tree | 136d1cac30e3b07333be46da4b777edaf300389a /fs/crypto/policy.c | |
parent | 5a8c345ca8b99a9f54b89991f2f6a20521cb05f4 (diff) | |
download | linux-9a50ee4f8db6e4dd0d8d757b7adaf0591776860a.tar.gz linux-9a50ee4f8db6e4dd0d8d757b7adaf0591776860a.tar.bz2 linux-9a50ee4f8db6e4dd0d8d757b7adaf0591776860a.zip |
xfs: track cow/shared record domains explicitly in xfs_refcount_irec
Just prior to committing the reflink code into upstream, the xfs
maintainer at the time requested that I find a way to shard the refcount
records into two domains -- one for records tracking shared extents, and
a second for tracking CoW staging extents. The idea here was to
minimize mount time CoW reclamation by pushing all the CoW records to
the right edge of the keyspace, and it was accomplished by setting the
upper bit in rc_startblock. We don't allow AGs to have more than 2^31
blocks, so the bit was free.
Unfortunately, this was a very late addition to the codebase, so most of
the refcount record processing code still treats rc_startblock as a u32
and pays no attention to whether or not the upper bit (the cow flag) is
set. This is a weakness is theoretically exploitable, since we're not
fully validating the incoming metadata records.
Fuzzing demonstrates practical exploits of this weakness. If the cow
flag of a node block key record is corrupted, a lookup operation can go
to the wrong record block and start returning records from the wrong
cow/shared domain. This causes the math to go all wrong (since cow
domain is still implicit in the upper bit of rc_startblock) and we can
crash the kernel by tricking xfs into jumping into a nonexistent AG and
tripping over xfs_perag_get(mp, <nonexistent AG>) returning NULL.
To fix this, start tracking the domain as an explicit part of struct
xfs_refcount_irec, adjust all refcount functions to check the domain
of a returned record, and alter the function definitions to accept them
where necessary.
Found by fuzzing keys[2].cowflag = add in xfs/464.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/crypto/policy.c')
0 files changed, 0 insertions, 0 deletions