From: sashiko-bot@kernel.org
To: "Andrey Albershteyn via Linux-f2fs-devel"
<linux-f2fs-devel@lists.sourceforge.net>,
linux-ext4 <linux-ext4@vger.kernel.org>,
"Eric Biggers" <ebiggers@kernel.org>,
"Christoph Hellwig" <hch@lst.de>,
"Carlos Maiolino" <cem@kernel.org>,
fsverity <fsverity@lists.linux.dev>
Cc: david@fromorbit.com, "Christian Brauner" <brauner@kernel.org>,
"Andrey Albershteyn" <aalbersh@kernel.org>,
"Darrick J. Wong" <djwong@kernel.org>,
dsterba@suse.cz, tytso@mit.edu
Subject: Re: [f2fs-dev] [PATCH v20 21/23] xfs: check and repair the verity inode flag state
Date: Wed, 02 Dec 2026 17:35:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-246340@kernel.org> (raw)
In-Reply-To: <20261202165653.767961-22-aalbersh@kernel.org>
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [High] xfs: XFS_DIFLAG2_VERITY on metadata inodes causes repair to
unmap quota blocks
- [Medium] xfs: CONFIG_FS_VERITY guard in xrep_dinode_flags() fails
dinode repair
- [Medium] xfs: unhandled error codes in xchk_inode_setup_verity() abort
scrub and repair
- [Medium] xfs: missing VERITY+APPEND check in xchk_inode_flags2() and
flag sync in repair
- [Medium] xfs: zero block reservation in xrep_dinode_core() for
bigrtalloc verity zap
- [Medium] xfs: verity scrub and repair mishandle corrupt or zapped data
forks
- [Medium] xfs: race in xchk_prepare_iscrub() leaves stale post-EOF
verity folios
- [Low] xfs: xchk_inode() passes sm_ino instead of I_INO(sc->ip) on
broken verity
- [Low] xfs: xrep_inode_verity() runs after reflink and flag repairs in
xrep_inode()
--
commit bc2ede889b804f9a3cfcdae388d72f25dd72bc0e
Author: Darrick J. Wong <djwong@kernel.org>
xfs: check and repair the verity inode flag state
This commit adds dinode verification, online scrub checks, and repair
support for the fsverity inode flag and post-EOF Merkle tree extents.
> diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
> index cbfe5e6f779df..29b7d67a270c4 100644
> --- a/fs/xfs/scrub/common.c
> +++ b/fs/xfs/scrub/common.c
> @@ -45,6 +45,8 @@
> #include "scrub/health.h"
> #include "scrub/tempfile.h"
>
> +#include <linux/fsverity.h>
> +
> /* Common code for the metadata scrubbers. */
>
> /*
> @@ -1765,3 +1767,60 @@ xchk_inode_count_blocks(
> return xfs_bmap_count_blocks(sc->tp, sc->ip, whichfork, nextents,
> count);
> }
> +
> +/*
> + * If this inode has S_VERITY set on it, read the verity info. If the reading
> + * fails with anything other than ENOMEM, the file is corrupt, which we can
> + * detect later with fsverity_active.
> + *
> + * Callers must hold the IOLOCK and must not hold the ILOCK of sc->ip because
> + * activation reads inode data.
> + */
> +int
> +xchk_inode_setup_verity(
> + struct xfs_scrub *sc)
> +{
> + int error;
> +
> + if (!fsverity_active(VFS_I(sc->ip)))
> + return 0;
> +
> + error = fsverity_ensure_verity_info(VFS_I(sc->ip));
> + switch (error) {
> + case 0:
> + /* fsverity is active */
> + break;
> + case -EFBIG:
> + case -EINVAL:
> + case -ENODATA:
> + case -EMSGSIZE:
> + case -EFSCORRUPTED:
> + case -ERANGE:
> + case -EBADMSG:
> + /*
> + * The nonzero errno codes above are the error codes that can
> + * be returned from fsverity on metadata validation errors.
> + *
> + * EINVAL and EFBIG are not always mean corruption. For example,
> + * missing hash algorithm could mean kernel doesn't support it
> + * or fsverity descriptor has corrupted value. Let's clear it.
> + */
> + return 0;
> + default:
> + /* runtime errors */
> + return error;
> + }
[Severity: Medium]
Can unhandled validation errors from fsverity_ensure_verity_info() abort
inode scrub and repair before xchk_inode() or xrep_inode() can run?
xfs_fsverity_get_descriptor() returns -EOPNOTSUPP when sb_blocksize >
PAGE_SIZE, xfs_bmap_last_extent() can return -EFSBADCRC on a BMBT block
with a bad CRC, and fsverity_verify_signature() can return -ENOKEY,
-EKEYREJECTED, -EPERM, -ENOPKG, -EKEYEXPIRED, or -EKEYREVOKED when
CONFIG_FS_VERITY_BUILTIN_SIGNATURES is enabled (for example, -ENOKEY for
any non-zero sig_size when the .fs-verity keyring is empty). Because
those codes hit the default branch, xchk_prepare_iscrub() and
xrep_dinode_core() fail instead of treating verity activation as broken.
[ ... ]
> diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
> index bb8d2bc008e01..09770fec70cad 100644
> --- a/fs/xfs/scrub/inode.c
> +++ b/fs/xfs/scrub/inode.c
> @@ -33,9 +33,28 @@ xchk_prepare_iscrub(
> struct xfs_scrub *sc)
> {
> int error;
> + struct xfs_inode *ip = sc->ip;
>
> xchk_ilock(sc, XFS_IOLOCK_EXCL);
>
> + error = xchk_inode_setup_verity(sc);
> + if (error)
> + return error;
> +
> + /*
> + * If we're going to repair a file whose fsverity descriptor cannot be
> + * activated, drop the stale Merkle tree folios. Once the
> + * post-EOF Merkle extents are freed during repair, those uptodate
> + * folios would otherwise sit over a hole and could be exposed as file
> + * data by a later extending write or truncate.
> + *
> + * The lock would be unlocked by global scrub machinery.
> + */
> + if (xchk_could_repair(sc) && xchk_inode_verity_broken(ip)) {
> + xchk_ilock(sc, XFS_MMAPLOCK_EXCL);
> + truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
> + }
[Severity: Medium]
Can a concurrent open() fault post-EOF verity folios back into
i_mapping after truncate_inode_pages() runs here (and in
xrep_dinode_core()) before xrep_inode_zap_verity() clears S_VERITY?
CPU0 CPU1
xchk_prepare_iscrub()
xchk_ilock(sc, XFS_MMAPLOCK_EXCL)
truncate_inode_pages(..., isize)
xfs_file_open()
fsverity_file_open()
...
xfs_fsverity_get_descriptor()
xfs_ilock(ip, XFS_ILOCK_EXCL)
/* S_VERITY is still set */
xfs_bmap_last_extent(...)
xfs_iunlock(ip, XFS_ILOCK_EXCL)
fsverity_pagecache_read()
read_mapping_folio()
/* re-populates post-EOF
* folio in i_mapping */
xchk_trans_alloc(sc, 0)
xchk_ino_dqattach(sc)
xchk_ilock(sc, XFS_ILOCK_EXCL)
...
xrep_inode_zap_verity()
xfs_bunmapi_range(...)
inode_set_flags(inode, 0, S_VERITY)
<-- uptodate post-EOF folio remains
over unmapped hole
Neither xfs_fsverity_get_descriptor() nor read_mapping_folio() takes
XFS_MMAPLOCK (mapping->invalidate_lock) or XFS_IOLOCK, so holding
XFS_MMAPLOCK_EXCL does not serialize against concurrent descriptor reads
while S_VERITY is still set. Once xrep_inode_zap_verity() unmaps the
post-EOF blocks and clears S_VERITY, those newly faulted folios remain in
the page cache and can be exposed as file data by a later extending write
or truncate.
[ ... ]
> @@ -833,6 +870,9 @@ xchk_inode(
> if (S_ISREG(VFS_I(sc->ip)->i_mode))
> xchk_inode_check_reflink_iflag(sc, I_INO(sc->ip));
>
> + if (xchk_inode_verity_broken(sc->ip))
> + xchk_ino_set_corrupt(sc, sc->sm->sm_ino);
[Severity: Low]
Should this pass I_INO(sc->ip) instead of sc->sm->sm_ino to
xchk_ino_set_corrupt()? When scrubbing by file descriptor with
sm_ino == 0, passing sc->sm->sm_ino records inode 0 in
trace_xchk_ino_error().
> diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c
> index a9ccf763c0596..e7e9cecf912b9 100644
> --- a/fs/xfs/scrub/inode_repair.c
> +++ b/fs/xfs/scrub/inode_repair.c
[ ... ]
> @@ -577,6 +585,24 @@ xrep_dinode_flags(
> dip->di_nrext64_pad = 0;
> else if (dip->di_version >= 3)
> dip->di_v3_pad = 0;
> + if (!xfs_has_verity(mp) || !S_ISREG(mode))
> + flags2 &= ~XFS_DIFLAG2_VERITY;
> +
> + /*
> + * fs-verity does not work on zoned inodes or on realtime inodes
> + * with a realtime allocation unit larger than a filesystem block.
> + * The realtime flag cannot be cleared here because the file's data
> + * is already stored on the realtime device, so the fsverity flag
> + * has to go. Free the orphaned Merkle tree past EOF once the inode
> + * can be loaded again.
> + */
> + if (IS_ENABLED(CONFIG_FS_VERITY) &&
> + (flags & XFS_DIFLAG_REALTIME) && (flags2 & XFS_DIFLAG2_VERITY) &&
> + (xfs_has_zoned(mp) || mp->m_sb.sb_rextsize > 1)) {
> + flags2 &= ~XFS_DIFLAG2_VERITY;
> + if (xfs_has_verity(mp) && S_ISREG(mode))
> + ri->zap_verity = true;
> + }
[Severity: Medium]
Does guarding this block with IS_ENABLED(CONFIG_FS_VERITY) cause dinode
repair to fail when CONFIG_FS_VERITY is disabled? xfs_dinode_verify()
rejects XFS_DIFLAG2_VERITY combined with XFS_DIFLAG_REALTIME on zoned or
sb_rextsize > 1 filesystems unconditionally, so leaving XFS_DIFLAG2_VERITY
set here causes the subsequent xchk_iget() in xrep_dinode_core() to fail
with -EFSCORRUPTED.
[ ... ]
> @@ -1659,6 +1685,22 @@ xrep_dinode_core(
> if (iget_error)
> return iget_error;
>
> + error = xchk_inode_setup_verity(sc);
> + if (error)
> + return error;
[Severity: Medium]
What happens when xrep_dinode_core() zaps a corrupt data fork (setting
XFS_SICK_INO_BMBTD_ZAPPED and resetting the fork to 0 extents) or when an
inode has a corrupt out-of-line data fork BMBT?
If xrep_dinode_zap_forks() just zapped the data fork, calling
xchk_inode_setup_verity() on the empty fork fails with -ENODATA, which
causes xrep_inode_verity() to clear XFS_DIFLAG2_VERITY while
xfs_bunmapi_range() is a no-op on the empty fork; when BMBT repair later
reconstructs the data fork from rmapbt, it reattaches the post-EOF Merkle
tree extents onto a non-verity file. Conversely, if an inode passes
xfs_iget() with XFS_DIFLAG2_VERITY set but has a corrupt out-of-line
BMBT, xchk_inode_setup_verity() swallows -EFSCORRUPTED from
xfs_iread_extents(), causing xchk_inode() to mark the inode core corrupt
and xrep_inode() to fail in xrep_inode_blockcounts() before BMBT repair
can fix the data fork.
> +
> + /*
> + * If verity activation failed, the descriptor read above may have left
> + * uptodate post-EOF folios in the page cache. Drop them before
> + * xrep_inode_verity frees the Merkle tree, as xchk_prepare_iscrub does
> + * for the normal setup path.
> + */
> + if (xchk_inode_verity_broken(sc->ip) || ri->zap_verity) {
> + xchk_ilock(sc, XFS_MMAPLOCK_EXCL);
> + truncate_inode_pages(VFS_I(sc->ip)->i_mapping,
> + XFS_ISIZE(sc->ip));
> + }
> +
> error = xchk_trans_alloc(sc, 0);
> if (error)
> return error;
[Severity: Medium]
Is a zero block reservation sufficient here when ri->zap_verity is set on
a realtime inode with sb_rextsize > 1?
When xrep_inode_zap_verity() calls xfs_bunmapi_range() starting at
XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip)) on an inode with
xfs_inode_has_bigrtalloc(ip), __xfs_bunmapi() requires block reservation
(such as XFS_DIOSTRAT_SPACE_RES(mp, 0)) to split or convert a partial
realtime extent to unwritten; with t_blk_res == 0 it can trip
ASSERT(tp->t_blk_res > 0), skip unmapping the partial tail extent at
startoff, or fail a BMBT split with -ENOSPC on a dirty transaction.
> @@ -1893,6 +1935,14 @@ xrep_inode_flags(
> /* DAX only applies to files and dirs. */
> if (!(S_ISREG(mode) || S_ISDIR(mode)))
> sc->ip->i_diflags2 &= ~XFS_DIFLAG2_DAX;
> +
> + /* DAX and fsverity do not mix. */
> + if (sc->ip->i_diflags2 & XFS_DIFLAG2_VERITY)
> + sc->ip->i_diflags2 &= ~XFS_DIFLAG2_DAX;
> +
> + /* APPEND and fsverity do not mix. */
> + if (sc->ip->i_diflags2 & XFS_DIFLAG2_VERITY)
> + sc->ip->i_diflags &= ~XFS_DIFLAG_APPEND;
> }
[Severity: Medium]
Does clearing XFS_DIFLAG_APPEND here leave S_APPEND set in
VFS_I(sc->ip)->i_flags, and is xchk_inode_flags2() missing the
corresponding check for (flags2 & XFS_DIFLAG2_VERITY) &&
(flags & XFS_DIFLAG_APPEND)?
xchk_inode_flags2() checks for VERITY combined with DAX but never checks
for VERITY combined with APPEND, so xchk_inode() will not flag an inode
with both flags set as corrupt. When xrep_inode_flags() does run and
clears XFS_DIFLAG_APPEND, nothing syncs VFS_I(sc->ip)->i_flags (unlike
xrep_inode_zap_verity(), which calls inode_set_flags()), leaving the
in-core VFS inode append-only.
> @@ -2198,6 +2248,60 @@ xrep_inode_reset_dquots(
> # define xrep_inode_reset_dquots(sc) (0)
> #endif
>
> +/*
> + * Disable fsverity on this file and free the Merkle tree, which XFS stores
> + * in extents beyond EOF. The stale Merkle tree page cache must have been
> + * dropped before calling this function.
> + */
> +STATIC int
> +xrep_inode_zap_verity(
> + struct xfs_scrub *sc)
> +{
> + struct inode *inode = VFS_I(sc->ip);
> + struct xfs_mount *mp = sc->mp;
> + int error;
> +
> + error = xfs_bunmapi_range(&sc->tp, sc->ip, 0,
> + XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip)), XFS_MAX_FILEOFF);
> + if (error)
> + return error;
> +
> + sc->ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
> + inode_set_flags(inode, 0, S_VERITY);
> +
> + xfs_trans_log_inode(sc->tp, sc->ip, XFS_ILOG_CORE);
> + return 0;
> +}
[Severity: High]
What happens if XFS_DIFLAG2_VERITY is corruptly set on a metadata regular
file such as a quota inode or a META_BTREE inode?
Neither xfs_dinode_verify(), xfs_dinode_verify_metadir(),
xchk_inode_flags2(), xrep_dinode_flags(), nor xrep_inode_flags() forbids
or clears XFS_DIFLAG2_VERITY on metadata inodes. When a metadata inode is
repaired via xrep_metadata_inode_forks() -> xrep_inode(),
xrep_inode_zap_verity() unmaps from XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip)) to
XFS_MAX_FILEOFF. On a quota inode, XFS_ISIZE(sc->ip) is always 0 while
allocated dquot chunks reside in the data fork, so xfs_bunmapi_range()
frees all dquot blocks from offset 0 while live in-core dquots still
reference them. On an XFS_DINODE_FMT_META_BTREE inode, __xfs_bunmapi()
fails with -EFSCORRUPTED before XFS_DIFLAG2_VERITY can be cleared.
> +
> +/*
> + * If this file was a fsverity file, xchk_prepare_iscrub or xrep_dinode_core
> + * should have activated it. If it's still not active, then there's something
> + * wrong with the verity descriptor, so turn verity off and free the orphaned
> + * Merkle tree that XFS keeps in extents beyond EOF. We also free the Merkle
> + * tree if dinode repair had to clear the verity flag.
> + */
> +STATIC int
> +xrep_inode_verity(
> + struct xfs_scrub *sc)
> +{
> + struct xrep_inode *ri = sc->buf;
> +
> + /*
> + * If we had to clear the fsverity flag while repairing the ondisk
> + * inode or we failed to activate the fsverity descriptor, clear the
> + * fsverity flag and free the orphaned Merkle tree that XFS stores
> + * past EOF.
> + */
> + if (!xchk_inode_verity_broken(sc->ip) && !(ri && ri->zap_verity))
> + return 0;
> +
> + /*
> + * The post-EOF verity folios were dropped by xchk_prepare_iscrub or
> + * xrep_dinode_core before we got here.
> + */
> + return xrep_inode_zap_verity(sc);
> +}
> +
> /* Repair an inode's fields. */
> int
> xrep_inode(
> @@ -2247,6 +2351,15 @@ xrep_inode(
> return error;
> }
>
> + /*
> + * Disable fsverity if it cannot be activated. Activation failure
> + * prohibits the file from being opened, so there cannot be another
> + * program with an open fd to what it thinks is a verity file.
> + */
> + error = xrep_inode_verity(sc);
> + if (error)
> + return error;
[Severity: Low]
Should xrep_inode_verity() run before xrep_inode_problems() and
xfs_reflink_clear_inode_flag()?
Running xrep_inode_problems() first causes xrep_inode_flags() to strip
XFS_DIFLAG2_DAX and XFS_DIFLAG_APPEND on the basis of a broken
XFS_DIFLAG2_VERITY flag that xrep_inode_verity() is about to clear.
Running xfs_reflink_clear_inode_flag() before xrep_inode_verity() also
scans post-EOF Merkle tree extents before they are unmapped; if only those
post-EOF extents were shared, XFS_DIFLAG2_REFLINK is left set on an inode
with no remaining shared extents.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202165653.767961-1-aalbersh@kernel.org?part=21
next prev parent reply other threads:[~2026-12-02 17:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 16:56 [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 01/23] fs: constify inode argument of inode_state_read_once() Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 02/23] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 03/23] fs,fsverity: add I_VERITY_BUILDING inode state flag Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 04/23] fs,fsverity: reject S_APPEND on fsverity inodes Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 05/23] iomap: use fsverity_is_building() to check for fsverity IO Andrey Albershteyn
2026-12-02 17:09 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 06/23] btrfs: use I_VERITY_BUILDING instead of private flags Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 07/23] ext4: " Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 08/23] f2fs: " Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 09/23] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 10/23] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 11/23] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 12/23] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 13/23] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-12-02 17:28 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 14/23] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-12-02 17:15 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 15/23] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-12-02 17:09 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 16/23] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 17/23] xfs: add fs-verity support Andrey Albershteyn
2026-12-02 17:49 ` [f2fs-dev] " sashiko-bot
2026-12-02 16:56 ` [PATCH v20 18/23] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 19/23] xfs: add fs-verity ioctls Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 20/23] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-12-02 16:56 ` [PATCH v20 21/23] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-12-02 17:35 ` sashiko-bot [this message]
2026-12-02 16:56 ` [PATCH v20 22/23] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-12-02 17:17 ` [f2fs-dev] " sashiko-bot
2026-12-02 16:56 ` [PATCH v20 23/23] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-12-02 17:17 ` [f2fs-dev] " sashiko-bot
2026-12-02 17:49 ` [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-246340@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aalbersh@kernel.org \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.cz \
--cc=ebiggers@kernel.org \
--cc=fsverity@lists.linux.dev \
--cc=hch@lst.de \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox