Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796232959; b=jDFdpgk2OXA33c9cK/wdPn/2RTyaMud00iH2deAqUrE5Kcrup5e8bxisev6aFaRA4kuH 1nxYHixUSYznKbqm1jk7XPJDoWawSqZibY4u+d6V0zeHGFQoTDHP8WJZWK0YqvzMP3Vww FzzXMGXvqO05hZjeGG24Kl5ZbG5TIrPH80pol5gn+kBaND+jfbDqHDUWYERPgdBvraeJ8 XMxrG1X4evoFD3WBzbBXHnuQWlzJn5pvpvyHhbaakqItKdEEBHtVrjBM/xcn/r1AgZ5Y4 wk0CXSAliOZN2ZsHIBQXnQDxZkmTnS/465ZAkGEVkSWRxiSv16YiwvnC0cAx52JhMsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796232959; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=S1UfRSZhr40/oCx0YH9voUxKRqAYNSW2/X2WRpwe9ck=; b=Kq46WNSisxUhPfGLp1/GlKLHv1tCCG0i6c9IQPMF/7znpnTD5d5OmyVrzdSXfgq2oNfT MgVKZ7WjbUD1qoXPRaVZ37TVeN7690fSAvzUN8Q8Wgd79pP/plUOCxqrIqWJy4KzfoF2F t6LVLmAkKZkrxyZmWal3EBZJv6rw2tCne68KQJNXBVsxSqGRVMAxXcBx1JOOf9+rAK4nY HM5VqFgrH7WU39GjJvEoBCM6I++MZ2zpPqY+RPYwdODStX/VHSkgRPvFIl4HOXZd90JTG pI9ocAilyfRjrGfYZKAgDrKZTMn/yMYoJjC9S1enm02Lo9VUG2f0nqy9AeNn5QC3V9w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ow1P7T+V; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5088B606A32D; Wed, 2 Dec 2026 17:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ow1P7T+V Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BCEE1F00899; Wed, 2 Dec 2026 17:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796232958; bh=S1UfRSZhr40/oCx0YH9voUxKRqAYNSW2/X2WRpwe9ck=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ow1P7T+Vi6o8c4aNH7umudK1oZL6W2D8w65xBIiMYJpChiSb+HvVyFTekAnPyEjcl Dd5/EbDab0iYYTAPjmbyugWMIcn8f8dDUB3jLbtdCuG/dVnJQIBTU7hvv5kvSXoeaM qVllOKy2wWPDticlfuMnU6FVxLzP76ifur/Dl0a8/67U0wKEDWUtBIC6NjP3PForDE ESIz8bK7MZt1vENHYldx69jkLI3sbgw5fCaL+LZOd09OdtNfmk6Q75fa8Qc8/VI+TK l6Xdr6Suwrg0SzGZZT2QmwmbV6JKQfQgcpuRK4BzePz+j4wkVQWipY1ir1oHtfToC1 uyW5U1uPaHsmw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [f2fs-dev] [PATCH v20 21/23] xfs: check and repair the verity inode flag state Reply-To: sashiko-reviews@lists.linux.dev To: "Andrey Albershteyn via Linux-f2fs-devel" , linux-ext4 , "Eric Biggers" , "Christoph Hellwig" , "Carlos Maiolino" , fsverity Cc: david@fromorbit.com, "Christian Brauner" , "Andrey Albershteyn" , "Darrick J. Wong" , dsterba@suse.cz, tytso@mit.edu In-Reply-To: <20261202165653.767961-22-aalbersh@kernel.org> References: <20261202165653.767961-1-aalbersh@kernel.org> <20261202165653.767961-22-aalbersh@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 17:35:57 +0000 X-Mailing-List: fsverity@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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" > =20 > +#include > + > /* Common code for the metadata scrubbers. */ > =20 > /* > @@ -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 re= ading > + * 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 be= cause > + * 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 =3D 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 =3D sc->ip; > =20 > xchk_ilock(sc, XFS_IOLOCK_EXCL); > =20 > + error =3D 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)); > =20 > + 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 =3D=3D 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 =3D 0; > else if (dip->di_version >=3D 3) > dip->di_v3_pad =3D 0; > + if (!xfs_has_verity(mp) || !S_ISREG(mode)) > + flags2 &=3D ~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 &=3D ~XFS_DIFLAG2_VERITY; > + if (xfs_has_verity(mp) && S_ISREG(mode)) > + ri->zap_verity =3D 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; > =20 > + error =3D 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 =3D 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 =3D=3D 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 &=3D ~XFS_DIFLAG2_DAX; > + > + /* DAX and fsverity do not mix. */ > + if (sc->ip->i_diflags2 & XFS_DIFLAG2_VERITY) > + sc->ip->i_diflags2 &=3D ~XFS_DIFLAG2_DAX; > + > + /* APPEND and fsverity do not mix. */ > + if (sc->ip->i_diflags2 & XFS_DIFLAG2_VERITY) > + sc->ip->i_diflags &=3D ~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 > =20 > +/* > + * Disable fsverity on this file and free the Merkle tree, which XFS sto= res > + * in extents beyond EOF. The stale Merkle tree page cache must have be= en > + * dropped before calling this function. > + */ > +STATIC int > +xrep_inode_zap_verity( > + struct xfs_scrub *sc) > +{ > + struct inode *inode =3D VFS_I(sc->ip); > + struct xfs_mount *mp =3D sc->mp; > + int error; > + > + error =3D 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 &=3D ~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 som= ething > + * wrong with the verity descriptor, so turn verity off and free the orp= haned > + * Merkle tree that XFS keeps in extents beyond EOF. We also free the M= erkle > + * tree if dinode repair had to clear the verity flag. > + */ > +STATIC int > +xrep_inode_verity( > + struct xfs_scrub *sc) > +{ > + struct xrep_inode *ri =3D 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; > } > =20 > + /* > + * 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202165653.7679= 61-1-aalbersh@kernel.org?part=3D21