From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796230659; b=5cOFxWKzr7ot3NwMHO4hS2iObL8C5iXHqN0BheK/7LmhLd4o8SIna3GWCJm9VGb29R3C VtgA0FiMD6rbwnPu2Fl6Nc1CLCisRwBp7SRBtusuAO6JvgPXf1PkyrhaXhEqUkdYBsWyu lhcmwwEz+AxDLi4x0jwzo1SVcBxZF1dm79RD/eeW47UtGO3IHz3czYK32SftUx8qRcGO/ 2wiZDlvfHFOI9pIOjJ5YF2XElJJTi0EIfafTb1v+RUc+cWmy5j7C9y0NubVpMwMDbuajS bDkZL9cgukqv531UHCPKpwm53rgGyKb4WsZQAOOFizrLW+vJaF4XlrsQKeXuAC8ITXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230659; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=Y+sQgV/wuLl5uRWieX8FXOeU49++3DMQE3wG9MMqIN0=; b=WjHId1TrfVA5lFyzMO7rj/jS4w9bbjrraVqBKhxm/EWNKmVxLRTtqszw+gaAQ2a76I+f nZGC9OSOEoxbcK9Dc6b9agI2B3CPkttr3wIhtRtE83PhrtxooP37e9rojiQjfdR02zBkH pcLyxS5soGMDufNzU38EgWlJ2IgmjrtNVVyU+FC4S6XuG4FOxwG5HrxiZz3hpYETGoZ4R P1gx9J9c4/sB1rnVJCTfVqlb4Kw6Bx/2zsnirdCk8UkG2AKiZwY2kFpZPDrpFl1/j7w3c 1Gh3RdiyYGnn4NOCjNob78ETOPy5qOfJ8i5ZZ/GSpUJmR7DaUZVwQb1jYTKl1vEFOZw== 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=ijz0WPkt; 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 DA30F606A32A; Wed, 2 Dec 2026 16:57:39 +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=ijz0WPkt Received: by smtp.kernel.org (Postfix) with ESMTPSA id C86691F000C1; Wed, 2 Dec 2026 16:57:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796230659; bh=Y+sQgV/wuLl5uRWieX8FXOeU49++3DMQE3wG9MMqIN0=; h=From:To:Cc:Subject:Date; b=ijz0WPktHBu751J3owxqF5R3cs4mfxfHESBqgbIvpL2Fe9UDNJijlayc2CufkvIj7 QEmW1p+/UArSUXBJm19cC9h6VdZcswnQDhODxVPUZj+X0Fp90c8skk6gijsualw0S2 dCvt7hQFMYeVEkWrZ0nVa5sVq1OCw0PY4oeUYo9+oCHUwCcHb1mcu5tOYatScEJTMq HxWpLoQDcZCdroWqFwnukPGBGHevbsxg/baWBq71bHyaobxmwAD9JIHKIL9oiPj7l/ 4RUSh3OE1LydgqdXE7VZwxYVWtGBEzSMb5ZXlk17xbJW0Pu8LMPPW+XOXz87DQ2SDu 7KOrkTdat8FmA== From: Andrey Albershteyn To: "fsdevel" , "linux-ext4" , "linux-btrfs" , "linux-f2fs" , "Eric Biggers" , "Christoph Hellwig" , "Carlos Maiolino" , "fsverity" , "linux-xfs" Cc: "Christian Brauner" , Andrey Albershteyn , david@fromorbit.com Subject: [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree Date: Wed, 2 Dec 2026 17:56:30 +0100 Message-ID: <20261202165653.767961-1-aalbersh@kernel.org> X-Mailer: git-send-email 2.54.0 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi all, This series add fsverity support to XFS. This series include more changes to the common code: - No-op'ing FS_VERITY_FL in FS_IOC_SETFLAGS ioctl() - Minor fix of setting S_APPEND on inode with fsverity - Runtime fsverity construction flag on inode The second part of the patchset is fsverity support for XFS. This revision includes a bit more improvements to the xfs scrub/repair. Testing of the common changes -g verity passes for all fs, except btrfs/277 and btrfs+generic/574. The btrfs/277 seems to fail due to difference between what kernel and userspace versions support (btrfs-progs v7.1 doesn't seem to support latest streams v3). The generic/574 on BTRFS fails only for 1024 block size no matter the change (fails on v7.3 too). I haven't checked why. Patches without review: [PATCH v20 04/23] fs,fsverity: reject S_APPEND on fsverity inodes [PATCH v20 05/23] iomap: use fsverity_is_building() to check for [PATCH v20 08/23] f2fs: use I_VERITY_BUILDING instead of private [PATCH v20 13/23] xfs: handle fsverity I/O in write/read path [PATCH v20 16/23] xfs: don't remove written extents past EOF on [PATCH v20 17/23] xfs: add fs-verity support [PATCH v20 21/23] xfs: check and repair the verity inode flag state This series based on v7.4-rc4 kernel: https://git.kernel.org/pub/scm/linux/kernel/git/aalbersh/xfs-linux.git/log/?h=fsverity xfsprogs: https://git.kernel.org/pub/scm/linux/kernel/git/aalbersh/xfsprogs-dev.git/log/?h=fsverity xfstests: https://git.kernel.org/pub/scm/linux/kernel/git/aalbersh/xfstests-dev.git/log/?h=fsverity v19: https://lore.kernel.org/fsverity/20261120155752.192025-1-aalbersh@kernel.org/T/#t v18: https://lore.kernel.org/fsverity/20261102144147.2393369-1-aalbersh@kernel.org/T/#t v17: https://lore.kernel.org/fsverity/20261002223705.2175542-1-aalbersh@kernel.org/T/#u v16: https://lore.kernel.org/fsverity/arJC542mXklAeswE@aalbersh-thinkpadx1carbongen13.rmtcz.csb/T/#t v15: https://lore.kernel.org/fsverity/20260817070240.GA17371@lst.de/T/#t To: ebiggers@kernel.org To: hch@lst.de To: Carlos Maiolino To: fsverity@lists.linux.dev To: linux-xfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: david@fromorbit.com --- Changes in v20: - Merge with common fsverity code changes patchset - Add a fix for S_APPEND - Comments and commit message updates - Convert WARN in writeback into strict check for folio position - In xfs scrub/repair zap fsverity metadata on fsverity flag removal - Treat EINVAL and EFBIG as reason to repair fsverity - xfs scrub/repair detect invalid fsverity flag combinations on inode - Refactor xfs_free_eofblocks() to not clear EOF tag on fsverity inode - Don't treat buf_size smaller than desc_size as a corruption - Add a corruption check for too small desc_size Changes in v19: - Add guard to forbid use on Zoned devices - Add a guard against using with LBS (compound pages no-go for fsverity) - move IOMAP_F_FSVERITY to xfs_bmbt_to_iomap() - Use I_VERITY_BUILDING instead of XFS inode flag - Add guard against DAX during fsverity enable - Change XFS_FSVERITY_LARGEST_FILE to macro for 32-bit kernel check - Forbid opening too large fsverity files on 32-bit kernels - xfs_free_eofblocks() doesn't depend on I_VERITY (disk flag instead) - Keep EOF cleanup tag on inode if fsverity build failed - Invalidate past EOF page cache in scrub on corrupted inodes - Remove past EOF extents in scrub on corrupted inodes Changes in v18: - Rebase to latest origin/for-next and drop core fsverity patches - Move truncate_inode_pages() before xfs_trans_alloc() - Move xfs_fsverity_metadata_offset() to libxfs as used in xfs_bmap.c Changes in v17: - Add mempool for fsverity ioends cache - Add xfs_fsverity_reset_inode() as a common clean up function - Changed ILOCK_SHARED to ILOCK_EXCL for xfs_bmap_last_extent() - Swap order of truncate_inode_pages() and ilock() due to ABBA - Add xfs_fsverity_is_hashes_of_zeroed_blocks() helper - Removed EINVAL and EFBIG from scrub as ambiguous Changes in v16: - Rebase to block/for-next - Removed work_struct from ioend in favor of kmem_cache structs - Minor adjustments from v15 review - Skip written extents in lower level of __xfs_bunmapi() Changes in v15: - Pull BIO in task context patches - Drop flag argument in xfs_free_eofblocks() - Call xfs_free_eofblocks() on fsverity inodes - Comments and commit messages updates - Rebased to v7.2-rc7 - Dropped patch for fsverity_fill_zerohash() with highmem optimization Changes in v14: - Rebase to lazy-bounce@hch-misc - Adjust read ioends to BIO in task context flow - MMAPLOCK/sb_internal deadlock fix reported by sashiko - Add missing delalloc clean up in verity_end_enable - Use xfs_free_eofblocks() instead of writing own clean up routine - Modify xfs_free_eofblocks() to be able to clean unwritten only - Dropped fix patch for truncate/set_size check - Various minor code and #include rearrangements for bisecting Changes in v13: - Hoisted statx reporting to common code - Added read ioend sorted for worker self-deadlock fix - Adjusted fsverity flags in zoned write path Changes in v12: - Refactored xfs_fsverity_cancel_unwritten() - Switched to using inode_set_flags() - Add a lock for COW fork reading - Add pagecache truncation in cleanup path - Added ERANGE and EBADMSG to fsverity scrub handling - Add missing XFS_FSVERITY_CONSTRUCTION in various xfs_iomap - Rebase to -rc3 Changes in v11: - Drop wrong overlayfs patch - Drop already merged iomap and fsverity patches - Update to I_INO() use instead of ip->i_ino - Sashiko.dev fixes. See list of issues below. Changes in v10: - Rebase to v7.1-rc3 with relevant adjustments - Initialize ioend->io_vi to NULL to not get write work onto verity wq - Range diff below Changes in v9: - Fix fsverity_fill_zerohash() parameter names - A few fixes found by sashiko.dev: - Replace ip->i_mount->m_attr_geo->blksize with m_sb.sb_blocksize - Don't call xfs_trans_cancel() after xfs_trans_commit() in xfs_fsverity_end_enable() - Call xfs_fsverity_delete_metadata() if verity enable failed - Change start/end type from xfs_fileoff_t to loff_t - Return xfs_trans_commit() error from xfs_fsverity_cancel_unwritten() Changes in v8: - Return fsverity_ensure_verity_info() errors from ovl_ensure_verity_loaded() Changes in v7: - Move kerneldoc to fsverity_ensure_verity_info() definition - Drop patch adding XFS traces - Fix overly long line in the comment - Make order of fserror and fsverity_error consistent - Add overlay patch converting to fsverity_ensure_verity_info() Changes in v6: - Removed stub for fsverity_ensure_verity_info() as it's optimized out - Rename fsverity_folio_zero_hash() to fsverify_fill_zerohash() - Merge patches 8 to 10 into one - Merge patch gerating zero_hash and fsverity_fill_zerohash() into one - Add kerneldoc to fsverity_ensure_verity_info() - Add comments to iomap_block_needs_zeroing() Changes in v5: - Add fserror_report_data_lost() for data blocks in page spanning EOF - Issue fsverity metadata readahead in data readahead - iomap_fsverity_write() return type fix - Use of S_ISREG(mode) - Make 65536 #define instead of open-coded - Use transaction per unwritten extent removal - Fetch fsverity_info for all fsverity metadata - Revert fsverity_folio_zero_hash() stub as used in iomap - Extend cancel_unwritten to whole file range to remove cow leftovers - Drop delayed allocation on the COW fork on fsverity completion Changes in v4: - Use fserror interface in fsverity instead of fs callback - Hoist pagecache_read from f2fs/ext4 to fsverity - Refactor iomap code - Fetch fsverity_info only for file data and merkle tree holes - Do not disable preallocation, remove unwritten extents instead - Offload fsverity hash I/O to fsverity workqueue in read path - Store merkle tree at round_up(i_size, 64k) - Add a spacing between merkle tree and fsverity descriptor as next 64k aligned block - Squash helpers into first user commits - Squash on-disk format changes into single commit - Drop different offset for pagecache/on-disk - Don't zero out pages in higher order folios in write path - Link to v3: https://lore.kernel.org/fsverity/20260217231937.1183679-1-aalbersh@kernel.org/T/#t Changes in v3: - Different on-disk and pagecache offset - Use read path ioends - Switch to hashtable fsverity info - Synthesize merkle tree blocks full of zeroes - Other minor refactors - Link to v2: https://lore.kernel.org/fsverity/20260114164210.GO15583@frogsfrogsfrogs/T/#t Changes in v2: - Move to VFS interface for merkle tree block reading - Drop patchset for per filesystem workqueues - Change how offsets of the descriptor and tree metadata is calculated - Store fs-verity descriptor in data fork side by side with merkle tree - Simplify iomap changes, remove interface for post eof read/write - Get rid of extended attribute implementation - Link to v1: https://lore.kernel.org/r/20250728-fsverity-v1-0-9e5443af0e34@kernel.org Andrey Albershteyn (21): fs: constify inode argument of inode_state_read_once() fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS fs,fsverity: add I_VERITY_BUILDING inode state flag fs,fsverity: reject S_APPEND on fsverity inodes iomap: use fsverity_is_building() to check for fsverity IO btrfs: use I_VERITY_BUILDING instead of private flags ext4: use I_VERITY_BUILDING instead of private flags f2fs: use I_VERITY_BUILDING instead of private flags xfs: introduce fsverity on-disk changes xfs: don't allow to enable DAX on fs-verity sealed inode xfs: disable direct read path for fs-verity files xfs: don't report dio_mem_align and dio_offset_align for fsverity files xfs: handle fsverity I/O in write/read path xfs: use read ioend for fsverity data verification xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() xfs: don't remove written extents past EOF on fsverity inodes xfs: add fs-verity support xfs: initialize fs-verity on file open xfs: add fs-verity ioctls xfs: introduce health state for corrupted fsverity metadata xfs: enable ro-compat fs-verity flag Darrick J. Wong (2): xfs: advertise fs-verity being available on filesystem xfs: check and repair the verity inode flag state fs/btrfs/btrfs_inode.h | 7 - fs/btrfs/verity.c | 12 +- fs/ext4/ext4.h | 7 - fs/ext4/file.c | 2 +- fs/ext4/inode.c | 17 +- fs/ext4/ioctl.c | 3 +- fs/ext4/verity.c | 19 +- fs/f2fs/data.c | 10 +- fs/f2fs/f2fs.h | 7 - fs/f2fs/verity.c | 12 +- fs/file_attr.c | 23 ++ fs/iomap/buffered-io.c | 11 +- fs/verity/enable.c | 30 +- fs/xfs/Makefile | 2 + fs/xfs/libxfs/xfs_bmap.c | 26 +- fs/xfs/libxfs/xfs_bmap.h | 6 +- fs/xfs/libxfs/xfs_format.h | 31 +- fs/xfs/libxfs/xfs_fs.h | 2 + fs/xfs/libxfs/xfs_health.h | 4 +- fs/xfs/libxfs/xfs_inode_buf.c | 27 ++ fs/xfs/libxfs/xfs_inode_util.c | 5 +- fs/xfs/libxfs/xfs_sb.c | 4 + fs/xfs/libxfs/xfs_verity.c | 20 ++ fs/xfs/libxfs/xfs_verity.h | 13 + fs/xfs/scrub/common.c | 59 ++++ fs/xfs/scrub/common.h | 2 + fs/xfs/scrub/inode.c | 40 +++ fs/xfs/scrub/inode_repair.c | 121 +++++++- fs/xfs/xfs_aops.c | 19 +- fs/xfs/xfs_bmap_util.c | 44 ++- fs/xfs/xfs_file.c | 71 +++-- fs/xfs/xfs_fsverity.c | 513 +++++++++++++++++++++++++++++++ fs/xfs/xfs_fsverity.h | 42 +++ fs/xfs/xfs_health.c | 1 + fs/xfs/xfs_icache.c | 11 +- fs/xfs/xfs_ioctl.c | 33 ++ fs/xfs/xfs_ioend.c | 53 +++- fs/xfs/xfs_ioend.h | 4 +- fs/xfs/xfs_iomap.c | 61 +++- fs/xfs/xfs_iomap.h | 5 +- fs/xfs/xfs_iops.c | 20 +- fs/xfs/xfs_message.c | 4 + fs/xfs/xfs_message.h | 1 + fs/xfs/xfs_mount.h | 4 + fs/xfs/xfs_pnfs.c | 2 +- fs/xfs/xfs_super.c | 31 +- include/linux/fs.h | 9 +- include/linux/fsverity.h | 29 +- include/trace/events/writeback.h | 3 +- 49 files changed, 1320 insertions(+), 162 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_verity.c create mode 100644 fs/xfs/libxfs/xfs_verity.h create mode 100644 fs/xfs/xfs_fsverity.c create mode 100644 fs/xfs/xfs_fsverity.h Range-diff against v19: -: ------------ > 1: a0f90a3dc2e4 fs: constify inode argument of inode_state_read_once() 1: e26f4b6bcb69 ! 2: 30209262280a fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS @@ Commit message however, BTRFS returns -EOPNOTSUPP. So, the modification of other flags doesn't work on BTRFS for fsverity inodes. - Fix it for BTRFS and anyone else, the ext4 and f2fs masking becomes - no-op. The file_get/setattr() path is fine here as this flag is cleared - right before fileattr_set_prepare(). The future fsverity support in XFS - would also need it. + Make FS_VERITY_FL be silently ignored if it's attempted to be set on a + file that didn't have it before. This fixes get-modify-set loop for + BTRFS and anyone else, the ext4 and f2fs masking becomes no-op. The + file_get/setattr() path is fine here as this flag is cleared right + before fileattr_set_prepare(). The future fsverity support in XFS would + also need it. Cc: Boris Burkov Cc: David Sterba 2: 8286293f4f2c ! 3: 899e1c8a85a6 fs,fsverity: add I_VERITY_BUILDING inode state flag @@ Commit message flag meaning Merkle tree is currently being built *_VERITY_IN_PROGRESS. They all serve the same two purposes: reject a concurrent enable with -EBUSY and let the write paths recognize the special writes done while - the tree is under construction. + the tree is under construction. Except in BTRFS, which use only the + former. Hoist this flag into the VFS as a new inode state flag, I_VERITY_BUILDING, and manage its lifetime in the generic fs-verity @@ include/linux/fs.h: is_uncached_acl(struct posix_acl *acl) * + * I_VERITY_BUILDING fs-verity is being enabled on the inode: the Merkle + * tree is under construction. The file is effectively -+ * read-only to userspace; the only writes happening are -+ * for the fs-verity metadata. ++ * read-only to userspace. Most of the writes are merkle ++ * tree blocks but inode still can have data writeback ++ * in-flight. + * * Q: What is the difference between I_WILL_FREE and I_FREEING? * @@ include/linux/fsverity.h: struct fsverity_operations { * * i_rwsem is held for write. * -+ * I_VERITY_BUILDING is set on the inode for the duration of enabling. +@@ include/linux/fsverity.h: struct fsverity_operations { + * i_rwsem is held for write, but it may have been dropped between + * ->begin_enable_verity() and ->end_enable_verity(). + * ++ * I_VERITY_BUILDING flag is set for the duration of the enablement. The ++ * flag is set right after ->begin_enable_verity() is done and cleared ++ * after ->end_enable_verity(). + * * Return: 0 on success, -errno on failure */ - int (*begin_enable_verity)(struct file *filp); + int (*end_enable_verity)(struct file *filp, const void *desc, @@ include/linux/fsverity.h: static inline bool fsverity_active(const struct inode *inode) return false; } @@ include/linux/fsverity.h: static inline bool fsverity_active(const struct inode + * + * This checks whether the inode's Merkle tree is currently being built. + * While this is the case the file is read-only to userspace and the only writes -+ * allowed are for the fs-verity metadata. This becomes false when fsverity -+ * metadata is fully created and written to disk or building failed. ++ * allowed are for the fs-verity metadata, although, inode can still have ++ * in-flight data writeback. This becomes false when fsverity metadata is fully ++ * created and written to disk or building failed. + * + * Return: true if fs-verity is being enabled on the inode + */ 7: 28c72f9b678d ! 4: 3871964438a6 fs-verity support for XFS with post EOF merkle tree @@ Metadata Author: Andrey Albershteyn ## Commit message ## - fs-verity support for XFS with post EOF merkle tree - - Hi all, - - This is next revision of fsverity for XFS. Changes: - - Add guard to forbid use on Zoned devices - - Add a guard against using with LBS (compound pages no-go for fsverity) - - move IOMAP_F_FSVERITY to xfs_bmbt_to_iomap() - - Use I_VERITY_BUILDING instead of XFS inode flag - - Add guard against DAX during fsverity enable - - Change XFS_FSVERITY_LARGEST_FILE to macro for 32-bit kernel check - - Forbid opening too large fsverity files on 32-bit kernels - - xfs_free_eofblocks() doesn't depend on I_VERITY (disk flag instead) - - Keep EOF cleanup tag on inode if fsverity build failed - - Invalidate past EOF page cache in scrub on corrupted inodes - - Remove past EOF extents in scrub on corrupted inodes - - Patches without review: - [PATCH v19 05/15] xfs: handle fsverity I/O in write/read path - [PATCH v19 09/15] xfs: add fs-verity support - [PATCH v19 13/15] xfs: check and repair the verity inode flag state - - The RO_COMPAT with CONFIG_FS_VERITY=n should be fine as fsverity inode - won't open (this is same for all fs). - - This series based on v7.4-rc3 and my series adding I_VERITY_BUILDING [1] - - 1: https://lore.kernel.org/linux-xfs/20261120155032.187246-1-aalbersh@kernel.org - - kernel: - https://git.kernel.org/pub/scm/linux/kernel/git/aalbersh/xfs-linux.git/log/?h=fsverity - - xfsprogs: - https://git.kernel.org/pub/scm/linux/kernel/git/aalbersh/xfsprogs-dev.git/log/?h=fsverity - - xfstests: - https://git.kernel.org/pub/scm/linux/kernel/git/aalbersh/xfstests-dev.git/log/?h=fsverity - - v18: - https://lore.kernel.org/fsverity/20261102144147.2393369-1-aalbersh@kernel.org/T/#t - - v17: - https://lore.kernel.org/fsverity/20261002223705.2175542-1-aalbersh@kernel.org/T/#u - - v16: - https://lore.kernel.org/fsverity/arJC542mXklAeswE@aalbersh-thinkpadx1carbongen13.rmtcz.csb/T/#t - - v15: - https://lore.kernel.org/fsverity/20260817070240.GA17371@lst.de/T/#t - - To: ebiggers@kernel.org - To: hch@lst.de - To: Carlos Maiolino - To: fsverity@lists.linux.dev - To: linux-xfs@vger.kernel.org - - Cc: linux-fsdevel@vger.kernel.org - Cc: david@fromorbit.com - - --- - Changes in v19: - - Add guard to forbid use on Zoned devices - - Add a guard against using with LBS (compound pages no-go for fsverity) - - move IOMAP_F_FSVERITY to xfs_bmbt_to_iomap() - - Use I_VERITY_BUILDING instead of XFS inode flag - - Add guard against DAX during fsverity enable - - Change XFS_FSVERITY_LARGEST_FILE to macro for 32-bit kernel check - - Forbid opening too large fsverity files on 32-bit kernels - - xfs_free_eofblocks() doesn't depend on I_VERITY (disk flag instead) - - Keep EOF cleanup tag on inode if fsverity build failed - - Invalidate past EOF page cache in scrub on corrupted inodes - - Remove past EOF extents in scrub on corrupted inodes - Changes in v18: - - Rebase to latest origin/for-next and drop core fsverity patches - - Move truncate_inode_pages() before xfs_trans_alloc() - - Move xfs_fsverity_metadata_offset() to libxfs as used in xfs_bmap.c - Changes in v17: - - Add mempool for fsverity ioends cache - - Add xfs_fsverity_reset_inode() as a common clean up function - - Changed ILOCK_SHARED to ILOCK_EXCL for xfs_bmap_last_extent() - - Swap order of truncate_inode_pages() and ilock() due to ABBA - - Add xfs_fsverity_is_hashes_of_zeroed_blocks() helper - - Removed EINVAL and EFBIG from scrub as ambiguous - Changes in v16: - - Rebase to block/for-next - - Removed work_struct from ioend in favor of kmem_cache structs - - Minor adjustments from v15 review - - Skip written extents in lower level of __xfs_bunmapi() - Changes in v15: - - Pull BIO in task context patches - - Drop flag argument in xfs_free_eofblocks() - - Call xfs_free_eofblocks() on fsverity inodes - - Comments and commit messages updates - - Rebased to v7.2-rc7 - - Dropped patch for fsverity_fill_zerohash() with highmem optimization - Changes in v14: - - Rebase to lazy-bounce@hch-misc - - Adjust read ioends to BIO in task context flow - - MMAPLOCK/sb_internal deadlock fix reported by sashiko - - Add missing delalloc clean up in verity_end_enable - - Use xfs_free_eofblocks() instead of writing own clean up routine - - Modify xfs_free_eofblocks() to be able to clean unwritten only - - Dropped fix patch for truncate/set_size check - - Various minor code and #include rearrangements for bisecting - Changes in v13: - - Hoisted statx reporting to common code - - Added read ioend sorted for worker self-deadlock fix - - Adjusted fsverity flags in zoned write path - Changes in v12: - - Refactored xfs_fsverity_cancel_unwritten() - - Switched to using inode_set_flags() - - Add a lock for COW fork reading - - Add pagecache truncation in cleanup path - - Added ERANGE and EBADMSG to fsverity scrub handling - - Add missing XFS_FSVERITY_CONSTRUCTION in various xfs_iomap - - Rebase to -rc3 - Changes in v11: - - Drop wrong overlayfs patch - - Drop already merged iomap and fsverity patches - - Update to I_INO() use instead of ip->i_ino - - Sashiko.dev fixes. See list of issues below. - Changes in v10: - - Rebase to v7.1-rc3 with relevant adjustments - - Initialize ioend->io_vi to NULL to not get write work onto verity wq - - Range diff below - Changes in v9: - - Fix fsverity_fill_zerohash() parameter names - - A few fixes found by sashiko.dev: - - Replace ip->i_mount->m_attr_geo->blksize with m_sb.sb_blocksize - - Don't call xfs_trans_cancel() after xfs_trans_commit() in - xfs_fsverity_end_enable() - - Call xfs_fsverity_delete_metadata() if verity enable failed - - Change start/end type from xfs_fileoff_t to loff_t - - Return xfs_trans_commit() error from - xfs_fsverity_cancel_unwritten() - Changes in v8: - - Return fsverity_ensure_verity_info() errors from - ovl_ensure_verity_loaded() - Changes in v7: - - Move kerneldoc to fsverity_ensure_verity_info() definition - - Drop patch adding XFS traces - - Fix overly long line in the comment - - Make order of fserror and fsverity_error consistent - - Add overlay patch converting to fsverity_ensure_verity_info() - Changes in v6: - - Removed stub for fsverity_ensure_verity_info() as it's optimized out - - Rename fsverity_folio_zero_hash() to fsverify_fill_zerohash() - - Merge patches 8 to 10 into one - - Merge patch gerating zero_hash and fsverity_fill_zerohash() into one - - Add kerneldoc to fsverity_ensure_verity_info() - - Add comments to iomap_block_needs_zeroing() - Changes in v5: - - Add fserror_report_data_lost() for data blocks in page spanning EOF - - Issue fsverity metadata readahead in data readahead - - iomap_fsverity_write() return type fix - - Use of S_ISREG(mode) - - Make 65536 #define instead of open-coded - - Use transaction per unwritten extent removal - - Fetch fsverity_info for all fsverity metadata - - Revert fsverity_folio_zero_hash() stub as used in iomap - - Extend cancel_unwritten to whole file range to remove cow leftovers - - Drop delayed allocation on the COW fork on fsverity completion - Changes in v4: - - Use fserror interface in fsverity instead of fs callback - - Hoist pagecache_read from f2fs/ext4 to fsverity - - Refactor iomap code - - Fetch fsverity_info only for file data and merkle tree holes - - Do not disable preallocation, remove unwritten extents instead - - Offload fsverity hash I/O to fsverity workqueue in read path - - Store merkle tree at round_up(i_size, 64k) - - Add a spacing between merkle tree and fsverity descriptor as next 64k - aligned block - - Squash helpers into first user commits - - Squash on-disk format changes into single commit - - Drop different offset for pagecache/on-disk - - Don't zero out pages in higher order folios in write path - - Link to v3: https://lore.kernel.org/fsverity/20260217231937.1183679-1-aalbersh@kernel.org/T/#t - Changes in v3: - - Different on-disk and pagecache offset - - Use read path ioends - - Switch to hashtable fsverity info - - Synthesize merkle tree blocks full of zeroes - - Other minor refactors - - Link to v2: https://lore.kernel.org/fsverity/20260114164210.GO15583@frogsfrogsfrogs/T/#t - Changes in v2: - - Move to VFS interface for merkle tree block reading - - Drop patchset for per filesystem workqueues - - Change how offsets of the descriptor and tree metadata is calculated - - Store fs-verity descriptor in data fork side by side with merkle tree - - Simplify iomap changes, remove interface for post eof read/write - - Get rid of extended attribute implementation - - Link to v1: https://lore.kernel.org/r/20250728-fsverity-v1-0-9e5443af0e34@kernel.org + fs,fsverity: reject S_APPEND on fsverity inodes + + fs-verity rejects enabling fsverity on append only files. However, there + are two cases when FS_IOC_SETFLAGS can turn inode append only. + + The first one is right before the lock is taken in the enable_verity(), + making original check useless. + + The second one is after lock in enable_verity() is unlocked, therefore, + when merkle tree is being build and after fs-verity inode is sealed. + This one is not critical, it just sets incompatible flags on inode but + append-only inode will not get any writes anyway. + + Fix it by checking S_APPEND again under the lock, serializing this with + vfs_fileattr_set() and reject S_APPEND on fsverity inodes. + + Fixes: 3fda4c617e84 ("fs-verity: implement FS_IOC_ENABLE_VERITY ioctl") + Signed-off-by: Andrey Albershteyn + + ## fs/file_attr.c ## +@@ + #include + #include + #include ++#include + #include + #include + #include +@@ fs/file_attr.c: static int fileattr_set_prepare(struct inode *inode, + fa->flags &= ~FS_VERITY_FL; + fa->fsx_xflags &= ~FS_XFLAG_VERITY; + ++ /* ++ * FS_APPEND_FL is incompatible with fs-verity. FS_IOC_ENABLE_VERITY ++ * rejects append-only files, also reject turning a verity file ++ * append-only. ++ * ++ * Reject in both cases, after it has been sealed and while its Merkle ++ * tree is being built. ++ */ ++ if ((fa->flags & FS_APPEND_FL) && ++ ((old_ma->flags & FS_VERITY_FL) || fsverity_is_building(inode))) ++ return -EPERM; ++ + /* + * Project Quota ID state is only allowed to change from within the init + * namespace. Enforce that restriction only if we are trying to change + + ## fs/verity/enable.c ## +@@ fs/verity/enable.c: static int enable_verity(struct file *filp, + err = -EEXIST; + } else if (fsverity_is_building(inode)) { + err = -EBUSY; ++ } else if (IS_APPEND(inode)) { ++ /* ++ * The check in fsverity_ioctl_enable() is done without the ++ * inode lock, so a concurrent FS_IOC_SETFLAGS could have set ++ * S_APPEND in the meantime. Recheck it here, serialized with ++ * ->fileattr_set(). ++ */ ++ err = -EPERM; + } else { + err = vops->begin_enable_verity(filp); + if (!err) { 3: 522b11667d13 ! 5: b3e905834f43 iomap: use fsverity_is_building() to check for fsverity IO @@ Commit message Recently, inode gained new I_VERITY_BUILDING flag. This flag indicates that inode is undergoing fsverity metadata construction. Previously, it was indicated by stale iomap flag on the IO, now we can check the inode - instead. As fsverity inodes are read-only, the only write IO happening - during I_VERITY_BUILDING is fsverity metadata. + instead. Signed-off-by: Andrey Albershteyn ## fs/iomap/buffered-io.c ## -@@ fs/iomap/buffered-io.c: static bool iomap_writeback_handle_eof(struct folio *folio, - struct inode *inode = wpc->inode; +@@ fs/iomap/buffered-io.c: static int iomap_writeback_range(struct iomap_writepage_ctx *wpc, + * i_size, adjust end_pos and zero all data beyond i_size. Don't skip fsverity + * folios as those are beyond i_size. + */ +-static bool iomap_writeback_handle_eof(struct folio *folio, +- struct iomap_writepage_ctx *wpc, u64 *end_pos) ++static bool iomap_writeback_handle_eof(struct folio *folio, struct inode *inode, ++ u64 *end_pos) + { +- struct inode *inode = wpc->inode; u64 isize = i_size_read(inode); - if (wpc->iomap.flags & IOMAP_F_FSVERITY) { -+ if (fsverity_is_building(inode)) { - WARN_ON_ONCE(folio_pos(folio) < isize); +- WARN_ON_ONCE(folio_pos(folio) < isize); ++ if (fsverity_is_building(inode) && folio_pos(folio) >= isize) return true; - } +- } + + if (*end_pos > isize) { + size_t poff = offset_in_folio(folio, isize); +@@ fs/iomap/buffered-io.c: int iomap_writeback_folio(struct iomap_writepage_ctx *wpc, struct folio *folio) + + trace_iomap_writeback_folio(inode, pos, folio_size(folio)); + +- if (!iomap_writeback_handle_eof(folio, wpc, &end_pos)) ++ if (!iomap_writeback_handle_eof(folio, inode, &end_pos)) + return 0; + WARN_ON_ONCE(end_pos <= pos); + 4: 0145d2d05fb0 = 6: f1b9fd251602 btrfs: use I_VERITY_BUILDING instead of private flags 5: 77fce535e46e = 7: 79eed12171a8 ext4: use I_VERITY_BUILDING instead of private flags 6: 084d6adc7d1c ! 8: 65a9eea27c75 f2fs: use I_VERITY_BUILDING instead of private flags @@ Commit message duplicated this state. Replace f2fs own helper f2fs_verity_in_progress() with - fsverity_is_building(), and remove the and FI_VERITY_IN_PROGRESS flags. + fsverity_is_building(), and remove the FI_VERITY_IN_PROGRESS flag. It's fine to remove IS_ENABLED() guard as fsverity_is_building() has stub. 8: ca9aa48fa04b = 9: a14c4c3e59f2 xfs: introduce fsverity on-disk changes 9: a019dc4ec4b8 = 10: 8c105dee8aae xfs: don't allow to enable DAX on fs-verity sealed inode 10: b8f1466cf632 = 11: d015dbb96f4c xfs: disable direct read path for fs-verity files 11: d7810bcef90a = 12: d88b9f4e83c5 xfs: don't report dio_mem_align and dio_offset_align for fsverity files 12: 30fa010febff ! 13: ad90aa77fc54 xfs: handle fsverity I/O in write/read path @@ Metadata ## Commit message ## xfs: handle fsverity I/O in write/read path - For write/writeback set IOMAP_F_FSVERITY flag telling iomap to not - update inode size and to not skip folios beyond EOF. + For write path set IOMAP_F_FSVERITY flag telling iomap to not update + inode size and to not skip folios beyond EOF. - Initiate fsverity writeback with IOMAP_F_FSVERITY set to tell iomap - should not skip folio that is dirty beyond EOF. - - In read path let iomap know that we are reading fsverity metadata. So, + For read path let iomap know that we are reading fsverity metadata. So, treat holes in the tree as request to synthesize tree blocks and hole after descriptor as end of the fsverity region. 13: fe7a17bb65c6 ! 14: 3f2349fca7a8 xfs: use read ioend for fsverity data verification @@ fs/xfs/xfs_super.c: init_xfs_fs(void) xfs_destroy_caches(); out: @@ fs/xfs/xfs_super.c: exit_xfs_fs(void) - xfs_cleanup_procfs(); + free_percpu(xfsstats.xs_stats); xfs_mru_cache_uninit(); xfs_destroy_workqueues(); + xfs_fsverity_exit(); 14: c428bb5ceba4 ! 15: 550e52c75b98 xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() @@ Commit message Signed-off-by: Andrey Albershteyn Reviewed-by: "Darrick J. Wong" + Reviewed-by: Christoph Hellwig ## fs/xfs/libxfs/xfs_bmap.c ## @@ fs/xfs/libxfs/xfs_bmap.c: __xfs_bunmapi( 15: f62ffd5f8991 ! 16: f7787e59edb3 xfs: don't remove written extents past EOF on fsverity inodes @@ Commit message takes place. Signed-off-by: Andrey Albershteyn - Reviewed-by: "Darrick J. Wong" ## fs/xfs/xfs_bmap_util.c ## @@ @@ fs/xfs/xfs_bmap_util.c: xfs_free_eofblocks( struct xfs_mount *mp = ip->i_mount; int error; + int bmapi_flags = XFS_BMAPI_NODISCARD; -+ bool verity = fsverity_is_building(VFS_I(ip)); ++ xfs_off_t aligned_size; /* Attach the dquots to the inode up front. */ error = xfs_qm_dqattach(ip); @@ fs/xfs/xfs_bmap_util.c: xfs_free_eofblocks( + inode_dio_wait(VFS_I(ip)); + + /* +- * For preallocated files only free delayed allocations. ++ * On fs-verity inodes, while fs-verity builds metadata past EOF, it can ++ * leave delayed preallocations and unwritten extents. Clear delayed ++ * preallocation here and tell bmapi to remove unwritten extents. * - * Note that this means we also leave speculative preallocations in - * place for preallocated files. -+ * -+ * Clean up delalloc reservations for fsverity too as those won't be -+ * used +- * Note that this means we also leave speculative preallocations in +- * place for preallocated files. ++ * The xfs_free_eofblocks() is called by fs-verity when building is ++ * complete but fsverity_is_building() is still not cleared. */ - if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { -+ if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) || -+ verity) { - if (ip->i_delayed_blks) { +- if (ip->i_delayed_blks) { ++ aligned_size = round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize); ++ if (fsverity_is_building(VFS_I(ip))) { ++ if (ip->i_delayed_blks) xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, - round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), - LLONG_MAX, NULL); - } +- round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), +- LLONG_MAX, NULL); +- } ++ aligned_size, LLONG_MAX, NULL); ++ bmapi_flags |= XFS_BMAPI_UNWRITTEN; ++ } else if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { ++ /* ++ * For preallocated files only free delayed allocations. ++ * ++ * Note that this means we also leave speculative preallocations ++ * in place for preallocated files. ++ */ ++ if (ip->i_delayed_blks) ++ xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, ++ aligned_size, LLONG_MAX, NULL); xfs_inode_clear_eofblocks_tag(ip); -- return 0; -+ if (!verity) -+ return 0; + return 0; } - - error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); -@@ fs/xfs/xfs_bmap_util.c: xfs_free_eofblocks( - xfs_ilock(ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, 0); - -+ /* -+ * While fs-verity writes metadata after EOF, it can leave unwritten -+ * preallocations. Clear all that out. -+ */ -+ if (verity) -+ bmapi_flags |= XFS_BMAPI_UNWRITTEN; -+ - /* - * Do not update the on-disk file size. If we update the on-disk file - * size and then the system crashes before the contents of the file are @@ fs/xfs/xfs_bmap_util.c: xfs_free_eofblocks( * bug). */ 16: 5f6f04fde6e4 ! 17: 63971a4f3d09 xfs: add fs-verity support @@ Commit message region iomap doesn't call into fsverity to verify it against Merkle tree. For data, verification is done at ioend completion in a workqueue. - When fs-verity is enabled on an inode, the XFS_IVERITY_CONSTRUCTION - flag is set meaning that the Merkle tree is being build. The - initialization ends with storing of verity descriptor and setting - inode on-disk flag (XFS_DIFLAG2_VERITY). Lastly, the - XFS_IVERITY_CONSTRUCTION is dropped and I_VERITY is set on inode. + The metadata building starts with flushing pagecache and cleaning up any + residue extents past EOF. Over whole initialization period + I_VERITY_BUILDING indicates that merkle tree building is in progress. No + iolock is held over this period. After core fsverity code done with + building the tree, XFS stores verity descriptor, then flushes page cache + again, then pro-actively remove any delayed allocation and unwritten + extents past EOF and ends up with setting inode on-disk flag + (XFS_DIFLAG2_VERITY). The descriptor is stored in a new block aligned to 64k after the last Merkle tree block. The size of the descriptor is stored at the end of the last descriptor block (descriptor can be multiple blocks). - Pro-actively remove any unwritten extents as we use last extent to - locate descriptor. - Signed-off-by: Andrey Albershteyn ## fs/xfs/libxfs/xfs_inode_buf.c ## @@ fs/xfs/xfs_fsverity.c: xfs_fsverity_is_file_data( + if (!buf_size) + return desc_size; + -+ if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) ++ if (desc_size > buf_size) ++ return -ERANGE; ++ ++ if (XFS_IS_CORRUPT(mp, ++ desc_size < sizeof(struct fsverity_descriptor))) + return -ERANGE; + + desc_pos = round_down(desc_size_pos - desc_size, blocksize); @@ fs/xfs/xfs_fsverity.h bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset); ## fs/xfs/xfs_ioctl.c ## +@@ + + #include + #include ++#include + + /* Return 0 on success or positive error */ + int @@ fs/xfs/xfs_ioctl.c: xfs_ioctl_setattr_xflags( if (xfs_inode_has_filedata(ip)) return -EINVAL; @@ fs/xfs/xfs_ioctl.c: xfs_ioctl_setattr_xflags( + /* * If S_DAX is enabled on this file, we can only switch the - * device if both support fsdax. We can't update S_DAX because + * device if both support fsdax, and the zoned code does not. @@ fs/xfs/xfs_ioctl.c: xfs_ioctl_setattr_xflags( return -EINVAL; } @@ fs/xfs/xfs_super.c #include "xfs_ondisk.h" #include "xfs_rmap_item.h" #include "xfs_refcount_item.h" +@@ + #include "xfs_rtalloc.h" + #include "xfs_zone_alloc.h" + #include "xfs_healthmon.h" +-#include "xfs_fsverity.h" + #include "scrub/stats.h" + #include "scrub/rcbag_btree.h" + @@ fs/xfs/xfs_super.c: xfs_fs_fill_super( sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; #endif 17: 9206c4a644f1 = 18: 8bb18397606d xfs: initialize fs-verity on file open 18: 856483dbd534 ! 19: 595f010968d3 xfs: add fs-verity ioctls @@ Commit message Signed-off-by: Andrey Albershteyn ## fs/xfs/xfs_ioctl.c ## -@@ - - #include - #include -+#include - - /* Return 0 on success or positive error */ - int @@ fs/xfs/xfs_ioctl.c: xfs_file_ioctl( case XFS_IOC_VERIFY_MEDIA: return xfs_ioc_verify_media(filp, arg); 19: 31f7e8a2669e = 20: 2ab9a2b11d75 xfs: advertise fs-verity being available on filesystem 20: dfabd8df8c89 ! 21: 80d1aaf6e39c xfs: check and repair the verity inode flag state @@ Commit message Signed-off-by: Darrick J. Wong Signed-off-by: Andrey Albershteyn + ## fs/xfs/libxfs/xfs_inode_buf.c ## +@@ fs/xfs/libxfs/xfs_inode_buf.c: xfs_dinode_verify( + */ + if ((flags & XFS_DIFLAG_REALTIME) && mp->m_sb.sb_rextsize > 1) + return __this_address; ++ ++ /* ++ * fs-verity doesn't work on zoned filesystems, where all ++ * data writes are directed to the sequential zones of the ++ * realtime device. ++ */ ++ if (xfs_has_zoned(mp) && (flags & XFS_DIFLAG_REALTIME)) ++ return __this_address; + } + + if (xfs_has_zoned(mp) && + ## fs/xfs/scrub/common.c ## @@ #include "scrub/health.h" @@ fs/xfs/scrub/common.c: xchk_inode_count_blocks( + case 0: + /* fsverity is active */ + break; ++ case -EFBIG: ++ case -EINVAL: + case -ENODATA: + case -EMSGSIZE: + case -EFSCORRUPTED: @@ fs/xfs/scrub/common.c: xchk_inode_count_blocks( + /* + * 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: @@ fs/xfs/scrub/inode.c: xchk_prepare_iscrub( error = xchk_trans_alloc(sc, 0); if (error) return error; +@@ fs/xfs/scrub/inode.c: xchk_inode_flags2( + if ((flags2 & XFS_DIFLAG2_NREXT64) && !xfs_has_large_extent_counts(mp)) + goto bad; + ++ /* no verity iflag without the filesystem feature or on non-files */ ++ if ((flags2 & XFS_DIFLAG2_VERITY) && ++ (!xfs_has_verity(mp) || !S_ISREG(mode))) ++ goto bad; ++ ++ /* verity and DAX do not mix */ ++ if ((flags2 & XFS_DIFLAG2_VERITY) && (flags2 & XFS_DIFLAG2_DAX)) ++ goto bad; ++ ++ /* ++ * no verity iflag on realtime files that cannot support it, i.e. ++ * zoned files and files with a realtime allocation unit larger ++ * than a filesystem block ++ */ ++ if ((flags2 & XFS_DIFLAG2_VERITY) && (flags & XFS_DIFLAG_REALTIME) && ++ (xfs_has_zoned(mp) || mp->m_sb.sb_rextsize > 1)) ++ goto bad; ++ + return; + bad: + xchk_ino_set_corrupt(sc, ino); @@ fs/xfs/scrub/inode.c: xchk_inode( if (S_ISREG(VFS_I(sc->ip)->i_mode)) xchk_inode_check_reflink_iflag(sc, I_INO(sc->ip)); @@ fs/xfs/scrub/inode.c: xchk_inode( xchk_inode_xref(sc, I_INO(sc->ip), &di); ## fs/xfs/scrub/inode_repair.c ## +@@ fs/xfs/scrub/inode_repair.c: struct xrep_inode { + /* Must we remove all access from this file? */ + bool zap_acls; + ++ /* ++ * Did we have to clear the fsverity flag while repairing the ondisk ++ * inode? If so, free the orphaned Merkle tree after reloading the ++ * inode. ++ */ ++ bool zap_verity; ++ + /* Inode scanner to see if we can find the ftype from dirents */ + struct xchk_iscan ftype_iscan; + uint8_t alleged_ftype; +@@ fs/xfs/scrub/inode_repair.c: xrep_dinode_nlinks( + /* Fix any conflicting flags that the verifiers complain about. */ + STATIC void + xrep_dinode_flags( +- struct xfs_scrub *sc, +- struct xfs_dinode *dip, +- bool isrt) ++ struct xrep_inode *ri, ++ struct xfs_dinode *dip) + { ++ struct xfs_scrub *sc = ri->sc; + struct xfs_mount *mp = sc->mp; + uint64_t flags2 = be64_to_cpu(dip->di_flags2); + uint16_t flags = be16_to_cpu(dip->di_flags); + uint16_t mode = be16_to_cpu(dip->di_mode); ++ bool isrt = ri->rt_extents > 0; + + trace_xrep_dinode_flags(sc, dip); + @@ fs/xfs/scrub/inode_repair.c: 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; ++ } if (flags2 & XFS_DIFLAG2_METADATA) { xfs_failaddr_t fa; +@@ fs/xfs/scrub/inode_repair.c: xrep_dinode_core( + if (iget_error) + goto write; + xrep_dinode_nlinks(dip); +- xrep_dinode_flags(sc, dip, ri->rt_extents > 0); ++ xrep_dinode_flags(ri, dip); + xrep_dinode_size(ri, dip); + xrep_dinode_extsize_hints(sc, dip); + xrep_dinode_zap_forks(ri, dip); @@ fs/xfs/scrub/inode_repair.c: xrep_dinode_core( if (iget_error) return iget_error; @@ fs/xfs/scrub/inode_repair.c: xrep_dinode_core( + error = xchk_inode_setup_verity(sc); + if (error) + return error; ++ ++ /* ++ * 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; +@@ fs/xfs/scrub/inode_repair.c: 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; + } + + /* @@ fs/xfs/scrub/inode_repair.c: xrep_inode_reset_dquots( # define xrep_inode_reset_dquots(sc) (0) #endif +/* -+ * If this file is 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. ++ * 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_verity( ++xrep_inode_zap_verity( + struct xfs_scrub *sc) +{ + struct inode *inode = VFS_I(sc->ip); + struct xfs_mount *mp = sc->mp; + int error; + -+ if (!xchk_inode_verity_broken(sc->ip)) -+ return 0; -+ -+ /* -+ * The fsverity descriptor cannot be activated, so disable verity and -+ * free the Merkle tree, which XFS stores in beyond EOF. The stale -+ * Merkle tree page cache was already dropped during scrub setup. -+ */ + error = xfs_bunmapi_range(&sc->tp, sc->ip, 0, + XFS_B_TO_FSB(mp, XFS_ISIZE(sc->ip)), XFS_MAX_FILEOFF); + if (error) @@ fs/xfs/scrub/inode_repair.c: xrep_inode_reset_dquots( + xfs_trans_log_inode(sc->tp, sc->ip, XFS_ILOG_CORE); + return 0; +} ++ ++/* ++ * 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 21: 6e4fdcf643b6 ! 22: cb61498e6095 xfs: introduce health state for corrupted fsverity metadata @@ fs/xfs/xfs_fsverity.c: xfs_fsverity_get_descriptor( if (!buf_size) return desc_size; +@@ fs/xfs/xfs_fsverity.c: xfs_fsverity_get_descriptor( + return -ERANGE; -- if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) -+ if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) { + if (XFS_IS_CORRUPT(mp, +- desc_size < sizeof(struct fsverity_descriptor))) ++ desc_size < sizeof(struct fsverity_descriptor))) { + xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY); return -ERANGE; + } 22: 28c74513a1bf = 23: 53d1aafb63f3 xfs: enable ro-compat fs-verity flag -- 2.54.0