AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/11/03 04:02 flow patch-triage
8m Args:
null

Results:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_readahead_merkle_tree",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity"
  ],
  "KMSANReasoning": "The patch series introduces fs-verity support to XFS, hooking up XFS to fs-verity operations and the iomap subsystem with the IOMAP_F_FSVERITY flag. This change exposes significant uninitialized memory risks that can only be detected by KMSAN:\n\n1. Hole handling in post-EOF fs-verity metadata during descriptor lookup:\nIn `xfs_fsverity_get_descriptor()`, the descriptor location `desc_pos` is calculated as `round_down(desc_size_pos - desc_size, blocksize)`. Because fs-verity metadata is spaced out past EOF with `XFS_FSVERITY_START_ALIGN` (64KB alignment) and zero-digest blocks can be omitted, holes can exist between the Merkle tree and descriptor, or across corrupted/crafted metadata extents.\nWhen `fsverity_pagecache_read()` reads from `desc_pos`, `xfs_read_iomap_begin()` sets `IOMAP_F_FSVERITY`. In `iomap_read_folio_iter()`, if `(iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026 iomap-\u003etype == IOMAP_HOLE`:\n```c\nif (ctx-\u003evi)\n    fsverity_fill_zerohash(folio, poff, plen, ctx-\u003evi);\niomap_set_range_uptodate(folio, poff, plen);\n```\nDuring descriptor reading (`xfs_fsverity_get_descriptor()` called from `fsverity_ensure_verity_info()`), `ctx-\u003evi` is NULL because the `fsverity_info` structure has not yet been instantiated. Consequently, `fsverity_fill_zerohash()` is skipped, `folio_zero_range()` is bypassed, and the newly allocated folio is marked uptodate while still containing uninitialized memory.\n\n2. Branching on uninitialized memory and user info-leaks:\nThe uninitialized bytes from the folio are copied into the `desc` buffer (allocated with `kmalloc()` in `fsverity_get_descriptor()`). Immediately thereafter, `validate_fsverity_descriptor()` evaluates conditional branches depending directly on these uninitialized struct fields (`desc-\u003eversion`, `desc-\u003esalt_size`, `desc-\u003edata_size`). Furthermore, through `FS_IOC_READ_VERITY_METADATA` or descriptor reads, uninitialized buffer data can be leaked to userspace via `copy_to_user()`.\n\n3. KASAN vs KMSAN applicability:\nKASAN only monitors memory bounds and life cycle events (out-of-bounds accesses, use-after-free, double-free). Because all folio and descriptor buffer accesses remain within their legitimate allocation bounds, KASAN is blind to uninitialized memory being marked valid, copied, and evaluated in conditional logic. Only KMSAN tracks uninitialized shadow memory and catches uninitialized variable reads and kernel-to-user info-leaks.\n\nTherefore, running a dedicated KMSAN fuzzing session is justified.",
  "NeedsKMSAN": true,
  "Reasoning": "The patch adds fs-verity support to the XFS filesystem. It introduces filesystem-specific operations for fs-verity (enabling verity, writing and reading Merkle tree blocks, retrieving descriptors), iomap handling for post-EOF metadata, asynchronous read verification via dedicated workqueue ioend handling, and online scrub/repair support for fs-verity inodes. This is complex core filesystem code reachable via standard syscalls (ioctls, read/write, scrub) and warrants fuzzing.",
  "WorthFuzzing": true
}

1/1 2026/11/03 04:02 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 511718d13990c977011c96cea0d9e44818696ad2\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Nov 3 04:02:33 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/fs/xfs/Makefile b/fs/xfs/Makefile\nindex 399a207f2d0e71..9edb2850f09413 100644\n--- a/fs/xfs/Makefile\n+++ b/fs/xfs/Makefile\n@@ -59,6 +59,7 @@ xfs-y\t\t\t\t+= $(addprefix libxfs/, \\\n \t\t\t\t   xfs_trans_resv.o \\\n \t\t\t\t   xfs_trans_space.o \\\n \t\t\t\t   xfs_types.o \\\n+\t\t\t\t   xfs_verity.o \\\n \t\t\t\t   )\n # xfs_rtbitmap is shared with libxfs\n xfs-$(CONFIG_XFS_RT)\t\t+= $(addprefix libxfs/, \\\n@@ -150,6 +151,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL)\t+= xfs_acl.o\n xfs-$(CONFIG_SYSCTL)\t\t+= xfs_sysctl.o\n xfs-$(CONFIG_COMPAT)\t\t+= xfs_ioctl32.o\n xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)\t+= xfs_pnfs.o\n+xfs-$(CONFIG_FS_VERITY)\t\t+= xfs_fsverity.o\n \n # notify failure\n ifeq ($(CONFIG_MEMORY_FAILURE),y)\ndiff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c\nindex ca49bf4a50c5f2..706f2ead42f582 100644\n--- a/fs/xfs/libxfs/xfs_bmap.c\n+++ b/fs/xfs/libxfs/xfs_bmap.c\n@@ -41,6 +41,7 @@\n #include \"xfs_inode_util.h\"\n #include \"xfs_rtgroup.h\"\n #include \"xfs_zone_alloc.h\"\n+#include \"xfs_verity.h\"\n \n struct kmem_cache\t\t*xfs_bmap_intent_cache;\n \n@@ -4404,6 +4405,9 @@ xfs_bmapi_convert_one_delalloc(\n \t * the extent.  Just return the real extent at this offset.\n \t */\n \tif (!isnullstartblock(bma.got.br_startblock)) {\n+\t\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) \u0026\u0026\n+\t\t    offset \u003e= xfs_fsverity_metadata_offset(ip))\n+\t\t\tflags |= IOMAP_F_FSVERITY;\n \t\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, 0, flags,\n \t\t\t\txfs_iomap_inode_sequence(ip, flags));\n \t\tif (seq)\n@@ -4451,6 +4455,10 @@ xfs_bmapi_convert_one_delalloc(\n \tXFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));\n \tXFS_STATS_INC(mp, xs_xstrat_quick);\n \n+\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) \u0026\u0026\n+\t    offset \u003e= xfs_fsverity_metadata_offset(ip))\n+\t\tflags |= IOMAP_F_FSVERITY;\n+\n \tASSERT(!isnullstartblock(bma.got.br_startblock));\n \txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, 0, flags,\n \t\t\t\txfs_iomap_inode_sequence(ip, flags));\n@@ -5271,6 +5279,10 @@ __xfs_bunmapi(\n \t\tif (del.br_startoff + del.br_blockcount \u003e end + 1)\n \t\t\tdel.br_blockcount = end + 1 - del.br_startoff;\n \n+\t\tif ((flags \u0026 XFS_BMAPI_UNWRITTEN) \u0026\u0026\n+\t\t    del.br_state != XFS_EXT_UNWRITTEN)\n+\t\t\tgoto skip;\n+\n \t\tif (!isrt || (flags \u0026 XFS_BMAPI_REMAP))\n \t\t\tgoto delete;\n \n@@ -5405,7 +5417,7 @@ __xfs_bunmapi(\n \t\t\tif (error)\n \t\t\t\tgoto error0;\n \t\t}\n-\n+skip:\n \t\tend = del.br_startoff - 1;\n nodelete:\n \t\t/*\ndiff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h\nindex e9f5416e4c050d..25b24ff8e4de35 100644\n--- a/fs/xfs/libxfs/xfs_bmap.h\n+++ b/fs/xfs/libxfs/xfs_bmap.h\n@@ -90,6 +90,9 @@ struct xfs_bmalloca {\n /* Try to align allocations to the extent size hint */\n #define XFS_BMAPI_EXTSZALIGN\t(1u \u003c\u003c 11)\n \n+/* Process unwritten extents only. Used for unmapping */\n+#define XFS_BMAPI_UNWRITTEN\t(1u \u003c\u003c 12)\n+\n #define XFS_BMAPI_FLAGS \\\n \t{ XFS_BMAPI_ENTIRE,\t\"ENTIRE\" }, \\\n \t{ XFS_BMAPI_METADATA,\t\"METADATA\" }, \\\n@@ -102,7 +105,8 @@ struct xfs_bmalloca {\n \t{ XFS_BMAPI_COWFORK,\t\"COWFORK\" }, \\\n \t{ XFS_BMAPI_NODISCARD,\t\"NODISCARD\" }, \\\n \t{ XFS_BMAPI_NORMAP,\t\"NORMAP\" },\\\n-\t{ XFS_BMAPI_EXTSZALIGN,\t\"EXTSZALIGN\" }\n+\t{ XFS_BMAPI_EXTSZALIGN,\t\"EXTSZALIGN\" }, \\\n+\t{ XFS_BMAPI_UNWRITTEN,\t\"UNWRITTEN\" }\n \n \n static inline int xfs_bmapi_aflag(int w)\ndiff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h\nindex 469e879149ac21..6594fbe4f7f6a0 100644\n--- a/fs/xfs/libxfs/xfs_format.h\n+++ b/fs/xfs/libxfs/xfs_format.h\n@@ -374,11 +374,13 @@ xfs_sb_has_compat_feature(\n #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 \u003c\u003c 1)\t\t/* reverse map btree */\n #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 \u003c\u003c 2)\t\t/* reflinked files */\n #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 \u003c\u003c 3)\t\t/* inobt block counts */\n+#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 \u003c\u003c 4)\t\t/* fs-verity */\n #define XFS_SB_FEAT_RO_COMPAT_ALL \\\n \t\t(XFS_SB_FEAT_RO_COMPAT_FINOBT | \\\n \t\t XFS_SB_FEAT_RO_COMPAT_RMAPBT | \\\n-\t\t XFS_SB_FEAT_RO_COMPAT_REFLINK| \\\n-\t\t XFS_SB_FEAT_RO_COMPAT_INOBTCNT)\n+\t\t XFS_SB_FEAT_RO_COMPAT_REFLINK | \\\n+\t\t XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \\\n+\t\t XFS_SB_FEAT_RO_COMPAT_VERITY)\n #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN\t~XFS_SB_FEAT_RO_COMPAT_ALL\n static inline bool\n xfs_sb_has_ro_compat_feature(\n@@ -1234,16 +1236,21 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)\n  */\n #define XFS_DIFLAG2_METADATA_BIT\t5\n \n+/* inodes sealed with fs-verity */\n+#define XFS_DIFLAG2_VERITY_BIT\t\t6\n+\n #define XFS_DIFLAG2_DAX\t\t(1ULL \u003c\u003c XFS_DIFLAG2_DAX_BIT)\n #define XFS_DIFLAG2_REFLINK\t(1ULL \u003c\u003c XFS_DIFLAG2_REFLINK_BIT)\n #define XFS_DIFLAG2_COWEXTSIZE\t(1ULL \u003c\u003c XFS_DIFLAG2_COWEXTSIZE_BIT)\n #define XFS_DIFLAG2_BIGTIME\t(1ULL \u003c\u003c XFS_DIFLAG2_BIGTIME_BIT)\n #define XFS_DIFLAG2_NREXT64\t(1ULL \u003c\u003c XFS_DIFLAG2_NREXT64_BIT)\n #define XFS_DIFLAG2_METADATA\t(1ULL \u003c\u003c XFS_DIFLAG2_METADATA_BIT)\n+#define XFS_DIFLAG2_VERITY\t(1ULL \u003c\u003c XFS_DIFLAG2_VERITY_BIT)\n \n #define XFS_DIFLAG2_ANY \\\n \t(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \\\n-\t XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)\n+\t XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \\\n+\t XFS_DIFLAG2_VERITY)\n \n static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)\n {\n@@ -2031,4 +2038,26 @@ struct xfs_acl {\n #define SGI_ACL_FILE_SIZE\t(sizeof(SGI_ACL_FILE)-1)\n #define SGI_ACL_DEFAULT_SIZE\t(sizeof(SGI_ACL_DEFAULT)-1)\n \n+/*\n+ * At maximum of 8 levels with 128 hashes per block (32 bytes SHA-256) maximum\n+ * tree size is ((128^8 − 1)/(128 − 1)) = 567*10^12 blocks. This should fit in\n+ * 53 bits address space.\n+ *\n+ * At this Merkle tree size we can cover 295EB large file. This is much larger\n+ * than the currently supported file size.\n+ *\n+ * For sha512 the largest file we can cover ends at 1 \u003c\u003c 50 offset, this is also\n+ * good.\n+ */\n+#define XFS_FSVERITY_LARGEST_FILE\t((loff_t)1ULL \u003c\u003c 53)\n+\n+/*\n+ * Alignment of the fsverity metadata placement. This is largest supported PAGE\n+ * SIZE for fsverity. This is used to space out data and metadata in page cache.\n+ * The spacing is necessary for non-exposure of metadata to userspace and\n+ * correct merkle tree synthesis in the iomap.\n+ */\n+#define XFS_FSVERITY_START_ALIGN\t(65536)\n+\n+\n #endif /* __XFS_FORMAT_H__ */\ndiff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h\nindex 185f09f327c00c..84d62b7506a9ad 100644\n--- a/fs/xfs/libxfs/xfs_fs.h\n+++ b/fs/xfs/libxfs/xfs_fs.h\n@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {\n #define XFS_FSOP_GEOM_FLAGS_PARENT\t(1 \u003c\u003c 25) /* linux parent pointers */\n #define XFS_FSOP_GEOM_FLAGS_METADIR\t(1 \u003c\u003c 26) /* metadata directories */\n #define XFS_FSOP_GEOM_FLAGS_ZONED\t(1 \u003c\u003c 27) /* zoned rt device */\n+#define XFS_FSOP_GEOM_FLAGS_VERITY\t(1 \u003c\u003c 28) /* fs-verity */\n \n /*\n  * Minimum and maximum sizes need for growth checks.\n@@ -421,6 +422,7 @@ struct xfs_bulkstat {\n #define XFS_BS_SICK_SYMLINK\t(1 \u003c\u003c 6)  /* symbolic link remote target */\n #define XFS_BS_SICK_PARENT\t(1 \u003c\u003c 7)  /* parent pointers */\n #define XFS_BS_SICK_DIRTREE\t(1 \u003c\u003c 8)  /* directory tree structure */\n+#define XFS_BS_SICK_FSVERITY\t(1 \u003c\u003c 9)  /* fsverity metadata */\n \n /*\n  * Project quota id helpers (previously projid was 16bit only\ndiff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h\nindex 1d45cf5789e864..932b447190da76 100644\n--- a/fs/xfs/libxfs/xfs_health.h\n+++ b/fs/xfs/libxfs/xfs_health.h\n@@ -104,6 +104,7 @@ struct xfs_rtgroup;\n /* Don't propagate sick status to ag health summary during inactivation */\n #define XFS_SICK_INO_FORGET\t(1 \u003c\u003c 12)\n #define XFS_SICK_INO_DIRTREE\t(1 \u003c\u003c 13)  /* directory tree structure */\n+#define XFS_SICK_INO_FSVERITY\t(1 \u003c\u003c 14)  /* fsverity metadata */\n \n /* Primary evidence of health problems in a given group. */\n #define XFS_SICK_FS_PRIMARY\t(XFS_SICK_FS_COUNTERS | \\\n@@ -140,7 +141,8 @@ struct xfs_rtgroup;\n \t\t\t\t XFS_SICK_INO_XATTR | \\\n \t\t\t\t XFS_SICK_INO_SYMLINK | \\\n \t\t\t\t XFS_SICK_INO_PARENT | \\\n-\t\t\t\t XFS_SICK_INO_DIRTREE)\n+\t\t\t\t XFS_SICK_INO_DIRTREE | \\\n+\t\t\t\t XFS_SICK_INO_FSVERITY)\n \n #define XFS_SICK_INO_ZAPPED\t(XFS_SICK_INO_BMBTD_ZAPPED | \\\n \t\t\t\t XFS_SICK_INO_BMBTA_ZAPPED | \\\ndiff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c\nindex 8c9d296ebfe97f..13042e1eaf3519 100644\n--- a/fs/xfs/libxfs/xfs_inode_buf.c\n+++ b/fs/xfs/libxfs/xfs_inode_buf.c\n@@ -758,6 +758,14 @@ xfs_dinode_verify(\n \t    !xfs_has_rtreflink(mp))\n \t\treturn __this_address;\n \n+\t/* only regular files can have fsverity */\n+\tif (flags2 \u0026 XFS_DIFLAG2_VERITY) {\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn __this_address;\n+\t\tif (!S_ISREG(mode))\n+\t\t\treturn __this_address;\n+\t}\n+\n \tif (xfs_has_zoned(mp) \u0026\u0026\n \t    dip-\u003edi_metatype == cpu_to_be16(XFS_METAFILE_RTRMAP)) {\n \t\tif (be32_to_cpu(dip-\u003edi_used_blocks) \u003e mp-\u003em_sb.sb_rgextents)\ndiff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c\nindex f486b23a9b5230..a717b19558afab 100644\n--- a/fs/xfs/libxfs/xfs_inode_util.c\n+++ b/fs/xfs/libxfs/xfs_inode_util.c\n@@ -73,7 +73,8 @@ xfs_flags2diflags2(\n \tuint64_t\t\tdi_flags2 =\n \t\t(ip-\u003ei_diflags2 \u0026 (XFS_DIFLAG2_REFLINK |\n \t\t\t\t   XFS_DIFLAG2_BIGTIME |\n-\t\t\t\t   XFS_DIFLAG2_NREXT64));\n+\t\t\t\t   XFS_DIFLAG2_NREXT64 |\n+\t\t\t\t   XFS_DIFLAG2_VERITY));\n \n \tif (xflags \u0026 FS_XFLAG_DAX)\n \t\tdi_flags2 |= XFS_DIFLAG2_DAX;\n@@ -125,6 +126,8 @@ xfs_ip2xflags(\n \t\t\tflags |= FS_XFLAG_DAX;\n \t\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_COWEXTSIZE)\n \t\t\tflags |= FS_XFLAG_COWEXTSIZE;\n+\t\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY)\n+\t\t\tflags |= FS_XFLAG_VERITY;\n \t}\n \n \tif (xfs_inode_has_attr_fork(ip))\ndiff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c\nindex ce44123c98cef6..3323b8dcc7939b 100644\n--- a/fs/xfs/libxfs/xfs_sb.c\n+++ b/fs/xfs/libxfs/xfs_sb.c\n@@ -164,6 +164,8 @@ xfs_sb_version_to_features(\n \t\tfeatures |= XFS_FEAT_REFLINK;\n \tif (sbp-\u003esb_features_ro_compat \u0026 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)\n \t\tfeatures |= XFS_FEAT_INOBTCNT;\n+\tif (sbp-\u003esb_features_ro_compat \u0026 XFS_SB_FEAT_RO_COMPAT_VERITY)\n+\t\tfeatures |= XFS_FEAT_VERITY;\n \tif (sbp-\u003esb_features_incompat \u0026 XFS_SB_FEAT_INCOMPAT_FTYPE)\n \t\tfeatures |= XFS_FEAT_FTYPE;\n \tif (sbp-\u003esb_features_incompat \u0026 XFS_SB_FEAT_INCOMPAT_SPINODES)\n@@ -1544,6 +1546,8 @@ xfs_fs_geometry(\n \t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_METADIR;\n \tif (xfs_has_zoned(mp))\n \t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_ZONED;\n+\tif (xfs_has_verity(mp))\n+\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_VERITY;\n \tgeo-\u003ertsectsize = sbp-\u003esb_blocksize;\n \tgeo-\u003edirblocksize = xfs_dir2_dirblock_bytes(sbp);\n \ndiff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c\nnew file mode 100644\nindex 00000000000000..c1731b89a5a12c\n--- /dev/null\n+++ b/fs/xfs/libxfs/xfs_verity.c\n@@ -0,0 +1,20 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#include \"xfs_platform.h\"\n+#include \"xfs_fs.h\"\n+#include \"xfs_shared.h\"\n+#include \"xfs_format.h\"\n+#include \"xfs_log_format.h\"\n+#include \"xfs_trans_resv.h\"\n+#include \"xfs_mount.h\"\n+#include \"xfs_inode.h\"\n+#include \"xfs_verity.h\"\n+\n+loff_t\n+xfs_fsverity_metadata_offset(\n+\tconst struct xfs_inode\t*ip)\n+{\n+\treturn round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);\n+}\ndiff --git a/fs/xfs/libxfs/xfs_verity.h b/fs/xfs/libxfs/xfs_verity.h\nnew file mode 100644\nindex 00000000000000..db89d557edcd3e\n--- /dev/null\n+++ b/fs/xfs/libxfs/xfs_verity.h\n@@ -0,0 +1,12 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#ifndef __XFS_VERITY_H__\n+#define __XFS_VERITY_H__\n+\n+#include \"xfs_platform.h\"\n+\n+loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);\n+\n+#endif\t/* __XFS_VERITY_H__ */\ndiff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c\nindex cbfe5e6f779dfc..fb0ae227df54a8 100644\n--- a/fs/xfs/scrub/common.c\n+++ b/fs/xfs/scrub/common.c\n@@ -45,6 +45,8 @@\n #include \"scrub/health.h\"\n #include \"scrub/tempfile.h\"\n \n+#include \u003clinux/fsverity.h\u003e\n+\n /* Common code for the metadata scrubbers. */\n \n /*\n@@ -1765,3 +1767,54 @@ xchk_inode_count_blocks(\n \treturn xfs_bmap_count_blocks(sc-\u003etp, sc-\u003eip, whichfork, nextents,\n \t\t\tcount);\n }\n+\n+/*\n+ * If this inode has S_VERITY set on it, read the verity info. If the reading\n+ * fails with anything other than ENOMEM, the file is corrupt, which we can\n+ * detect later with fsverity_active.\n+ *\n+ * Callers must hold the IOLOCK and must not hold the ILOCK of sc-\u003eip because\n+ * activation reads inode data.\n+ */\n+int\n+xchk_inode_setup_verity(\n+\tstruct xfs_scrub\t*sc)\n+{\n+\tint\t\t\terror;\n+\n+\tif (!fsverity_active(VFS_I(sc-\u003eip)))\n+\t\treturn 0;\n+\n+\terror = fsverity_ensure_verity_info(VFS_I(sc-\u003eip));\n+\tswitch (error) {\n+\tcase 0:\n+\t\t/* fsverity is active */\n+\t\tbreak;\n+\tcase -ENODATA:\n+\tcase -EMSGSIZE:\n+\tcase -EFSCORRUPTED:\n+\tcase -ERANGE:\n+\tcase -EBADMSG:\n+\t\t/*\n+\t\t * The nonzero errno codes above are the error codes that can\n+\t\t * be returned from fsverity on metadata validation errors.\n+\t\t */\n+\t\treturn 0;\n+\tdefault:\n+\t\t/* runtime errors */\n+\t\treturn error;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Is this a verity file that failed to activate?  Callers must have tried to\n+ * activate fsverity via xchk_inode_setup_verity.\n+ */\n+bool\n+xchk_inode_verity_broken(\n+\tstruct xfs_inode\t*ip)\n+{\n+\treturn fsverity_active(VFS_I(ip)) \u0026\u0026 !fsverity_get_info(VFS_I(ip));\n+}\ndiff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h\nindex 181028f0c65526..b59d4792a80507 100644\n--- a/fs/xfs/scrub/common.h\n+++ b/fs/xfs/scrub/common.h\n@@ -261,6 +261,8 @@ int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_agino_t agino,\n \t\tbool *inuse);\n int xchk_inode_count_blocks(struct xfs_scrub *sc, int whichfork,\n \t\txfs_extnum_t *nextents, xfs_filblks_t *count);\n+int xchk_inode_setup_verity(struct xfs_scrub *sc);\n+bool xchk_inode_verity_broken(struct xfs_inode *ip);\n \n bool xchk_inode_is_dirtree_root(const struct xfs_inode *ip);\n bool xchk_inode_is_sb_rooted(const struct xfs_inode *ip);\ndiff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c\nindex bb8d2bc008e019..1d21758e0df068 100644\n--- a/fs/xfs/scrub/inode.c\n+++ b/fs/xfs/scrub/inode.c\n@@ -36,6 +36,10 @@ xchk_prepare_iscrub(\n \n \txchk_ilock(sc, XFS_IOLOCK_EXCL);\n \n+\terror = xchk_inode_setup_verity(sc);\n+\tif (error)\n+\t\treturn error;\n+\n \terror = xchk_trans_alloc(sc, 0);\n \tif (error)\n \t\treturn error;\n@@ -833,6 +837,9 @@ xchk_inode(\n \tif (S_ISREG(VFS_I(sc-\u003eip)-\u003ei_mode))\n \t\txchk_inode_check_reflink_iflag(sc, I_INO(sc-\u003eip));\n \n+\tif (xchk_inode_verity_broken(sc-\u003eip))\n+\t\txchk_ino_set_corrupt(sc, sc-\u003esm-\u003esm_ino);\n+\n \txchk_inode_check_unlinked(sc);\n \n \txchk_inode_xref(sc, I_INO(sc-\u003eip), \u0026di);\ndiff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c\nindex a9ccf763c05969..e84eaa8178dc79 100644\n--- a/fs/xfs/scrub/inode_repair.c\n+++ b/fs/xfs/scrub/inode_repair.c\n@@ -577,6 +577,8 @@ xrep_dinode_flags(\n \t\tdip-\u003edi_nrext64_pad = 0;\n \telse if (dip-\u003edi_version \u003e= 3)\n \t\tdip-\u003edi_v3_pad = 0;\n+\tif (!xfs_has_verity(mp) || !S_ISREG(mode))\n+\t\tflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n \n \tif (flags2 \u0026 XFS_DIFLAG2_METADATA) {\n \t\txfs_failaddr_t\tfa;\n@@ -1659,6 +1661,10 @@ xrep_dinode_core(\n \tif (iget_error)\n \t\treturn iget_error;\n \n+\terror = xchk_inode_setup_verity(sc);\n+\tif (error)\n+\t\treturn error;\n+\n \terror = xchk_trans_alloc(sc, 0);\n \tif (error)\n \t\treturn error;\n@@ -2198,6 +2204,27 @@ xrep_inode_reset_dquots(\n # define xrep_inode_reset_dquots(sc)\t\t(0)\n #endif\n \n+/*\n+ * If this file is a fsverity file, xchk_prepare_iscrub or xrep_dinode_core\n+ * should have activated it.  If it's still not active, then there's something\n+ * wrong with the verity descriptor and we should turn it off.\n+ */\n+STATIC int\n+xrep_inode_verity(\n+\tstruct xfs_scrub\t*sc)\n+{\n+\tstruct inode\t\t*inode = VFS_I(sc-\u003eip);\n+\n+\tif (xchk_inode_verity_broken(sc-\u003eip)) {\n+\t\tsc-\u003eip-\u003ei_diflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n+\t\tinode_set_flags(inode, 0, S_VERITY);\n+\n+\t\txfs_trans_log_inode(sc-\u003etp, sc-\u003eip, XFS_ILOG_CORE);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /* Repair an inode's fields. */\n int\n xrep_inode(\n@@ -2247,6 +2274,15 @@ xrep_inode(\n \t\t\treturn error;\n \t}\n \n+\t/*\n+\t * Disable fsverity if it cannot be activated.  Activation failure\n+\t * prohibits the file from being opened, so there cannot be another\n+\t * program with an open fd to what it thinks is a verity file.\n+\t */\n+\terror = xrep_inode_verity(sc);\n+\tif (error)\n+\t\treturn error;\n+\n \t/* Reconnect incore unlinked list */\n \terror = xrep_inode_unlinked(sc);\n \tif (error)\ndiff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c\nindex c30e688cfc9f6e..2f6e87991d8361 100644\n--- a/fs/xfs/xfs_aops.c\n+++ b/fs/xfs/xfs_aops.c\n@@ -23,6 +23,7 @@\n #include \"xfs_ioend.h\"\n #include \"xfs_zone_alloc.h\"\n #include \"xfs_rtgroup.h\"\n+#include \"xfs_fsverity.h\"\n \n struct xfs_writepage_ctx {\n \tstruct iomap_writepage_ctx ctx;\n@@ -172,12 +173,16 @@ xfs_map_blocks(\n \tint\t\t\tretries = 0;\n \tint\t\t\terror = 0;\n \tunsigned int\t\t*seq;\n+\tunsigned int\t\tiomap_flags = 0;\n \n \tif (xfs_is_shutdown(mp))\n \t\treturn -EIO;\n \n \tXFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);\n \n+\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\n+\t\tiomap_flags |= IOMAP_F_FSVERITY;\n+\n \t/*\n \t * COW fork blocks can overlap data fork blocks even if the blocks\n \t * aren't shared.  COW I/O always takes precedent, so we must always\n@@ -265,7 +270,8 @@ xfs_map_blocks(\n \t    isnullstartblock(imap.br_startblock))\n \t\tgoto allocate_blocks;\n \n-\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, 0, 0, XFS_WPC(wpc)-\u003edata_seq);\n+\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, 0, iomap_flags,\n+\t\t\t  XFS_WPC(wpc)-\u003edata_seq);\n \ttrace_xfs_map_blocks_found(ip, offset, count, whichfork, \u0026imap);\n \treturn 0;\n allocate_blocks:\n@@ -412,12 +418,16 @@ xfs_zoned_map_blocks(\n \txfs_filblks_t\t\tcount_fsb;\n \tstruct xfs_bmbt_irec\timap, del;\n \tstruct xfs_iext_cursor\ticur;\n+\tu16\t\t\tiomap_flags = 0;\n \n \tif (xfs_is_shutdown(mp))\n \t\treturn -EIO;\n \n \tXFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);\n \n+\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\n+\t\tiomap_flags |= IOMAP_F_FSVERITY;\n+\n \t/*\n \t * All dirty data must be covered by delalloc extents.  But truncate can\n \t * remove delalloc extents underneath us or reduce their size.\n@@ -441,7 +451,7 @@ xfs_zoned_map_blocks(\n \t\timap.br_startblock = HOLESTARTBLOCK;\n \t\timap.br_state = XFS_EXT_NORM;\n \t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n-\t\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, 0, 0, 0);\n+\t\txfs_bmbt_to_iomap(ip, \u0026wpc-\u003eiomap, \u0026imap, 0, iomap_flags, 0);\n \t\treturn 0;\n \t}\n \tend_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount);\n@@ -454,7 +464,7 @@ xfs_zoned_map_blocks(\n \txfs_iunlock(ip, XFS_ILOCK_EXCL);\n \n \txfs_iomap_set_anon_write(ip, \u0026wpc-\u003eiomap, offset,\n-\t\t\tXFS_FSB_TO_B(mp, count_fsb));\n+\t\t\tXFS_FSB_TO_B(mp, count_fsb), iomap_flags);\n \ttrace_xfs_zoned_map_blocks(ip, offset, wpc-\u003eiomap.length);\n \treturn 0;\n }\n@@ -507,6 +517,22 @@ static const struct iomap_writeback_ops xfs_zoned_writeback_ops = {\n \t.writeback_submit\t= xfs_zoned_writeback_submit,\n };\n \n+static int\n+xfs_iomap_writepages(\n+\tstruct xfs_inode\t\t*ip,\n+\tstruct iomap_writepage_ctx\t*ctx)\n+{\n+\t/*\n+\t * Writeback does not work for folios past EOF, let it know that\n+\t * I/O happens for fsverity metadata and this restriction need\n+\t * to be skipped\n+\t */\n+\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\n+\t\tctx-\u003eiomap.flags |= IOMAP_F_FSVERITY;\n+\n+\treturn iomap_writepages(ctx);\n+}\n+\n STATIC int\n xfs_vm_writepages(\n \tstruct address_space\t*mapping,\n@@ -526,7 +552,7 @@ xfs_vm_writepages(\n \t\t};\n \t\tint\t\t\t\terror;\n \n-\t\terror = iomap_writepages(\u0026xc.ctx);\n+\t\terror = xfs_iomap_writepages(ip, \u0026xc.ctx);\n \t\tif (xc.open_zone)\n \t\t\txfs_open_zone_put(xc.open_zone);\n \t\treturn error;\n@@ -539,7 +565,7 @@ xfs_vm_writepages(\n \t\t\t},\n \t\t};\n \n-\t\treturn iomap_writepages(\u0026wpc.ctx);\n+\t\treturn xfs_iomap_writepages(ip, \u0026wpc.ctx);\n \t}\n }\n \n@@ -585,7 +611,7 @@ xfs_bio_submit_read(\n {\n \txfs_ioend_submit_read(iter-\u003einode, ctx-\u003eread_ctx,\n \t\t\tctx-\u003eread_ctx_file_offset,\n-\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap));\n+\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap), ctx-\u003evi);\n \tctx-\u003eread_ctx = NULL;\n }\n \n@@ -597,11 +623,13 @@ static const struct iomap_read_ops xfs_iomap_read_ops = {\n \n static inline const struct iomap_read_ops *\n xfs_get_iomap_read_ops(\n-\tconst struct address_space\t*mapping)\n+\tconst struct address_space\t*mapping,\n+\tloff_t\t\t\t\tpos)\n {\n \tstruct xfs_inode\t\t*ip = XFS_I(mapping-\u003ehost);\n \n-\tif (bdev_has_integrity_csum(xfs_inode_buftarg(ip)-\u003ebt_bdev))\n+\tif (bdev_has_integrity_csum(xfs_inode_buftarg(ip)-\u003ebt_bdev) ||\n+\t    xfs_fsverity_is_file_data(ip, pos))\n \t\treturn \u0026xfs_iomap_read_ops;\n \treturn \u0026iomap_bio_read_ops;\n }\n@@ -613,7 +641,7 @@ xfs_vm_read_folio(\n {\n \tstruct iomap_read_folio_ctx\tctx = { .cur_folio = folio };\n \n-\tctx.ops = xfs_get_iomap_read_ops(folio-\u003emapping);\n+\tctx.ops = xfs_get_iomap_read_ops(folio-\u003emapping, folio_pos(folio));\n \tiomap_read_folio(\u0026xfs_read_iomap_ops, \u0026ctx, NULL);\n \treturn 0;\n }\n@@ -624,7 +652,7 @@ xfs_vm_readahead(\n {\n \tstruct iomap_read_folio_ctx\tctx = { .rac = rac };\n \n-\tctx.ops = xfs_get_iomap_read_ops(rac-\u003emapping),\n+\tctx.ops = xfs_get_iomap_read_ops(rac-\u003emapping, readahead_pos(rac));\n \tiomap_readahead(\u0026xfs_read_iomap_ops, \u0026ctx, NULL);\n }\n \ndiff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c\nindex 865aec3ae5ab32..32cec523fd52d7 100644\n--- a/fs/xfs/xfs_bmap_util.c\n+++ b/fs/xfs/xfs_bmap_util.c\n@@ -31,6 +31,7 @@\n #include \"xfs_rtbitmap.h\"\n #include \"xfs_rtgroup.h\"\n #include \"xfs_zone_alloc.h\"\n+#include \u003clinux/fsverity.h\u003e\n \n /* Kernel only BMAP related definitions and functions */\n \n@@ -553,6 +554,15 @@ xfs_can_free_eofblocks(\n \tif (last_fsb \u003c= end_fsb)\n \t\treturn false;\n \n+\t/*\n+\t * Don't clean fsverity inodes as they already have been cleaned up and\n+\t * are read-only. Skip inodes which have merkle tree being built, the\n+\t * merkle tree is written beyond EOF\n+\t */\n+\tif (fsverity_active(VFS_IC(ip)) ||\n+\t    xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\n+\t\treturn false;\n+\n \t/*\n \t * Check if there is an post-EOF extent to free.  If there are any\n \t * delalloc blocks attached to the inode (data fork delalloc\n@@ -579,6 +589,9 @@ xfs_free_eofblocks(\n \tstruct xfs_trans\t*tp;\n \tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n \tint\t\t\terror;\n+\tint\t\t\tbmapi_flags = XFS_BMAPI_NODISCARD;\n+\tbool\t\t\thas_verity =\n+\t\t\tip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY;\n \n \t/* Attach the dquots to the inode up front. */\n \terror = xfs_qm_dqattach(ip);\n@@ -593,15 +606,20 @@ xfs_free_eofblocks(\n \t *\n \t * Note that this means we also leave speculative preallocations in\n \t * place for preallocated files.\n+\t *\n+\t * Clean up delalloc reservations for fsverity too as those won't be\n+\t * used\n \t */\n-\tif (ip-\u003ei_diflags \u0026 (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) {\n+\tif (ip-\u003ei_diflags \u0026 (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) ||\n+\t\t\thas_verity) {\n \t\tif (ip-\u003ei_delayed_blks) {\n \t\t\txfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK,\n \t\t\t\tround_up(XFS_ISIZE(ip), mp-\u003em_sb.sb_blocksize),\n \t\t\t\tLLONG_MAX, NULL);\n \t\t}\n \t\txfs_inode_clear_eofblocks_tag(ip);\n-\t\treturn 0;\n+\t\tif (!has_verity)\n+\t\t\treturn 0;\n \t}\n \n \terror = xfs_trans_alloc(mp, \u0026M_RES(mp)-\u003etr_itruncate, 0, 0, 0, \u0026tp);\n@@ -613,6 +631,13 @@ xfs_free_eofblocks(\n \txfs_ilock(ip, XFS_ILOCK_EXCL);\n \txfs_trans_ijoin(tp, ip, 0);\n \n+\t/*\n+\t * While fs-verity writes metadata after EOF, it can leave unwritten\n+\t * preallocations.  Clear all that out.\n+\t */\n+\tif (has_verity)\n+\t\tbmapi_flags |= XFS_BMAPI_UNWRITTEN;\n+\n \t/*\n \t * Do not update the on-disk file size.  If we update the on-disk file\n \t * size and then the system crashes before the contents of the file are\n@@ -620,7 +645,7 @@ xfs_free_eofblocks(\n \t * bug).\n \t */\n \terror = xfs_itruncate_extents_flags(\u0026tp, ip, XFS_DATA_FORK,\n-\t\t\t\tXFS_ISIZE(ip), XFS_BMAPI_NODISCARD);\n+\t\t\t\tXFS_ISIZE(ip), bmapi_flags);\n \tif (error)\n \t\tgoto err_cancel;\n \ndiff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c\nindex 7d0c8a197575cf..a610adc90c0289 100644\n--- a/fs/xfs/xfs_file.c\n+++ b/fs/xfs/xfs_file.c\n@@ -38,6 +38,7 @@\n #include \u003clinux/mount.h\u003e\n #include \u003clinux/filelock.h\u003e\n #include \u003clinux/bio-integrity.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n \n static const struct vm_operations_struct xfs_file_vm_ops;\n \n@@ -223,7 +224,8 @@ xfs_dio_read_bounce_submit_io(\n \tloff_t\t\t\tfile_offset)\n {\n \txfs_ioend_submit_read(iter-\u003einode, bio, file_offset,\n-\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap) | IOMAP_IOEND_DIRECT);\n+\t\t\tiomap_ioend_flags(\u0026iter-\u003eiomap) | IOMAP_IOEND_DIRECT,\n+\t\t\tNULL);\n }\n \n static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {\n@@ -231,6 +233,25 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {\n \t.bio_set\t= \u0026iomap_ioend_bioset,\n };\n \n+STATIC ssize_t\n+xfs_file_buffered_read(\n+\tstruct kiocb\t\t*iocb,\n+\tstruct iov_iter\t\t*to)\n+{\n+\tstruct xfs_inode\t*ip = XFS_I(file_inode(iocb-\u003eki_filp));\n+\tssize_t\t\t\tret;\n+\n+\ttrace_xfs_file_buffered_read(iocb, to);\n+\n+\tret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);\n+\tif (ret)\n+\t\treturn ret;\n+\tret = generic_file_read_iter(iocb, to);\n+\txfs_iunlock(ip, XFS_IOLOCK_SHARED);\n+\n+\treturn ret;\n+}\n+\n STATIC ssize_t\n xfs_file_dio_read(\n \tstruct kiocb\t\t*iocb,\n@@ -249,6 +270,17 @@ xfs_file_dio_read(\n \tret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);\n \tif (ret)\n \t\treturn ret;\n+\n+\t/*\n+\t * Re-check verity status after acquiring lock. This prevents TOCTOU in\n+\t * xfs_file_read_iter() while falling back from DIO to buffered I/O as\n+\t * now we are holding a lock\n+\t */\n+\tif (fsverity_active(VFS_I(ip))) {\n+\t\txfs_iunlock(ip, XFS_IOLOCK_SHARED);\n+\t\tiocb-\u003eki_flags \u0026= ~IOCB_DIRECT;\n+\t\treturn xfs_file_buffered_read(iocb, to);\n+\t}\n \tif (mapping_stable_writes(iocb-\u003eki_filp-\u003ef_mapping)) {\n \t\tret = iomap_dio_rw(iocb, to, \u0026xfs_read_iomap_ops,\n \t\t\t\t\u0026xfs_dio_read_bounce_ops, 0, NULL, 0);\n@@ -268,7 +300,8 @@ xfs_file_dax_read(\n \tstruct kiocb\t\t*iocb,\n \tstruct iov_iter\t\t*to)\n {\n-\tstruct xfs_inode\t*ip = XFS_I(iocb-\u003eki_filp-\u003ef_mapping-\u003ehost);\n+\tstruct inode\t\t*inode = iocb-\u003eki_filp-\u003ef_mapping-\u003ehost;\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n \tssize_t\t\t\tret = 0;\n \n \ttrace_xfs_file_dax_read(iocb, to);\n@@ -286,25 +319,6 @@ xfs_file_dax_read(\n \treturn ret;\n }\n \n-STATIC ssize_t\n-xfs_file_buffered_read(\n-\tstruct kiocb\t\t*iocb,\n-\tstruct iov_iter\t\t*to)\n-{\n-\tstruct xfs_inode\t*ip = XFS_I(file_inode(iocb-\u003eki_filp));\n-\tssize_t\t\t\tret;\n-\n-\ttrace_xfs_file_buffered_read(iocb, to);\n-\n-\tret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);\n-\tif (ret)\n-\t\treturn ret;\n-\tret = generic_file_read_iter(iocb, to);\n-\txfs_iunlock(ip, XFS_IOLOCK_SHARED);\n-\n-\treturn ret;\n-}\n-\n STATIC ssize_t\n xfs_file_read_iter(\n \tstruct kiocb\t\t*iocb,\n@@ -319,6 +333,14 @@ xfs_file_read_iter(\n \tif (xfs_is_shutdown(mp))\n \t\treturn -EIO;\n \n+\t/*\n+\t * In case fs-verity is enabled, we also fallback to the buffered read\n+\t * from the direct read path. Therefore, IOCB_DIRECT is set and need to\n+\t * be cleared (see generic_file_read_iter())\n+\t */\n+\tif (fsverity_active(inode))\n+\t\tiocb-\u003eki_flags \u0026= ~IOCB_DIRECT;\n+\n \tif (IS_DAX(inode))\n \t\tret = xfs_file_dax_read(iocb, to);\n \telse if (iocb-\u003eki_flags \u0026 IOCB_DIRECT)\n@@ -1771,11 +1793,18 @@ xfs_file_open(\n \tstruct inode\t*inode,\n \tstruct file\t*file)\n {\n+\tint\t\terror;\n+\n \tif (xfs_is_shutdown(XFS_M(inode-\u003ei_sb)))\n \t\treturn -EIO;\n \tfile-\u003ef_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;\n \tif (xfs_get_atomic_write_min(XFS_I(inode)) \u003e 0)\n \t\tfile-\u003ef_mode |= FMODE_CAN_ATOMIC_WRITE;\n+\n+\terror = fsverity_file_open(inode, file);\n+\tif (error)\n+\t\treturn error;\n+\n \treturn generic_file_open(inode, file);\n }\n \ndiff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c\nnew file mode 100644\nindex 00000000000000..9b83a0735dc049\n--- /dev/null\n+++ b/fs/xfs/xfs_fsverity.c\n@@ -0,0 +1,482 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#include \"xfs_platform.h\"\n+#include \"xfs_fs.h\"\n+#include \"xfs_shared.h\"\n+#include \"xfs_format.h\"\n+#include \"xfs_trans_resv.h\"\n+#include \"xfs_mount.h\"\n+#include \"xfs_inode.h\"\n+#include \"xfs_log_format.h\"\n+#include \"xfs_trans.h\"\n+#include \"xfs_trace.h\"\n+#include \"xfs_quota.h\"\n+#include \"xfs_fsverity.h\"\n+#include \"xfs_iomap.h\"\n+#include \"xfs_error.h\"\n+#include \"xfs_health.h\"\n+#include \"xfs_bmap_util.h\"\n+#include \"xfs_icache.h\"\n+#include \u003clinux/fsverity.h\u003e\n+#include \u003clinux/iomap.h\u003e\n+#include \u003clinux/pagemap.h\u003e\n+\n+struct kmem_cache *xfs_fsverity_ioend_cache;\n+mempool_t xfs_fsverity_ioend_pool;\n+\n+#define XFS_FSVERITY_IOEND_POOL_MIN\t128\n+\n+/*\n+ * Back the fsverity ioend allocations with a mempool so that read I/O\n+ * completion always makes forward progress and cannot deadlock\n+ */\n+int\n+xfs_fsverity_init(void)\n+{\n+\treturn mempool_init_slab_pool(\u0026xfs_fsverity_ioend_pool,\n+\t\t\tXFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);\n+}\n+\n+void\n+xfs_fsverity_exit(void)\n+{\n+\tmempool_exit(\u0026xfs_fsverity_ioend_pool);\n+}\n+\n+bool\n+xfs_fsverity_is_file_data(\n+\tconst struct xfs_inode\t*ip,\n+\tloff_t\t\t\toffset)\n+{\n+\treturn fsverity_active(VFS_IC(ip)) \u0026\u0026\n+\t\t\toffset \u003c xfs_fsverity_metadata_offset(ip);\n+}\n+\n+/*\n+ * Retrieve the verity descriptor.\n+ */\n+static int\n+xfs_fsverity_get_descriptor(\n+\tstruct inode\t\t*inode,\n+\tvoid\t\t\t*buf,\n+\tsize_t\t\t\tbuf_size)\n+{\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\t__be32\t\t\td_desc_size;\n+\tu32\t\t\tdesc_size;\n+\tu64\t\t\tdesc_size_pos;\n+\tint\t\t\terror;\n+\tu64\t\t\tdesc_pos;\n+\tstruct xfs_bmbt_irec\trec;\n+\tint\t\t\tis_empty;\n+\tuint32_t\t\tblocksize = i_blocksize(VFS_I(ip));\n+\txfs_fileoff_t\t\tlast_block_offset;\n+\n+\txfs_ilock(ip, XFS_ILOCK_EXCL);\n+\t/*\n+\t * Serialize reading of inode-\u003ei_flags with xfs_scrub clearing of this\n+\t * flag if inode is corrupted.\n+\t */\n+\tif (!(inode-\u003ei_flags \u0026 S_VERITY)) {\n+\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\t\treturn -ENODATA;\n+\t}\n+\terror = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, \u0026rec, \u0026is_empty);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\tif (error)\n+\t\treturn error;\n+\n+\tif (is_empty) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ENODATA;\n+\t}\n+\n+\tlast_block_offset =\n+\t\tXFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);\n+\tif (last_block_offset \u003c= xfs_fsverity_metadata_offset(ip)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ENODATA;\n+\t}\n+\n+\tdesc_size_pos = last_block_offset - sizeof(__be32);\n+\terror = fsverity_pagecache_read(inode, (char *)\u0026d_desc_size,\n+\t\t\tsizeof(d_desc_size), desc_size_pos);\n+\tif (error)\n+\t\treturn error;\n+\n+\tdesc_size = be32_to_cpu(d_desc_size);\n+\tif (XFS_IS_CORRUPT(mp, desc_size \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\tif (XFS_IS_CORRUPT(mp, desc_size \u003e desc_size_pos)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\tif (!buf_size)\n+\t\treturn desc_size;\n+\n+\tif (XFS_IS_CORRUPT(mp, desc_size \u003e buf_size)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\tdesc_pos = round_down(desc_size_pos - desc_size, blocksize);\n+\tif (desc_pos \u003c xfs_fsverity_metadata_offset(ip)) {\n+\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\n+\t\treturn -ERANGE;\n+\t}\n+\n+\terror = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);\n+\tif (error)\n+\t\treturn error;\n+\n+\treturn desc_size;\n+}\n+\n+static int\n+xfs_fsverity_write_descriptor(\n+\tstruct file\t\t*file,\n+\tconst void\t\t*desc,\n+\tu32\t\t\tdesc_size,\n+\tu64\t\t\tmerkle_tree_size)\n+{\n+\tint\t\t\terror;\n+\tstruct inode\t\t*inode = file_inode(file);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tunsigned int\t\tblksize = ip-\u003ei_mount-\u003em_sb.sb_blocksize;\n+\tu64\t\t\ttree_last_block =\n+\t\t\txfs_fsverity_metadata_offset(ip) + merkle_tree_size;\n+\tu64\t\t\tdesc_pos =\n+\t\t\tround_up(tree_last_block, XFS_FSVERITY_START_ALIGN);\n+\tu64\t\t\tdesc_end = desc_pos + desc_size;\n+\t__be32\t\t\tdesc_size_disk = cpu_to_be32(desc_size);\n+\tu64\t\t\tdesc_size_pos =\n+\t\t\tround_up(desc_end + sizeof(desc_size_disk), blksize) -\n+\t\t\tsizeof(desc_size_disk);\n+\n+\terror = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),\n+\t\t\t(const void *)\u0026desc_size_disk,\n+\t\t\t\u0026xfs_buffered_write_iomap_ops,\n+\t\t\t\u0026xfs_iomap_write_ops);\n+\tif (error)\n+\t\treturn error;\n+\n+\treturn iomap_fsverity_write(file, desc_pos, desc_size, desc,\n+\t\t\t\u0026xfs_buffered_write_iomap_ops,\n+\t\t\t\u0026xfs_iomap_write_ops);\n+}\n+\n+/*\n+ * Try to remove all the fsverity metadata after a failed enablement.\n+ */\n+static int\n+xfs_fsverity_delete_metadata(\n+\tstruct xfs_inode\t*ip)\n+{\n+\tstruct xfs_trans\t*tp;\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\tint\t\t\terror;\n+\n+\txfs_ilock(ip, XFS_MMAPLOCK_EXCL);\n+\ttruncate_inode_pages(VFS_I(ip)-\u003ei_mapping, XFS_ISIZE(ip));\n+\n+\terror = xfs_trans_alloc(mp, \u0026M_RES(mp)-\u003etr_itruncate, 0, 0, 0, \u0026tp);\n+\tif (error) {\n+\t\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL);\n+\t\treturn error;\n+\t}\n+\n+\txfs_ilock(ip, XFS_ILOCK_EXCL);\n+\txfs_trans_ijoin(tp, ip, 0);\n+\n+\t/*\n+\t * We remove post EOF data, no need to update i_size as fsverity\n+\t * didn't move i_size in the first place\n+\t */\n+\terror = xfs_itruncate_extents(\u0026tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));\n+\tif (error)\n+\t\tgoto err_cancel;\n+\n+\terror = xfs_trans_commit(tp);\n+\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);\n+\treturn error;\n+err_cancel:\n+\txfs_trans_cancel(tp);\n+\txfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);\n+\treturn error;\n+}\n+\n+static int\n+xfs_fsverity_reset_inode(\n+\tstruct xfs_inode\t*ip)\n+{\n+\tint\t\t\terror;\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\tstruct xfs_trans\t*tp;\n+\n+\terror = xfs_fsverity_delete_metadata(ip);\n+\tif (error)\n+\t\treturn error;\n+\n+\t/*\n+\t * First, let's clean in-memory fsverity flag and then reset it on the\n+\t * disk\n+\t */\n+\tinode_set_flags(VFS_I(ip), 0, S_VERITY);\n+\n+\t/*\n+\t * Set fsverity inode flag\n+\t */\n+\terror = xfs_trans_alloc_inode(ip, \u0026M_RES(mp)-\u003etr_ichange,\n+\t\t\t0, 0, false, \u0026tp);\n+\tif (error)\n+\t\treturn error;\n+\n+\tip-\u003ei_diflags2 \u0026= ~XFS_DIFLAG2_VERITY;\n+\n+\txfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);\n+\txfs_trans_set_sync(tp);\n+\n+\terror = xfs_trans_commit(tp);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\treturn error;\n+}\n+\n+/*\n+ * Prepare to enable fsverity by clearing old metadata.\n+ */\n+static int\n+xfs_fsverity_begin_enable(\n+\tstruct file\t\t*filp)\n+{\n+\tstruct inode\t\t*inode = file_inode(filp);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tint\t\t\terror;\n+\n+\txfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);\n+\n+\tif (IS_DAX(inode) || ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_DAX)\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * fs-verity stores the Merkle tree past EOF in units of the filesystem\n+\t * block size, so it cannot support realtime files whose allocation unit\n+\t * (extent size) is larger than the block size.\n+\t */\n+\tif (xfs_inode_has_bigrtalloc(ip))\n+\t\treturn -EINVAL;\n+\n+\tif (inode-\u003ei_size \u003e XFS_FSVERITY_LARGEST_FILE)\n+\t\treturn -EFBIG;\n+\n+\t/*\n+\t * Flush pagecache before building Merkle tree. Inode is locked and no\n+\t * further writes will happen to the file except fsverity metadata\n+\t */\n+\terror = filemap_write_and_wait(inode-\u003ei_mapping);\n+\tif (error)\n+\t\treturn error;\n+\n+\tif (xfs_iflags_test_and_set(ip, XFS_VERITY_CONSTRUCTION))\n+\t\treturn -EBUSY;\n+\n+\terror = xfs_qm_dqattach(ip);\n+\tif (error)\n+\t\tgoto out_clear;\n+\n+\terror = xfs_fsverity_delete_metadata(ip);\n+\tif (error)\n+\t\tgoto out_clear;\n+\treturn error;\n+out_clear:\n+\txfs_iflags_clear(ip, XFS_VERITY_CONSTRUCTION);\n+\treturn error;\n+}\n+\n+/*\n+ * Complete (or fail) the process of enabling fsverity.\n+ */\n+static int\n+xfs_fsverity_end_enable(\n+\tstruct file\t\t*file,\n+\tconst void\t\t*desc,\n+\tsize_t\t\t\tdesc_size,\n+\tu64\t\t\tmerkle_tree_size)\n+{\n+\tstruct inode\t\t*inode = file_inode(file);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n+\tstruct xfs_trans\t*tp;\n+\tint\t\t\terror = 0;\n+\tloff_t\t\t\trange_start = xfs_fsverity_metadata_offset(ip);\n+\n+\txfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);\n+\n+\t/* fs-verity failed, just cleanup */\n+\tif (desc == NULL)\n+\t\tgoto out;\n+\n+\terror = xfs_fsverity_write_descriptor(file, desc, desc_size,\n+\t\t\tmerkle_tree_size);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Wait for Merkle tree get written to disk before setting on-disk inode\n+\t * flag and clearing XFS_VERITY_CONSTRUCTION\n+\t */\n+\terror = filemap_write_and_wait_range(inode-\u003ei_mapping, range_start,\n+\t\t\tLLONG_MAX);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Set fsverity inode flag\n+\t */\n+\terror = xfs_trans_alloc_inode(ip, \u0026M_RES(mp)-\u003etr_ichange,\n+\t\t\t0, 0, false, \u0026tp);\n+\tif (error)\n+\t\tgoto out;\n+\n+\t/*\n+\t * Ensure that we've persisted the verity information before we enable\n+\t * it on the inode and tell the caller we have sealed the inode.\n+\t */\n+\tip-\u003ei_diflags2 |= XFS_DIFLAG2_VERITY;\n+\n+\txfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);\n+\txfs_trans_set_sync(tp);\n+\n+\terror = xfs_trans_commit(tp);\n+\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n+\tif (error)\n+\t\tgoto out;\n+\n+\tinode_set_flags(inode, S_VERITY, S_VERITY);\n+\n+\t/*\n+\t * Proactively remove unwritten extents left by COW preallocations and\n+\t * write preallocation in the merkle tree holes and past descriptor,\n+\t * and any delayed preallocations\n+\t */\n+\terror = xfs_free_eofblocks(ip);\n+out:\n+\tif (error) {\n+\t\tint\terror2;\n+\n+\t\terror2 = xfs_fsverity_reset_inode(ip);\n+\t\tif (error2)\n+\t\t\txfs_alert(ip-\u003ei_mount,\n+\"ino 0x%llx failed to clean up new fsverity metadata, err %d\",\n+\t\t\t\t\tI_INO(ip), error2);\n+\t}\n+\n+\txfs_iflags_clear(ip, XFS_VERITY_CONSTRUCTION);\n+\treturn error;\n+}\n+\n+/*\n+ * Retrieve a merkle tree block.\n+ */\n+static struct page *\n+xfs_fsverity_read_merkle(\n+\tstruct inode\t\t*inode,\n+\tpgoff_t\t\t\tindex)\n+{\n+\tindex += xfs_fsverity_metadata_offset(XFS_I(inode)) \u003e\u003e PAGE_SHIFT;\n+\n+\treturn generic_read_merkle_tree_page(inode, index);\n+}\n+\n+/*\n+ * Retrieve a merkle tree block.\n+ */\n+static void\n+xfs_fsverity_readahead_merkle_tree(\n+\tstruct inode\t\t*inode,\n+\tpgoff_t\t\t\tindex,\n+\tunsigned long\t\tnr_pages)\n+{\n+\tindex += xfs_fsverity_metadata_offset(XFS_I(inode)) \u003e\u003e PAGE_SHIFT;\n+\n+\tgeneric_readahead_merkle_tree(inode, index, nr_pages);\n+}\n+\n+static inline bool\n+xfs_fsverity_is_hashes_of_zeroed_blocks(\n+\tstruct xfs_inode\t*ip,\n+\tconst void\t\t*buf,\n+\tunsigned int\t\tsize,\n+\tconst u8\t\t*zero_digest,\n+\tunsigned int\t\tdigest_size)\n+{\n+\t/*\n+\t * If this is a block full of hashes of zeroed blocks, don't bother\n+\t * storing the block. We can synthesize them later.\n+\t *\n+\t * However, do this only in case Merkle tree block == fs block size.\n+\t * Iomap synthesizes these blocks based on holes in the merkle tree. We\n+\t * won't be able to tell if something need to be synthesizes for the\n+\t * range in the fs block. For example, for 4k filesystem block\n+\t *\n+\t *\t[ 1k | zero hashes | zero hashes | 1k ]\n+\t *\n+\t * Iomap won't know about these empty blocks.\n+\t */\n+\tif (size != ip-\u003ei_mount-\u003em_sb.sb_blocksize)\n+\t\treturn false;\n+\t/*\n+\t * First digest is zero_digest\n+\t */\n+\tif (memcmp(buf, zero_digest, digest_size))\n+\t\treturn false;\n+\t/*\n+\t * Every digest is same as previous, thus all are\n+\t * zero_digest\n+\t */\n+\treturn memcmp(buf + digest_size, buf, size - digest_size) == 0;\n+}\n+\n+/*\n+ * Write a merkle tree block.\n+ */\n+static int\n+xfs_fsverity_write_merkle(\n+\tstruct file\t\t*file,\n+\tconst void\t\t*buf,\n+\tu64\t\t\tpos,\n+\tunsigned int\t\tsize,\n+\tconst u8\t\t*zero_digest,\n+\tunsigned int\t\tdigest_size)\n+{\n+\tstruct inode\t\t*inode = file_inode(file);\n+\tstruct xfs_inode\t*ip = XFS_I(inode);\n+\tloff_t\t\t\tposition = pos +\n+\t\txfs_fsverity_metadata_offset(ip);\n+\n+\tif (position + size \u003e inode-\u003ei_sb-\u003es_maxbytes)\n+\t\treturn -EFBIG;\n+\n+\tif (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,\n+\t\t\t\t\t\t    digest_size))\n+\t\treturn 0;\n+\n+\treturn iomap_fsverity_write(file, position, size, buf,\n+\t\t\t\u0026xfs_buffered_write_iomap_ops,\n+\t\t\t\u0026xfs_iomap_write_ops);\n+}\n+\n+const struct fsverity_operations xfs_fsverity_ops = {\n+\t.begin_enable_verity\t\t= xfs_fsverity_begin_enable,\n+\t.end_enable_verity\t\t= xfs_fsverity_end_enable,\n+\t.get_verity_descriptor\t\t= xfs_fsverity_get_descriptor,\n+\t.read_merkle_tree_page\t\t= xfs_fsverity_read_merkle,\n+\t.readahead_merkle_tree\t\t= xfs_fsverity_readahead_merkle_tree,\n+\t.write_merkle_tree_block\t= xfs_fsverity_write_merkle,\n+};\ndiff --git a/fs/xfs/xfs_fsverity.h b/fs/xfs/xfs_fsverity.h\nnew file mode 100644\nindex 00000000000000..43f8ef62e12a1a\n--- /dev/null\n+++ b/fs/xfs/xfs_fsverity.h\n@@ -0,0 +1,42 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Copyright (C) 2026 Red Hat, Inc.\n+ */\n+#ifndef __XFS_FSVERITY_H__\n+#define __XFS_FSVERITY_H__\n+\n+#include \"xfs_platform.h\"\n+#include \"xfs_verity.h\"\n+#include \u003clinux/iomap.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n+#include \u003clinux/mempool.h\u003e\n+\n+#ifdef CONFIG_FS_VERITY\n+extern const struct fsverity_operations xfs_fsverity_ops;\n+int xfs_fsverity_init(void);\n+void xfs_fsverity_exit(void);\n+bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset);\n+#else\n+static inline int xfs_fsverity_init(void)\n+{\n+\treturn 0;\n+}\n+static inline void xfs_fsverity_exit(void)\n+{\n+}\n+static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,\n+\t\t\t\t\t    loff_t offset)\n+{\n+\treturn false;\n+}\n+#endif\t/* CONFIG_FS_VERITY */\n+\n+struct xfs_fsverity_ioend {\n+\tstruct iomap_ioend\t*ioend;\n+\tstruct work_struct\twork;\n+};\n+\n+extern struct kmem_cache *xfs_fsverity_ioend_cache;\n+extern mempool_t xfs_fsverity_ioend_pool;\n+\n+#endif\t/* __XFS_FSVERITY_H__ */\ndiff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c\nindex 239b843e83d42a..be66760fb120f7 100644\n--- a/fs/xfs/xfs_health.c\n+++ b/fs/xfs/xfs_health.c\n@@ -625,6 +625,7 @@ static const struct ioctl_sick_map ino_map[] = {\n \t{ XFS_SICK_INO_DIR_ZAPPED,\tXFS_BS_SICK_DIR },\n \t{ XFS_SICK_INO_SYMLINK_ZAPPED,\tXFS_BS_SICK_SYMLINK },\n \t{ XFS_SICK_INO_DIRTREE,\tXFS_BS_SICK_DIRTREE },\n+\t{ XFS_SICK_INO_FSVERITY,\tXFS_BS_SICK_FSVERITY },\n };\n \n /* Fill out bulkstat health info. */\ndiff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h\nindex 75eff68c1e3950..034d3f6072a932 100644\n--- a/fs/xfs/xfs_inode.h\n+++ b/fs/xfs/xfs_inode.h\n@@ -428,6 +428,12 @@ static inline bool xfs_inode_can_sw_atomic_write(const struct xfs_inode *ip)\n  */\n #define XFS_IREMAPPING\t\t(1U \u003c\u003c 15)\n \n+/*\n+ * fs-verity's Merkle tree is under construction. The file is read-only, the\n+ * only writes happening are for the fsverity metadata.\n+ */\n+#define XFS_VERITY_CONSTRUCTION\t(1U \u003c\u003c 16)\n+\n /* All inode state flags related to inode reclaim. */\n #define XFS_ALL_IRECLAIM_FLAGS\t(XFS_IRECLAIMABLE | \\\n \t\t\t\t XFS_IRECLAIM | \\\ndiff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c\nindex f81b6e52ac403d..37c6a2fae58cc0 100644\n--- a/fs/xfs/xfs_ioctl.c\n+++ b/fs/xfs/xfs_ioctl.c\n@@ -49,6 +49,7 @@\n \n #include \u003clinux/mount.h\u003e\n #include \u003clinux/fileattr.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n \n /* Return 0 on success or positive error */\n int\n@@ -1575,6 +1576,19 @@ xfs_file_ioctl(\n \tcase XFS_IOC_VERIFY_MEDIA:\n \t\treturn xfs_ioc_verify_media(filp, arg);\n \n+\tcase FS_IOC_ENABLE_VERITY:\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn -EOPNOTSUPP;\n+\t\treturn fsverity_ioctl_enable(filp, arg);\n+\tcase FS_IOC_MEASURE_VERITY:\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn -EOPNOTSUPP;\n+\t\treturn fsverity_ioctl_measure(filp, arg);\n+\tcase FS_IOC_READ_VERITY_METADATA:\n+\t\tif (!xfs_has_verity(mp))\n+\t\t\treturn -EOPNOTSUPP;\n+\t\treturn fsverity_ioctl_read_metadata(filp, arg);\n+\n \tdefault:\n \t\treturn -ENOTTY;\n \t}\ndiff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c\nindex 48becc3bf60889..d30aee973a876a 100644\n--- a/fs/xfs/xfs_ioend.c\n+++ b/fs/xfs/xfs_ioend.c\n@@ -18,7 +18,26 @@\n #include \"xfs_ioend.h\"\n #include \"xfs_error.h\"\n #include \"xfs_errortag.h\"\n+#include \"xfs_fsverity.h\"\n #include \u003clinux/bio-integrity.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n+\n+static void\n+xfs_end_fsverity_io_read(\n+\tstruct work_struct\t\t*work)\n+{\n+\tstruct xfs_fsverity_ioend\t*fsv_ioend =\n+\t\t\tcontainer_of(work, struct xfs_fsverity_ioend, work);\n+\tstruct iomap_ioend\t\t*ioend = fsv_ioend-\u003eioend;\n+\tstruct bio\t\t\t*bio = \u0026ioend-\u003eio_bio;\n+\n+\tmempool_free(fsv_ioend, \u0026xfs_fsverity_ioend_pool);\n+\n+\tif (!bio-\u003ebi_status)\n+\t\tfsverity_verify_bio(ioend-\u003eio_vi, bio);\n+\n+\tiomap_finish_ioends(ioend, blk_status_to_errno(bio-\u003ebi_status));\n+}\n \n static void\n xfs_dio_bounce_end_io(\n@@ -93,12 +112,14 @@ xfs_read_bounce_and_resubmit(\n \n static void\n xfs_end_io_read(\n-\tstruct bio\t\t*bio)\n+\tstruct bio\t\t\t*bio)\n {\n-\tstruct iomap_ioend\t*ioend = iomap_ioend_from_bio(bio);\n-\tstruct xfs_inode\t*ip = XFS_I(ioend-\u003eio_inode);\n-\tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n-\tint\t\t\terror = blk_status_to_errno(bio-\u003ebi_status);\n+\tstruct iomap_ioend\t\t*ioend = iomap_ioend_from_bio(bio);\n+\tstruct xfs_inode\t\t*ip = XFS_I(ioend-\u003eio_inode);\n+\tstruct xfs_mount\t\t*mp = ip-\u003ei_mount;\n+\tint\t\t\t\terror =\n+\t\t\tblk_status_to_errno(bio-\u003ebi_status);\n+\tstruct xfs_fsverity_ioend\t*fsv_ioend;\n \n \tif (!error \u0026\u0026 (ioend-\u003eio_flags \u0026 IOMAP_IOEND_INTEGRITY)) {\n \t\terror = iomap_ioend_integrity_verify(ioend);\n@@ -117,6 +138,24 @@ xfs_end_io_read(\n \t\t}\n \t}\n \n+\t/*\n+\t * If we have fsverity on this bio, we need to run fsverity verification\n+\t * of data folios from a separate fsverity workqueue. This is necessary\n+\t * to avoid deadlocking due to fsverity issuing more reads of fsverity\n+\t * metadata which would be processed by the same worker in the BIO\n+\t * completion workqueue.\n+\t */\n+\tif (IS_ENABLED(CONFIG_FS_VERITY) \u0026\u0026 !error \u0026\u0026 ioend-\u003eio_vi \u0026\u0026\n+\t\t\txfs_fsverity_is_file_data(ip, ioend-\u003eio_offset)) {\n+\t\tfsv_ioend = mempool_alloc(\u0026xfs_fsverity_ioend_pool,\n+\t\t\t\tGFP_NOFS);\n+\t\tfsv_ioend-\u003eioend = ioend;\n+\t\tINIT_WORK(\u0026fsv_ioend-\u003ework, xfs_end_fsverity_io_read);\n+\n+\t\tfsverity_enqueue_verify_work(\u0026fsv_ioend-\u003ework);\n+\t\treturn;\n+\t}\n+\n \tiomap_finish_ioends(ioend, error);\n }\n \n@@ -125,13 +164,15 @@ xfs_ioend_submit_read(\n \tstruct inode\t\t*inode,\n \tstruct bio\t\t*bio,\n \tloff_t\t\t\tfile_offset,\n-\tu16\t\t\tioend_flags)\n+\tu16\t\t\tioend_flags,\n+\tstruct fsverity_info\t*vi)\n {\n \tstruct xfs_inode\t*ip = XFS_I(inode);\n \tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n \tstruct iomap_ioend\t*ioend;\n \n \tioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags);\n+\tioend-\u003eio_vi = vi;\n \tif ((ioend_flags \u0026 IOMAP_IOEND_DIRECT) \u0026\u0026\n \t    READ_ONCE(mp-\u003em_read_bounce) == XFS_READ_BOUNCE_ALWAYS) {\n \t\tiomap_bounce_read(ioend, bdev_logical_block_size(bio-\u003ebi_bdev),\ndiff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h\nindex 7c2a1ea3e6eddc..992c248a693aaf 100644\n--- a/fs/xfs/xfs_ioend.h\n+++ b/fs/xfs/xfs_ioend.h\n@@ -2,6 +2,8 @@\n #ifndef __XFS_IOEND_H\n #define __XFS_IOEND_H\n \n+#include \u003clinux/fsverity.h\u003e\n+\n /*\n  * Fast and loose check if this write could update the on-disk inode size.\n  */\n@@ -13,6 +15,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)\n \n void xfs_end_bio(struct bio *bio);\n void xfs_ioend_submit_read(struct inode *inode, struct bio *bio,\n-\t\tloff_t file_offset, u16 ioend_flags);\n+\t\tloff_t file_offset, u16 ioend_flags, struct fsverity_info *vi);\n \n #endif /* __XFS_IOEND_H */\ndiff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c\nindex 329c745e312045..68fef657644202 100644\n--- a/fs/xfs/xfs_iomap.c\n+++ b/fs/xfs/xfs_iomap.c\n@@ -32,6 +32,8 @@\n #include \"xfs_rtbitmap.h\"\n #include \"xfs_icache.h\"\n #include \"xfs_zone_alloc.h\"\n+#include \"xfs_verity.h\"\n+#include \u003clinux/fsverity.h\u003e\n \n #define XFS_ALLOC_ALIGN(mp, off) \\\n \t(((off) \u003e\u003e mp-\u003em_allocsize_log) \u003c\u003c mp-\u003em_allocsize_log)\n@@ -883,6 +885,9 @@ xfs_direct_write_iomap_begin(\n \tif (flags \u0026 IOMAP_ATOMIC)\n \t\tiomap_flags |= IOMAP_F_ATOMIC_BIO;\n \n+\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\n+\t\tiomap_flags |= IOMAP_F_FSVERITY;\n+\n \t/*\n \t * COW writes may allocate delalloc space or convert unwritten COW\n \t * extents, so we need to make sure to take the lock exclusively here.\n@@ -1023,7 +1028,8 @@ xfs_direct_write_iomap_begin(\n \ttrace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, \u0026cmap);\n \tif (imap.br_startblock != HOLESTARTBLOCK) {\n \t\tseq = xfs_iomap_inode_sequence(ip, 0);\n-\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags, 0, seq);\n+\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags,\n+\t\t\t\tiomap_flags \u0026 IOMAP_F_FSVERITY, seq);\n \t\tif (error)\n \t\t\tgoto out_unlock;\n \t}\n@@ -1083,7 +1089,7 @@ xfs_zoned_direct_write_iomap_begin(\n \t\t\treturn error;\n \t}\n \n-\txfs_iomap_set_anon_write(ip, iomap, offset, length);\n+\txfs_iomap_set_anon_write(ip, iomap, offset, length, 0);\n \treturn 0;\n }\n \n@@ -1594,7 +1600,8 @@ xfs_zoned_fill_srcmap(\n \txfs_fileoff_t\t\toffset_fsb,\n \txfs_fileoff_t\t\t*end_fsb,\n \tunsigned\t\tflags,\n-\tstruct iomap\t\t*srcmap)\n+\tstruct iomap\t\t*srcmap,\n+\tu16\t\t\tiomap_flags)\n {\n \tstruct xfs_bmbt_irec\tsmap;\n \tstruct xfs_iext_cursor\tscur;\n@@ -1615,7 +1622,7 @@ xfs_zoned_fill_srcmap(\n \t */\n \txfs_trim_extent(\u0026smap, offset_fsb, *end_fsb - offset_fsb);\n \t*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);\n-\treturn xfs_bmbt_to_iomap(ip, srcmap, \u0026smap, flags, 0,\n+\treturn xfs_bmbt_to_iomap(ip, srcmap, \u0026smap, flags, iomap_flags,\n \t\t\txfs_iomap_inode_sequence(ip, 0));\n }\n \n@@ -1626,7 +1633,8 @@ xfs_zoned_buffered_write_iomap_begin(\n \tloff_t\t\t\tcount,\n \tunsigned\t\tflags,\n \tstruct iomap\t\t*iomap,\n-\tstruct iomap\t\t*srcmap)\n+\tstruct iomap\t\t*srcmap,\n+\tu16\t\t\tiomap_flags)\n {\n \tstruct iomap_iter\t*iter =\n \t\tcontainer_of(iomap, struct iomap_iter, iomap);\n@@ -1636,7 +1644,6 @@ xfs_zoned_buffered_write_iomap_begin(\n \tstruct xfs_mount\t*mp = ip-\u003ei_mount;\n \txfs_fileoff_t\t\toffset_fsb = XFS_B_TO_FSBT(mp, offset);\n \txfs_fileoff_t\t\tend_fsb = xfs_iomap_end_fsb(mp, offset, count);\n-\tu16\t\t\tiomap_flags = IOMAP_F_SHARED;\n \tunsigned int\t\tlockmode = XFS_ILOCK_EXCL;\n \txfs_filblks_t\t\tcount_fsb;\n \txfs_extlen_t\t\tindlen;\n@@ -1687,7 +1694,7 @@ xfs_zoned_buffered_write_iomap_begin(\n \t    !IS_ALIGNED(offset + count, mp-\u003em_sb.sb_blocksize) ||\n \t    (flags \u0026 IOMAP_ZERO)) {\n \t\terror = xfs_zoned_fill_srcmap(ip, offset_fsb, \u0026end_fsb, flags,\n-\t\t\t\tsrcmap);\n+\t\t\t\tsrcmap, iomap_flags);\n \t\tif (error)\n \t\t\tgoto out_unlock;\n \t}\n@@ -1695,6 +1702,8 @@ xfs_zoned_buffered_write_iomap_begin(\n \tif (!ip-\u003ei_cowfp)\n \t\txfs_ifork_init_cow(ip);\n \n+\tiomap_flags |= IOMAP_F_SHARED;\n+\n \tif (!xfs_iext_lookup_extent(ip, ip-\u003ei_cowfp, offset_fsb, \u0026icur, \u0026got))\n \t\tgot.br_startoff = end_fsb;\n \tif (got.br_startoff \u003c= offset_fsb) {\n@@ -1826,9 +1835,12 @@ xfs_buffered_write_iomap_begin(\n \tif (xfs_is_shutdown(mp))\n \t\treturn -EIO;\n \n+\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\n+\t\tiomap_flags |= IOMAP_F_FSVERITY;\n+\n \tif (xfs_is_zoned_inode(ip))\n \t\treturn xfs_zoned_buffered_write_iomap_begin(inode, offset,\n-\t\t\t\tcount, flags, iomap, srcmap);\n+\t\t\t\tcount, flags, iomap, srcmap, iomap_flags);\n \n \t/* we can't use delayed allocations when using extent size hints */\n \tif (xfs_get_extsz_hint(ip))\n@@ -2112,7 +2124,8 @@ xfs_buffered_write_iomap_begin(\n \n found_cow:\n \tif (imap.br_startoff \u003c= offset_fsb) {\n-\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags, 0,\n+\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags,\n+\t\t\t\tiomap_flags \u0026 IOMAP_F_FSVERITY,\n \t\t\t\txfs_iomap_inode_sequence(ip, 0));\n \t\tif (error)\n \t\t\tgoto out_unlock;\n@@ -2216,12 +2229,17 @@ xfs_read_iomap_begin(\n \tbool\t\t\tshared = false;\n \tunsigned int\t\tlockmode = XFS_ILOCK_SHARED;\n \tu64\t\t\tseq;\n+\tunsigned int\t\tiomap_flags = 0;\n \n \tASSERT(!(flags \u0026 (IOMAP_WRITE | IOMAP_ZERO)));\n \n \tif (xfs_is_shutdown(mp))\n \t\treturn -EIO;\n \n+\tif (fsverity_active(inode) \u0026\u0026\n+\t    (offset \u003e= xfs_fsverity_metadata_offset(ip)))\n+\t\tiomap_flags |= IOMAP_F_FSVERITY;\n+\n \terror = xfs_ilock_for_iomap(ip, flags, \u0026lockmode);\n \tif (error)\n \t\treturn error;\n@@ -2235,8 +2253,9 @@ xfs_read_iomap_begin(\n \tif (error)\n \t\treturn error;\n \ttrace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, \u0026imap);\n-\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags,\n-\t\t\t\t shared ? IOMAP_F_SHARED : 0, seq);\n+\tiomap_flags |= shared ? IOMAP_F_SHARED : 0;\n+\n+\treturn xfs_bmbt_to_iomap(ip, iomap, \u0026imap, flags, iomap_flags, seq);\n }\n \n static DEFINE_IOMAP_ITER_NEXT(xfs_read_iomap_next, xfs_read_iomap_begin);\ndiff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h\nindex f2520a9b3a13e6..d3ca0f2afc9f79 100644\n--- a/fs/xfs/xfs_iomap.h\n+++ b/fs/xfs/xfs_iomap.h\n@@ -34,13 +34,14 @@ xfs_iomap_set_anon_write(\n \tstruct xfs_inode\t\t*ip,\n \tstruct iomap\t\t\t*iomap,\n \tloff_t\t\t\t\toffset,\n-\tloff_t\t\t\t\tlength)\n+\tloff_t\t\t\t\tlength,\n+\tu16\t\t\t\tiomap_flags)\n {\n \tiomap-\u003etype = IOMAP_MAPPED;\n \tiomap-\u003ebdev = ip-\u003ei_mount-\u003em_rtdev_targp-\u003ebt_bdev;\n \tiomap-\u003eoffset = offset;\n \tiomap-\u003elength = length;\n-\tiomap-\u003eflags = IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;\n+\tiomap-\u003eflags = iomap_flags | IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;\n \tif (bdev_has_integrity_csum(iomap-\u003ebdev))\n \t\tiomap-\u003eflags |= IOMAP_F_INTEGRITY;\n }\ndiff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c\nindex d307ec97fac820..150bbd705807f0 100644\n--- a/fs/xfs/xfs_iops.c\n+++ b/fs/xfs/xfs_iops.c\n@@ -35,6 +35,7 @@\n #include \u003clinux/security.h\u003e\n #include \u003clinux/iversion.h\u003e\n #include \u003clinux/fiemap.h\u003e\n+#include \u003clinux/fsverity.h\u003e\n \n /*\n  * Directories have different lock order w.r.t. mmap_lock compared to regular\n@@ -579,6 +580,10 @@ xfs_report_dioalign(\n \tstruct block_device\t*bdev = target-\u003ebt_bdev;\n \n \tstat-\u003eresult_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;\n+\n+\tif (fsverity_active(VFS_I(ip)))\n+\t\treturn;\n+\n \tstat-\u003edio_mem_align = bdev_dma_alignment(bdev) + 1;\n \n \t/*\n@@ -1387,6 +1392,8 @@ xfs_inode_should_enable_dax(\n \t\treturn false;\n \tif (!xfs_inode_supports_dax(ip))\n \t\treturn false;\n+\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY)\n+\t\treturn false;\n \tif (xfs_has_dax_always(ip-\u003ei_mount))\n \t\treturn true;\n \tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_DAX)\n@@ -1415,12 +1422,15 @@ xfs_diflags_to_iflags(\n \t\tflags |= S_NOATIME;\n \tif (init \u0026\u0026 xfs_inode_should_enable_dax(ip))\n \t\tflags |= S_DAX;\n+\tif (xflags \u0026 FS_XFLAG_VERITY)\n+\t\tflags |= S_VERITY;\n \n \t/*\n \t * S_DAX can only be set during inode initialization and is never set by\n \t * the VFS, so we cannot mask off S_DAX in i_flags.\n \t */\n-\tinode-\u003ei_flags \u0026= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);\n+\tinode-\u003ei_flags \u0026=\n+\t\t~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME | S_VERITY);\n \tinode-\u003ei_flags |= flags;\n }\n \ndiff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c\nindex 0243e509a46891..44b13d46049c62 100644\n--- a/fs/xfs/xfs_message.c\n+++ b/fs/xfs/xfs_message.c\n@@ -149,6 +149,10 @@ xfs_warn_experimental(\n \t\t\t.opstate\t= XFS_OPSTATE_WARNED_LARP,\n \t\t\t.name\t\t= \"logged extended attributes\",\n \t\t},\n+\t\t[XFS_EXPERIMENTAL_FSVERITY] = {\n+\t\t\t.opstate\t= XFS_OPSTATE_WARNED_FSVERITY,\n+\t\t\t.name\t\t= \"fsverity\",\n+\t\t},\n \t};\n \tASSERT(feat \u003e= 0 \u0026\u0026 feat \u003c XFS_EXPERIMENTAL_MAX);\n \tBUILD_BUG_ON(ARRAY_SIZE(features) != XFS_EXPERIMENTAL_MAX);\ndiff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h\nindex 811b885f41c35a..364fcc7e42b084 100644\n--- a/fs/xfs/xfs_message.h\n+++ b/fs/xfs/xfs_message.h\n@@ -93,6 +93,7 @@ void xfs_buf_alert_ratelimited(struct xfs_buf *bp, const char *rlmsg,\n enum xfs_experimental_feat {\n \tXFS_EXPERIMENTAL_SHRINK,\n \tXFS_EXPERIMENTAL_LARP,\n+\tXFS_EXPERIMENTAL_FSVERITY,\n \n \tXFS_EXPERIMENTAL_MAX,\n };\ndiff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h\nindex cbcfb89c67a440..0b64636635996f 100644\n--- a/fs/xfs/xfs_mount.h\n+++ b/fs/xfs/xfs_mount.h\n@@ -403,6 +403,7 @@ typedef struct xfs_mount {\n #define XFS_FEAT_EXCHANGE_RANGE\t(1ULL \u003c\u003c 27)\t/* exchange range */\n #define XFS_FEAT_METADIR\t(1ULL \u003c\u003c 28)\t/* metadata directory tree */\n #define XFS_FEAT_ZONED\t\t(1ULL \u003c\u003c 29)\t/* zoned RT device */\n+#define XFS_FEAT_VERITY\t\t(1ULL \u003c\u003c 30)\t/* fs-verity */\n \n /* Mount features */\n #define XFS_FEAT_NOLIFETIME\t(1ULL \u003c\u003c 47)\t/* disable lifetime hints */\n@@ -460,6 +461,7 @@ __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE)\n __XFS_HAS_FEAT(metadir, METADIR)\n __XFS_HAS_FEAT(zoned, ZONED)\n __XFS_HAS_FEAT(nolifetime, NOLIFETIME)\n+__XFS_HAS_FEAT(verity, VERITY)\n \n static inline bool xfs_has_rtgroups(const struct xfs_mount *mp)\n {\n@@ -597,6 +599,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)\n #define XFS_OPSTATE_RESUMING_QUOTAON\t18\n /* (Zoned) GC is in progress */\n #define XFS_OPSTATE_ZONEGC_RUNNING\t20\n+/* Kernel has logged a warning about fsverity support */\n+#define XFS_OPSTATE_WARNED_FSVERITY\t21\n \n #define __XFS_IS_OPSTATE(name, NAME) \\\n static inline bool xfs_is_ ## name (struct xfs_mount *mp) \\\ndiff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c\nindex 5a06132aa38466..af679b6ab52b32 100644\n--- a/fs/xfs/xfs_super.c\n+++ b/fs/xfs/xfs_super.c\n@@ -30,6 +30,7 @@\n #include \"xfs_filestream.h\"\n #include \"xfs_quota.h\"\n #include \"xfs_sysfs.h\"\n+#include \"xfs_fsverity.h\"\n #include \"xfs_ondisk.h\"\n #include \"xfs_rmap_item.h\"\n #include \"xfs_refcount_item.h\"\n@@ -1736,6 +1737,9 @@ xfs_fs_fill_super(\n \tsb-\u003es_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;\n #endif\n \tsb-\u003es_op = \u0026xfs_super_operations;\n+#ifdef CONFIG_FS_VERITY\n+\tsb-\u003es_vop = \u0026xfs_fsverity_ops;\n+#endif\n \n \t/*\n \t * Delay mount work if the debug hook is set. This is debug\n@@ -1988,6 +1992,9 @@ xfs_fs_fill_super(\n \tif (error)\n \t\tgoto out_filestream_unmount;\n \n+\tif (xfs_has_verity(mp))\n+\t\txfs_warn_experimental(mp, XFS_EXPERIMENTAL_FSVERITY);\n+\n \troot = igrab(VFS_I(mp-\u003em_rootip));\n \tif (!root) {\n \t\terror = -ENOENT;\n@@ -2516,8 +2523,20 @@ xfs_init_caches(void)\n \tif (!xfs_parent_args_cache)\n \t\tgoto out_destroy_xmi_cache;\n \n+#ifdef CONFIG_FS_VERITY\n+\txfs_fsverity_ioend_cache = kmem_cache_create(\"xfs_fsverity_ioend\",\n+\t\t\t\t\t     sizeof(struct xfs_fsverity_ioend),\n+\t\t\t\t\t     0, 0, NULL);\n+\tif (!xfs_fsverity_ioend_cache)\n+\t\tgoto out_destroy_parent_args_cache;\n+#endif\n+\n \treturn 0;\n \n+#ifdef CONFIG_FS_VERITY\n+ out_destroy_parent_args_cache:\n+\tkmem_cache_destroy(xfs_parent_args_cache);\n+#endif\n  out_destroy_xmi_cache:\n \tkmem_cache_destroy(xfs_xmi_cache);\n  out_destroy_xmd_cache:\n@@ -2580,6 +2599,9 @@ xfs_destroy_caches(void)\n \t * destroy caches.\n \t */\n \trcu_barrier();\n+#ifdef CONFIG_FS_VERITY\n+\tkmem_cache_destroy(xfs_fsverity_ioend_cache);\n+#endif\n \tkmem_cache_destroy(xfs_parent_args_cache);\n \tkmem_cache_destroy(xfs_xmd_cache);\n \tkmem_cache_destroy(xfs_xmi_cache);\n@@ -2660,10 +2682,14 @@ init_xfs_fs(void)\n \tif (error)\n \t\tgoto out;\n \n-\terror = xfs_init_workqueues();\n+\terror = xfs_fsverity_init();\n \tif (error)\n \t\tgoto out_destroy_caches;\n \n+\terror = xfs_init_workqueues();\n+\tif (error)\n+\t\tgoto out_fsverity_exit;\n+\n \terror = xfs_mru_cache_init();\n \tif (error)\n \t\tgoto out_destroy_wq;\n@@ -2740,6 +2766,8 @@ init_xfs_fs(void)\n \txfs_mru_cache_uninit();\n  out_destroy_wq:\n \txfs_destroy_workqueues();\n+ out_fsverity_exit:\n+\txfs_fsverity_exit();\n  out_destroy_caches:\n \txfs_destroy_caches();\n  out:\n@@ -2763,6 +2791,7 @@ exit_xfs_fs(void)\n \txfs_cleanup_procfs();\n \txfs_mru_cache_uninit();\n \txfs_destroy_workqueues();\n+\txfs_fsverity_exit();\n \txfs_destroy_caches();\n \txfs_uuid_table_free();\n }\n"
}

2/1 2026/11/03 04:02 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_readahead_merkle_tree",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity"
  ],
  "Reasoning": "The patch adds fs-verity support to the XFS filesystem. It introduces filesystem-specific operations for fs-verity (enabling verity, writing and reading Merkle tree blocks, retrieving descriptors), iomap handling for post-EOF metadata, asynchronous read verification via dedicated workqueue ioend handling, and online scrub/repair support for fs-verity inodes. This is complex core filesystem code reachable via standard syscalls (ioctls, read/write, scrub) and warrants fuzzing.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 511718d13990c977011c96cea0d9e44818696ad2
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Nov 3 04:02:33 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 399a207f2d0e71..9edb2850f09413 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -59,6 +59,7 @@ xfs-y				+= $(addprefix libxfs/, \
 				   xfs_trans_resv.o \
 				   xfs_trans_space.o \
 				   xfs_types.o \
+				   xfs_verity.o \
 				   )
 # xfs_rtbitmap is shared with libxfs
 xfs-$(CONFIG_XFS_RT)		+= $(addprefix libxfs/, \
@@ -150,6 +151,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL)	+= xfs_acl.o
 xfs-$(CONFIG_SYSCTL)		+= xfs_sysctl.o
 xfs-$(CONFIG_COMPAT)		+= xfs_ioctl32.o
 xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)	+= xfs_pnfs.o
+xfs-$(CONFIG_FS_VERITY)		+= xfs_fsverity.o
 
 # notify failure
 ifeq ($(CONFIG_MEMORY_FAILURE),y)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index ca49bf4a50c5f2..706f2ead42f582 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -41,6 +41,7 @@
 #include "xfs_inode_util.h"
 #include "xfs_rtgroup.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_verity.h"
 
 struct kmem_cache		*xfs_bmap_intent_cache;
 
@@ -4404,6 +4405,9 @@ xfs_bmapi_convert_one_delalloc(
 	 * the extent.  Just return the real extent at this offset.
 	 */
 	if (!isnullstartblock(bma.got.br_startblock)) {
+		if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) &&
+		    offset >= xfs_fsverity_metadata_offset(ip))
+			flags |= IOMAP_F_FSVERITY;
 		xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
 		if (seq)
@@ -4451,6 +4455,10 @@ xfs_bmapi_convert_one_delalloc(
 	XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
 	XFS_STATS_INC(mp, xs_xstrat_quick);
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) &&
+	    offset >= xfs_fsverity_metadata_offset(ip))
+		flags |= IOMAP_F_FSVERITY;
+
 	ASSERT(!isnullstartblock(bma.got.br_startblock));
 	xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
@@ -5271,6 +5279,10 @@ __xfs_bunmapi(
 		if (del.br_startoff + del.br_blockcount > end + 1)
 			del.br_blockcount = end + 1 - del.br_startoff;
 
+		if ((flags & XFS_BMAPI_UNWRITTEN) &&
+		    del.br_state != XFS_EXT_UNWRITTEN)
+			goto skip;
+
 		if (!isrt || (flags & XFS_BMAPI_REMAP))
 			goto delete;
 
@@ -5405,7 +5417,7 @@ __xfs_bunmapi(
 			if (error)
 				goto error0;
 		}
-
+skip:
 		end = del.br_startoff - 1;
 nodelete:
 		/*
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index e9f5416e4c050d..25b24ff8e4de35 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -90,6 +90,9 @@ struct xfs_bmalloca {
 /* Try to align allocations to the extent size hint */
 #define XFS_BMAPI_EXTSZALIGN	(1u << 11)
 
+/* Process unwritten extents only. Used for unmapping */
+#define XFS_BMAPI_UNWRITTEN	(1u << 12)
+
 #define XFS_BMAPI_FLAGS \
 	{ XFS_BMAPI_ENTIRE,	"ENTIRE" }, \
 	{ XFS_BMAPI_METADATA,	"METADATA" }, \
@@ -102,7 +105,8 @@ struct xfs_bmalloca {
 	{ XFS_BMAPI_COWFORK,	"COWFORK" }, \
 	{ XFS_BMAPI_NODISCARD,	"NODISCARD" }, \
 	{ XFS_BMAPI_NORMAP,	"NORMAP" },\
-	{ XFS_BMAPI_EXTSZALIGN,	"EXTSZALIGN" }
+	{ XFS_BMAPI_EXTSZALIGN,	"EXTSZALIGN" }, \
+	{ XFS_BMAPI_UNWRITTEN,	"UNWRITTEN" }
 
 
 static inline int xfs_bmapi_aflag(int w)
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 469e879149ac21..6594fbe4f7f6a0 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -374,11 +374,13 @@ xfs_sb_has_compat_feature(
 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 << 1)		/* reverse map btree */
 #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 << 2)		/* reflinked files */
 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)		/* inobt block counts */
+#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 << 4)		/* fs-verity */
 #define XFS_SB_FEAT_RO_COMPAT_ALL \
 		(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
 		 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
-		 XFS_SB_FEAT_RO_COMPAT_REFLINK| \
-		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
+		 XFS_SB_FEAT_RO_COMPAT_REFLINK | \
+		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \
+		 XFS_SB_FEAT_RO_COMPAT_VERITY)
 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN	~XFS_SB_FEAT_RO_COMPAT_ALL
 static inline bool
 xfs_sb_has_ro_compat_feature(
@@ -1234,16 +1236,21 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
  */
 #define XFS_DIFLAG2_METADATA_BIT	5
 
+/* inodes sealed with fs-verity */
+#define XFS_DIFLAG2_VERITY_BIT		6
+
 #define XFS_DIFLAG2_DAX		(1ULL << XFS_DIFLAG2_DAX_BIT)
 #define XFS_DIFLAG2_REFLINK	(1ULL << XFS_DIFLAG2_REFLINK_BIT)
 #define XFS_DIFLAG2_COWEXTSIZE	(1ULL << XFS_DIFLAG2_COWEXTSIZE_BIT)
 #define XFS_DIFLAG2_BIGTIME	(1ULL << XFS_DIFLAG2_BIGTIME_BIT)
 #define XFS_DIFLAG2_NREXT64	(1ULL << XFS_DIFLAG2_NREXT64_BIT)
 #define XFS_DIFLAG2_METADATA	(1ULL << XFS_DIFLAG2_METADATA_BIT)
+#define XFS_DIFLAG2_VERITY	(1ULL << XFS_DIFLAG2_VERITY_BIT)
 
 #define XFS_DIFLAG2_ANY \
 	(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \
-	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)
+	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \
+	 XFS_DIFLAG2_VERITY)
 
 static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
 {
@@ -2031,4 +2038,26 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+/*
+ * At maximum of 8 levels with 128 hashes per block (32 bytes SHA-256) maximum
+ * tree size is ((128^8 − 1)/(128 − 1)) = 567*10^12 blocks. This should fit in
+ * 53 bits address space.
+ *
+ * At this Merkle tree size we can cover 295EB large file. This is much larger
+ * than the currently supported file size.
+ *
+ * For sha512 the largest file we can cover ends at 1 << 50 offset, this is also
+ * good.
+ */
+#define XFS_FSVERITY_LARGEST_FILE	((loff_t)1ULL << 53)
+
+/*
+ * Alignment of the fsverity metadata placement. This is largest supported PAGE
+ * SIZE for fsverity. This is used to space out data and metadata in page cache.
+ * The spacing is necessary for non-exposure of metadata to userspace and
+ * correct merkle tree synthesis in the iomap.
+ */
+#define XFS_FSVERITY_START_ALIGN	(65536)
+
+
 #endif /* __XFS_FORMAT_H__ */
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 185f09f327c00c..84d62b7506a9ad 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {
 #define XFS_FSOP_GEOM_FLAGS_PARENT	(1 << 25) /* linux parent pointers */
 #define XFS_FSOP_GEOM_FLAGS_METADIR	(1 << 26) /* metadata directories */
 #define XFS_FSOP_GEOM_FLAGS_ZONED	(1 << 27) /* zoned rt device */
+#define XFS_FSOP_GEOM_FLAGS_VERITY	(1 << 28) /* fs-verity */
 
 /*
  * Minimum and maximum sizes need for growth checks.
@@ -421,6 +422,7 @@ struct xfs_bulkstat {
 #define XFS_BS_SICK_SYMLINK	(1 << 6)  /* symbolic link remote target */
 #define XFS_BS_SICK_PARENT	(1 << 7)  /* parent pointers */
 #define XFS_BS_SICK_DIRTREE	(1 << 8)  /* directory tree structure */
+#define XFS_BS_SICK_FSVERITY	(1 << 9)  /* fsverity metadata */
 
 /*
  * Project quota id helpers (previously projid was 16bit only
diff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h
index 1d45cf5789e864..932b447190da76 100644
--- a/fs/xfs/libxfs/xfs_health.h
+++ b/fs/xfs/libxfs/xfs_health.h
@@ -104,6 +104,7 @@ struct xfs_rtgroup;
 /* Don't propagate sick status to ag health summary during inactivation */
 #define XFS_SICK_INO_FORGET	(1 << 12)
 #define XFS_SICK_INO_DIRTREE	(1 << 13)  /* directory tree structure */
+#define XFS_SICK_INO_FSVERITY	(1 << 14)  /* fsverity metadata */
 
 /* Primary evidence of health problems in a given group. */
 #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
@@ -140,7 +141,8 @@ struct xfs_rtgroup;
 				 XFS_SICK_INO_XATTR | \
 				 XFS_SICK_INO_SYMLINK | \
 				 XFS_SICK_INO_PARENT | \
-				 XFS_SICK_INO_DIRTREE)
+				 XFS_SICK_INO_DIRTREE | \
+				 XFS_SICK_INO_FSVERITY)
 
 #define XFS_SICK_INO_ZAPPED	(XFS_SICK_INO_BMBTD_ZAPPED | \
 				 XFS_SICK_INO_BMBTA_ZAPPED | \
diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
index 8c9d296ebfe97f..13042e1eaf3519 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.c
+++ b/fs/xfs/libxfs/xfs_inode_buf.c
@@ -758,6 +758,14 @@ xfs_dinode_verify(
 	    !xfs_has_rtreflink(mp))
 		return __this_address;
 
+	/* only regular files can have fsverity */
+	if (flags2 & XFS_DIFLAG2_VERITY) {
+		if (!xfs_has_verity(mp))
+			return __this_address;
+		if (!S_ISREG(mode))
+			return __this_address;
+	}
+
 	if (xfs_has_zoned(mp) &&
 	    dip->di_metatype == cpu_to_be16(XFS_METAFILE_RTRMAP)) {
 		if (be32_to_cpu(dip->di_used_blocks) > mp->m_sb.sb_rgextents)
diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c
index f486b23a9b5230..a717b19558afab 100644
--- a/fs/xfs/libxfs/xfs_inode_util.c
+++ b/fs/xfs/libxfs/xfs_inode_util.c
@@ -73,7 +73,8 @@ xfs_flags2diflags2(
 	uint64_t		di_flags2 =
 		(ip->i_diflags2 & (XFS_DIFLAG2_REFLINK |
 				   XFS_DIFLAG2_BIGTIME |
-				   XFS_DIFLAG2_NREXT64));
+				   XFS_DIFLAG2_NREXT64 |
+				   XFS_DIFLAG2_VERITY));
 
 	if (xflags & FS_XFLAG_DAX)
 		di_flags2 |= XFS_DIFLAG2_DAX;
@@ -125,6 +126,8 @@ xfs_ip2xflags(
 			flags |= FS_XFLAG_DAX;
 		if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
 			flags |= FS_XFLAG_COWEXTSIZE;
+		if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+			flags |= FS_XFLAG_VERITY;
 	}
 
 	if (xfs_inode_has_attr_fork(ip))
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index ce44123c98cef6..3323b8dcc7939b 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -164,6 +164,8 @@ xfs_sb_version_to_features(
 		features |= XFS_FEAT_REFLINK;
 	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
 		features |= XFS_FEAT_INOBTCNT;
+	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_VERITY)
+		features |= XFS_FEAT_VERITY;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE)
 		features |= XFS_FEAT_FTYPE;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES)
@@ -1544,6 +1546,8 @@ xfs_fs_geometry(
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_METADIR;
 	if (xfs_has_zoned(mp))
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_ZONED;
+	if (xfs_has_verity(mp))
+		geo->flags |= XFS_FSOP_GEOM_FLAGS_VERITY;
 	geo->rtsectsize = sbp->sb_blocksize;
 	geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
 
diff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c
new file mode 100644
index 00000000000000..c1731b89a5a12c
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_verity.h"
+
+loff_t
+xfs_fsverity_metadata_offset(
+	const struct xfs_inode	*ip)
+{
+	return round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);
+}
diff --git a/fs/xfs/libxfs/xfs_verity.h b/fs/xfs/libxfs/xfs_verity.h
new file mode 100644
index 00000000000000..db89d557edcd3e
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.h
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_VERITY_H__
+#define __XFS_VERITY_H__
+
+#include "xfs_platform.h"
+
+loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);
+
+#endif	/* __XFS_VERITY_H__ */
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index cbfe5e6f779dfc..fb0ae227df54a8 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,54 @@ 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 -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.
+		 */
+		return 0;
+	default:
+		/* runtime errors */
+		return error;
+	}
+
+	return 0;
+}
+
+/*
+ * Is this a verity file that failed to activate?  Callers must have tried to
+ * activate fsverity via xchk_inode_setup_verity.
+ */
+bool
+xchk_inode_verity_broken(
+	struct xfs_inode	*ip)
+{
+	return fsverity_active(VFS_I(ip)) && !fsverity_get_info(VFS_I(ip));
+}
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index 181028f0c65526..b59d4792a80507 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -261,6 +261,8 @@ int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_agino_t agino,
 		bool *inuse);
 int xchk_inode_count_blocks(struct xfs_scrub *sc, int whichfork,
 		xfs_extnum_t *nextents, xfs_filblks_t *count);
+int xchk_inode_setup_verity(struct xfs_scrub *sc);
+bool xchk_inode_verity_broken(struct xfs_inode *ip);
 
 bool xchk_inode_is_dirtree_root(const struct xfs_inode *ip);
 bool xchk_inode_is_sb_rooted(const struct xfs_inode *ip);
diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
index bb8d2bc008e019..1d21758e0df068 100644
--- a/fs/xfs/scrub/inode.c
+++ b/fs/xfs/scrub/inode.c
@@ -36,6 +36,10 @@ xchk_prepare_iscrub(
 
 	xchk_ilock(sc, XFS_IOLOCK_EXCL);
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -833,6 +837,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);
+
 	xchk_inode_check_unlinked(sc);
 
 	xchk_inode_xref(sc, I_INO(sc->ip), &di);
diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c
index a9ccf763c05969..e84eaa8178dc79 100644
--- a/fs/xfs/scrub/inode_repair.c
+++ b/fs/xfs/scrub/inode_repair.c
@@ -577,6 +577,8 @@ 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;
 
 	if (flags2 & XFS_DIFLAG2_METADATA) {
 		xfs_failaddr_t	fa;
@@ -1659,6 +1661,10 @@ xrep_dinode_core(
 	if (iget_error)
 		return iget_error;
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -2198,6 +2204,27 @@ 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 and we should turn it off.
+ */
+STATIC int
+xrep_inode_verity(
+	struct xfs_scrub	*sc)
+{
+	struct inode		*inode = VFS_I(sc->ip);
+
+	if (xchk_inode_verity_broken(sc->ip)) {
+		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;
+}
+
 /* Repair an inode's fields. */
 int
 xrep_inode(
@@ -2247,6 +2274,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;
+
 	/* Reconnect incore unlinked list */
 	error = xrep_inode_unlinked(sc);
 	if (error)
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index c30e688cfc9f6e..2f6e87991d8361 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -23,6 +23,7 @@
 #include "xfs_ioend.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_rtgroup.h"
+#include "xfs_fsverity.h"
 
 struct xfs_writepage_ctx {
 	struct iomap_writepage_ctx ctx;
@@ -172,12 +173,16 @@ xfs_map_blocks(
 	int			retries = 0;
 	int			error = 0;
 	unsigned int		*seq;
+	unsigned int		iomap_flags = 0;
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
 	XFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * COW fork blocks can overlap data fork blocks even if the blocks
 	 * aren't shared.  COW I/O always takes precedent, so we must always
@@ -265,7 +270,8 @@ xfs_map_blocks(
 	    isnullstartblock(imap.br_startblock))
 		goto allocate_blocks;
 
-	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, XFS_WPC(wpc)->data_seq);
+	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, iomap_flags,
+			  XFS_WPC(wpc)->data_seq);
 	trace_xfs_map_blocks_found(ip, offset, count, whichfork, &imap);
 	return 0;
 allocate_blocks:
@@ -412,12 +418,16 @@ xfs_zoned_map_blocks(
 	xfs_filblks_t		count_fsb;
 	struct xfs_bmbt_irec	imap, del;
 	struct xfs_iext_cursor	icur;
+	u16			iomap_flags = 0;
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
 	XFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * All dirty data must be covered by delalloc extents.  But truncate can
 	 * remove delalloc extents underneath us or reduce their size.
@@ -441,7 +451,7 @@ xfs_zoned_map_blocks(
 		imap.br_startblock = HOLESTARTBLOCK;
 		imap.br_state = XFS_EXT_NORM;
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
-		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, 0);
+		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, iomap_flags, 0);
 		return 0;
 	}
 	end_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount);
@@ -454,7 +464,7 @@ xfs_zoned_map_blocks(
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
 	xfs_iomap_set_anon_write(ip, &wpc->iomap, offset,
-			XFS_FSB_TO_B(mp, count_fsb));
+			XFS_FSB_TO_B(mp, count_fsb), iomap_flags);
 	trace_xfs_zoned_map_blocks(ip, offset, wpc->iomap.length);
 	return 0;
 }
@@ -507,6 +517,22 @@ static const struct iomap_writeback_ops xfs_zoned_writeback_ops = {
 	.writeback_submit	= xfs_zoned_writeback_submit,
 };
 
+static int
+xfs_iomap_writepages(
+	struct xfs_inode		*ip,
+	struct iomap_writepage_ctx	*ctx)
+{
+	/*
+	 * Writeback does not work for folios past EOF, let it know that
+	 * I/O happens for fsverity metadata and this restriction need
+	 * to be skipped
+	 */
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		ctx->iomap.flags |= IOMAP_F_FSVERITY;
+
+	return iomap_writepages(ctx);
+}
+
 STATIC int
 xfs_vm_writepages(
 	struct address_space	*mapping,
@@ -526,7 +552,7 @@ xfs_vm_writepages(
 		};
 		int				error;
 
-		error = iomap_writepages(&xc.ctx);
+		error = xfs_iomap_writepages(ip, &xc.ctx);
 		if (xc.open_zone)
 			xfs_open_zone_put(xc.open_zone);
 		return error;
@@ -539,7 +565,7 @@ xfs_vm_writepages(
 			},
 		};
 
-		return iomap_writepages(&wpc.ctx);
+		return xfs_iomap_writepages(ip, &wpc.ctx);
 	}
 }
 
@@ -585,7 +611,7 @@ xfs_bio_submit_read(
 {
 	xfs_ioend_submit_read(iter->inode, ctx->read_ctx,
 			ctx->read_ctx_file_offset,
-			iomap_ioend_flags(&iter->iomap));
+			iomap_ioend_flags(&iter->iomap), ctx->vi);
 	ctx->read_ctx = NULL;
 }
 
@@ -597,11 +623,13 @@ static const struct iomap_read_ops xfs_iomap_read_ops = {
 
 static inline const struct iomap_read_ops *
 xfs_get_iomap_read_ops(
-	const struct address_space	*mapping)
+	const struct address_space	*mapping,
+	loff_t				pos)
 {
 	struct xfs_inode		*ip = XFS_I(mapping->host);
 
-	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev))
+	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev) ||
+	    xfs_fsverity_is_file_data(ip, pos))
 		return &xfs_iomap_read_ops;
 	return &iomap_bio_read_ops;
 }
@@ -613,7 +641,7 @@ xfs_vm_read_folio(
 {
 	struct iomap_read_folio_ctx	ctx = { .cur_folio = folio };
 
-	ctx.ops = xfs_get_iomap_read_ops(folio->mapping);
+	ctx.ops = xfs_get_iomap_read_ops(folio->mapping, folio_pos(folio));
 	iomap_read_folio(&xfs_read_iomap_ops, &ctx, NULL);
 	return 0;
 }
@@ -624,7 +652,7 @@ xfs_vm_readahead(
 {
 	struct iomap_read_folio_ctx	ctx = { .rac = rac };
 
-	ctx.ops = xfs_get_iomap_read_ops(rac->mapping),
+	ctx.ops = xfs_get_iomap_read_ops(rac->mapping, readahead_pos(rac));
 	iomap_readahead(&xfs_read_iomap_ops, &ctx, NULL);
 }
 
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 865aec3ae5ab32..32cec523fd52d7 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -31,6 +31,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_rtgroup.h"
 #include "xfs_zone_alloc.h"
+#include <linux/fsverity.h>
 
 /* Kernel only BMAP related definitions and functions */
 
@@ -553,6 +554,15 @@ xfs_can_free_eofblocks(
 	if (last_fsb <= end_fsb)
 		return false;
 
+	/*
+	 * Don't clean fsverity inodes as they already have been cleaned up and
+	 * are read-only. Skip inodes which have merkle tree being built, the
+	 * merkle tree is written beyond EOF
+	 */
+	if (fsverity_active(VFS_IC(ip)) ||
+	    xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		return false;
+
 	/*
 	 * Check if there is an post-EOF extent to free.  If there are any
 	 * delalloc blocks attached to the inode (data fork delalloc
@@ -579,6 +589,9 @@ xfs_free_eofblocks(
 	struct xfs_trans	*tp;
 	struct xfs_mount	*mp = ip->i_mount;
 	int			error;
+	int			bmapi_flags = XFS_BMAPI_NODISCARD;
+	bool			has_verity =
+			ip->i_diflags2 & XFS_DIFLAG2_VERITY;
 
 	/* Attach the dquots to the inode up front. */
 	error = xfs_qm_dqattach(ip);
@@ -593,15 +606,20 @@ xfs_free_eofblocks(
 	 *
 	 * 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
 	 */
-	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) {
+	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) ||
+			has_verity) {
 		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);
 		}
 		xfs_inode_clear_eofblocks_tag(ip);
-		return 0;
+		if (!has_verity)
+			return 0;
 	}
 
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
@@ -613,6 +631,13 @@ 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 (has_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
@@ -620,7 +645,7 @@ xfs_free_eofblocks(
 	 * bug).
 	 */
 	error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK,
-				XFS_ISIZE(ip), XFS_BMAPI_NODISCARD);
+				XFS_ISIZE(ip), bmapi_flags);
 	if (error)
 		goto err_cancel;
 
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 7d0c8a197575cf..a610adc90c0289 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -38,6 +38,7 @@
 #include <linux/mount.h>
 #include <linux/filelock.h>
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
 
 static const struct vm_operations_struct xfs_file_vm_ops;
 
@@ -223,7 +224,8 @@ xfs_dio_read_bounce_submit_io(
 	loff_t			file_offset)
 {
 	xfs_ioend_submit_read(iter->inode, bio, file_offset,
-			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT);
+			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT,
+			NULL);
 }
 
 static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
@@ -231,6 +233,25 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
 	.bio_set	= &iomap_ioend_bioset,
 };
 
+STATIC ssize_t
+xfs_file_buffered_read(
+	struct kiocb		*iocb,
+	struct iov_iter		*to)
+{
+	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
+	ssize_t			ret;
+
+	trace_xfs_file_buffered_read(iocb, to);
+
+	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
+	if (ret)
+		return ret;
+	ret = generic_file_read_iter(iocb, to);
+	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+
+	return ret;
+}
+
 STATIC ssize_t
 xfs_file_dio_read(
 	struct kiocb		*iocb,
@@ -249,6 +270,17 @@ xfs_file_dio_read(
 	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
 	if (ret)
 		return ret;
+
+	/*
+	 * Re-check verity status after acquiring lock. This prevents TOCTOU in
+	 * xfs_file_read_iter() while falling back from DIO to buffered I/O as
+	 * now we are holding a lock
+	 */
+	if (fsverity_active(VFS_I(ip))) {
+		xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+		iocb->ki_flags &= ~IOCB_DIRECT;
+		return xfs_file_buffered_read(iocb, to);
+	}
 	if (mapping_stable_writes(iocb->ki_filp->f_mapping)) {
 		ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops,
 				&xfs_dio_read_bounce_ops, 0, NULL, 0);
@@ -268,7 +300,8 @@ xfs_file_dax_read(
 	struct kiocb		*iocb,
 	struct iov_iter		*to)
 {
-	struct xfs_inode	*ip = XFS_I(iocb->ki_filp->f_mapping->host);
+	struct inode		*inode = iocb->ki_filp->f_mapping->host;
+	struct xfs_inode	*ip = XFS_I(inode);
 	ssize_t			ret = 0;
 
 	trace_xfs_file_dax_read(iocb, to);
@@ -286,25 +319,6 @@ xfs_file_dax_read(
 	return ret;
 }
 
-STATIC ssize_t
-xfs_file_buffered_read(
-	struct kiocb		*iocb,
-	struct iov_iter		*to)
-{
-	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
-	ssize_t			ret;
-
-	trace_xfs_file_buffered_read(iocb, to);
-
-	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
-	if (ret)
-		return ret;
-	ret = generic_file_read_iter(iocb, to);
-	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-
-	return ret;
-}
-
 STATIC ssize_t
 xfs_file_read_iter(
 	struct kiocb		*iocb,
@@ -319,6 +333,14 @@ xfs_file_read_iter(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	/*
+	 * In case fs-verity is enabled, we also fallback to the buffered read
+	 * from the direct read path. Therefore, IOCB_DIRECT is set and need to
+	 * be cleared (see generic_file_read_iter())
+	 */
+	if (fsverity_active(inode))
+		iocb->ki_flags &= ~IOCB_DIRECT;
+
 	if (IS_DAX(inode))
 		ret = xfs_file_dax_read(iocb, to);
 	else if (iocb->ki_flags & IOCB_DIRECT)
@@ -1771,11 +1793,18 @@ xfs_file_open(
 	struct inode	*inode,
 	struct file	*file)
 {
+	int		error;
+
 	if (xfs_is_shutdown(XFS_M(inode->i_sb)))
 		return -EIO;
 	file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
 	if (xfs_get_atomic_write_min(XFS_I(inode)) > 0)
 		file->f_mode |= FMODE_CAN_ATOMIC_WRITE;
+
+	error = fsverity_file_open(inode, file);
+	if (error)
+		return error;
+
 	return generic_file_open(inode, file);
 }
 
diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
new file mode 100644
index 00000000000000..9b83a0735dc049
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.c
@@ -0,0 +1,482 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_log_format.h"
+#include "xfs_trans.h"
+#include "xfs_trace.h"
+#include "xfs_quota.h"
+#include "xfs_fsverity.h"
+#include "xfs_iomap.h"
+#include "xfs_error.h"
+#include "xfs_health.h"
+#include "xfs_bmap_util.h"
+#include "xfs_icache.h"
+#include <linux/fsverity.h>
+#include <linux/iomap.h>
+#include <linux/pagemap.h>
+
+struct kmem_cache *xfs_fsverity_ioend_cache;
+mempool_t xfs_fsverity_ioend_pool;
+
+#define XFS_FSVERITY_IOEND_POOL_MIN	128
+
+/*
+ * Back the fsverity ioend allocations with a mempool so that read I/O
+ * completion always makes forward progress and cannot deadlock
+ */
+int
+xfs_fsverity_init(void)
+{
+	return mempool_init_slab_pool(&xfs_fsverity_ioend_pool,
+			XFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);
+}
+
+void
+xfs_fsverity_exit(void)
+{
+	mempool_exit(&xfs_fsverity_ioend_pool);
+}
+
+bool
+xfs_fsverity_is_file_data(
+	const struct xfs_inode	*ip,
+	loff_t			offset)
+{
+	return fsverity_active(VFS_IC(ip)) &&
+			offset < xfs_fsverity_metadata_offset(ip);
+}
+
+/*
+ * Retrieve the verity descriptor.
+ */
+static int
+xfs_fsverity_get_descriptor(
+	struct inode		*inode,
+	void			*buf,
+	size_t			buf_size)
+{
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	__be32			d_desc_size;
+	u32			desc_size;
+	u64			desc_size_pos;
+	int			error;
+	u64			desc_pos;
+	struct xfs_bmbt_irec	rec;
+	int			is_empty;
+	uint32_t		blocksize = i_blocksize(VFS_I(ip));
+	xfs_fileoff_t		last_block_offset;
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	/*
+	 * Serialize reading of inode->i_flags with xfs_scrub clearing of this
+	 * flag if inode is corrupted.
+	 */
+	if (!(inode->i_flags & S_VERITY)) {
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		return -ENODATA;
+	}
+	error = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, &rec, &is_empty);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		return error;
+
+	if (is_empty) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	last_block_offset =
+		XFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);
+	if (last_block_offset <= xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	desc_size_pos = last_block_offset - sizeof(__be32);
+	error = fsverity_pagecache_read(inode, (char *)&d_desc_size,
+			sizeof(d_desc_size), desc_size_pos);
+	if (error)
+		return error;
+
+	desc_size = be32_to_cpu(d_desc_size);
+	if (XFS_IS_CORRUPT(mp, desc_size > FS_VERITY_MAX_DESCRIPTOR_SIZE)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (XFS_IS_CORRUPT(mp, desc_size > desc_size_pos)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (!buf_size)
+		return desc_size;
+
+	if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	desc_pos = round_down(desc_size_pos - desc_size, blocksize);
+	if (desc_pos < xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
+	if (error)
+		return error;
+
+	return desc_size;
+}
+
+static int
+xfs_fsverity_write_descriptor(
+	struct file		*file,
+	const void		*desc,
+	u32			desc_size,
+	u64			merkle_tree_size)
+{
+	int			error;
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	unsigned int		blksize = ip->i_mount->m_sb.sb_blocksize;
+	u64			tree_last_block =
+			xfs_fsverity_metadata_offset(ip) + merkle_tree_size;
+	u64			desc_pos =
+			round_up(tree_last_block, XFS_FSVERITY_START_ALIGN);
+	u64			desc_end = desc_pos + desc_size;
+	__be32			desc_size_disk = cpu_to_be32(desc_size);
+	u64			desc_size_pos =
+			round_up(desc_end + sizeof(desc_size_disk), blksize) -
+			sizeof(desc_size_disk);
+
+	error = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),
+			(const void *)&desc_size_disk,
+			&xfs_buffered_write_iomap_ops,
+			&xfs_iomap_write_ops);
+	if (error)
+		return error;
+
+	return iomap_fsverity_write(file, desc_pos, desc_size, desc,
+			&xfs_buffered_write_iomap_ops,
+			&xfs_iomap_write_ops);
+}
+
+/*
+ * Try to remove all the fsverity metadata after a failed enablement.
+ */
+static int
+xfs_fsverity_delete_metadata(
+	struct xfs_inode	*ip)
+{
+	struct xfs_trans	*tp;
+	struct xfs_mount	*mp = ip->i_mount;
+	int			error;
+
+	xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
+	truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
+
+	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
+	if (error) {
+		xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
+		return error;
+	}
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, ip, 0);
+
+	/*
+	 * We remove post EOF data, no need to update i_size as fsverity
+	 * didn't move i_size in the first place
+	 */
+	error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));
+	if (error)
+		goto err_cancel;
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+err_cancel:
+	xfs_trans_cancel(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+}
+
+static int
+xfs_fsverity_reset_inode(
+	struct xfs_inode	*ip)
+{
+	int			error;
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+
+	error = xfs_fsverity_delete_metadata(ip);
+	if (error)
+		return error;
+
+	/*
+	 * First, let's clean in-memory fsverity flag and then reset it on the
+	 * disk
+	 */
+	inode_set_flags(VFS_I(ip), 0, S_VERITY);
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		return error;
+
+	ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return error;
+}
+
+/*
+ * Prepare to enable fsverity by clearing old metadata.
+ */
+static int
+xfs_fsverity_begin_enable(
+	struct file		*filp)
+{
+	struct inode		*inode = file_inode(filp);
+	struct xfs_inode	*ip = XFS_I(inode);
+	int			error;
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	if (IS_DAX(inode) || ip->i_diflags2 & XFS_DIFLAG2_DAX)
+		return -EINVAL;
+
+	/*
+	 * fs-verity stores the Merkle tree past EOF in units of the filesystem
+	 * block size, so it cannot support realtime files whose allocation unit
+	 * (extent size) is larger than the block size.
+	 */
+	if (xfs_inode_has_bigrtalloc(ip))
+		return -EINVAL;
+
+	if (inode->i_size > XFS_FSVERITY_LARGEST_FILE)
+		return -EFBIG;
+
+	/*
+	 * Flush pagecache before building Merkle tree. Inode is locked and no
+	 * further writes will happen to the file except fsverity metadata
+	 */
+	error = filemap_write_and_wait(inode->i_mapping);
+	if (error)
+		return error;
+
+	if (xfs_iflags_test_and_set(ip, XFS_VERITY_CONSTRUCTION))
+		return -EBUSY;
+
+	error = xfs_qm_dqattach(ip);
+	if (error)
+		goto out_clear;
+
+	error = xfs_fsverity_delete_metadata(ip);
+	if (error)
+		goto out_clear;
+	return error;
+out_clear:
+	xfs_iflags_clear(ip, XFS_VERITY_CONSTRUCTION);
+	return error;
+}
+
+/*
+ * Complete (or fail) the process of enabling fsverity.
+ */
+static int
+xfs_fsverity_end_enable(
+	struct file		*file,
+	const void		*desc,
+	size_t			desc_size,
+	u64			merkle_tree_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+	int			error = 0;
+	loff_t			range_start = xfs_fsverity_metadata_offset(ip);
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	/* fs-verity failed, just cleanup */
+	if (desc == NULL)
+		goto out;
+
+	error = xfs_fsverity_write_descriptor(file, desc, desc_size,
+			merkle_tree_size);
+	if (error)
+		goto out;
+
+	/*
+	 * Wait for Merkle tree get written to disk before setting on-disk inode
+	 * flag and clearing XFS_VERITY_CONSTRUCTION
+	 */
+	error = filemap_write_and_wait_range(inode->i_mapping, range_start,
+			LLONG_MAX);
+	if (error)
+		goto out;
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		goto out;
+
+	/*
+	 * Ensure that we've persisted the verity information before we enable
+	 * it on the inode and tell the caller we have sealed the inode.
+	 */
+	ip->i_diflags2 |= XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		goto out;
+
+	inode_set_flags(inode, S_VERITY, S_VERITY);
+
+	/*
+	 * Proactively remove unwritten extents left by COW preallocations and
+	 * write preallocation in the merkle tree holes and past descriptor,
+	 * and any delayed preallocations
+	 */
+	error = xfs_free_eofblocks(ip);
+out:
+	if (error) {
+		int	error2;
+
+		error2 = xfs_fsverity_reset_inode(ip);
+		if (error2)
+			xfs_alert(ip->i_mount,
+"ino 0x%llx failed to clean up new fsverity metadata, err %d",
+					I_INO(ip), error2);
+	}
+
+	xfs_iflags_clear(ip, XFS_VERITY_CONSTRUCTION);
+	return error;
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static struct page *
+xfs_fsverity_read_merkle(
+	struct inode		*inode,
+	pgoff_t			index)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	return generic_read_merkle_tree_page(inode, index);
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static void
+xfs_fsverity_readahead_merkle_tree(
+	struct inode		*inode,
+	pgoff_t			index,
+	unsigned long		nr_pages)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	generic_readahead_merkle_tree(inode, index, nr_pages);
+}
+
+static inline bool
+xfs_fsverity_is_hashes_of_zeroed_blocks(
+	struct xfs_inode	*ip,
+	const void		*buf,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	/*
+	 * If this is a block full of hashes of zeroed blocks, don't bother
+	 * storing the block. We can synthesize them later.
+	 *
+	 * However, do this only in case Merkle tree block == fs block size.
+	 * Iomap synthesizes these blocks based on holes in the merkle tree. We
+	 * won't be able to tell if something need to be synthesizes for the
+	 * range in the fs block. For example, for 4k filesystem block
+	 *
+	 *	[ 1k | zero hashes | zero hashes | 1k ]
+	 *
+	 * Iomap won't know about these empty blocks.
+	 */
+	if (size != ip->i_mount->m_sb.sb_blocksize)
+		return false;
+	/*
+	 * First digest is zero_digest
+	 */
+	if (memcmp(buf, zero_digest, digest_size))
+		return false;
+	/*
+	 * Every digest is same as previous, thus all are
+	 * zero_digest
+	 */
+	return memcmp(buf + digest_size, buf, size - digest_size) == 0;
+}
+
+/*
+ * Write a merkle tree block.
+ */
+static int
+xfs_fsverity_write_merkle(
+	struct file		*file,
+	const void		*buf,
+	u64			pos,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	loff_t			position = pos +
+		xfs_fsverity_metadata_offset(ip);
+
+	if (position + size > inode->i_sb->s_maxbytes)
+		return -EFBIG;
+
+	if (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,
+						    digest_size))
+		return 0;
+
+	return iomap_fsverity_write(file, position, size, buf,
+			&xfs_buffered_write_iomap_ops,
+			&xfs_iomap_write_ops);
+}
+
+const struct fsverity_operations xfs_fsverity_ops = {
+	.begin_enable_verity		= xfs_fsverity_begin_enable,
+	.end_enable_verity		= xfs_fsverity_end_enable,
+	.get_verity_descriptor		= xfs_fsverity_get_descriptor,
+	.read_merkle_tree_page		= xfs_fsverity_read_merkle,
+	.readahead_merkle_tree		= xfs_fsverity_readahead_merkle_tree,
+	.write_merkle_tree_block	= xfs_fsverity_write_merkle,
+};
diff --git a/fs/xfs/xfs_fsverity.h b/fs/xfs/xfs_fsverity.h
new file mode 100644
index 00000000000000..43f8ef62e12a1a
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.h
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_FSVERITY_H__
+#define __XFS_FSVERITY_H__
+
+#include "xfs_platform.h"
+#include "xfs_verity.h"
+#include <linux/iomap.h>
+#include <linux/fsverity.h>
+#include <linux/mempool.h>
+
+#ifdef CONFIG_FS_VERITY
+extern const struct fsverity_operations xfs_fsverity_ops;
+int xfs_fsverity_init(void);
+void xfs_fsverity_exit(void);
+bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset);
+#else
+static inline int xfs_fsverity_init(void)
+{
+	return 0;
+}
+static inline void xfs_fsverity_exit(void)
+{
+}
+static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,
+					    loff_t offset)
+{
+	return false;
+}
+#endif	/* CONFIG_FS_VERITY */
+
+struct xfs_fsverity_ioend {
+	struct iomap_ioend	*ioend;
+	struct work_struct	work;
+};
+
+extern struct kmem_cache *xfs_fsverity_ioend_cache;
+extern mempool_t xfs_fsverity_ioend_pool;
+
+#endif	/* __XFS_FSVERITY_H__ */
diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
index 239b843e83d42a..be66760fb120f7 100644
--- a/fs/xfs/xfs_health.c
+++ b/fs/xfs/xfs_health.c
@@ -625,6 +625,7 @@ static const struct ioctl_sick_map ino_map[] = {
 	{ XFS_SICK_INO_DIR_ZAPPED,	XFS_BS_SICK_DIR },
 	{ XFS_SICK_INO_SYMLINK_ZAPPED,	XFS_BS_SICK_SYMLINK },
 	{ XFS_SICK_INO_DIRTREE,	XFS_BS_SICK_DIRTREE },
+	{ XFS_SICK_INO_FSVERITY,	XFS_BS_SICK_FSVERITY },
 };
 
 /* Fill out bulkstat health info. */
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index 75eff68c1e3950..034d3f6072a932 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -428,6 +428,12 @@ static inline bool xfs_inode_can_sw_atomic_write(const struct xfs_inode *ip)
  */
 #define XFS_IREMAPPING		(1U << 15)
 
+/*
+ * fs-verity's Merkle tree is under construction. The file is read-only, the
+ * only writes happening are for the fsverity metadata.
+ */
+#define XFS_VERITY_CONSTRUCTION	(1U << 16)
+
 /* All inode state flags related to inode reclaim. */
 #define XFS_ALL_IRECLAIM_FLAGS	(XFS_IRECLAIMABLE | \
 				 XFS_IRECLAIM | \
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index f81b6e52ac403d..37c6a2fae58cc0 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -49,6 +49,7 @@
 
 #include <linux/mount.h>
 #include <linux/fileattr.h>
+#include <linux/fsverity.h>
 
 /* Return 0 on success or positive error */
 int
@@ -1575,6 +1576,19 @@ xfs_file_ioctl(
 	case XFS_IOC_VERIFY_MEDIA:
 		return xfs_ioc_verify_media(filp, arg);
 
+	case FS_IOC_ENABLE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_enable(filp, arg);
+	case FS_IOC_MEASURE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_measure(filp, arg);
+	case FS_IOC_READ_VERITY_METADATA:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_read_metadata(filp, arg);
+
 	default:
 		return -ENOTTY;
 	}
diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c
index 48becc3bf60889..d30aee973a876a 100644
--- a/fs/xfs/xfs_ioend.c
+++ b/fs/xfs/xfs_ioend.c
@@ -18,7 +18,26 @@
 #include "xfs_ioend.h"
 #include "xfs_error.h"
 #include "xfs_errortag.h"
+#include "xfs_fsverity.h"
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
+
+static void
+xfs_end_fsverity_io_read(
+	struct work_struct		*work)
+{
+	struct xfs_fsverity_ioend	*fsv_ioend =
+			container_of(work, struct xfs_fsverity_ioend, work);
+	struct iomap_ioend		*ioend = fsv_ioend->ioend;
+	struct bio			*bio = &ioend->io_bio;
+
+	mempool_free(fsv_ioend, &xfs_fsverity_ioend_pool);
+
+	if (!bio->bi_status)
+		fsverity_verify_bio(ioend->io_vi, bio);
+
+	iomap_finish_ioends(ioend, blk_status_to_errno(bio->bi_status));
+}
 
 static void
 xfs_dio_bounce_end_io(
@@ -93,12 +112,14 @@ xfs_read_bounce_and_resubmit(
 
 static void
 xfs_end_io_read(
-	struct bio		*bio)
+	struct bio			*bio)
 {
-	struct iomap_ioend	*ioend = iomap_ioend_from_bio(bio);
-	struct xfs_inode	*ip = XFS_I(ioend->io_inode);
-	struct xfs_mount	*mp = ip->i_mount;
-	int			error = blk_status_to_errno(bio->bi_status);
+	struct iomap_ioend		*ioend = iomap_ioend_from_bio(bio);
+	struct xfs_inode		*ip = XFS_I(ioend->io_inode);
+	struct xfs_mount		*mp = ip->i_mount;
+	int				error =
+			blk_status_to_errno(bio->bi_status);
+	struct xfs_fsverity_ioend	*fsv_ioend;
 
 	if (!error && (ioend->io_flags & IOMAP_IOEND_INTEGRITY)) {
 		error = iomap_ioend_integrity_verify(ioend);
@@ -117,6 +138,24 @@ xfs_end_io_read(
 		}
 	}
 
+	/*
+	 * If we have fsverity on this bio, we need to run fsverity verification
+	 * of data folios from a separate fsverity workqueue. This is necessary
+	 * to avoid deadlocking due to fsverity issuing more reads of fsverity
+	 * metadata which would be processed by the same worker in the BIO
+	 * completion workqueue.
+	 */
+	if (IS_ENABLED(CONFIG_FS_VERITY) && !error && ioend->io_vi &&
+			xfs_fsverity_is_file_data(ip, ioend->io_offset)) {
+		fsv_ioend = mempool_alloc(&xfs_fsverity_ioend_pool,
+				GFP_NOFS);
+		fsv_ioend->ioend = ioend;
+		INIT_WORK(&fsv_ioend->work, xfs_end_fsverity_io_read);
+
+		fsverity_enqueue_verify_work(&fsv_ioend->work);
+		return;
+	}
+
 	iomap_finish_ioends(ioend, error);
 }
 
@@ -125,13 +164,15 @@ xfs_ioend_submit_read(
 	struct inode		*inode,
 	struct bio		*bio,
 	loff_t			file_offset,
-	u16			ioend_flags)
+	u16			ioend_flags,
+	struct fsverity_info	*vi)
 {
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	struct iomap_ioend	*ioend;
 
 	ioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags);
+	ioend->io_vi = vi;
 	if ((ioend_flags & IOMAP_IOEND_DIRECT) &&
 	    READ_ONCE(mp->m_read_bounce) == XFS_READ_BOUNCE_ALWAYS) {
 		iomap_bounce_read(ioend, bdev_logical_block_size(bio->bi_bdev),
diff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h
index 7c2a1ea3e6eddc..992c248a693aaf 100644
--- a/fs/xfs/xfs_ioend.h
+++ b/fs/xfs/xfs_ioend.h
@@ -2,6 +2,8 @@
 #ifndef __XFS_IOEND_H
 #define __XFS_IOEND_H
 
+#include <linux/fsverity.h>
+
 /*
  * Fast and loose check if this write could update the on-disk inode size.
  */
@@ -13,6 +15,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)
 
 void xfs_end_bio(struct bio *bio);
 void xfs_ioend_submit_read(struct inode *inode, struct bio *bio,
-		loff_t file_offset, u16 ioend_flags);
+		loff_t file_offset, u16 ioend_flags, struct fsverity_info *vi);
 
 #endif /* __XFS_IOEND_H */
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 329c745e312045..68fef657644202 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -32,6 +32,8 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_icache.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_verity.h"
+#include <linux/fsverity.h>
 
 #define XFS_ALLOC_ALIGN(mp, off) \
 	(((off) >> mp->m_allocsize_log) << mp->m_allocsize_log)
@@ -883,6 +885,9 @@ xfs_direct_write_iomap_begin(
 	if (flags & IOMAP_ATOMIC)
 		iomap_flags |= IOMAP_F_ATOMIC_BIO;
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * COW writes may allocate delalloc space or convert unwritten COW
 	 * extents, so we need to make sure to take the lock exclusively here.
@@ -1023,7 +1028,8 @@ xfs_direct_write_iomap_begin(
 	trace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, &cmap);
 	if (imap.br_startblock != HOLESTARTBLOCK) {
 		seq = xfs_iomap_inode_sequence(ip, 0);
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0, seq);
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags,
+				iomap_flags & IOMAP_F_FSVERITY, seq);
 		if (error)
 			goto out_unlock;
 	}
@@ -1083,7 +1089,7 @@ xfs_zoned_direct_write_iomap_begin(
 			return error;
 	}
 
-	xfs_iomap_set_anon_write(ip, iomap, offset, length);
+	xfs_iomap_set_anon_write(ip, iomap, offset, length, 0);
 	return 0;
 }
 
@@ -1594,7 +1600,8 @@ xfs_zoned_fill_srcmap(
 	xfs_fileoff_t		offset_fsb,
 	xfs_fileoff_t		*end_fsb,
 	unsigned		flags,
-	struct iomap		*srcmap)
+	struct iomap		*srcmap,
+	u16			iomap_flags)
 {
 	struct xfs_bmbt_irec	smap;
 	struct xfs_iext_cursor	scur;
@@ -1615,7 +1622,7 @@ xfs_zoned_fill_srcmap(
 	 */
 	xfs_trim_extent(&smap, offset_fsb, *end_fsb - offset_fsb);
 	*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);
-	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, 0,
+	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, iomap_flags,
 			xfs_iomap_inode_sequence(ip, 0));
 }
 
@@ -1626,7 +1633,8 @@ xfs_zoned_buffered_write_iomap_begin(
 	loff_t			count,
 	unsigned		flags,
 	struct iomap		*iomap,
-	struct iomap		*srcmap)
+	struct iomap		*srcmap,
+	u16			iomap_flags)
 {
 	struct iomap_iter	*iter =
 		container_of(iomap, struct iomap_iter, iomap);
@@ -1636,7 +1644,6 @@ xfs_zoned_buffered_write_iomap_begin(
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
 	xfs_fileoff_t		end_fsb = xfs_iomap_end_fsb(mp, offset, count);
-	u16			iomap_flags = IOMAP_F_SHARED;
 	unsigned int		lockmode = XFS_ILOCK_EXCL;
 	xfs_filblks_t		count_fsb;
 	xfs_extlen_t		indlen;
@@ -1687,7 +1694,7 @@ xfs_zoned_buffered_write_iomap_begin(
 	    !IS_ALIGNED(offset + count, mp->m_sb.sb_blocksize) ||
 	    (flags & IOMAP_ZERO)) {
 		error = xfs_zoned_fill_srcmap(ip, offset_fsb, &end_fsb, flags,
-				srcmap);
+				srcmap, iomap_flags);
 		if (error)
 			goto out_unlock;
 	}
@@ -1695,6 +1702,8 @@ xfs_zoned_buffered_write_iomap_begin(
 	if (!ip->i_cowfp)
 		xfs_ifork_init_cow(ip);
 
+	iomap_flags |= IOMAP_F_SHARED;
+
 	if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &got))
 		got.br_startoff = end_fsb;
 	if (got.br_startoff <= offset_fsb) {
@@ -1826,9 +1835,12 @@ xfs_buffered_write_iomap_begin(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	if (xfs_is_zoned_inode(ip))
 		return xfs_zoned_buffered_write_iomap_begin(inode, offset,
-				count, flags, iomap, srcmap);
+				count, flags, iomap, srcmap, iomap_flags);
 
 	/* we can't use delayed allocations when using extent size hints */
 	if (xfs_get_extsz_hint(ip))
@@ -2112,7 +2124,8 @@ xfs_buffered_write_iomap_begin(
 
 found_cow:
 	if (imap.br_startoff <= offset_fsb) {
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0,
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags,
+				iomap_flags & IOMAP_F_FSVERITY,
 				xfs_iomap_inode_sequence(ip, 0));
 		if (error)
 			goto out_unlock;
@@ -2216,12 +2229,17 @@ xfs_read_iomap_begin(
 	bool			shared = false;
 	unsigned int		lockmode = XFS_ILOCK_SHARED;
 	u64			seq;
+	unsigned int		iomap_flags = 0;
 
 	ASSERT(!(flags & (IOMAP_WRITE | IOMAP_ZERO)));
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	if (fsverity_active(inode) &&
+	    (offset >= xfs_fsverity_metadata_offset(ip)))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	error = xfs_ilock_for_iomap(ip, flags, &lockmode);
 	if (error)
 		return error;
@@ -2235,8 +2253,9 @@ xfs_read_iomap_begin(
 	if (error)
 		return error;
 	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags,
-				 shared ? IOMAP_F_SHARED : 0, seq);
+	iomap_flags |= shared ? IOMAP_F_SHARED : 0;
+
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
 }
 
 static DEFINE_IOMAP_ITER_NEXT(xfs_read_iomap_next, xfs_read_iomap_begin);
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
index f2520a9b3a13e6..d3ca0f2afc9f79 100644
--- a/fs/xfs/xfs_iomap.h
+++ b/fs/xfs/xfs_iomap.h
@@ -34,13 +34,14 @@ xfs_iomap_set_anon_write(
 	struct xfs_inode		*ip,
 	struct iomap			*iomap,
 	loff_t				offset,
-	loff_t				length)
+	loff_t				length,
+	u16				iomap_flags)
 {
 	iomap->type = IOMAP_MAPPED;
 	iomap->bdev = ip->i_mount->m_rtdev_targp->bt_bdev;
 	iomap->offset = offset;
 	iomap->length = length;
-	iomap->flags = IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
+	iomap->flags = iomap_flags | IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
 	if (bdev_has_integrity_csum(iomap->bdev))
 		iomap->flags |= IOMAP_F_INTEGRITY;
 }
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index d307ec97fac820..150bbd705807f0 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -35,6 +35,7 @@
 #include <linux/security.h>
 #include <linux/iversion.h>
 #include <linux/fiemap.h>
+#include <linux/fsverity.h>
 
 /*
  * Directories have different lock order w.r.t. mmap_lock compared to regular
@@ -579,6 +580,10 @@ xfs_report_dioalign(
 	struct block_device	*bdev = target->bt_bdev;
 
 	stat->result_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;
+
+	if (fsverity_active(VFS_I(ip)))
+		return;
+
 	stat->dio_mem_align = bdev_dma_alignment(bdev) + 1;
 
 	/*
@@ -1387,6 +1392,8 @@ xfs_inode_should_enable_dax(
 		return false;
 	if (!xfs_inode_supports_dax(ip))
 		return false;
+	if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+		return false;
 	if (xfs_has_dax_always(ip->i_mount))
 		return true;
 	if (ip->i_diflags2 & XFS_DIFLAG2_DAX)
@@ -1415,12 +1422,15 @@ xfs_diflags_to_iflags(
 		flags |= S_NOATIME;
 	if (init && xfs_inode_should_enable_dax(ip))
 		flags |= S_DAX;
+	if (xflags & FS_XFLAG_VERITY)
+		flags |= S_VERITY;
 
 	/*
 	 * S_DAX can only be set during inode initialization and is never set by
 	 * the VFS, so we cannot mask off S_DAX in i_flags.
 	 */
-	inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
+	inode->i_flags &=
+		~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME | S_VERITY);
 	inode->i_flags |= flags;
 }
 
diff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c
index 0243e509a46891..44b13d46049c62 100644
--- a/fs/xfs/xfs_message.c
+++ b/fs/xfs/xfs_message.c
@@ -149,6 +149,10 @@ xfs_warn_experimental(
 			.opstate	= XFS_OPSTATE_WARNED_LARP,
 			.name		= "logged extended attributes",
 		},
+		[XFS_EXPERIMENTAL_FSVERITY] = {
+			.opstate	= XFS_OPSTATE_WARNED_FSVERITY,
+			.name		= "fsverity",
+		},
 	};
 	ASSERT(feat >= 0 && feat < XFS_EXPERIMENTAL_MAX);
 	BUILD_BUG_ON(ARRAY_SIZE(features) != XFS_EXPERIMENTAL_MAX);
diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h
index 811b885f41c35a..364fcc7e42b084 100644
--- a/fs/xfs/xfs_message.h
+++ b/fs/xfs/xfs_message.h
@@ -93,6 +93,7 @@ void xfs_buf_alert_ratelimited(struct xfs_buf *bp, const char *rlmsg,
 enum xfs_experimental_feat {
 	XFS_EXPERIMENTAL_SHRINK,
 	XFS_EXPERIMENTAL_LARP,
+	XFS_EXPERIMENTAL_FSVERITY,
 
 	XFS_EXPERIMENTAL_MAX,
 };
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index cbcfb89c67a440..0b64636635996f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -403,6 +403,7 @@ typedef struct xfs_mount {
 #define XFS_FEAT_EXCHANGE_RANGE	(1ULL << 27)	/* exchange range */
 #define XFS_FEAT_METADIR	(1ULL << 28)	/* metadata directory tree */
 #define XFS_FEAT_ZONED		(1ULL << 29)	/* zoned RT device */
+#define XFS_FEAT_VERITY		(1ULL << 30)	/* fs-verity */
 
 /* Mount features */
 #define XFS_FEAT_NOLIFETIME	(1ULL << 47)	/* disable lifetime hints */
@@ -460,6 +461,7 @@ __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE)
 __XFS_HAS_FEAT(metadir, METADIR)
 __XFS_HAS_FEAT(zoned, ZONED)
 __XFS_HAS_FEAT(nolifetime, NOLIFETIME)
+__XFS_HAS_FEAT(verity, VERITY)
 
 static inline bool xfs_has_rtgroups(const struct xfs_mount *mp)
 {
@@ -597,6 +599,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)
 #define XFS_OPSTATE_RESUMING_QUOTAON	18
 /* (Zoned) GC is in progress */
 #define XFS_OPSTATE_ZONEGC_RUNNING	20
+/* Kernel has logged a warning about fsverity support */
+#define XFS_OPSTATE_WARNED_FSVERITY	21
 
 #define __XFS_IS_OPSTATE(name, NAME) \
 static inline bool xfs_is_ ## name (struct xfs_mount *mp) \
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 5a06132aa38466..af679b6ab52b32 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -30,6 +30,7 @@
 #include "xfs_filestream.h"
 #include "xfs_quota.h"
 #include "xfs_sysfs.h"
+#include "xfs_fsverity.h"
 #include "xfs_ondisk.h"
 #include "xfs_rmap_item.h"
 #include "xfs_refcount_item.h"
@@ -1736,6 +1737,9 @@ xfs_fs_fill_super(
 	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
 #endif
 	sb->s_op = &xfs_super_operations;
+#ifdef CONFIG_FS_VERITY
+	sb->s_vop = &xfs_fsverity_ops;
+#endif
 
 	/*
 	 * Delay mount work if the debug hook is set. This is debug
@@ -1988,6 +1992,9 @@ xfs_fs_fill_super(
 	if (error)
 		goto out_filestream_unmount;
 
+	if (xfs_has_verity(mp))
+		xfs_warn_experimental(mp, XFS_EXPERIMENTAL_FSVERITY);
+
 	root = igrab(VFS_I(mp->m_rootip));
 	if (!root) {
 		error = -ENOENT;
@@ -2516,8 +2523,20 @@ xfs_init_caches(void)
 	if (!xfs_parent_args_cache)
 		goto out_destroy_xmi_cache;
 
+#ifdef CONFIG_FS_VERITY
+	xfs_fsverity_ioend_cache = kmem_cache_create("xfs_fsverity_ioend",
+					     sizeof(struct xfs_fsverity_ioend),
+					     0, 0, NULL);
+	if (!xfs_fsverity_ioend_cache)
+		goto out_destroy_parent_args_cache;
+#endif
+
 	return 0;
 
+#ifdef CONFIG_FS_VERITY
+ out_destroy_parent_args_cache:
+	kmem_cache_destroy(xfs_parent_args_cache);
+#endif
  out_destroy_xmi_cache:
 	kmem_cache_destroy(xfs_xmi_cache);
  out_destroy_xmd_cache:
@@ -2580,6 +2599,9 @@ xfs_destroy_caches(void)
 	 * destroy caches.
 	 */
 	rcu_barrier();
+#ifdef CONFIG_FS_VERITY
+	kmem_cache_destroy(xfs_fsverity_ioend_cache);
+#endif
 	kmem_cache_destroy(xfs_parent_args_cache);
 	kmem_cache_destroy(xfs_xmd_cache);
 	kmem_cache_destroy(xfs_xmi_cache);
@@ -2660,10 +2682,14 @@ init_xfs_fs(void)
 	if (error)
 		goto out;
 
-	error = xfs_init_workqueues();
+	error = xfs_fsverity_init();
 	if (error)
 		goto out_destroy_caches;
 
+	error = xfs_init_workqueues();
+	if (error)
+		goto out_fsverity_exit;
+
 	error = xfs_mru_cache_init();
 	if (error)
 		goto out_destroy_wq;
@@ -2740,6 +2766,8 @@ init_xfs_fs(void)
 	xfs_mru_cache_uninit();
  out_destroy_wq:
 	xfs_destroy_workqueues();
+ out_fsverity_exit:
+	xfs_fsverity_exit();
  out_destroy_caches:
 	xfs_destroy_caches();
  out:
@@ -2763,6 +2791,7 @@ exit_xfs_fs(void)
 	xfs_cleanup_procfs();
 	xfs_mru_cache_uninit();
 	xfs_destroy_workqueues();
+	xfs_fsverity_exit();
 	xfs_destroy_caches();
 	xfs_uuid_table_free();
 }

3/2 2026/11/03 04:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29859
							output: 49
							thoughts: 1018
						

Thoughts:
**Fuzzing Candidate: XFS fs-verity Support**

Okay, let's dive into this patch. My immediate thought is, "XFS *and* fs-verity? This is potentially *very* interesting from a fuzzing perspective."

First, I need to understand what this patch actually *does*. It looks like it's integrating fs-verity support into the XFS filesystem. And the modified files are quite extensive, touching core XFS components like bmap, inode handling, scrub/repair routines, and ioctl implementations. Essentially it's a deep dive into supporting fs-verity within XFS.

From a quick glance, it's implementing ioctl handlers for enabling, measuring, and reading verity metadata, along with the full set of `fsverity_operations`, read and write path changes to support fs-verity data and metadata. It's also integrating verity into scrubbing, online repair, disk format verification, writeback, and file reading. This involves substantial changes in multiple layers of the filesystem!

The core question is, "Is XFS a good target for syzkaller?" And the answer is a resounding "YES!" XFS is a well-established filesystem, easily set up, and extensively fuzzed. It's readily accessible in standard virtualized environments like QEMU, making it an ideal target.

So, is it worth fuzzing? Absolutely! This is a significant addition, introducing new code paths and complexity within a core filesystem component. The integration of fs-verity, especially the Merkle tree operations, extent mapping, and verification, means a high likelihood of finding new bugs via fuzzing. This level of filesystem integration means there is a good chance of finding bugs which are serious in nature.

Now, before I start building fuzzing campaigns, let's double-check the Kconfig options. It is important to ensure that the required configuration options for both XFS and FS_VERITY are enabled in the fuzzing environment. I will use `grepper` to quickly determine what Kconfig settings are required to enable all the relevant components. I need to make sure that the fuzzing config enables all the newly added code.



4/2 2026/11/03 04:02 tool grepper
0m Args:
{
  "Expression": "config XFS_FS|config FS_VERITY",
  "PathPrefixes": [
    "fs/xfs/Kconfig",
    "fs/verity/Kconfig"
  ]
}

Results:
{
  "Output": "fs/verity/Kconfig-2-\nfs/verity/Kconfig:3:config FS_VERITY\nfs/verity/Kconfig-4-\tbool \"FS Verity (read-only file-based authenticity protection)\"\n--\nfs/verity/Kconfig-33-\nfs/verity/Kconfig:34:config FS_VERITY_BUILTIN_SIGNATURES\nfs/verity/Kconfig-35-\tbool \"FS Verity builtin signature support\"\n--\nfs/xfs/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/xfs/Kconfig:2:config XFS_FS\nfs/xfs/Kconfig-3-\ttristate \"XFS filesystem support\"\n"
}

5/2 2026/11/03 04:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31575
							output: 28
							thoughts: 106
						

Thoughts:
**XFS Verity Configuration Analysis**

Okay, let's dive into this. I need to figure out how XFS handles file system verity, specifically if it has its own dedicated option or if it leverages the core FS_VERITY infrastructure. My first stop is going to be `fs/xfs/Kconfig`. I'll look for anything related to XFS_VERITY, or whether it directly uses `FS_VERITY`. Then, I'll need to confirm how the module is built via the `Makefile`. Looking ahead, I suspect, based on the presence of `libxfs/xfs_verity.o`, that it's using the core verity code. The `Makefile` lines:
`xfs-$(CONFIG_FS_VERITY)		+= xfs_fsverity.o`
`xfs-y				+= ... libxfs/xfs_verity.o`
appear to confirm my suspicions that there is conditional compilation based on the CONFIG_FS_VERITY setting. To be thorough, I'll also need to carefully examine `fs/xfs/Kconfig` to identify any other configurations that could potentially interact with or impact the verity implementation.



6/2 2026/11/03 04:02 tool grepper
0m Args:
{
  "Expression": "VERITY",
  "PathPrefixes": [
    "fs/xfs/"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 413 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (26 files in total):\nfs/xfs/Makefile:1\nfs/xfs/libxfs/xfs_bmap.c:4\nfs/xfs/libxfs/xfs_format.h:7\nfs/xfs/libxfs/xfs_fs.h:2\nfs/xfs/libxfs/xfs_health.h:2\nfs/xfs/libxfs/xfs_inode_buf.c:1\nfs/xfs/libxfs/xfs_inode_util.c:3\nfs/xfs/libxfs/xfs_sb.c:3\nfs/xfs/libxfs/xfs_verity.c:1\nfs/xfs/libxfs/xfs_verity.h:3\nfs/xfs/scrub/common.c:1\nfs/xfs/scrub/inode_repair.c:3\nfs/xfs/xfs_aops.c:6\nfs/xfs/xfs_bmap_util.c:2\nfs/xfs/xfs_fsverity.c:20\nfs/xfs/xfs_fsverity.h:5\nfs/xfs/xfs_health.c:1\nfs/xfs/xfs_inode.h:1\nfs/xfs/xfs_ioctl.c:3\nfs/xfs/xfs_ioend.c:1\nfs/xfs/xfs_iomap.c:7\nfs/xfs/xfs_iops.c:4\nfs/xfs/xfs_message.c:2\nfs/xfs/xfs_message.h:1\nfs/xfs/xfs_mount.h:3\nfs/xfs/xfs_super.c:5\n\nfs/xfs/Makefile=153=xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)\t+= xfs_pnfs.o\nfs/xfs/Makefile:154:xfs-$(CONFIG_FS_VERITY)\t\t+= xfs_fsverity.o\nfs/xfs/Makefile-155-\n--\nfs/xfs/libxfs/xfs_bmap.c=4356=xfs_bmapi_convert_one_delalloc(\n--\nfs/xfs/libxfs/xfs_bmap.c-4407-\tif (!isnullstartblock(bma.got.br_startblock)) {\nfs/xfs/libxfs/xfs_bmap.c:4408:\t\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) \u0026\u0026\nfs/xfs/libxfs/xfs_bmap.c-4409-\t\t    offset \u003e= xfs_fsverity_metadata_offset(ip))\nfs/xfs/libxfs/xfs_bmap.c:4410:\t\t\tflags |= IOMAP_F_FSVERITY;\nfs/xfs/libxfs/xfs_bmap.c-4411-\t\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, 0, flags,\n--\nfs/xfs/libxfs/xfs_bmap.c-4457-\nfs/xfs/libxfs/xfs_bmap.c:4458:\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) \u0026\u0026\nfs/xfs/libxfs/xfs_bmap.c-4459-\t    offset \u003e= xfs_fsverity_metadata_offset(ip))\nfs/xfs/libxfs/xfs_bmap.c:4460:\t\tflags |= IOMAP_F_FSVERITY;\nfs/xfs/libxfs/xfs_bmap.c-4461-\n--\nfs/xfs/libxfs/xfs_format.h=366=xfs_sb_has_compat_feature(\n--\nfs/xfs/libxfs/xfs_format.h-376-#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 \u003c\u003c 3)\t\t/* inobt block counts */\nfs/xfs/libxfs/xfs_format.h:377:#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 \u003c\u003c 4)\t\t/* fs-verity */\nfs/xfs/libxfs/xfs_format.h-378-#define XFS_SB_FEAT_RO_COMPAT_ALL \\\n--\nfs/xfs/libxfs/xfs_format.h-382-\t\t XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \\\nfs/xfs/libxfs/xfs_format.h:383:\t\t XFS_SB_FEAT_RO_COMPAT_VERITY)\nfs/xfs/libxfs/xfs_format.h-384-#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN\t~XFS_SB_FEAT_RO_COMPAT_ALL\n--\nfs/xfs/libxfs/xfs_format.h=1143=static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)\n--\nfs/xfs/libxfs/xfs_format.h-1239-/* inodes sealed with fs-verity */\nfs/xfs/libxfs/xfs_format.h:1240:#define XFS_DIFLAG2_VERITY_BIT\t\t6\nfs/xfs/libxfs/xfs_format.h-1241-\n--\nfs/xfs/libxfs/xfs_format.h-1247-#define XFS_DIFLAG2_METADATA\t(1ULL \u003c\u003c XFS_DIFLAG2_METADATA_BIT)\nfs/xfs/libxfs/xfs_format.h:1248:#define XFS_DIFLAG2_VERITY\t(1ULL \u003c\u003c XFS_DIFLAG2_VERITY_BIT)\nfs/xfs/libxfs/xfs_format.h-1249-\n--\nfs/xfs/libxfs/xfs_format.h-1252-\t XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \\\nfs/xfs/libxfs/xfs_format.h:1253:\t XFS_DIFLAG2_VERITY)\nfs/xfs/libxfs/xfs_format.h-1254-\n--\nfs/xfs/libxfs/xfs_format.h=2011=struct xfs_acl {\n--\nfs/xfs/libxfs/xfs_format.h-2051- */\nfs/xfs/libxfs/xfs_format.h:2052:#define XFS_FSVERITY_LARGEST_FILE\t((loff_t)1ULL \u003c\u003c 53)\nfs/xfs/libxfs/xfs_format.h-2053-\n--\nfs/xfs/libxfs/xfs_format.h-2059- */\nfs/xfs/libxfs/xfs_format.h:2060:#define XFS_FSVERITY_START_ALIGN\t(65536)\nfs/xfs/libxfs/xfs_format.h-2061-\n--\nfs/xfs/libxfs/xfs_fs.h=217=typedef struct xfs_fsop_resblks {\n--\nfs/xfs/libxfs/xfs_fs.h-252-#define XFS_FSOP_GEOM_FLAGS_ZONED\t(1 \u003c\u003c 27) /* zoned rt device */\nfs/xfs/libxfs/xfs_fs.h:253:#define XFS_FSOP_GEOM_FLAGS_VERITY\t(1 \u003c\u003c 28) /* fs-verity */\nfs/xfs/libxfs/xfs_fs.h-254-\n--\nfs/xfs/libxfs/xfs_fs.h=369=struct xfs_bulkstat {\n--\nfs/xfs/libxfs/xfs_fs.h-424-#define XFS_BS_SICK_DIRTREE\t(1 \u003c\u003c 8)  /* directory tree structure */\nfs/xfs/libxfs/xfs_fs.h:425:#define XFS_BS_SICK_FSVERITY\t(1 \u003c\u003c 9)  /* fsverity metadata */\nfs/xfs/libxfs/xfs_fs.h-426-\n--\nfs/xfs/libxfs/xfs_health.h=57=struct xfs_rtgroup;\n--\nfs/xfs/libxfs/xfs_health.h-106-#define XFS_SICK_INO_DIRTREE\t(1 \u003c\u003c 13)  /* directory tree structure */\nfs/xfs/libxfs/xfs_health.h:107:#define XFS_SICK_INO_FSVERITY\t(1 \u003c\u003c 14)  /* fsverity metadata */\nfs/xfs/libxfs/xfs_health.h-108-\n--\nfs/xfs/libxfs/xfs_health.h-144-\t\t\t\t XFS_SICK_INO_DIRTREE | \\\nfs/xfs/libxfs/xfs_health.h:145:\t\t\t\t XFS_SICK_INO_FSVERITY)\nfs/xfs/libxfs/xfs_health.h-146-\n--\nfs/xfs/libxfs/xfs_inode_buf.c=591=xfs_dinode_verify(\n--\nfs/xfs/libxfs/xfs_inode_buf.c-761-\t/* only regular files can have fsverity */\nfs/xfs/libxfs/xfs_inode_buf.c:762:\tif (flags2 \u0026 XFS_DIFLAG2_VERITY) {\nfs/xfs/libxfs/xfs_inode_buf.c-763-\t\tif (!xfs_has_verity(mp))\n--\nfs/xfs/libxfs/xfs_inode_util.c=69=xfs_flags2diflags2(\n--\nfs/xfs/libxfs/xfs_inode_util.c-76-\t\t\t\t   XFS_DIFLAG2_NREXT64 |\nfs/xfs/libxfs/xfs_inode_util.c:77:\t\t\t\t   XFS_DIFLAG2_VERITY));\nfs/xfs/libxfs/xfs_inode_util.c-78-\n--\nfs/xfs/libxfs/xfs_inode_util.c=88=xfs_ip2xflags(\n--\nfs/xfs/libxfs/xfs_inode_util.c-128-\t\t\tflags |= FS_XFLAG_COWEXTSIZE;\nfs/xfs/libxfs/xfs_inode_util.c:129:\t\tif (ip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY)\nfs/xfs/libxfs/xfs_inode_util.c:130:\t\t\tflags |= FS_XFLAG_VERITY;\nfs/xfs/libxfs/xfs_inode_util.c-131-\t}\n--\nfs/xfs/libxfs/xfs_sb.c=115=xfs_sb_version_to_features(\n--\nfs/xfs/libxfs/xfs_sb.c-166-\t\tfeatures |= XFS_FEAT_INOBTCNT;\nfs/xfs/libxfs/xfs_sb.c:167:\tif (sbp-\u003esb_features_ro_compat \u0026 XFS_SB_FEAT_RO_COMPAT_VERITY)\nfs/xfs/libxfs/xfs_sb.c:168:\t\tfeatures |= XFS_FEAT_VERITY;\nfs/xfs/libxfs/xfs_sb.c-169-\tif (sbp-\u003esb_features_incompat \u0026 XFS_SB_FEAT_INCOMPAT_FTYPE)\n--\nfs/xfs/libxfs/xfs_sb.c=1465=xfs_fs_geometry(\n--\nfs/xfs/libxfs/xfs_sb.c-1549-\tif (xfs_has_verity(mp))\nfs/xfs/libxfs/xfs_sb.c:1550:\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_VERITY;\nfs/xfs/libxfs/xfs_sb.c-1551-\tgeo-\u003ertsectsize = sbp-\u003esb_blocksize;\n--\nfs/xfs/libxfs/xfs_verity.c=16=xfs_fsverity_metadata_offset(\n--\nfs/xfs/libxfs/xfs_verity.c-18-{\nfs/xfs/libxfs/xfs_verity.c:19:\treturn round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);\nfs/xfs/libxfs/xfs_verity.c-20-}\n--\nfs/xfs/libxfs/xfs_verity.h-4- */\nfs/xfs/libxfs/xfs_verity.h:5:#ifndef __XFS_VERITY_H__\nfs/xfs/libxfs/xfs_verity.h:6:#define __XFS_VERITY_H__\nfs/xfs/libxfs/xfs_verity.h-7-\n--\nfs/xfs/libxfs/xfs_verity.h=10=loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);\nfs/xfs/libxfs/xfs_verity.h-11-\nfs/xfs/libxfs/xfs_verity.h:12:#endif\t/* __XFS_VERITY_H__ */\n--\nfs/xfs/scrub/common.c=1748=xchk_inode_count_blocks(\n--\nfs/xfs/scrub/common.c-1771-/*\nfs/xfs/scrub/common.c:1772: * If this inode has S_VERITY set on it, read the verity info. If the reading\nfs/xfs/scrub/common.c-1773- * fails with anything other than ENOMEM, the file is corrupt, which we can\n--\nfs/xfs/scrub/inode_repair.c=544=xrep_dinode_flags(\n--\nfs/xfs/scrub/inode_repair.c-580-\tif (!xfs_has_verity(mp) || !S_ISREG(mode))\nfs/xfs/scrub/inode_repair.c:581:\t\tflags2 \u0026= ~XFS_DIFLAG2_VERITY;\nfs/xfs/scrub/inode_repair.c-582-\n--\nfs/xfs/scrub/inode_repair.c=2213=xrep_inode_verity(\n--\nfs/xfs/scrub/inode_repair.c-2218-\tif (xchk_inode_verity_broken(sc-\u003eip)) {\nfs/xfs/scrub/inode_repair.c:2219:\t\tsc-\u003eip-\u003ei_diflags2 \u0026= ~XFS_DIFLAG2_VERITY;\nfs/xfs/scrub/inode_repair.c:2220:\t\tinode_set_flags(inode, 0, S_VERITY);\nfs/xfs/scrub/inode_repair.c-2221-\n--\nfs/xfs/xfs_aops.c=159=xfs_map_blocks(\n--\nfs/xfs/xfs_aops.c-182-\nfs/xfs/xfs_aops.c:183:\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_aops.c:184:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_aops.c-185-\n--\nfs/xfs/xfs_aops.c=409=xfs_zoned_map_blocks(\n--\nfs/xfs/xfs_aops.c-427-\nfs/xfs/xfs_aops.c:428:\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_aops.c:429:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_aops.c-430-\n--\nfs/xfs/xfs_aops.c=521=xfs_iomap_writepages(\n--\nfs/xfs/xfs_aops.c-529-\t */\nfs/xfs/xfs_aops.c:530:\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_aops.c:531:\t\tctx-\u003eiomap.flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_aops.c-532-\n--\nfs/xfs/xfs_bmap_util.c=504=xfs_can_free_eofblocks(\n--\nfs/xfs/xfs_bmap_util.c-562-\tif (fsverity_active(VFS_IC(ip)) ||\nfs/xfs/xfs_bmap_util.c:563:\t    xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_bmap_util.c-564-\t\treturn false;\n--\nfs/xfs/xfs_bmap_util.c=586=xfs_free_eofblocks(\n--\nfs/xfs/xfs_bmap_util.c-593-\tbool\t\t\thas_verity =\nfs/xfs/xfs_bmap_util.c:594:\t\t\tip-\u003ei_diflags2 \u0026 XFS_DIFLAG2_VERITY;\nfs/xfs/xfs_bmap_util.c-595-\n--\nfs/xfs/xfs_fsverity.c=27=mempool_t xfs_fsverity_ioend_pool;\nfs/xfs/xfs_fsverity.c-28-\nfs/xfs/xfs_fsverity.c:29:#define XFS_FSVERITY_IOEND_POOL_MIN\t128\nfs/xfs/xfs_fsverity.c-30-\n--\nfs/xfs/xfs_fsverity.c=36=xfs_fsverity_init(void)\n--\nfs/xfs/xfs_fsverity.c-38-\treturn mempool_init_slab_pool(\u0026xfs_fsverity_ioend_pool,\nfs/xfs/xfs_fsverity.c:39:\t\t\tXFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);\nfs/xfs/xfs_fsverity.c-40-}\n--\nfs/xfs/xfs_fsverity.c=61=xfs_fsverity_get_descriptor(\n--\nfs/xfs/xfs_fsverity.c-82-\t */\nfs/xfs/xfs_fsverity.c:83:\tif (!(inode-\u003ei_flags \u0026 S_VERITY)) {\nfs/xfs/xfs_fsverity.c-84-\t\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n--\nfs/xfs/xfs_fsverity.c-92-\tif (is_empty) {\nfs/xfs/xfs_fsverity.c:93:\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\nfs/xfs/xfs_fsverity.c-94-\t\treturn -ENODATA;\n--\nfs/xfs/xfs_fsverity.c-99-\tif (last_block_offset \u003c= xfs_fsverity_metadata_offset(ip)) {\nfs/xfs/xfs_fsverity.c:100:\t\txfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);\nfs/xfs/xfs_fsverity.c-101-\t\treturn -ENODATA;\n--\nfs/xfs/xfs_fsverity.c-110-\tdesc_size = be32_to_cpu(d_desc_size);\nfs/xfs/xfs_fsverity.c:111:\tif (XFS_IS_CORRUPT(mp, desc_size \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE)) {\n\n"
}

7/2 2026/11/03 04:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37320
							output: 32
							thoughts: 27
						

Thoughts:
Here's my thought process, as if I were considering this myself:

**Investigating XFS and FS_VERITY**

Okay, so I need to see if XFS has integrated with, or even considered, FS_VERITY. My first stop should definitely be the `fs/xfs/Kconfig` file. That's the logical place to check for any configuration options related to file system verification, or anything new that might have been added recently. I'll search for "FS_VERITY" directly, but I'll also keep an eye out for any related keywords or features that might have been introduced, even if they don't explicitly use that term. This is just the starting point, but it should give me a good initial picture of the situation.



8/2 2026/11/03 04:02 tool grepper
0m Args:
{
  "Expression": "FS_VERITY",
  "PathPrefixes": [
    "fs/xfs/Kconfig"
  ]
}

Results:
{
  "Output": "no matches"
}

9/2 2026/11/03 04:02 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37556
							output: 33
							thoughts: 126
						

Thoughts:
**Examining the Verity Integration within XFS**

Okay, so I'm trying to figure out how `FS_VERITY` gets integrated with the XFS filesystem. It seems like I can't find a direct option for `FS_VERITY` within `fs/xfs/Kconfig`. That's a bit odd. Let's dig deeper. Ah, right, looking at `fs/xfs/Makefile`, the inclusion of `xfs_fsverity.o` is tied directly to `CONFIG_FS_VERITY`: `xfs-$(CONFIG_FS_VERITY) += xfs_fsverity.o`. So, XFS seems to leverage `CONFIG_FS_VERITY` directly. I'll need to remember that XFS also depends on `CONFIG_XFS_FS`, of course.

To be sure I understand the relationship, let me check the definition of `CONFIG_FS_VERITY` itself. I'll look inside `fs/verity/Kconfig`. I need to see if `CONFIG_FS_VERITY` has any dependencies or selects that are relevant to XFS's usage. Time to read through `fs/verity/Kconfig` carefully.



10/2 2026/11/03 04:03 tool read-file
0m Args:
{
  "File": "fs/verity/Kconfig",
  "FirstLine": 1,
  "LineCount": 40
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0\n   2:\t\n   3:\tconfig FS_VERITY\n   4:\t\tbool \"FS Verity (read-only file-based authenticity protection)\"\n   5:\t\t# Filesystems cache the Merkle tree at a 64K aligned offset in the\n   6:\t\t# pagecache.  That approach assumes the page size is at most 64K.\n   7:\t\tdepends on PAGE_SHIFT \u003c= 16\n   8:\t\tselect CRYPTO_HASH_INFO\n   9:\t\tselect CRYPTO_LIB_SHA256\n  10:\t\tselect CRYPTO_LIB_SHA512\n  11:\t\thelp\n  12:\t\t  This option enables fs-verity.  fs-verity is the dm-verity\n  13:\t\t  mechanism implemented at the file level.  On supported\n  14:\t\t  filesystems (currently ext4, f2fs, and btrfs), userspace can\n  15:\t\t  use an ioctl to enable verity for a file, which causes the\n  16:\t\t  filesystem to build a Merkle tree for the file.  The filesystem\n  17:\t\t  will then transparently verify any data read from the file\n  18:\t\t  against the Merkle tree.  The file is also made read-only.\n  19:\t\n  20:\t\t  This serves as an integrity check, but the availability of the\n  21:\t\t  Merkle tree root hash also allows efficiently supporting\n  22:\t\t  various use cases where normally the whole file would need to\n  23:\t\t  be hashed at once, such as: (a) auditing (logging the file's\n  24:\t\t  hash), or (b) authenticity verification (comparing the hash\n  25:\t\t  against a known good value, e.g. from a digital signature).\n  26:\t\n  27:\t\t  fs-verity is especially useful on large files where not all\n  28:\t\t  the contents may actually be needed.  Also, fs-verity verifies\n  29:\t\t  data each time it is paged back in, which provides better\n  30:\t\t  protection against malicious disks vs. an ahead-of-time hash.\n  31:\t\n  32:\t\t  If unsure, say N.\n  33:\t\n  34:\tconfig FS_VERITY_BUILTIN_SIGNATURES\n  35:\t\tbool \"FS Verity builtin signature support\"\n  36:\t\tdepends on FS_VERITY\n  37:\t\tselect SYSTEM_DATA_VERIFICATION\n  38:\t\thelp\n  39:\t\t  This option adds support for in-kernel verification of\n  40:\t\t  fs-verity builtin signatures.\n"
}

11/2 2026/11/03 04:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38642
							output: 32
							thoughts: 35
						

Thoughts:
Okay, let's see what I can recall about online XFS scrubbing.

**XFS Online Scrub Configuration Check**

Alright, before I dive too deep, I should probably double-check if online XFS scrubs have any specific configuration requirements. I recall it generally being pretty straightforward, but a quick confirmation never hurts, especially when dealing with potentially delicate filesystem operations. So, my initial thought is, let's grep for `CONFIG_XFS_ONLINE` within the kernel configuration files, specifically in the `fs/xfs/Kconfig` file. That should point me directly to any relevant options or dependencies related to this feature, if they exist. That's usually the go-to spot for kernel module configuration.



12/2 2026/11/03 04:03 tool grepper
0m Args:
{
  "Expression": "XFS_ONLINE",
  "PathPrefixes": [
    "fs/xfs/Kconfig"
  ]
}

Results:
{
  "Output": "fs/xfs/Kconfig=144=config XFS_BTREE_IN_MEM\n--\nfs/xfs/Kconfig-146-\nfs/xfs/Kconfig:147:config XFS_ONLINE_SCRUB\nfs/xfs/Kconfig-148-\tbool \"XFS online metadata check support\"\n--\nfs/xfs/Kconfig-163-\nfs/xfs/Kconfig:164:config XFS_ONLINE_SCRUB_STATS\nfs/xfs/Kconfig-165-\tbool \"XFS online metadata check usage data collection\"\nfs/xfs/Kconfig-166-\tdefault y\nfs/xfs/Kconfig:167:\tdepends on XFS_ONLINE_SCRUB\nfs/xfs/Kconfig-168-\tdepends on DEBUG_FS\n--\nfs/xfs/Kconfig-178-\nfs/xfs/Kconfig:179:config XFS_ONLINE_REPAIR\nfs/xfs/Kconfig-180-\tbool \"XFS online metadata repair support\"\nfs/xfs/Kconfig-181-\tdefault y\nfs/xfs/Kconfig:182:\tdepends on XFS_FS \u0026\u0026 XFS_ONLINE_SCRUB\nfs/xfs/Kconfig-183-\tselect XFS_BTREE_IN_MEM\n"
}

13/2 2026/11/03 04:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39201
							output: 29
							thoughts: 47
						

Thoughts:
Okay, here's my interpretation of those thoughts, tailored for an expert audience, and delivered as a first-person summary:

**XFS Scrub and Repair Dependencies**

Right, so my mind is immediately drawn to the XFS online scrub and repair functionality. I need to quickly establish the scope of what those modules touch, specifically the `fs/xfs/scrub/*` area. I know these guards, `XFS_ONLINE_SCRUB` and `XFS_ONLINE_REPAIR`, are crucial for conditional compilation and runtime behavior related to scrubbing and online repair. It's a key part of ensuring the safety and correctness of the filesystem operations.

My first step is to definitively understand the build environment. I need to make *absolutely* sure of how these features are enabled. Therefore, I'm going to quickly check `fs/xfs/Makefile`. It's the Makefile that controls the build process for the XFS filesystem modules, so any configuration options, dependencies, or conditional compilation directives for scrubbing or online repair will be evident there. I expect to see the logic for those flags, and I'll immediately recognize the implications. Knowing how the build system handles these features is vital for any troubleshooting or modification to the scrub code.



14/2 2026/11/03 04:03 tool grepper
0m Args:
{
  "Expression": "scrub",
  "PathPrefixes": [
    "fs/xfs/Makefile"
  ]
}

Results:
{
  "Output": "fs/xfs/Makefile=164=xfs-$(CONFIG_XFS_BTREE_IN_MEM)\t+= libxfs/xfs_btree_mem.o\nfs/xfs/Makefile-165-\nfs/xfs/Makefile:166:# online scrub/repair\nfs/xfs/Makefile-167-ifeq ($(CONFIG_XFS_ONLINE_SCRUB),y)\n--\nfs/xfs/Makefile-170-\nfs/xfs/Makefile:171:xfs-y\t\t\t\t+= $(addprefix scrub/, \\\nfs/xfs/Makefile-172-\t\t\t\t   trace.o \\\n--\nfs/xfs/Makefile-195-\t\t\t\t   rmap.o \\\nfs/xfs/Makefile:196:\t\t\t\t   scrub.o \\\nfs/xfs/Makefile-197-\t\t\t\t   symlink.o \\\n--\nfs/xfs/Makefile-202-\nfs/xfs/Makefile:203:xfs-$(CONFIG_XFS_ONLINE_SCRUB_STATS) += scrub/stats.o\nfs/xfs/Makefile-204-\nfs/xfs/Makefile:205:xfs-$(CONFIG_XFS_RT)\t\t+= $(addprefix scrub/, \\\nfs/xfs/Makefile-206-\t\t\t\t   rgsuper.o \\\n--\nfs/xfs/Makefile-212-\nfs/xfs/Makefile:213:xfs-$(CONFIG_XFS_QUOTA)\t\t+= $(addprefix scrub/, \\\nfs/xfs/Makefile-214-\t\t\t\t   dqiterate.o \\\n--\nfs/xfs/Makefile=220=ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y)\nfs/xfs/Makefile:221:xfs-y\t\t\t\t+= $(addprefix scrub/, \\\nfs/xfs/Makefile-222-\t\t\t\t   agheader_repair.o \\\n--\nfs/xfs/Makefile-246-\nfs/xfs/Makefile:247:xfs-$(CONFIG_XFS_RT)\t\t+= $(addprefix scrub/, \\\nfs/xfs/Makefile-248-\t\t\t\t   rtbitmap_repair.o \\\n--\nfs/xfs/Makefile-253-\nfs/xfs/Makefile:254:xfs-$(CONFIG_XFS_QUOTA)\t\t+= $(addprefix scrub/, \\\nfs/xfs/Makefile-255-\t\t\t\t   quota_repair.o \\\n"
}

15/2 2026/11/03 04:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40140
							output: 33
							thoughts: 2355
						

Thoughts:
**Focus Symbol Selection for XFS FS-Verity Feature**

Okay, so we're diving into identifying the most effective `FocusSymbols` to guide fuzzing for this XFS FS-verity implementation. The essential configurations are `XFS_FS`, `FS_VERITY`, `XFS_ONLINE_SCRUB`, and `XFS_ONLINE_REPAIR`. My goal is to pinpoint the *specific* functions that are central to the new verity logic, avoiding any generic or ubiquitous functions that would dilute the fuzzing effort, adhering to the provided guidelines from Section 4.

First, I need to thoroughly inspect the code additions and modifications.  Based on the diff, the core functions appear to be located in `fs/xfs/xfs_fsverity.c`.  I've noted these functions:

*   `xfs_fsverity_begin_enable`
*   `xfs_fsverity_end_enable`
*   `xfs_fsverity_get_descriptor`
*   `xfs_fsverity_read_merkle`
*   `xfs_fsverity_readahead_merkle_tree`
*   `xfs_fsverity_write_merkle`

All these are static functions, but *critically* they are assigned to function pointers within the `xfs_fsverity_ops` struct. Because their addresses are taken, the compiler *cannot* inline them, thus, they have distinct symbols within `vmlinux`. They are not inlined, and are thus valid targets for symbol coverage.

I've also noted other useful functions, specifically:

*   `xfs_fsverity_metadata_offset` (in `fs/xfs/libxfs/xfs_verity.c`)
*   `xchk_inode_setup_verity` (in `fs/xfs/scrub/common.c`)
*   `xchk_inode_verity_broken` (in `fs/xfs/scrub/common.c`)
*   `xrep_inode_verity` (in `fs/xfs/scrub/inode_repair.c`)
*   `xfs_end_fsverity_io_read` (in `fs/xfs/xfs_ioend.c`)

Next, the ioctl entrypoints are important.  Specifically, `fsverity_ioctl_enable`, `fsverity_ioctl_measure`, and `fsverity_ioctl_read_metadata` which call these `xfs_fsverity_ops`:

*   `fsverity_ioctl_enable` calls `xfs_fsverity_begin_enable`, `xfs_fsverity_write_merkle`, `xfs_fsverity_end_enable`
*   `fsverity_ioctl_measure` calls `xfs_fsverity_get_descriptor`
*   `fsverity_ioctl_read_metadata` calls `xfs_fsverity_get_descriptor` and `xfs_fsverity_read_merkle`

When a verity file is read, `xfs_end_io_read` calls `xfs_end_fsverity_io_read` (workqueue callback).  Again, since the address of the latter is taken, it's a valid symbol.

I considered `xfs_iomap_writepages` but realized it is not specific and is the writepages address_space op for all files in xfs, which is common. I confirmed that `xrep_inode_verity` which is specifically for verity repair, and that `xchk_inode_setup_verity` and `xchk_inode_verity_broken` are specifically for verity scrub setup and checking.

So, here's my final list of `FocusSymbols`:

*   `xfs_fsverity_begin_enable`
*   `xfs_fsverity_end_enable`
*   `xfs_fsverity_get_descriptor`
*   `xfs_fsverity_read_merkle`
*   `xfs_fsverity_readahead_merkle_tree`
*   `xfs_fsverity_write_merkle`
*   `xfs_end_fsverity_io_read`
*   `xchk_inode_setup_verity`
*   `xchk_inode_verity_broken`
*   `xrep_inode_verity`
*   `xfs_fsverity_metadata_offset`

I've verified that


16/2 2026/11/03 04:03 tool grepper
0m Args:
{
  "Expression": "config XFS_FS",
  "PathPrefixes": [
    "fs/xfs/Kconfig"
  ]
}

Results:
{
  "Output": "fs/xfs/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/xfs/Kconfig:2:config XFS_FS\nfs/xfs/Kconfig-3-\ttristate \"XFS filesystem support\"\n"
}

17/2 2026/11/03 04:03 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43626
							output: 33
							thoughts: 20
						

Thoughts:
Here's my take on the initial lines of `fs/xfs/Kconfig`, summarized as if they were my own thoughts:

**XFS Configuration: Initial Considerations**

Alright, let's dive into this Kconfig file for XFS, starting from the top. Lines 1 through 30, huh? I expect this to lay the groundwork for how XFS's features are presented to the user during kernel configuration. I'm looking for the core options, the dependencies, and the basic structure. I bet we'll see the top-level symbol for enabling XFS, probably a dependency on something fundamental like block device support, and then the selection of the XFS superblock type. I bet this is where they've set up the enabling of the code base. I hope to see the important features, whether they have a default value or not, and what is the minimum set up for a build. Should be pretty standard, maybe a few surprises but likely no real curveballs in the basics. Okay, let's see what they've got.



18/2 2026/11/03 04:04 tool read-file
0m Args:
{
  "File": "fs/xfs/Kconfig",
  "FirstLine": 1,
  "LineCount": 30
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tconfig XFS_FS\n   3:\t\ttristate \"XFS filesystem support\"\n   4:\t\tdepends on BLOCK\n   5:\t\tselect EXPORTFS\n   6:\t\tselect CRC32\n   7:\t\tselect FS_IOMAP\n   8:\t\thelp\n   9:\t\t  XFS is a high performance journaling filesystem which originated\n  10:\t\t  on the SGI IRIX platform.  It is completely multi-threaded, can\n  11:\t\t  support large files and large filesystems, extended attributes,\n  12:\t\t  variable block sizes, is extent based, and makes extensive use of\n  13:\t\t  Btrees (directories, extents, free space) to aid both performance\n  14:\t\t  and scalability.\n  15:\t\n  16:\t\t  Refer to the documentation at \u003chttp://oss.sgi.com/projects/xfs/\u003e\n  17:\t\t  for complete details.  This implementation is on-disk compatible\n  18:\t\t  with the IRIX version of XFS.\n  19:\t\n  20:\t\t  To compile this file system support as a module, choose M here: the\n  21:\t\t  module will be called xfs.  Be aware, however, that if the file\n  22:\t\t  system of your root partition is compiled as a module, you'll need\n  23:\t\t  to use an initial ramdisk (initrd) to boot.\n  24:\t\n  25:\tconfig XFS_SUPPORT_V4\n  26:\t\tbool \"Support deprecated V4 (crc=0) format\"\n  27:\t\tdepends on XFS_FS\n  28:\t\tdefault n\n  29:\t\thelp\n  30:\t\t  The V4 filesystem format lacks certain features that are supported\n"
}

19/2 2026/11/03 04:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 44357
							output: 35
							thoughts: 151
						

Thoughts:
**Kernel Configuration Deep Dive**

Okay, let's get down to brass tacks. I need to understand the dependencies of `FS_VERITY`. First instinct? Check the `Kconfig` file, naturally. Diving into `fs/verity/Kconfig`, I see it's quite straightforward. The key dependencies are `PAGE_SHIFT <= 16`, `select CRYPTO_HASH_INFO`, `select CRYPTO_LIB_SHA256`, and `select CRYPTO_LIB_SHA512`. No real surprises there, everything looks self-contained. Good.

Now, shifting gears, let's look at `XFS_ONLINE_SCRUB`. The immediate thought is, "Okay, what does *that* depend on?" Initial inspection suggests a dependence on `XFS_FS`, and a question mark around `DEBUG_FS`. Hold on a second! A closer look is warranted. Let me examine `fs/xfs/Kconfig` specifically, starting from lines 147-185. I need to confirm that `DEBUG_FS` isn't a hard dependency, or that there's any nuance to it. Right. Let's see...



20/2 2026/11/03 04:04 tool read-file
0m Args:
{
  "File": "fs/xfs/Kconfig",
  "FirstLine": 146,
  "LineCount": 40
}

Results:
{
  "Contents": " 146:\t\n 147:\tconfig XFS_ONLINE_SCRUB\n 148:\t\tbool \"XFS online metadata check support\"\n 149:\t\tdefault y\n 150:\t\tdepends on XFS_FS\n 151:\t\tdepends on TMPFS \u0026\u0026 SHMEM\n 152:\t\tselect XFS_LIVE_HOOKS\n 153:\t\tselect XFS_DRAIN_INTENTS\n 154:\t\tselect XFS_MEMORY_BUFS\n 155:\t\thelp\n 156:\t\t  If you say Y here you will be able to check metadata on a\n 157:\t\t  mounted XFS filesystem.  This feature is intended to reduce\n 158:\t\t  filesystem downtime by supplementing xfs_repair.  The key\n 159:\t\t  advantage here is to look for problems proactively so that\n 160:\t\t  they can be dealt with in a controlled manner.\n 161:\t\n 162:\t\t  See the xfs_scrub man page in section 8 for additional information.\n 163:\t\n 164:\tconfig XFS_ONLINE_SCRUB_STATS\n 165:\t\tbool \"XFS online metadata check usage data collection\"\n 166:\t\tdefault y\n 167:\t\tdepends on XFS_ONLINE_SCRUB\n 168:\t\tdepends on DEBUG_FS\n 169:\t\thelp\n 170:\t\t  If you say Y here, the kernel will gather usage data about\n 171:\t\t  the online metadata check subsystem.  This includes the number\n 172:\t\t  of invocations, the outcomes, and the results of repairs, if any.\n 173:\t\t  This may slow down scrub slightly due to the use of high precision\n 174:\t\t  timers and the need to merge per-invocation information into the\n 175:\t\t  filesystem counters.\n 176:\t\n 177:\t\t  Usage data are collected in /sys/kernel/debug/xfs/scrub.\n 178:\t\n 179:\tconfig XFS_ONLINE_REPAIR\n 180:\t\tbool \"XFS online metadata repair support\"\n 181:\t\tdefault y\n 182:\t\tdepends on XFS_FS \u0026\u0026 XFS_ONLINE_SCRUB\n 183:\t\tselect XFS_BTREE_IN_MEM\n 184:\t\thelp\n 185:\t\t  If you say Y here you will be able to repair metadata on a\n"
}

21/2 2026/11/03 04:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45419
							output: 312
							thoughts: 526
						

Thoughts:
**My Assessment of the XFS Verity Patch Configuration**

Okay, let's break this down for the `set-results` call. I've reviewed the dependencies, and it looks straightforward. `XFS_ONLINE_SCRUB` clearly depends on `XFS_FS` and `TMPFS && SHMEM`, and `XFS_ONLINE_REPAIR` requires both `XFS_FS` and `XFS_ONLINE_SCRUB`. `TMPFS` and `SHMEM` are essentially baseline kernel components, so we don't need to explicitly include them unless there's a specific need to be extremely explicit.

Therefore, the minimal, clean, and precise configuration to enable this functionality is:

*   `XFS_FS`
*   `FS_VERITY`
*   `XFS_ONLINE_SCRUB`
*   `XFS_ONLINE_REPAIR`

This setup gets the job done without unnecessary clutter.

Now, concerning the `set-results` parameters, here's what I've determined:

*   **`WorthFuzzing`: true** – Absolutely. The patch implements fs-verity support within XFS, introducing new ioctl handlers, Merkle tree operations, readahead optimizations, post-EOF metadata manipulation, bio read verification, and online scrub/repair checks for verity metadata. This is core filesystem logic, and it's all reachable in standard virtualized environments, making it a prime target for fuzzing.
*   **`Reasoning`: Explain that the patch implements fs-verity support in XFS, introducing ioctl handlers for enabling/measuring verity, Merkle tree construction and readahead/reading, post-EOF metadata mapping/unmapping, bio read verification via workqueues, and online scrub/repair checks for verity metadata. This is core filesystem logic fully reachable in standard virtualized environments.** – This is a good explanation of the patch's scope. It highlights the new functionality and the potential attack surface.
*   **`FocusSymbols`**: I've confirmed that these are the most relevant symbols:
    *   `xfs_fsverity_begin_enable`
    *   `xfs_fsverity_end_enable`
    *   `xfs_fsverity_get_descriptor`
    *   `xfs_fsverity_read_merkle`
    *   `xfs_fsverity_readahead_merkle_tree`
    *   `xfs_fsverity_write_merkle`
    *   `xfs_fsverity_metadata_offset`
    *   `xfs_end_fsverity_io_read`
    *   `xchk_inode_setup_verity`
    *   `xchk_inode_verity_broken`
    *   `xrep_inode_verity`
*   **`EnableConfigs`**: This is just the same as my earlier config list:
    *   `XFS_FS`
    *   `FS_VERITY`
    *   `XFS_ONLINE_SCRUB`
    *   `XFS_ONLINE_REPAIR`

Based on my analysis and verification against the source code, everything here is sound. I'm ready to proceed with calling `set-results`.



22/2 2026/11/03 04:04 tool set-results
0m Args:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_readahead_merkle_tree",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity"
  ],
  "Reasoning": "The patch adds fs-verity support to the XFS filesystem. It introduces filesystem-specific operations for fs-verity (enabling verity, writing and reading Merkle tree blocks, retrieving descriptors), iomap handling for post-EOF metadata, asynchronous read verification via dedicated workqueue ioend handling, and online scrub/repair support for fs-verity inodes. This is complex core filesystem code reachable via standard syscalls (ioctls, read/write, scrub) and warrants fuzzing.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "XFS_FS",
    "FS_VERITY",
    "XFS_ONLINE_SCRUB",
    "XFS_ONLINE_REPAIR"
  ],
  "FocusSymbols": [
    "xfs_fsverity_begin_enable",
    "xfs_fsverity_end_enable",
    "xfs_fsverity_get_descriptor",
    "xfs_fsverity_read_merkle",
    "xfs_fsverity_readahead_merkle_tree",
    "xfs_fsverity_write_merkle",
    "xfs_fsverity_metadata_offset",
    "xfs_end_fsverity_io_read",
    "xchk_inode_setup_verity",
    "xchk_inode_verity_broken",
    "xrep_inode_verity"
  ],
  "Reasoning": "The patch adds fs-verity support to the XFS filesystem. It introduces filesystem-specific operations for fs-verity (enabling verity, writing and reading Merkle tree blocks, retrieving descriptors), iomap handling for post-EOF metadata, asynchronous read verification via dedicated workqueue ioend handling, and online scrub/repair support for fs-verity inodes. This is complex core filesystem code reachable via standard syscalls (ioctls, read/write, scrub) and warrants fuzzing.",
  "WorthFuzzing": true
}

23/1 2026/11/03 04:04 action If
6m Args:
{
  "WorthFuzzing": true
}

Results:
null

24/2 2026/11/03 04:04 agent kmsan-evaluator
6m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series introduces fs-verity support to XFS, hooking up XFS to fs-verity operations and the iomap subsystem with the IOMAP_F_FSVERITY flag. This change exposes significant uninitialized memory risks that can only be detected by KMSAN:\n\n1. Hole handling in post-EOF fs-verity metadata during descriptor lookup:\nIn `xfs_fsverity_get_descriptor()`, the descriptor location `desc_pos` is calculated as `round_down(desc_size_pos - desc_size, blocksize)`. Because fs-verity metadata is spaced out past EOF with `XFS_FSVERITY_START_ALIGN` (64KB alignment) and zero-digest blocks can be omitted, holes can exist between the Merkle tree and descriptor, or across corrupted/crafted metadata extents.\nWhen `fsverity_pagecache_read()` reads from `desc_pos`, `xfs_read_iomap_begin()` sets `IOMAP_F_FSVERITY`. In `iomap_read_folio_iter()`, if `(iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026 iomap-\u003etype == IOMAP_HOLE`:\n```c\nif (ctx-\u003evi)\n    fsverity_fill_zerohash(folio, poff, plen, ctx-\u003evi);\niomap_set_range_uptodate(folio, poff, plen);\n```\nDuring descriptor reading (`xfs_fsverity_get_descriptor()` called from `fsverity_ensure_verity_info()`), `ctx-\u003evi` is NULL because the `fsverity_info` structure has not yet been instantiated. Consequently, `fsverity_fill_zerohash()` is skipped, `folio_zero_range()` is bypassed, and the newly allocated folio is marked uptodate while still containing uninitialized memory.\n\n2. Branching on uninitialized memory and user info-leaks:\nThe uninitialized bytes from the folio are copied into the `desc` buffer (allocated with `kmalloc()` in `fsverity_get_descriptor()`). Immediately thereafter, `validate_fsverity_descriptor()` evaluates conditional branches depending directly on these uninitialized struct fields (`desc-\u003eversion`, `desc-\u003esalt_size`, `desc-\u003edata_size`). Furthermore, through `FS_IOC_READ_VERITY_METADATA` or descriptor reads, uninitialized buffer data can be leaked to userspace via `copy_to_user()`.\n\n3. KASAN vs KMSAN applicability:\nKASAN only monitors memory bounds and life cycle events (out-of-bounds accesses, use-after-free, double-free). Because all folio and descriptor buffer accesses remain within their legitimate allocation bounds, KASAN is blind to uninitialized memory being marked valid, copied, and evaluated in conditional logic. Only KMSAN tracks uninitialized shadow memory and catches uninitialized variable reads and kernel-to-user info-leaks.\n\nTherefore, running a dedicated KMSAN fuzzing session is justified.",
  "NeedsKMSAN": true
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 511718d13990c977011c96cea0d9e44818696ad2
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Nov 3 04:02:33 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 399a207f2d0e71..9edb2850f09413 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -59,6 +59,7 @@ xfs-y				+= $(addprefix libxfs/, \
 				   xfs_trans_resv.o \
 				   xfs_trans_space.o \
 				   xfs_types.o \
+				   xfs_verity.o \
 				   )
 # xfs_rtbitmap is shared with libxfs
 xfs-$(CONFIG_XFS_RT)		+= $(addprefix libxfs/, \
@@ -150,6 +151,7 @@ xfs-$(CONFIG_XFS_POSIX_ACL)	+= xfs_acl.o
 xfs-$(CONFIG_SYSCTL)		+= xfs_sysctl.o
 xfs-$(CONFIG_COMPAT)		+= xfs_ioctl32.o
 xfs-$(CONFIG_EXPORTFS_BLOCK_OPS)	+= xfs_pnfs.o
+xfs-$(CONFIG_FS_VERITY)		+= xfs_fsverity.o
 
 # notify failure
 ifeq ($(CONFIG_MEMORY_FAILURE),y)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index ca49bf4a50c5f2..706f2ead42f582 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -41,6 +41,7 @@
 #include "xfs_inode_util.h"
 #include "xfs_rtgroup.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_verity.h"
 
 struct kmem_cache		*xfs_bmap_intent_cache;
 
@@ -4404,6 +4405,9 @@ xfs_bmapi_convert_one_delalloc(
 	 * the extent.  Just return the real extent at this offset.
 	 */
 	if (!isnullstartblock(bma.got.br_startblock)) {
+		if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) &&
+		    offset >= xfs_fsverity_metadata_offset(ip))
+			flags |= IOMAP_F_FSVERITY;
 		xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
 		if (seq)
@@ -4451,6 +4455,10 @@ xfs_bmapi_convert_one_delalloc(
 	XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
 	XFS_STATS_INC(mp, xs_xstrat_quick);
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION) &&
+	    offset >= xfs_fsverity_metadata_offset(ip))
+		flags |= IOMAP_F_FSVERITY;
+
 	ASSERT(!isnullstartblock(bma.got.br_startblock));
 	xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
 				xfs_iomap_inode_sequence(ip, flags));
@@ -5271,6 +5279,10 @@ __xfs_bunmapi(
 		if (del.br_startoff + del.br_blockcount > end + 1)
 			del.br_blockcount = end + 1 - del.br_startoff;
 
+		if ((flags & XFS_BMAPI_UNWRITTEN) &&
+		    del.br_state != XFS_EXT_UNWRITTEN)
+			goto skip;
+
 		if (!isrt || (flags & XFS_BMAPI_REMAP))
 			goto delete;
 
@@ -5405,7 +5417,7 @@ __xfs_bunmapi(
 			if (error)
 				goto error0;
 		}
-
+skip:
 		end = del.br_startoff - 1;
 nodelete:
 		/*
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index e9f5416e4c050d..25b24ff8e4de35 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -90,6 +90,9 @@ struct xfs_bmalloca {
 /* Try to align allocations to the extent size hint */
 #define XFS_BMAPI_EXTSZALIGN	(1u << 11)
 
+/* Process unwritten extents only. Used for unmapping */
+#define XFS_BMAPI_UNWRITTEN	(1u << 12)
+
 #define XFS_BMAPI_FLAGS \
 	{ XFS_BMAPI_ENTIRE,	"ENTIRE" }, \
 	{ XFS_BMAPI_METADATA,	"METADATA" }, \
@@ -102,7 +105,8 @@ struct xfs_bmalloca {
 	{ XFS_BMAPI_COWFORK,	"COWFORK" }, \
 	{ XFS_BMAPI_NODISCARD,	"NODISCARD" }, \
 	{ XFS_BMAPI_NORMAP,	"NORMAP" },\
-	{ XFS_BMAPI_EXTSZALIGN,	"EXTSZALIGN" }
+	{ XFS_BMAPI_EXTSZALIGN,	"EXTSZALIGN" }, \
+	{ XFS_BMAPI_UNWRITTEN,	"UNWRITTEN" }
 
 
 static inline int xfs_bmapi_aflag(int w)
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 469e879149ac21..6594fbe4f7f6a0 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -374,11 +374,13 @@ xfs_sb_has_compat_feature(
 #define XFS_SB_FEAT_RO_COMPAT_RMAPBT   (1 << 1)		/* reverse map btree */
 #define XFS_SB_FEAT_RO_COMPAT_REFLINK  (1 << 2)		/* reflinked files */
 #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)		/* inobt block counts */
+#define XFS_SB_FEAT_RO_COMPAT_VERITY   (1 << 4)		/* fs-verity */
 #define XFS_SB_FEAT_RO_COMPAT_ALL \
 		(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
 		 XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
-		 XFS_SB_FEAT_RO_COMPAT_REFLINK| \
-		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
+		 XFS_SB_FEAT_RO_COMPAT_REFLINK | \
+		 XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \
+		 XFS_SB_FEAT_RO_COMPAT_VERITY)
 #define XFS_SB_FEAT_RO_COMPAT_UNKNOWN	~XFS_SB_FEAT_RO_COMPAT_ALL
 static inline bool
 xfs_sb_has_ro_compat_feature(
@@ -1234,16 +1236,21 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
  */
 #define XFS_DIFLAG2_METADATA_BIT	5
 
+/* inodes sealed with fs-verity */
+#define XFS_DIFLAG2_VERITY_BIT		6
+
 #define XFS_DIFLAG2_DAX		(1ULL << XFS_DIFLAG2_DAX_BIT)
 #define XFS_DIFLAG2_REFLINK	(1ULL << XFS_DIFLAG2_REFLINK_BIT)
 #define XFS_DIFLAG2_COWEXTSIZE	(1ULL << XFS_DIFLAG2_COWEXTSIZE_BIT)
 #define XFS_DIFLAG2_BIGTIME	(1ULL << XFS_DIFLAG2_BIGTIME_BIT)
 #define XFS_DIFLAG2_NREXT64	(1ULL << XFS_DIFLAG2_NREXT64_BIT)
 #define XFS_DIFLAG2_METADATA	(1ULL << XFS_DIFLAG2_METADATA_BIT)
+#define XFS_DIFLAG2_VERITY	(1ULL << XFS_DIFLAG2_VERITY_BIT)
 
 #define XFS_DIFLAG2_ANY \
 	(XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \
-	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)
+	 XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA | \
+	 XFS_DIFLAG2_VERITY)
 
 static inline bool xfs_dinode_has_bigtime(const struct xfs_dinode *dip)
 {
@@ -2031,4 +2038,26 @@ struct xfs_acl {
 #define SGI_ACL_FILE_SIZE	(sizeof(SGI_ACL_FILE)-1)
 #define SGI_ACL_DEFAULT_SIZE	(sizeof(SGI_ACL_DEFAULT)-1)
 
+/*
+ * At maximum of 8 levels with 128 hashes per block (32 bytes SHA-256) maximum
+ * tree size is ((128^8 − 1)/(128 − 1)) = 567*10^12 blocks. This should fit in
+ * 53 bits address space.
+ *
+ * At this Merkle tree size we can cover 295EB large file. This is much larger
+ * than the currently supported file size.
+ *
+ * For sha512 the largest file we can cover ends at 1 << 50 offset, this is also
+ * good.
+ */
+#define XFS_FSVERITY_LARGEST_FILE	((loff_t)1ULL << 53)
+
+/*
+ * Alignment of the fsverity metadata placement. This is largest supported PAGE
+ * SIZE for fsverity. This is used to space out data and metadata in page cache.
+ * The spacing is necessary for non-exposure of metadata to userspace and
+ * correct merkle tree synthesis in the iomap.
+ */
+#define XFS_FSVERITY_START_ALIGN	(65536)
+
+
 #endif /* __XFS_FORMAT_H__ */
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 185f09f327c00c..84d62b7506a9ad 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {
 #define XFS_FSOP_GEOM_FLAGS_PARENT	(1 << 25) /* linux parent pointers */
 #define XFS_FSOP_GEOM_FLAGS_METADIR	(1 << 26) /* metadata directories */
 #define XFS_FSOP_GEOM_FLAGS_ZONED	(1 << 27) /* zoned rt device */
+#define XFS_FSOP_GEOM_FLAGS_VERITY	(1 << 28) /* fs-verity */
 
 /*
  * Minimum and maximum sizes need for growth checks.
@@ -421,6 +422,7 @@ struct xfs_bulkstat {
 #define XFS_BS_SICK_SYMLINK	(1 << 6)  /* symbolic link remote target */
 #define XFS_BS_SICK_PARENT	(1 << 7)  /* parent pointers */
 #define XFS_BS_SICK_DIRTREE	(1 << 8)  /* directory tree structure */
+#define XFS_BS_SICK_FSVERITY	(1 << 9)  /* fsverity metadata */
 
 /*
  * Project quota id helpers (previously projid was 16bit only
diff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h
index 1d45cf5789e864..932b447190da76 100644
--- a/fs/xfs/libxfs/xfs_health.h
+++ b/fs/xfs/libxfs/xfs_health.h
@@ -104,6 +104,7 @@ struct xfs_rtgroup;
 /* Don't propagate sick status to ag health summary during inactivation */
 #define XFS_SICK_INO_FORGET	(1 << 12)
 #define XFS_SICK_INO_DIRTREE	(1 << 13)  /* directory tree structure */
+#define XFS_SICK_INO_FSVERITY	(1 << 14)  /* fsverity metadata */
 
 /* Primary evidence of health problems in a given group. */
 #define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
@@ -140,7 +141,8 @@ struct xfs_rtgroup;
 				 XFS_SICK_INO_XATTR | \
 				 XFS_SICK_INO_SYMLINK | \
 				 XFS_SICK_INO_PARENT | \
-				 XFS_SICK_INO_DIRTREE)
+				 XFS_SICK_INO_DIRTREE | \
+				 XFS_SICK_INO_FSVERITY)
 
 #define XFS_SICK_INO_ZAPPED	(XFS_SICK_INO_BMBTD_ZAPPED | \
 				 XFS_SICK_INO_BMBTA_ZAPPED | \
diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
index 8c9d296ebfe97f..13042e1eaf3519 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.c
+++ b/fs/xfs/libxfs/xfs_inode_buf.c
@@ -758,6 +758,14 @@ xfs_dinode_verify(
 	    !xfs_has_rtreflink(mp))
 		return __this_address;
 
+	/* only regular files can have fsverity */
+	if (flags2 & XFS_DIFLAG2_VERITY) {
+		if (!xfs_has_verity(mp))
+			return __this_address;
+		if (!S_ISREG(mode))
+			return __this_address;
+	}
+
 	if (xfs_has_zoned(mp) &&
 	    dip->di_metatype == cpu_to_be16(XFS_METAFILE_RTRMAP)) {
 		if (be32_to_cpu(dip->di_used_blocks) > mp->m_sb.sb_rgextents)
diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c
index f486b23a9b5230..a717b19558afab 100644
--- a/fs/xfs/libxfs/xfs_inode_util.c
+++ b/fs/xfs/libxfs/xfs_inode_util.c
@@ -73,7 +73,8 @@ xfs_flags2diflags2(
 	uint64_t		di_flags2 =
 		(ip->i_diflags2 & (XFS_DIFLAG2_REFLINK |
 				   XFS_DIFLAG2_BIGTIME |
-				   XFS_DIFLAG2_NREXT64));
+				   XFS_DIFLAG2_NREXT64 |
+				   XFS_DIFLAG2_VERITY));
 
 	if (xflags & FS_XFLAG_DAX)
 		di_flags2 |= XFS_DIFLAG2_DAX;
@@ -125,6 +126,8 @@ xfs_ip2xflags(
 			flags |= FS_XFLAG_DAX;
 		if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
 			flags |= FS_XFLAG_COWEXTSIZE;
+		if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+			flags |= FS_XFLAG_VERITY;
 	}
 
 	if (xfs_inode_has_attr_fork(ip))
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index ce44123c98cef6..3323b8dcc7939b 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -164,6 +164,8 @@ xfs_sb_version_to_features(
 		features |= XFS_FEAT_REFLINK;
 	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_INOBTCNT)
 		features |= XFS_FEAT_INOBTCNT;
+	if (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_VERITY)
+		features |= XFS_FEAT_VERITY;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_FTYPE)
 		features |= XFS_FEAT_FTYPE;
 	if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_SPINODES)
@@ -1544,6 +1546,8 @@ xfs_fs_geometry(
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_METADIR;
 	if (xfs_has_zoned(mp))
 		geo->flags |= XFS_FSOP_GEOM_FLAGS_ZONED;
+	if (xfs_has_verity(mp))
+		geo->flags |= XFS_FSOP_GEOM_FLAGS_VERITY;
 	geo->rtsectsize = sbp->sb_blocksize;
 	geo->dirblocksize = xfs_dir2_dirblock_bytes(sbp);
 
diff --git a/fs/xfs/libxfs/xfs_verity.c b/fs/xfs/libxfs/xfs_verity.c
new file mode 100644
index 00000000000000..c1731b89a5a12c
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_log_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_verity.h"
+
+loff_t
+xfs_fsverity_metadata_offset(
+	const struct xfs_inode	*ip)
+{
+	return round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);
+}
diff --git a/fs/xfs/libxfs/xfs_verity.h b/fs/xfs/libxfs/xfs_verity.h
new file mode 100644
index 00000000000000..db89d557edcd3e
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_verity.h
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_VERITY_H__
+#define __XFS_VERITY_H__
+
+#include "xfs_platform.h"
+
+loff_t xfs_fsverity_metadata_offset(const struct xfs_inode *ip);
+
+#endif	/* __XFS_VERITY_H__ */
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index cbfe5e6f779dfc..fb0ae227df54a8 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,54 @@ 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 -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.
+		 */
+		return 0;
+	default:
+		/* runtime errors */
+		return error;
+	}
+
+	return 0;
+}
+
+/*
+ * Is this a verity file that failed to activate?  Callers must have tried to
+ * activate fsverity via xchk_inode_setup_verity.
+ */
+bool
+xchk_inode_verity_broken(
+	struct xfs_inode	*ip)
+{
+	return fsverity_active(VFS_I(ip)) && !fsverity_get_info(VFS_I(ip));
+}
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index 181028f0c65526..b59d4792a80507 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -261,6 +261,8 @@ int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_agino_t agino,
 		bool *inuse);
 int xchk_inode_count_blocks(struct xfs_scrub *sc, int whichfork,
 		xfs_extnum_t *nextents, xfs_filblks_t *count);
+int xchk_inode_setup_verity(struct xfs_scrub *sc);
+bool xchk_inode_verity_broken(struct xfs_inode *ip);
 
 bool xchk_inode_is_dirtree_root(const struct xfs_inode *ip);
 bool xchk_inode_is_sb_rooted(const struct xfs_inode *ip);
diff --git a/fs/xfs/scrub/inode.c b/fs/xfs/scrub/inode.c
index bb8d2bc008e019..1d21758e0df068 100644
--- a/fs/xfs/scrub/inode.c
+++ b/fs/xfs/scrub/inode.c
@@ -36,6 +36,10 @@ xchk_prepare_iscrub(
 
 	xchk_ilock(sc, XFS_IOLOCK_EXCL);
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -833,6 +837,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);
+
 	xchk_inode_check_unlinked(sc);
 
 	xchk_inode_xref(sc, I_INO(sc->ip), &di);
diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c
index a9ccf763c05969..e84eaa8178dc79 100644
--- a/fs/xfs/scrub/inode_repair.c
+++ b/fs/xfs/scrub/inode_repair.c
@@ -577,6 +577,8 @@ 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;
 
 	if (flags2 & XFS_DIFLAG2_METADATA) {
 		xfs_failaddr_t	fa;
@@ -1659,6 +1661,10 @@ xrep_dinode_core(
 	if (iget_error)
 		return iget_error;
 
+	error = xchk_inode_setup_verity(sc);
+	if (error)
+		return error;
+
 	error = xchk_trans_alloc(sc, 0);
 	if (error)
 		return error;
@@ -2198,6 +2204,27 @@ 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 and we should turn it off.
+ */
+STATIC int
+xrep_inode_verity(
+	struct xfs_scrub	*sc)
+{
+	struct inode		*inode = VFS_I(sc->ip);
+
+	if (xchk_inode_verity_broken(sc->ip)) {
+		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;
+}
+
 /* Repair an inode's fields. */
 int
 xrep_inode(
@@ -2247,6 +2274,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;
+
 	/* Reconnect incore unlinked list */
 	error = xrep_inode_unlinked(sc);
 	if (error)
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index c30e688cfc9f6e..2f6e87991d8361 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -23,6 +23,7 @@
 #include "xfs_ioend.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_rtgroup.h"
+#include "xfs_fsverity.h"
 
 struct xfs_writepage_ctx {
 	struct iomap_writepage_ctx ctx;
@@ -172,12 +173,16 @@ xfs_map_blocks(
 	int			retries = 0;
 	int			error = 0;
 	unsigned int		*seq;
+	unsigned int		iomap_flags = 0;
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
 	XFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * COW fork blocks can overlap data fork blocks even if the blocks
 	 * aren't shared.  COW I/O always takes precedent, so we must always
@@ -265,7 +270,8 @@ xfs_map_blocks(
 	    isnullstartblock(imap.br_startblock))
 		goto allocate_blocks;
 
-	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, XFS_WPC(wpc)->data_seq);
+	xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, iomap_flags,
+			  XFS_WPC(wpc)->data_seq);
 	trace_xfs_map_blocks_found(ip, offset, count, whichfork, &imap);
 	return 0;
 allocate_blocks:
@@ -412,12 +418,16 @@ xfs_zoned_map_blocks(
 	xfs_filblks_t		count_fsb;
 	struct xfs_bmbt_irec	imap, del;
 	struct xfs_iext_cursor	icur;
+	u16			iomap_flags = 0;
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
 	XFS_ERRORTAG_DELAY(mp, XFS_ERRTAG_WB_DELAY_MS);
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * All dirty data must be covered by delalloc extents.  But truncate can
 	 * remove delalloc extents underneath us or reduce their size.
@@ -441,7 +451,7 @@ xfs_zoned_map_blocks(
 		imap.br_startblock = HOLESTARTBLOCK;
 		imap.br_state = XFS_EXT_NORM;
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
-		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, 0, 0);
+		xfs_bmbt_to_iomap(ip, &wpc->iomap, &imap, 0, iomap_flags, 0);
 		return 0;
 	}
 	end_fsb = min(end_fsb, imap.br_startoff + imap.br_blockcount);
@@ -454,7 +464,7 @@ xfs_zoned_map_blocks(
 	xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
 	xfs_iomap_set_anon_write(ip, &wpc->iomap, offset,
-			XFS_FSB_TO_B(mp, count_fsb));
+			XFS_FSB_TO_B(mp, count_fsb), iomap_flags);
 	trace_xfs_zoned_map_blocks(ip, offset, wpc->iomap.length);
 	return 0;
 }
@@ -507,6 +517,22 @@ static const struct iomap_writeback_ops xfs_zoned_writeback_ops = {
 	.writeback_submit	= xfs_zoned_writeback_submit,
 };
 
+static int
+xfs_iomap_writepages(
+	struct xfs_inode		*ip,
+	struct iomap_writepage_ctx	*ctx)
+{
+	/*
+	 * Writeback does not work for folios past EOF, let it know that
+	 * I/O happens for fsverity metadata and this restriction need
+	 * to be skipped
+	 */
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		ctx->iomap.flags |= IOMAP_F_FSVERITY;
+
+	return iomap_writepages(ctx);
+}
+
 STATIC int
 xfs_vm_writepages(
 	struct address_space	*mapping,
@@ -526,7 +552,7 @@ xfs_vm_writepages(
 		};
 		int				error;
 
-		error = iomap_writepages(&xc.ctx);
+		error = xfs_iomap_writepages(ip, &xc.ctx);
 		if (xc.open_zone)
 			xfs_open_zone_put(xc.open_zone);
 		return error;
@@ -539,7 +565,7 @@ xfs_vm_writepages(
 			},
 		};
 
-		return iomap_writepages(&wpc.ctx);
+		return xfs_iomap_writepages(ip, &wpc.ctx);
 	}
 }
 
@@ -585,7 +611,7 @@ xfs_bio_submit_read(
 {
 	xfs_ioend_submit_read(iter->inode, ctx->read_ctx,
 			ctx->read_ctx_file_offset,
-			iomap_ioend_flags(&iter->iomap));
+			iomap_ioend_flags(&iter->iomap), ctx->vi);
 	ctx->read_ctx = NULL;
 }
 
@@ -597,11 +623,13 @@ static const struct iomap_read_ops xfs_iomap_read_ops = {
 
 static inline const struct iomap_read_ops *
 xfs_get_iomap_read_ops(
-	const struct address_space	*mapping)
+	const struct address_space	*mapping,
+	loff_t				pos)
 {
 	struct xfs_inode		*ip = XFS_I(mapping->host);
 
-	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev))
+	if (bdev_has_integrity_csum(xfs_inode_buftarg(ip)->bt_bdev) ||
+	    xfs_fsverity_is_file_data(ip, pos))
 		return &xfs_iomap_read_ops;
 	return &iomap_bio_read_ops;
 }
@@ -613,7 +641,7 @@ xfs_vm_read_folio(
 {
 	struct iomap_read_folio_ctx	ctx = { .cur_folio = folio };
 
-	ctx.ops = xfs_get_iomap_read_ops(folio->mapping);
+	ctx.ops = xfs_get_iomap_read_ops(folio->mapping, folio_pos(folio));
 	iomap_read_folio(&xfs_read_iomap_ops, &ctx, NULL);
 	return 0;
 }
@@ -624,7 +652,7 @@ xfs_vm_readahead(
 {
 	struct iomap_read_folio_ctx	ctx = { .rac = rac };
 
-	ctx.ops = xfs_get_iomap_read_ops(rac->mapping),
+	ctx.ops = xfs_get_iomap_read_ops(rac->mapping, readahead_pos(rac));
 	iomap_readahead(&xfs_read_iomap_ops, &ctx, NULL);
 }
 
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 865aec3ae5ab32..32cec523fd52d7 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -31,6 +31,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_rtgroup.h"
 #include "xfs_zone_alloc.h"
+#include <linux/fsverity.h>
 
 /* Kernel only BMAP related definitions and functions */
 
@@ -553,6 +554,15 @@ xfs_can_free_eofblocks(
 	if (last_fsb <= end_fsb)
 		return false;
 
+	/*
+	 * Don't clean fsverity inodes as they already have been cleaned up and
+	 * are read-only. Skip inodes which have merkle tree being built, the
+	 * merkle tree is written beyond EOF
+	 */
+	if (fsverity_active(VFS_IC(ip)) ||
+	    xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		return false;
+
 	/*
 	 * Check if there is an post-EOF extent to free.  If there are any
 	 * delalloc blocks attached to the inode (data fork delalloc
@@ -579,6 +589,9 @@ xfs_free_eofblocks(
 	struct xfs_trans	*tp;
 	struct xfs_mount	*mp = ip->i_mount;
 	int			error;
+	int			bmapi_flags = XFS_BMAPI_NODISCARD;
+	bool			has_verity =
+			ip->i_diflags2 & XFS_DIFLAG2_VERITY;
 
 	/* Attach the dquots to the inode up front. */
 	error = xfs_qm_dqattach(ip);
@@ -593,15 +606,20 @@ xfs_free_eofblocks(
 	 *
 	 * 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
 	 */
-	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) {
+	if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND) ||
+			has_verity) {
 		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);
 		}
 		xfs_inode_clear_eofblocks_tag(ip);
-		return 0;
+		if (!has_verity)
+			return 0;
 	}
 
 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
@@ -613,6 +631,13 @@ 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 (has_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
@@ -620,7 +645,7 @@ xfs_free_eofblocks(
 	 * bug).
 	 */
 	error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK,
-				XFS_ISIZE(ip), XFS_BMAPI_NODISCARD);
+				XFS_ISIZE(ip), bmapi_flags);
 	if (error)
 		goto err_cancel;
 
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 7d0c8a197575cf..a610adc90c0289 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -38,6 +38,7 @@
 #include <linux/mount.h>
 #include <linux/filelock.h>
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
 
 static const struct vm_operations_struct xfs_file_vm_ops;
 
@@ -223,7 +224,8 @@ xfs_dio_read_bounce_submit_io(
 	loff_t			file_offset)
 {
 	xfs_ioend_submit_read(iter->inode, bio, file_offset,
-			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT);
+			iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT,
+			NULL);
 }
 
 static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
@@ -231,6 +233,25 @@ static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
 	.bio_set	= &iomap_ioend_bioset,
 };
 
+STATIC ssize_t
+xfs_file_buffered_read(
+	struct kiocb		*iocb,
+	struct iov_iter		*to)
+{
+	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
+	ssize_t			ret;
+
+	trace_xfs_file_buffered_read(iocb, to);
+
+	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
+	if (ret)
+		return ret;
+	ret = generic_file_read_iter(iocb, to);
+	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+
+	return ret;
+}
+
 STATIC ssize_t
 xfs_file_dio_read(
 	struct kiocb		*iocb,
@@ -249,6 +270,17 @@ xfs_file_dio_read(
 	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
 	if (ret)
 		return ret;
+
+	/*
+	 * Re-check verity status after acquiring lock. This prevents TOCTOU in
+	 * xfs_file_read_iter() while falling back from DIO to buffered I/O as
+	 * now we are holding a lock
+	 */
+	if (fsverity_active(VFS_I(ip))) {
+		xfs_iunlock(ip, XFS_IOLOCK_SHARED);
+		iocb->ki_flags &= ~IOCB_DIRECT;
+		return xfs_file_buffered_read(iocb, to);
+	}
 	if (mapping_stable_writes(iocb->ki_filp->f_mapping)) {
 		ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops,
 				&xfs_dio_read_bounce_ops, 0, NULL, 0);
@@ -268,7 +300,8 @@ xfs_file_dax_read(
 	struct kiocb		*iocb,
 	struct iov_iter		*to)
 {
-	struct xfs_inode	*ip = XFS_I(iocb->ki_filp->f_mapping->host);
+	struct inode		*inode = iocb->ki_filp->f_mapping->host;
+	struct xfs_inode	*ip = XFS_I(inode);
 	ssize_t			ret = 0;
 
 	trace_xfs_file_dax_read(iocb, to);
@@ -286,25 +319,6 @@ xfs_file_dax_read(
 	return ret;
 }
 
-STATIC ssize_t
-xfs_file_buffered_read(
-	struct kiocb		*iocb,
-	struct iov_iter		*to)
-{
-	struct xfs_inode	*ip = XFS_I(file_inode(iocb->ki_filp));
-	ssize_t			ret;
-
-	trace_xfs_file_buffered_read(iocb, to);
-
-	ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
-	if (ret)
-		return ret;
-	ret = generic_file_read_iter(iocb, to);
-	xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-
-	return ret;
-}
-
 STATIC ssize_t
 xfs_file_read_iter(
 	struct kiocb		*iocb,
@@ -319,6 +333,14 @@ xfs_file_read_iter(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	/*
+	 * In case fs-verity is enabled, we also fallback to the buffered read
+	 * from the direct read path. Therefore, IOCB_DIRECT is set and need to
+	 * be cleared (see generic_file_read_iter())
+	 */
+	if (fsverity_active(inode))
+		iocb->ki_flags &= ~IOCB_DIRECT;
+
 	if (IS_DAX(inode))
 		ret = xfs_file_dax_read(iocb, to);
 	else if (iocb->ki_flags & IOCB_DIRECT)
@@ -1771,11 +1793,18 @@ xfs_file_open(
 	struct inode	*inode,
 	struct file	*file)
 {
+	int		error;
+
 	if (xfs_is_shutdown(XFS_M(inode->i_sb)))
 		return -EIO;
 	file->f_mode |= FMODE_NOWAIT | FMODE_CAN_ODIRECT;
 	if (xfs_get_atomic_write_min(XFS_I(inode)) > 0)
 		file->f_mode |= FMODE_CAN_ATOMIC_WRITE;
+
+	error = fsverity_file_open(inode, file);
+	if (error)
+		return error;
+
 	return generic_file_open(inode, file);
 }
 
diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
new file mode 100644
index 00000000000000..9b83a0735dc049
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.c
@@ -0,0 +1,482 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#include "xfs_platform.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_inode.h"
+#include "xfs_log_format.h"
+#include "xfs_trans.h"
+#include "xfs_trace.h"
+#include "xfs_quota.h"
+#include "xfs_fsverity.h"
+#include "xfs_iomap.h"
+#include "xfs_error.h"
+#include "xfs_health.h"
+#include "xfs_bmap_util.h"
+#include "xfs_icache.h"
+#include <linux/fsverity.h>
+#include <linux/iomap.h>
+#include <linux/pagemap.h>
+
+struct kmem_cache *xfs_fsverity_ioend_cache;
+mempool_t xfs_fsverity_ioend_pool;
+
+#define XFS_FSVERITY_IOEND_POOL_MIN	128
+
+/*
+ * Back the fsverity ioend allocations with a mempool so that read I/O
+ * completion always makes forward progress and cannot deadlock
+ */
+int
+xfs_fsverity_init(void)
+{
+	return mempool_init_slab_pool(&xfs_fsverity_ioend_pool,
+			XFS_FSVERITY_IOEND_POOL_MIN, xfs_fsverity_ioend_cache);
+}
+
+void
+xfs_fsverity_exit(void)
+{
+	mempool_exit(&xfs_fsverity_ioend_pool);
+}
+
+bool
+xfs_fsverity_is_file_data(
+	const struct xfs_inode	*ip,
+	loff_t			offset)
+{
+	return fsverity_active(VFS_IC(ip)) &&
+			offset < xfs_fsverity_metadata_offset(ip);
+}
+
+/*
+ * Retrieve the verity descriptor.
+ */
+static int
+xfs_fsverity_get_descriptor(
+	struct inode		*inode,
+	void			*buf,
+	size_t			buf_size)
+{
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	__be32			d_desc_size;
+	u32			desc_size;
+	u64			desc_size_pos;
+	int			error;
+	u64			desc_pos;
+	struct xfs_bmbt_irec	rec;
+	int			is_empty;
+	uint32_t		blocksize = i_blocksize(VFS_I(ip));
+	xfs_fileoff_t		last_block_offset;
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	/*
+	 * Serialize reading of inode->i_flags with xfs_scrub clearing of this
+	 * flag if inode is corrupted.
+	 */
+	if (!(inode->i_flags & S_VERITY)) {
+		xfs_iunlock(ip, XFS_ILOCK_EXCL);
+		return -ENODATA;
+	}
+	error = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, &rec, &is_empty);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		return error;
+
+	if (is_empty) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	last_block_offset =
+		XFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);
+	if (last_block_offset <= xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ENODATA;
+	}
+
+	desc_size_pos = last_block_offset - sizeof(__be32);
+	error = fsverity_pagecache_read(inode, (char *)&d_desc_size,
+			sizeof(d_desc_size), desc_size_pos);
+	if (error)
+		return error;
+
+	desc_size = be32_to_cpu(d_desc_size);
+	if (XFS_IS_CORRUPT(mp, desc_size > FS_VERITY_MAX_DESCRIPTOR_SIZE)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (XFS_IS_CORRUPT(mp, desc_size > desc_size_pos)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	if (!buf_size)
+		return desc_size;
+
+	if (XFS_IS_CORRUPT(mp, desc_size > buf_size)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	desc_pos = round_down(desc_size_pos - desc_size, blocksize);
+	if (desc_pos < xfs_fsverity_metadata_offset(ip)) {
+		xfs_inode_mark_sick(XFS_I(inode), XFS_SICK_INO_FSVERITY);
+		return -ERANGE;
+	}
+
+	error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
+	if (error)
+		return error;
+
+	return desc_size;
+}
+
+static int
+xfs_fsverity_write_descriptor(
+	struct file		*file,
+	const void		*desc,
+	u32			desc_size,
+	u64			merkle_tree_size)
+{
+	int			error;
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	unsigned int		blksize = ip->i_mount->m_sb.sb_blocksize;
+	u64			tree_last_block =
+			xfs_fsverity_metadata_offset(ip) + merkle_tree_size;
+	u64			desc_pos =
+			round_up(tree_last_block, XFS_FSVERITY_START_ALIGN);
+	u64			desc_end = desc_pos + desc_size;
+	__be32			desc_size_disk = cpu_to_be32(desc_size);
+	u64			desc_size_pos =
+			round_up(desc_end + sizeof(desc_size_disk), blksize) -
+			sizeof(desc_size_disk);
+
+	error = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),
+			(const void *)&desc_size_disk,
+			&xfs_buffered_write_iomap_ops,
+			&xfs_iomap_write_ops);
+	if (error)
+		return error;
+
+	return iomap_fsverity_write(file, desc_pos, desc_size, desc,
+			&xfs_buffered_write_iomap_ops,
+			&xfs_iomap_write_ops);
+}
+
+/*
+ * Try to remove all the fsverity metadata after a failed enablement.
+ */
+static int
+xfs_fsverity_delete_metadata(
+	struct xfs_inode	*ip)
+{
+	struct xfs_trans	*tp;
+	struct xfs_mount	*mp = ip->i_mount;
+	int			error;
+
+	xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
+	truncate_inode_pages(VFS_I(ip)->i_mapping, XFS_ISIZE(ip));
+
+	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
+	if (error) {
+		xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
+		return error;
+	}
+
+	xfs_ilock(ip, XFS_ILOCK_EXCL);
+	xfs_trans_ijoin(tp, ip, 0);
+
+	/*
+	 * We remove post EOF data, no need to update i_size as fsverity
+	 * didn't move i_size in the first place
+	 */
+	error = xfs_itruncate_extents(&tp, ip, XFS_DATA_FORK, XFS_ISIZE(ip));
+	if (error)
+		goto err_cancel;
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+err_cancel:
+	xfs_trans_cancel(tp);
+	xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_ILOCK_EXCL);
+	return error;
+}
+
+static int
+xfs_fsverity_reset_inode(
+	struct xfs_inode	*ip)
+{
+	int			error;
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+
+	error = xfs_fsverity_delete_metadata(ip);
+	if (error)
+		return error;
+
+	/*
+	 * First, let's clean in-memory fsverity flag and then reset it on the
+	 * disk
+	 */
+	inode_set_flags(VFS_I(ip), 0, S_VERITY);
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		return error;
+
+	ip->i_diflags2 &= ~XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	return error;
+}
+
+/*
+ * Prepare to enable fsverity by clearing old metadata.
+ */
+static int
+xfs_fsverity_begin_enable(
+	struct file		*filp)
+{
+	struct inode		*inode = file_inode(filp);
+	struct xfs_inode	*ip = XFS_I(inode);
+	int			error;
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	if (IS_DAX(inode) || ip->i_diflags2 & XFS_DIFLAG2_DAX)
+		return -EINVAL;
+
+	/*
+	 * fs-verity stores the Merkle tree past EOF in units of the filesystem
+	 * block size, so it cannot support realtime files whose allocation unit
+	 * (extent size) is larger than the block size.
+	 */
+	if (xfs_inode_has_bigrtalloc(ip))
+		return -EINVAL;
+
+	if (inode->i_size > XFS_FSVERITY_LARGEST_FILE)
+		return -EFBIG;
+
+	/*
+	 * Flush pagecache before building Merkle tree. Inode is locked and no
+	 * further writes will happen to the file except fsverity metadata
+	 */
+	error = filemap_write_and_wait(inode->i_mapping);
+	if (error)
+		return error;
+
+	if (xfs_iflags_test_and_set(ip, XFS_VERITY_CONSTRUCTION))
+		return -EBUSY;
+
+	error = xfs_qm_dqattach(ip);
+	if (error)
+		goto out_clear;
+
+	error = xfs_fsverity_delete_metadata(ip);
+	if (error)
+		goto out_clear;
+	return error;
+out_clear:
+	xfs_iflags_clear(ip, XFS_VERITY_CONSTRUCTION);
+	return error;
+}
+
+/*
+ * Complete (or fail) the process of enabling fsverity.
+ */
+static int
+xfs_fsverity_end_enable(
+	struct file		*file,
+	const void		*desc,
+	size_t			desc_size,
+	u64			merkle_tree_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	struct xfs_mount	*mp = ip->i_mount;
+	struct xfs_trans	*tp;
+	int			error = 0;
+	loff_t			range_start = xfs_fsverity_metadata_offset(ip);
+
+	xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
+
+	/* fs-verity failed, just cleanup */
+	if (desc == NULL)
+		goto out;
+
+	error = xfs_fsverity_write_descriptor(file, desc, desc_size,
+			merkle_tree_size);
+	if (error)
+		goto out;
+
+	/*
+	 * Wait for Merkle tree get written to disk before setting on-disk inode
+	 * flag and clearing XFS_VERITY_CONSTRUCTION
+	 */
+	error = filemap_write_and_wait_range(inode->i_mapping, range_start,
+			LLONG_MAX);
+	if (error)
+		goto out;
+
+	/*
+	 * Set fsverity inode flag
+	 */
+	error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange,
+			0, 0, false, &tp);
+	if (error)
+		goto out;
+
+	/*
+	 * Ensure that we've persisted the verity information before we enable
+	 * it on the inode and tell the caller we have sealed the inode.
+	 */
+	ip->i_diflags2 |= XFS_DIFLAG2_VERITY;
+
+	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	xfs_trans_set_sync(tp);
+
+	error = xfs_trans_commit(tp);
+	xfs_iunlock(ip, XFS_ILOCK_EXCL);
+	if (error)
+		goto out;
+
+	inode_set_flags(inode, S_VERITY, S_VERITY);
+
+	/*
+	 * Proactively remove unwritten extents left by COW preallocations and
+	 * write preallocation in the merkle tree holes and past descriptor,
+	 * and any delayed preallocations
+	 */
+	error = xfs_free_eofblocks(ip);
+out:
+	if (error) {
+		int	error2;
+
+		error2 = xfs_fsverity_reset_inode(ip);
+		if (error2)
+			xfs_alert(ip->i_mount,
+"ino 0x%llx failed to clean up new fsverity metadata, err %d",
+					I_INO(ip), error2);
+	}
+
+	xfs_iflags_clear(ip, XFS_VERITY_CONSTRUCTION);
+	return error;
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static struct page *
+xfs_fsverity_read_merkle(
+	struct inode		*inode,
+	pgoff_t			index)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	return generic_read_merkle_tree_page(inode, index);
+}
+
+/*
+ * Retrieve a merkle tree block.
+ */
+static void
+xfs_fsverity_readahead_merkle_tree(
+	struct inode		*inode,
+	pgoff_t			index,
+	unsigned long		nr_pages)
+{
+	index += xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT;
+
+	generic_readahead_merkle_tree(inode, index, nr_pages);
+}
+
+static inline bool
+xfs_fsverity_is_hashes_of_zeroed_blocks(
+	struct xfs_inode	*ip,
+	const void		*buf,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	/*
+	 * If this is a block full of hashes of zeroed blocks, don't bother
+	 * storing the block. We can synthesize them later.
+	 *
+	 * However, do this only in case Merkle tree block == fs block size.
+	 * Iomap synthesizes these blocks based on holes in the merkle tree. We
+	 * won't be able to tell if something need to be synthesizes for the
+	 * range in the fs block. For example, for 4k filesystem block
+	 *
+	 *	[ 1k | zero hashes | zero hashes | 1k ]
+	 *
+	 * Iomap won't know about these empty blocks.
+	 */
+	if (size != ip->i_mount->m_sb.sb_blocksize)
+		return false;
+	/*
+	 * First digest is zero_digest
+	 */
+	if (memcmp(buf, zero_digest, digest_size))
+		return false;
+	/*
+	 * Every digest is same as previous, thus all are
+	 * zero_digest
+	 */
+	return memcmp(buf + digest_size, buf, size - digest_size) == 0;
+}
+
+/*
+ * Write a merkle tree block.
+ */
+static int
+xfs_fsverity_write_merkle(
+	struct file		*file,
+	const void		*buf,
+	u64			pos,
+	unsigned int		size,
+	const u8		*zero_digest,
+	unsigned int		digest_size)
+{
+	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
+	loff_t			position = pos +
+		xfs_fsverity_metadata_offset(ip);
+
+	if (position + size > inode->i_sb->s_maxbytes)
+		return -EFBIG;
+
+	if (xfs_fsverity_is_hashes_of_zeroed_blocks(ip, buf, size, zero_digest,
+						    digest_size))
+		return 0;
+
+	return iomap_fsverity_write(file, position, size, buf,
+			&xfs_buffered_write_iomap_ops,
+			&xfs_iomap_write_ops);
+}
+
+const struct fsverity_operations xfs_fsverity_ops = {
+	.begin_enable_verity		= xfs_fsverity_begin_enable,
+	.end_enable_verity		= xfs_fsverity_end_enable,
+	.get_verity_descriptor		= xfs_fsverity_get_descriptor,
+	.read_merkle_tree_page		= xfs_fsverity_read_merkle,
+	.readahead_merkle_tree		= xfs_fsverity_readahead_merkle_tree,
+	.write_merkle_tree_block	= xfs_fsverity_write_merkle,
+};
diff --git a/fs/xfs/xfs_fsverity.h b/fs/xfs/xfs_fsverity.h
new file mode 100644
index 00000000000000..43f8ef62e12a1a
--- /dev/null
+++ b/fs/xfs/xfs_fsverity.h
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Red Hat, Inc.
+ */
+#ifndef __XFS_FSVERITY_H__
+#define __XFS_FSVERITY_H__
+
+#include "xfs_platform.h"
+#include "xfs_verity.h"
+#include <linux/iomap.h>
+#include <linux/fsverity.h>
+#include <linux/mempool.h>
+
+#ifdef CONFIG_FS_VERITY
+extern const struct fsverity_operations xfs_fsverity_ops;
+int xfs_fsverity_init(void);
+void xfs_fsverity_exit(void);
+bool xfs_fsverity_is_file_data(const struct xfs_inode *ip, loff_t offset);
+#else
+static inline int xfs_fsverity_init(void)
+{
+	return 0;
+}
+static inline void xfs_fsverity_exit(void)
+{
+}
+static inline bool xfs_fsverity_is_file_data(const struct xfs_inode *ip,
+					    loff_t offset)
+{
+	return false;
+}
+#endif	/* CONFIG_FS_VERITY */
+
+struct xfs_fsverity_ioend {
+	struct iomap_ioend	*ioend;
+	struct work_struct	work;
+};
+
+extern struct kmem_cache *xfs_fsverity_ioend_cache;
+extern mempool_t xfs_fsverity_ioend_pool;
+
+#endif	/* __XFS_FSVERITY_H__ */
diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
index 239b843e83d42a..be66760fb120f7 100644
--- a/fs/xfs/xfs_health.c
+++ b/fs/xfs/xfs_health.c
@@ -625,6 +625,7 @@ static const struct ioctl_sick_map ino_map[] = {
 	{ XFS_SICK_INO_DIR_ZAPPED,	XFS_BS_SICK_DIR },
 	{ XFS_SICK_INO_SYMLINK_ZAPPED,	XFS_BS_SICK_SYMLINK },
 	{ XFS_SICK_INO_DIRTREE,	XFS_BS_SICK_DIRTREE },
+	{ XFS_SICK_INO_FSVERITY,	XFS_BS_SICK_FSVERITY },
 };
 
 /* Fill out bulkstat health info. */
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index 75eff68c1e3950..034d3f6072a932 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -428,6 +428,12 @@ static inline bool xfs_inode_can_sw_atomic_write(const struct xfs_inode *ip)
  */
 #define XFS_IREMAPPING		(1U << 15)
 
+/*
+ * fs-verity's Merkle tree is under construction. The file is read-only, the
+ * only writes happening are for the fsverity metadata.
+ */
+#define XFS_VERITY_CONSTRUCTION	(1U << 16)
+
 /* All inode state flags related to inode reclaim. */
 #define XFS_ALL_IRECLAIM_FLAGS	(XFS_IRECLAIMABLE | \
 				 XFS_IRECLAIM | \
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index f81b6e52ac403d..37c6a2fae58cc0 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -49,6 +49,7 @@
 
 #include <linux/mount.h>
 #include <linux/fileattr.h>
+#include <linux/fsverity.h>
 
 /* Return 0 on success or positive error */
 int
@@ -1575,6 +1576,19 @@ xfs_file_ioctl(
 	case XFS_IOC_VERIFY_MEDIA:
 		return xfs_ioc_verify_media(filp, arg);
 
+	case FS_IOC_ENABLE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_enable(filp, arg);
+	case FS_IOC_MEASURE_VERITY:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_measure(filp, arg);
+	case FS_IOC_READ_VERITY_METADATA:
+		if (!xfs_has_verity(mp))
+			return -EOPNOTSUPP;
+		return fsverity_ioctl_read_metadata(filp, arg);
+
 	default:
 		return -ENOTTY;
 	}
diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c
index 48becc3bf60889..d30aee973a876a 100644
--- a/fs/xfs/xfs_ioend.c
+++ b/fs/xfs/xfs_ioend.c
@@ -18,7 +18,26 @@
 #include "xfs_ioend.h"
 #include "xfs_error.h"
 #include "xfs_errortag.h"
+#include "xfs_fsverity.h"
 #include <linux/bio-integrity.h>
+#include <linux/fsverity.h>
+
+static void
+xfs_end_fsverity_io_read(
+	struct work_struct		*work)
+{
+	struct xfs_fsverity_ioend	*fsv_ioend =
+			container_of(work, struct xfs_fsverity_ioend, work);
+	struct iomap_ioend		*ioend = fsv_ioend->ioend;
+	struct bio			*bio = &ioend->io_bio;
+
+	mempool_free(fsv_ioend, &xfs_fsverity_ioend_pool);
+
+	if (!bio->bi_status)
+		fsverity_verify_bio(ioend->io_vi, bio);
+
+	iomap_finish_ioends(ioend, blk_status_to_errno(bio->bi_status));
+}
 
 static void
 xfs_dio_bounce_end_io(
@@ -93,12 +112,14 @@ xfs_read_bounce_and_resubmit(
 
 static void
 xfs_end_io_read(
-	struct bio		*bio)
+	struct bio			*bio)
 {
-	struct iomap_ioend	*ioend = iomap_ioend_from_bio(bio);
-	struct xfs_inode	*ip = XFS_I(ioend->io_inode);
-	struct xfs_mount	*mp = ip->i_mount;
-	int			error = blk_status_to_errno(bio->bi_status);
+	struct iomap_ioend		*ioend = iomap_ioend_from_bio(bio);
+	struct xfs_inode		*ip = XFS_I(ioend->io_inode);
+	struct xfs_mount		*mp = ip->i_mount;
+	int				error =
+			blk_status_to_errno(bio->bi_status);
+	struct xfs_fsverity_ioend	*fsv_ioend;
 
 	if (!error && (ioend->io_flags & IOMAP_IOEND_INTEGRITY)) {
 		error = iomap_ioend_integrity_verify(ioend);
@@ -117,6 +138,24 @@ xfs_end_io_read(
 		}
 	}
 
+	/*
+	 * If we have fsverity on this bio, we need to run fsverity verification
+	 * of data folios from a separate fsverity workqueue. This is necessary
+	 * to avoid deadlocking due to fsverity issuing more reads of fsverity
+	 * metadata which would be processed by the same worker in the BIO
+	 * completion workqueue.
+	 */
+	if (IS_ENABLED(CONFIG_FS_VERITY) && !error && ioend->io_vi &&
+			xfs_fsverity_is_file_data(ip, ioend->io_offset)) {
+		fsv_ioend = mempool_alloc(&xfs_fsverity_ioend_pool,
+				GFP_NOFS);
+		fsv_ioend->ioend = ioend;
+		INIT_WORK(&fsv_ioend->work, xfs_end_fsverity_io_read);
+
+		fsverity_enqueue_verify_work(&fsv_ioend->work);
+		return;
+	}
+
 	iomap_finish_ioends(ioend, error);
 }
 
@@ -125,13 +164,15 @@ xfs_ioend_submit_read(
 	struct inode		*inode,
 	struct bio		*bio,
 	loff_t			file_offset,
-	u16			ioend_flags)
+	u16			ioend_flags,
+	struct fsverity_info	*vi)
 {
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	struct iomap_ioend	*ioend;
 
 	ioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags);
+	ioend->io_vi = vi;
 	if ((ioend_flags & IOMAP_IOEND_DIRECT) &&
 	    READ_ONCE(mp->m_read_bounce) == XFS_READ_BOUNCE_ALWAYS) {
 		iomap_bounce_read(ioend, bdev_logical_block_size(bio->bi_bdev),
diff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h
index 7c2a1ea3e6eddc..992c248a693aaf 100644
--- a/fs/xfs/xfs_ioend.h
+++ b/fs/xfs/xfs_ioend.h
@@ -2,6 +2,8 @@
 #ifndef __XFS_IOEND_H
 #define __XFS_IOEND_H
 
+#include <linux/fsverity.h>
+
 /*
  * Fast and loose check if this write could update the on-disk inode size.
  */
@@ -13,6 +15,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend)
 
 void xfs_end_bio(struct bio *bio);
 void xfs_ioend_submit_read(struct inode *inode, struct bio *bio,
-		loff_t file_offset, u16 ioend_flags);
+		loff_t file_offset, u16 ioend_flags, struct fsverity_info *vi);
 
 #endif /* __XFS_IOEND_H */
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 329c745e312045..68fef657644202 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -32,6 +32,8 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_icache.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_verity.h"
+#include <linux/fsverity.h>
 
 #define XFS_ALLOC_ALIGN(mp, off) \
 	(((off) >> mp->m_allocsize_log) << mp->m_allocsize_log)
@@ -883,6 +885,9 @@ xfs_direct_write_iomap_begin(
 	if (flags & IOMAP_ATOMIC)
 		iomap_flags |= IOMAP_F_ATOMIC_BIO;
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	/*
 	 * COW writes may allocate delalloc space or convert unwritten COW
 	 * extents, so we need to make sure to take the lock exclusively here.
@@ -1023,7 +1028,8 @@ xfs_direct_write_iomap_begin(
 	trace_xfs_iomap_found(ip, offset, length - offset, XFS_COW_FORK, &cmap);
 	if (imap.br_startblock != HOLESTARTBLOCK) {
 		seq = xfs_iomap_inode_sequence(ip, 0);
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0, seq);
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags,
+				iomap_flags & IOMAP_F_FSVERITY, seq);
 		if (error)
 			goto out_unlock;
 	}
@@ -1083,7 +1089,7 @@ xfs_zoned_direct_write_iomap_begin(
 			return error;
 	}
 
-	xfs_iomap_set_anon_write(ip, iomap, offset, length);
+	xfs_iomap_set_anon_write(ip, iomap, offset, length, 0);
 	return 0;
 }
 
@@ -1594,7 +1600,8 @@ xfs_zoned_fill_srcmap(
 	xfs_fileoff_t		offset_fsb,
 	xfs_fileoff_t		*end_fsb,
 	unsigned		flags,
-	struct iomap		*srcmap)
+	struct iomap		*srcmap,
+	u16			iomap_flags)
 {
 	struct xfs_bmbt_irec	smap;
 	struct xfs_iext_cursor	scur;
@@ -1615,7 +1622,7 @@ xfs_zoned_fill_srcmap(
 	 */
 	xfs_trim_extent(&smap, offset_fsb, *end_fsb - offset_fsb);
 	*end_fsb = min(*end_fsb, smap.br_startoff + smap.br_blockcount);
-	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, 0,
+	return xfs_bmbt_to_iomap(ip, srcmap, &smap, flags, iomap_flags,
 			xfs_iomap_inode_sequence(ip, 0));
 }
 
@@ -1626,7 +1633,8 @@ xfs_zoned_buffered_write_iomap_begin(
 	loff_t			count,
 	unsigned		flags,
 	struct iomap		*iomap,
-	struct iomap		*srcmap)
+	struct iomap		*srcmap,
+	u16			iomap_flags)
 {
 	struct iomap_iter	*iter =
 		container_of(iomap, struct iomap_iter, iomap);
@@ -1636,7 +1644,6 @@ xfs_zoned_buffered_write_iomap_begin(
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
 	xfs_fileoff_t		end_fsb = xfs_iomap_end_fsb(mp, offset, count);
-	u16			iomap_flags = IOMAP_F_SHARED;
 	unsigned int		lockmode = XFS_ILOCK_EXCL;
 	xfs_filblks_t		count_fsb;
 	xfs_extlen_t		indlen;
@@ -1687,7 +1694,7 @@ xfs_zoned_buffered_write_iomap_begin(
 	    !IS_ALIGNED(offset + count, mp->m_sb.sb_blocksize) ||
 	    (flags & IOMAP_ZERO)) {
 		error = xfs_zoned_fill_srcmap(ip, offset_fsb, &end_fsb, flags,
-				srcmap);
+				srcmap, iomap_flags);
 		if (error)
 			goto out_unlock;
 	}
@@ -1695,6 +1702,8 @@ xfs_zoned_buffered_write_iomap_begin(
 	if (!ip->i_cowfp)
 		xfs_ifork_init_cow(ip);
 
+	iomap_flags |= IOMAP_F_SHARED;
+
 	if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &got))
 		got.br_startoff = end_fsb;
 	if (got.br_startoff <= offset_fsb) {
@@ -1826,9 +1835,12 @@ xfs_buffered_write_iomap_begin(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	if (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	if (xfs_is_zoned_inode(ip))
 		return xfs_zoned_buffered_write_iomap_begin(inode, offset,
-				count, flags, iomap, srcmap);
+				count, flags, iomap, srcmap, iomap_flags);
 
 	/* we can't use delayed allocations when using extent size hints */
 	if (xfs_get_extsz_hint(ip))
@@ -2112,7 +2124,8 @@ xfs_buffered_write_iomap_begin(
 
 found_cow:
 	if (imap.br_startoff <= offset_fsb) {
-		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags, 0,
+		error = xfs_bmbt_to_iomap(ip, srcmap, &imap, flags,
+				iomap_flags & IOMAP_F_FSVERITY,
 				xfs_iomap_inode_sequence(ip, 0));
 		if (error)
 			goto out_unlock;
@@ -2216,12 +2229,17 @@ xfs_read_iomap_begin(
 	bool			shared = false;
 	unsigned int		lockmode = XFS_ILOCK_SHARED;
 	u64			seq;
+	unsigned int		iomap_flags = 0;
 
 	ASSERT(!(flags & (IOMAP_WRITE | IOMAP_ZERO)));
 
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
+	if (fsverity_active(inode) &&
+	    (offset >= xfs_fsverity_metadata_offset(ip)))
+		iomap_flags |= IOMAP_F_FSVERITY;
+
 	error = xfs_ilock_for_iomap(ip, flags, &lockmode);
 	if (error)
 		return error;
@@ -2235,8 +2253,9 @@ xfs_read_iomap_begin(
 	if (error)
 		return error;
 	trace_xfs_iomap_found(ip, offset, length, XFS_DATA_FORK, &imap);
-	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags,
-				 shared ? IOMAP_F_SHARED : 0, seq);
+	iomap_flags |= shared ? IOMAP_F_SHARED : 0;
+
+	return xfs_bmbt_to_iomap(ip, iomap, &imap, flags, iomap_flags, seq);
 }
 
 static DEFINE_IOMAP_ITER_NEXT(xfs_read_iomap_next, xfs_read_iomap_begin);
diff --git a/fs/xfs/xfs_iomap.h b/fs/xfs/xfs_iomap.h
index f2520a9b3a13e6..d3ca0f2afc9f79 100644
--- a/fs/xfs/xfs_iomap.h
+++ b/fs/xfs/xfs_iomap.h
@@ -34,13 +34,14 @@ xfs_iomap_set_anon_write(
 	struct xfs_inode		*ip,
 	struct iomap			*iomap,
 	loff_t				offset,
-	loff_t				length)
+	loff_t				length,
+	u16				iomap_flags)
 {
 	iomap->type = IOMAP_MAPPED;
 	iomap->bdev = ip->i_mount->m_rtdev_targp->bt_bdev;
 	iomap->offset = offset;
 	iomap->length = length;
-	iomap->flags = IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
+	iomap->flags = iomap_flags | IOMAP_F_ANON_WRITE | IOMAP_F_DIRTY;
 	if (bdev_has_integrity_csum(iomap->bdev))
 		iomap->flags |= IOMAP_F_INTEGRITY;
 }
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index d307ec97fac820..150bbd705807f0 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -35,6 +35,7 @@
 #include <linux/security.h>
 #include <linux/iversion.h>
 #include <linux/fiemap.h>
+#include <linux/fsverity.h>
 
 /*
  * Directories have different lock order w.r.t. mmap_lock compared to regular
@@ -579,6 +580,10 @@ xfs_report_dioalign(
 	struct block_device	*bdev = target->bt_bdev;
 
 	stat->result_mask |= STATX_DIOALIGN | STATX_DIO_READ_ALIGN;
+
+	if (fsverity_active(VFS_I(ip)))
+		return;
+
 	stat->dio_mem_align = bdev_dma_alignment(bdev) + 1;
 
 	/*
@@ -1387,6 +1392,8 @@ xfs_inode_should_enable_dax(
 		return false;
 	if (!xfs_inode_supports_dax(ip))
 		return false;
+	if (ip->i_diflags2 & XFS_DIFLAG2_VERITY)
+		return false;
 	if (xfs_has_dax_always(ip->i_mount))
 		return true;
 	if (ip->i_diflags2 & XFS_DIFLAG2_DAX)
@@ -1415,12 +1422,15 @@ xfs_diflags_to_iflags(
 		flags |= S_NOATIME;
 	if (init && xfs_inode_should_enable_dax(ip))
 		flags |= S_DAX;
+	if (xflags & FS_XFLAG_VERITY)
+		flags |= S_VERITY;
 
 	/*
 	 * S_DAX can only be set during inode initialization and is never set by
 	 * the VFS, so we cannot mask off S_DAX in i_flags.
 	 */
-	inode->i_flags &= ~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME);
+	inode->i_flags &=
+		~(S_IMMUTABLE | S_APPEND | S_SYNC | S_NOATIME | S_VERITY);
 	inode->i_flags |= flags;
 }
 
diff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c
index 0243e509a46891..44b13d46049c62 100644
--- a/fs/xfs/xfs_message.c
+++ b/fs/xfs/xfs_message.c
@@ -149,6 +149,10 @@ xfs_warn_experimental(
 			.opstate	= XFS_OPSTATE_WARNED_LARP,
 			.name		= "logged extended attributes",
 		},
+		[XFS_EXPERIMENTAL_FSVERITY] = {
+			.opstate	= XFS_OPSTATE_WARNED_FSVERITY,
+			.name		= "fsverity",
+		},
 	};
 	ASSERT(feat >= 0 && feat < XFS_EXPERIMENTAL_MAX);
 	BUILD_BUG_ON(ARRAY_SIZE(features) != XFS_EXPERIMENTAL_MAX);
diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h
index 811b885f41c35a..364fcc7e42b084 100644
--- a/fs/xfs/xfs_message.h
+++ b/fs/xfs/xfs_message.h
@@ -93,6 +93,7 @@ void xfs_buf_alert_ratelimited(struct xfs_buf *bp, const char *rlmsg,
 enum xfs_experimental_feat {
 	XFS_EXPERIMENTAL_SHRINK,
 	XFS_EXPERIMENTAL_LARP,
+	XFS_EXPERIMENTAL_FSVERITY,
 
 	XFS_EXPERIMENTAL_MAX,
 };
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index cbcfb89c67a440..0b64636635996f 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -403,6 +403,7 @@ typedef struct xfs_mount {
 #define XFS_FEAT_EXCHANGE_RANGE	(1ULL << 27)	/* exchange range */
 #define XFS_FEAT_METADIR	(1ULL << 28)	/* metadata directory tree */
 #define XFS_FEAT_ZONED		(1ULL << 29)	/* zoned RT device */
+#define XFS_FEAT_VERITY		(1ULL << 30)	/* fs-verity */
 
 /* Mount features */
 #define XFS_FEAT_NOLIFETIME	(1ULL << 47)	/* disable lifetime hints */
@@ -460,6 +461,7 @@ __XFS_HAS_FEAT(exchange_range, EXCHANGE_RANGE)
 __XFS_HAS_FEAT(metadir, METADIR)
 __XFS_HAS_FEAT(zoned, ZONED)
 __XFS_HAS_FEAT(nolifetime, NOLIFETIME)
+__XFS_HAS_FEAT(verity, VERITY)
 
 static inline bool xfs_has_rtgroups(const struct xfs_mount *mp)
 {
@@ -597,6 +599,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)
 #define XFS_OPSTATE_RESUMING_QUOTAON	18
 /* (Zoned) GC is in progress */
 #define XFS_OPSTATE_ZONEGC_RUNNING	20
+/* Kernel has logged a warning about fsverity support */
+#define XFS_OPSTATE_WARNED_FSVERITY	21
 
 #define __XFS_IS_OPSTATE(name, NAME) \
 static inline bool xfs_is_ ## name (struct xfs_mount *mp) \
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 5a06132aa38466..af679b6ab52b32 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -30,6 +30,7 @@
 #include "xfs_filestream.h"
 #include "xfs_quota.h"
 #include "xfs_sysfs.h"
+#include "xfs_fsverity.h"
 #include "xfs_ondisk.h"
 #include "xfs_rmap_item.h"
 #include "xfs_refcount_item.h"
@@ -1736,6 +1737,9 @@ xfs_fs_fill_super(
 	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
 #endif
 	sb->s_op = &xfs_super_operations;
+#ifdef CONFIG_FS_VERITY
+	sb->s_vop = &xfs_fsverity_ops;
+#endif
 
 	/*
 	 * Delay mount work if the debug hook is set. This is debug
@@ -1988,6 +1992,9 @@ xfs_fs_fill_super(
 	if (error)
 		goto out_filestream_unmount;
 
+	if (xfs_has_verity(mp))
+		xfs_warn_experimental(mp, XFS_EXPERIMENTAL_FSVERITY);
+
 	root = igrab(VFS_I(mp->m_rootip));
 	if (!root) {
 		error = -ENOENT;
@@ -2516,8 +2523,20 @@ xfs_init_caches(void)
 	if (!xfs_parent_args_cache)
 		goto out_destroy_xmi_cache;
 
+#ifdef CONFIG_FS_VERITY
+	xfs_fsverity_ioend_cache = kmem_cache_create("xfs_fsverity_ioend",
+					     sizeof(struct xfs_fsverity_ioend),
+					     0, 0, NULL);
+	if (!xfs_fsverity_ioend_cache)
+		goto out_destroy_parent_args_cache;
+#endif
+
 	return 0;
 
+#ifdef CONFIG_FS_VERITY
+ out_destroy_parent_args_cache:
+	kmem_cache_destroy(xfs_parent_args_cache);
+#endif
  out_destroy_xmi_cache:
 	kmem_cache_destroy(xfs_xmi_cache);
  out_destroy_xmd_cache:
@@ -2580,6 +2599,9 @@ xfs_destroy_caches(void)
 	 * destroy caches.
 	 */
 	rcu_barrier();
+#ifdef CONFIG_FS_VERITY
+	kmem_cache_destroy(xfs_fsverity_ioend_cache);
+#endif
 	kmem_cache_destroy(xfs_parent_args_cache);
 	kmem_cache_destroy(xfs_xmd_cache);
 	kmem_cache_destroy(xfs_xmi_cache);
@@ -2660,10 +2682,14 @@ init_xfs_fs(void)
 	if (error)
 		goto out;
 
-	error = xfs_init_workqueues();
+	error = xfs_fsverity_init();
 	if (error)
 		goto out_destroy_caches;
 
+	error = xfs_init_workqueues();
+	if (error)
+		goto out_fsverity_exit;
+
 	error = xfs_mru_cache_init();
 	if (error)
 		goto out_destroy_wq;
@@ -2740,6 +2766,8 @@ init_xfs_fs(void)
 	xfs_mru_cache_uninit();
  out_destroy_wq:
 	xfs_destroy_workqueues();
+ out_fsverity_exit:
+	xfs_fsverity_exit();
  out_destroy_caches:
 	xfs_destroy_caches();
  out:
@@ -2763,6 +2791,7 @@ exit_xfs_fs(void)
 	xfs_cleanup_procfs();
 	xfs_mru_cache_uninit();
 	xfs_destroy_workqueues();
+	xfs_fsverity_exit();
 	xfs_destroy_caches();
 	xfs_uuid_table_free();
 }

25/3 2026/11/03 04:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29071
							output: 22
							thoughts: 1504
						

Thoughts:
**Kernel Patch Review: XFS fs-verity Implementation**

Alright, let's dive into this patch. The goal is to figure out if this XFS fs-verity implementation warrants a dedicated KMSAN fuzzing session. This is a significant addition, so we need to be thorough.

First, I see the patch introduces full fs-verity support for XFS. From my initial glance at the diff highlights, this is not a trivial undertaking. The changes touch numerous files within the XFS filesystem structure. We have new Makefiles entries, various new structures and flags, new functions. The diffs range across the kernel's XFS implementation: bmap routines, file operations, I/O handling, superblock modifications, inode handling, and even health checks and scrubbing utilities. It appears we're looking at a complete integration, not just a simple add-on.

Specifically, I'm noting the implementation of `struct fsverity_operations xfs_fsverity_ops` in `xfs_fsverity.c`. This is where the core fs-verity logic resides – `begin_enable_verity`, `end_enable_verity`, `get_verity_descriptor`, `read_merkle_tree_page`, `readahead_merkle_tree`, and `write_merkle_tree_block` are all interesting. We've got workqueues and mempools, too, which could be sources of memory corruption issues if not handled meticulously.

I also see the inclusion of FS ioctls: `FS_IOC_ENABLE_VERITY`, `FS_IOC_MEASURE_VERITY`, and `FS_IOC_READ_VERITY_METADATA`, which are all potential attack surfaces. File open handling, direct read fallbacks, ioend management also need deeper looks.

I'm now honing in on the `xfs_fsverity_get_descriptor` function. It seems critical for retrieving the fs-verity descriptor. Specifically, I'm digging into `fsverity_pagecache_read`. This is a low-level operation, and the descriptor size calculations and reads using `fsverity_pagecache_read` raise a flag. We're reading data from the pagecache using offset and size calculations. The calculations look OK, but I want to understand more about the implementation of `fsverity_pagecache_read`, how it handles data, potential race conditions and how the descriptor is cached and validated. It's reading the descriptor size and the descriptor itself from the inode. I'll need to trace its call sites to fully grasp its behavior. I will look for any memory copy and allocation details.

The next step is to examine the `fs/verity` directory to fully grasp the implementation of `fsverity_pagecache_read` and understand how the descriptor is used, read, and most importantly, validated. Based on this, I'll then determine if there is a potential for out-of-bounds reads, writes, use-after-frees, or other memory safety issues that warrant fuzzing.



26/3 2026/11/03 04:04 tool grepper
0m Args:
{
  "Expression": "fsverity_pagecache_read"
}

Results:
{
  "Output": "fs/ext4/verity.c=245=static int ext4_get_verity_descriptor_location(struct inode *inode,\n--\nfs/ext4/verity.c-287-\nfs/ext4/verity.c:288:\terr = fsverity_pagecache_read(inode, \u0026desc_size_disk,\nfs/ext4/verity.c-289-\t\t\t\t      sizeof(desc_size_disk), desc_size_pos);\n--\nfs/ext4/verity.c=315=static int ext4_get_verity_descriptor(struct inode *inode, void *buf,\n--\nfs/ext4/verity.c-328-\t\t\treturn -ERANGE;\nfs/ext4/verity.c:329:\t\terr = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);\nfs/ext4/verity.c-330-\t\tif (err)\n--\nfs/f2fs/verity.c=193=static int f2fs_get_verity_descriptor(struct inode *inode, void *buf,\n--\nfs/f2fs/verity.c-226-\t\t\treturn -ERANGE;\nfs/f2fs/verity.c:227:\t\tres = fsverity_pagecache_read(inode, buf, size, pos);\nfs/f2fs/verity.c-228-\t\tif (res)\n--\nfs/verity/pagecache.c=80=EXPORT_SYMBOL_GPL(fsverity_fill_zerohash);\n--\nfs/verity/pagecache.c-82-/**\nfs/verity/pagecache.c:83: * fsverity_pagecache_read() - read verity metadata via the pagecache\nfs/verity/pagecache.c-84- * @inode:\tcopy from this inode's address space\n--\nfs/verity/pagecache.c-91- */\nfs/verity/pagecache.c:92:int fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,\nfs/verity/pagecache.c-93-\t\t\t  loff_t pos)\n--\nfs/verity/pagecache.c-112-}\nfs/verity/pagecache.c:113:EXPORT_SYMBOL_GPL(fsverity_pagecache_read);\n--\nfs/xfs/xfs_fsverity.c=61=xfs_fsverity_get_descriptor(\n--\nfs/xfs/xfs_fsverity.c-104-\tdesc_size_pos = last_block_offset - sizeof(__be32);\nfs/xfs/xfs_fsverity.c:105:\terror = fsverity_pagecache_read(inode, (char *)\u0026d_desc_size,\nfs/xfs/xfs_fsverity.c-106-\t\t\tsizeof(d_desc_size), desc_size_pos);\n--\nfs/xfs/xfs_fsverity.c-134-\nfs/xfs/xfs_fsverity.c:135:\terror = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);\nfs/xfs/xfs_fsverity.c-136-\tif (error)\n--\ninclude/linux/fsverity.h=329=void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index,\ninclude/linux/fsverity.h-330-\t\t\t\t   unsigned long nr_pages);\ninclude/linux/fsverity.h:331:int fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,\ninclude/linux/fsverity.h-332-\t\t\t    loff_t pos);\n"
}

27/3 2026/11/03 04:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32215
							output: 20
							thoughts: 69
						

Thoughts:
Here's my summary, as I see it:

**Verifying Data Integrity with `fsverity`**

Okay, so I'm looking into how `fsverity_pagecache_read` works. It's a pretty standard function, the helper used by `fsverity` for pagecache operations, and I know it's also integrated into file systems like `ext4` and `f2fs`. Now, I need to understand the interaction and control of integrity check. The best place to start understanding the mechanisms should be in `fs/verity/read_metadata.c`. I'll want to dig into how the `FS_IOC_READ_VERITY_METADATA` and `FS_IOC_MEASURE_VERITY` ioctls are implemented. Those are the key entry points for understanding how verification is triggered and how the metadata is used to perform integrity checks. I'll need to know more about how all of this ties together.



28/3 2026/11/03 04:04 tool grepper
0m Args:
{
  "Expression": "fsverity_ioctl_"
}

Results:
{
  "Output": "fs/btrfs/ioctl.c=5525=long btrfs_ioctl(struct file *file, unsigned int\n--\nfs/btrfs/ioctl.c-5666-\tcase FS_IOC_ENABLE_VERITY:\nfs/btrfs/ioctl.c:5667:\t\treturn fsverity_ioctl_enable(file, (const void __user *)argp);\nfs/btrfs/ioctl.c-5668-\tcase FS_IOC_MEASURE_VERITY:\nfs/btrfs/ioctl.c:5669:\t\treturn fsverity_ioctl_measure(file, argp);\nfs/btrfs/ioctl.c-5670-\tcase FS_IOC_READ_VERITY_METADATA:\nfs/btrfs/ioctl.c:5671:\t\treturn fsverity_ioctl_read_metadata(file, argp);\nfs/btrfs/ioctl.c-5672-\tcase BTRFS_IOC_ENCODED_READ:\n--\nfs/ext4/ioctl.c=1539=static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)\n--\nfs/ext4/ioctl.c-1892-\t\t\treturn -EOPNOTSUPP;\nfs/ext4/ioctl.c:1893:\t\treturn fsverity_ioctl_enable(filp, (const void __user *)arg);\nfs/ext4/ioctl.c-1894-\n--\nfs/ext4/ioctl.c-1897-\t\t\treturn -EOPNOTSUPP;\nfs/ext4/ioctl.c:1898:\t\treturn fsverity_ioctl_measure(filp, (void __user *)arg);\nfs/ext4/ioctl.c-1899-\n--\nfs/ext4/ioctl.c-1902-\t\t\treturn -EOPNOTSUPP;\nfs/ext4/ioctl.c:1903:\t\treturn fsverity_ioctl_read_metadata(filp,\nfs/ext4/ioctl.c-1904-\t\t\t\t\t\t    (const void __user *)arg);\n--\nfs/f2fs/file.c=4048=static int f2fs_ioc_enable_verity(struct file *filp, unsigned long arg)\n--\nfs/f2fs/file.c-4060-\nfs/f2fs/file.c:4061:\treturn fsverity_ioctl_enable(filp, (const void __user *)arg);\nfs/f2fs/file.c-4062-}\n--\nfs/f2fs/file.c=4064=static int f2fs_ioc_measure_verity(struct file *filp, unsigned long arg)\n--\nfs/f2fs/file.c-4068-\nfs/f2fs/file.c:4069:\treturn fsverity_ioctl_measure(filp, (void __user *)arg);\nfs/f2fs/file.c-4070-}\n--\nfs/f2fs/file.c=4072=static int f2fs_ioc_read_verity_metadata(struct file *filp, unsigned long arg)\n--\nfs/f2fs/file.c-4076-\nfs/f2fs/file.c:4077:\treturn fsverity_ioctl_read_metadata(filp, (const void __user *)arg);\nfs/f2fs/file.c-4078-}\n--\nfs/verity/enable.c=181=static int enable_verity(struct file *filp,\n--\nfs/verity/enable.c-318-/**\nfs/verity/enable.c:319: * fsverity_ioctl_enable() - enable verity on a file\nfs/verity/enable.c-320- * @filp: file to enable verity on\n--\nfs/verity/enable.c-327- */\nfs/verity/enable.c:328:int fsverity_ioctl_enable(struct file *filp, const void __user *uarg)\nfs/verity/enable.c-329-{\n--\nfs/verity/enable.c-414-}\nfs/verity/enable.c:415:EXPORT_SYMBOL_GPL(fsverity_ioctl_enable);\n--\nfs/verity/measure.c-15-/**\nfs/verity/measure.c:16: * fsverity_ioctl_measure() - get a verity file's digest\nfs/verity/measure.c-17- * @filp: file to get digest of\n--\nfs/verity/measure.c-25- */\nfs/verity/measure.c:26:int fsverity_ioctl_measure(struct file *filp, void __user *_uarg)\nfs/verity/measure.c-27-{\n--\nfs/verity/measure.c-61-}\nfs/verity/measure.c:62:EXPORT_SYMBOL_GPL(fsverity_ioctl_measure);\nfs/verity/measure.c-63-\n--\nfs/verity/read_metadata.c=128=static int fsverity_read_signature(struct inode *inode,\n--\nfs/verity/read_metadata.c-154-/**\nfs/verity/read_metadata.c:155: * fsverity_ioctl_read_metadata() - read verity metadata from a file\nfs/verity/read_metadata.c-156- * @filp: file to read the metadata from\n--\nfs/verity/read_metadata.c-160- */\nfs/verity/read_metadata.c:161:int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg)\nfs/verity/read_metadata.c-162-{\n--\nfs/verity/read_metadata.c-203-}\nfs/verity/read_metadata.c:204:EXPORT_SYMBOL_GPL(fsverity_ioctl_read_metadata);\n--\nfs/xfs/xfs_ioctl.c=1450=xfs_file_ioctl(\n--\nfs/xfs/xfs_ioctl.c-1581-\t\t\treturn -EOPNOTSUPP;\nfs/xfs/xfs_ioctl.c:1582:\t\treturn fsverity_ioctl_enable(filp, arg);\nfs/xfs/xfs_ioctl.c-1583-\tcase FS_IOC_MEASURE_VERITY:\n--\nfs/xfs/xfs_ioctl.c-1585-\t\t\treturn -EOPNOTSUPP;\nfs/xfs/xfs_ioctl.c:1586:\t\treturn fsverity_ioctl_measure(filp, arg);\nfs/xfs/xfs_ioctl.c-1587-\tcase FS_IOC_READ_VERITY_METADATA:\n--\nfs/xfs/xfs_ioctl.c-1589-\t\t\treturn -EOPNOTSUPP;\nfs/xfs/xfs_ioctl.c:1590:\t\treturn fsverity_ioctl_read_metadata(filp, arg);\nfs/xfs/xfs_ioctl.c-1591-\n--\ninclude/linux/fsverity.h=174=static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)\n--\ninclude/linux/fsverity.h-182-\ninclude/linux/fsverity.h:183:int fsverity_ioctl_enable(struct file *filp, const void __user *arg);\ninclude/linux/fsverity.h-184-\n--\ninclude/linux/fsverity.h-186-\ninclude/linux/fsverity.h:187:int fsverity_ioctl_measure(struct file *filp, void __user *arg);\ninclude/linux/fsverity.h-188-int fsverity_get_digest(struct inode *inode,\n--\ninclude/linux/fsverity.h=194=int __fsverity_file_open(struct inode *inode, struct file *filp);\n--\ninclude/linux/fsverity.h-197-\ninclude/linux/fsverity.h:198:int fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg);\ninclude/linux/fsverity.h-199-\n--\ninclude/linux/fsverity.h=218=static inline struct fsverity_info *fsverity_get_info(const struct inode *inode)\n--\ninclude/linux/fsverity.h-224-\ninclude/linux/fsverity.h:225:static inline int fsverity_ioctl_enable(struct file *filp,\ninclude/linux/fsverity.h-226-\t\t\t\t\tconst void __user *arg)\n--\ninclude/linux/fsverity.h-232-\ninclude/linux/fsverity.h:233:static inline int fsverity_ioctl_measure(struct file *filp, void __user *arg)\ninclude/linux/fsverity.h-234-{\n--\ninclude/linux/fsverity.h=251=static inline int __fsverity_file_open(struct inode *inode, struct file *filp)\n--\ninclude/linux/fsverity.h-257-\ninclude/linux/fsverity.h:258:static inline int fsverity_ioctl_read_metadata(struct file *filp,\ninclude/linux/fsverity.h-259-\t\t\t\t\t       const void __user *uarg)\n"
}

29/3 2026/11/03 04:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34924
							output: 39
							thoughts: 337
						

Thoughts:
**Analyzing fs-verity Implementation in XFS**

Okay, so I'm looking at this patch implementing fs-verity within XFS. My immediate focus is on potential security vulnerabilities, particularly uninitialized memory issues, so I'm going to carefully scrutinize the code changes. I need to understand exactly how fs-verity is being integrated and identify any areas where uninitialized memory might be exposed.

First, I should check the ioctls that were modified. Ah, right, the `xfs_bulkstat` struct. Okay, so in `fs/xfs/libxfs/xfs_fs.h`, there's a new flag, `XFS_BS_SICK_FSVERITY`. Wait a minute... is `xfs_bulkstat` copied to user space? That’s something I need to verify immediately because that's a prime spot for potential memory disclosure if not handled correctly.

Let's see, now I have to check `fs/xfs/xfs_health.c`. Right, here's the `ino_map` and the code that fills out the bulkstat health info. I need to understand how these structures relate to each other and how the information, including this new fs-verity flag, is being populated. I need to ensure that the data being sent to user space via `xfs_bulkstat` is properly initialized and sanitized to avoid information leaks or other unexpected behaviors. This is where the devil's in the details, so I need to go over these routines carefully.



30/3 2026/11/03 04:04 tool read-file
0m Args:
{
  "File": "fs/xfs/xfs_health.c",
  "FirstLine": 615,
  "LineCount": 45
}

Results:
{
  "Contents": " 615:\t\t{ XFS_SICK_INO_CORE,\tXFS_BS_SICK_INODE },\n 616:\t\t{ XFS_SICK_INO_BMBTD,\tXFS_BS_SICK_BMBTD },\n 617:\t\t{ XFS_SICK_INO_BMBTA,\tXFS_BS_SICK_BMBTA },\n 618:\t\t{ XFS_SICK_INO_BMBTC,\tXFS_BS_SICK_BMBTC },\n 619:\t\t{ XFS_SICK_INO_DIR,\tXFS_BS_SICK_DIR },\n 620:\t\t{ XFS_SICK_INO_XATTR,\tXFS_BS_SICK_XATTR },\n 621:\t\t{ XFS_SICK_INO_SYMLINK,\tXFS_BS_SICK_SYMLINK },\n 622:\t\t{ XFS_SICK_INO_PARENT,\tXFS_BS_SICK_PARENT },\n 623:\t\t{ XFS_SICK_INO_BMBTD_ZAPPED,\tXFS_BS_SICK_BMBTD },\n 624:\t\t{ XFS_SICK_INO_BMBTA_ZAPPED,\tXFS_BS_SICK_BMBTA },\n 625:\t\t{ XFS_SICK_INO_DIR_ZAPPED,\tXFS_BS_SICK_DIR },\n 626:\t\t{ XFS_SICK_INO_SYMLINK_ZAPPED,\tXFS_BS_SICK_SYMLINK },\n 627:\t\t{ XFS_SICK_INO_DIRTREE,\tXFS_BS_SICK_DIRTREE },\n 628:\t\t{ XFS_SICK_INO_FSVERITY,\tXFS_BS_SICK_FSVERITY },\n 629:\t};\n 630:\t\n 631:\t/* Fill out bulkstat health info. */\n 632:\tvoid\n 633:\txfs_bulkstat_health(\n 634:\t\tstruct xfs_inode\t\t*ip,\n 635:\t\tstruct xfs_bulkstat\t\t*bs)\n 636:\t{\n 637:\t\tconst struct ioctl_sick_map\t*m;\n 638:\t\tunsigned int\t\t\tsick;\n 639:\t\tunsigned int\t\t\tchecked;\n 640:\t\n 641:\t\tbs-\u003ebs_sick = 0;\n 642:\t\tbs-\u003ebs_checked = 0;\n 643:\t\n 644:\t\txfs_inode_measure_sickness(ip, \u0026sick, \u0026checked);\n 645:\t\tfor_each_sick_map(ino_map, m) {\n 646:\t\t\tif (checked \u0026 m-\u003esick_mask)\n 647:\t\t\t\tbs-\u003ebs_checked |= m-\u003eioctl_mask;\n 648:\t\t\tif (sick \u0026 m-\u003esick_mask)\n 649:\t\t\t\tbs-\u003ebs_sick |= m-\u003eioctl_mask;\n 650:\t\t}\n 651:\t}\n 652:\t\n 653:\t/* Translate XFS_SICK_INO_* into XFS_BS_SICK_*. */\n 654:\tunsigned int\n 655:\txfs_healthmon_inode_mask(\n 656:\t\tunsigned int\t\t\tsick_mask)\n 657:\t{\n 658:\t\tconst struct ioctl_sick_map\t*m;\n 659:\t\tunsigned int\t\t\tioctl_mask = 0;\n"
}

31/3 2026/11/03 04:04 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36533
							output: 31
							thoughts: 2688
						

Thoughts:
**XFS FS-Verity Descriptor Placement Analysis**

Okay, let's break this down. First, the basic structures seem straightforward: `bs_sick` and `bs_checked` are initialized, and the `xfs_bulkstat` structure is allocated appropriately. No issues there. Then, I see the addition of `VERITY` flags in `fs_geometry` and `xfs_ip2xflags`, which are just setting flags in the geometry and inode flags, respectively. This is all standard.

Now, the core operations in `xfs_fsverity.c` are where it gets interesting. I'm focusing on the descriptor handling. The `xfs_fsverity_get_descriptor` function is responsible for retrieving the FS-Verity descriptor. First, it checks the `S_VERITY` flag on the inode. Then, after locking, it determines the last extent of the file. It uses the offset of the last block (`last_block_offset`) to find the location of the descriptor size field (`d_desc_size`). If the file is empty, it returns `ENODATA` and marks the inode sick, which is correct. The function then reads the descriptor size from the end of the last extent, performing corruption checks. The crucial bit is calculating `desc_pos`, the actual location of the descriptor data. Here, the code does a `round_down(desc_size_pos - desc_size, blocksize)`. This needs careful examination.

The writing side is implemented by `xfs_fsverity_write_descriptor`. Here, the `desc_pos` is calculated as `round_up(tree_last_block, XFS_FSVERITY_START_ALIGN)`.  The `desc_size_pos` is where the descriptor size is written, calculated as `round_up(desc_end + sizeof(desc_size_disk), blksize) - sizeof(desc_size_disk)`.  This is how it should be written to the disk.

The question then becomes: why does `get_descriptor` calculate `desc_pos` with a `round_down`?

Let me walk through the potential issues, it is imperative to ensure that the read function always gets the valid descriptor. If it does not, then FS-Verity is broken, so the system is vulnerable.

Let's assume the alignment for `desc_pos` is not to a block size.

If `last_block_offset` from `get_descriptor` is larger than the block containing `desc_size_pos`, the operation is safe. However, the last block offset can be greater than the block containing `desc_size_pos`, that is a potential concern.

Now, consider `xfs_free_eofblocks(ip)` in `end_enable`. This seems relevant because it could free blocks containing the descriptor in certain scenarios involving COW preallocations and the Merkle tree. So, `xfs_free_eofblocks(ip)` could free the block containing the verity descriptor in some scenarios.

Okay, back to the alignment. The descriptor is aligned by a 64KB boundary, `XFS_FSVERITY_START_ALIGN`. Given that block sizes are typically 4KB or smaller, and the fact that `desc_pos` is aligned to a `blocksize` for the read function `xfs_fsverity_get_descriptor`, `desc_pos` *is* also block aligned because 64KB is greater than all supported block sizes. So, this isn't an issue.

But, what if `desc_size` is not a multiple of the blocksize? That looks like a potential problem. Let's make sure our example is correct, just for the case that `tree_last_block = 0`, `XFS_FSVERITY_START_ALIGN = 65536`, and `desc_size = 100`. Then, `desc_pos = 65536`.  Then `desc_end = 65636`, with `blksize = 4096`. So `round_up(65636 + 4, 4096)` becomes `69632`, and thus `desc_size_pos = 69628`. If we then check that the read code returns a consistent value, `desc_size_pos - desc_size = 69528`.  If we then round that down by 4096, we get `65536`, which is exactly the calculated value for `desc_pos`.

Because `desc_end + 4` (for the size field) fits in the same block, `desc_size_pos` is at


32/3 2026/11/03 04:05 tool grepper
0m Args:
{
  "Expression": "desc_size_pos",
  "PathPrefixes": [
    "fs/ext4/"
  ]
}

Results:
{
  "Output": "fs/ext4/verity.c=145=static int ext4_write_verity_descriptor(struct inode *inode, const void *desc,\n--\nfs/ext4/verity.c-151-\tconst __le32 desc_size_disk = cpu_to_le32(desc_size);\nfs/ext4/verity.c:152:\tconst u64 desc_size_pos = round_up(desc_end + sizeof(desc_size_disk),\nfs/ext4/verity.c-153-\t\t\t\t\t   i_blocksize(inode)) -\n--\nfs/ext4/verity.c-161-\treturn pagecache_write(inode, \u0026desc_size_disk, sizeof(desc_size_disk),\nfs/ext4/verity.c:162:\t\t\t       desc_size_pos);\nfs/ext4/verity.c-163-}\n--\nfs/ext4/verity.c=245=static int ext4_get_verity_descriptor_location(struct inode *inode,\n--\nfs/ext4/verity.c-251-\tu32 end_lblk;\nfs/ext4/verity.c:252:\tu64 desc_size_pos;\nfs/ext4/verity.c-253-\t__le32 desc_size_disk;\n--\nfs/ext4/verity.c-280-\t\t   ext4_ext_get_actual_len(last_extent);\nfs/ext4/verity.c:281:\tdesc_size_pos = EXT4_LBLK_TO_B(inode, end_lblk);\nfs/ext4/verity.c-282-\text4_free_ext_path(path);\nfs/ext4/verity.c-283-\nfs/ext4/verity.c:284:\tif (desc_size_pos \u003c sizeof(desc_size_disk))\nfs/ext4/verity.c-285-\t\tgoto bad;\nfs/ext4/verity.c:286:\tdesc_size_pos -= sizeof(desc_size_disk);\nfs/ext4/verity.c-287-\nfs/ext4/verity.c-288-\terr = fsverity_pagecache_read(inode, \u0026desc_size_disk,\nfs/ext4/verity.c:289:\t\t\t\t      sizeof(desc_size_disk), desc_size_pos);\nfs/ext4/verity.c-290-\tif (err)\n--\nfs/ext4/verity.c-298-\nfs/ext4/verity.c:299:\tif (desc_size \u003e INT_MAX || desc_size \u003e desc_size_pos)\nfs/ext4/verity.c-300-\t\tgoto bad;\nfs/ext4/verity.c-301-\nfs/ext4/verity.c:302:\tdesc_pos = round_down(desc_size_pos - desc_size, i_blocksize(inode));\nfs/ext4/verity.c-303-\tif (desc_pos \u003c ext4_verity_metadata_pos(inode))\n"
}

33/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41086
							output: 38
							thoughts: 66
						

Thoughts:
Okay, here's my assessment of the situation:

**Investigating fsverity's Interaction with ext4 Metadata Retrieval**

Right, this looks like it aligns with the core principles of ext4's architecture, which is good. That's a solid starting point. Now, the key question is how `fsverity` specifically interacts with the process of getting descriptors. Let's see... what functions are relevant here? Ah, `fsverity_ioctl_read_metadata` and `fsverity_get_descriptor`, of course. Those are the ones to focus on. To get a handle on the specifics of this, I need to look deeper. The next logical step is to dive into the implementation of those functions. Specifically, I'll go straight to `fs/verity/read_metadata.c` to see how it's all put together. This should reveal the details I need.



34/3 2026/11/03 04:05 tool read-file
0m Args:
{
  "File": "fs/verity/read_metadata.c",
  "FirstLine": 150,
  "LineCount": 55
}

Results:
{
  "Contents": " 150:\t\tkfree(desc);\n 151:\t\treturn res;\n 152:\t}\n 153:\t\n 154:\t/**\n 155:\t * fsverity_ioctl_read_metadata() - read verity metadata from a file\n 156:\t * @filp: file to read the metadata from\n 157:\t * @uarg: user pointer to fsverity_read_metadata_arg\n 158:\t *\n 159:\t * Return: length read on success, 0 on EOF, -errno on failure\n 160:\t */\n 161:\tint fsverity_ioctl_read_metadata(struct file *filp, const void __user *uarg)\n 162:\t{\n 163:\t\tstruct inode *inode = file_inode(filp);\n 164:\t\tconst struct fsverity_info *vi;\n 165:\t\tstruct fsverity_read_metadata_arg arg;\n 166:\t\tint length;\n 167:\t\tvoid __user *buf;\n 168:\t\n 169:\t\tvi = fsverity_get_info(inode);\n 170:\t\tif (!vi)\n 171:\t\t\treturn -ENODATA; /* not a verity file */\n 172:\t\t/*\n 173:\t\t * Note that we don't have to explicitly check that the file is open for\n 174:\t\t * reading, since verity files can only be opened for reading.\n 175:\t\t */\n 176:\t\n 177:\t\tif (copy_from_user(\u0026arg, uarg, sizeof(arg)))\n 178:\t\t\treturn -EFAULT;\n 179:\t\n 180:\t\tif (arg.__reserved)\n 181:\t\t\treturn -EINVAL;\n 182:\t\n 183:\t\t/* offset + length must not overflow. */\n 184:\t\tif (arg.offset + arg.length \u003c arg.offset)\n 185:\t\t\treturn -EINVAL;\n 186:\t\n 187:\t\t/* Ensure that the return value will fit in INT_MAX. */\n 188:\t\tlength = min_t(u64, arg.length, INT_MAX);\n 189:\t\n 190:\t\tbuf = u64_to_user_ptr(arg.buf_ptr);\n 191:\t\n 192:\t\tswitch (arg.metadata_type) {\n 193:\t\tcase FS_VERITY_METADATA_TYPE_MERKLE_TREE:\n 194:\t\t\treturn fsverity_read_merkle_tree(inode, vi, buf, arg.offset,\n 195:\t\t\t\t\t\t\t length);\n 196:\t\tcase FS_VERITY_METADATA_TYPE_DESCRIPTOR:\n 197:\t\t\treturn fsverity_read_descriptor(inode, buf, arg.offset, length);\n 198:\t\tcase FS_VERITY_METADATA_TYPE_SIGNATURE:\n 199:\t\t\treturn fsverity_read_signature(inode, buf, arg.offset, length);\n 200:\t\tdefault:\n 201:\t\t\treturn -EINVAL;\n 202:\t\t}\n 203:\t}\n 204:\tEXPORT_SYMBOL_GPL(fsverity_ioctl_read_metadata);\n"
}

35/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42243
							output: 37
							thoughts: 173
						

Thoughts:
Okay, let's break this down.

**Analyzing XFS's fsverity Implementation**

Right, so I'm looking at how XFS interacts with fsverity. Specifically, I'm noting that the core ioctls—`fsverity_ioctl_read_metadata`, `fsverity_ioctl_measure`, and `fsverity_ioctl_enable`—are all generic fsverity ioctls defined within the `fs/verity/` directory. These ioctls are the standard interface. The important thing is how they interact with the specific fsverity operations that XFS provides. My interest is piqued by XFS's implementation of the ops. They are: `begin_enable_verity`, `end_enable_verity`, `get_verity_descriptor`, `read_merkle_tree_page`, `readahead_merkle_tree`, and `write_merkle_tree_block`. These are clearly the hooks into XFS's internal data structures and functionality.

Hold on a second, I need to make sure I haven't missed anything. I should probably check `fsverity_read_merkle_tree` and `fsverity_read_descriptor` as well. That feels like a logical next step to make sure I am not missing anything essential. To properly understand this, I'm going to jump into `fs/verity/read_metadata.c` and take a good look, specifically lines 20 through 150. That should give me the context I need regarding those functions.



36/3 2026/11/03 04:05 tool read-file
0m Args:
{
  "File": "fs/verity/read_metadata.c",
  "FirstLine": 20,
  "LineCount": 80
}

Results:
{
  "Contents": "  20:\t\tconst struct fsverity_operations *vops = inode-\u003ei_sb-\u003es_vop;\n  21:\t\tu64 end_offset;\n  22:\t\tunsigned int offs_in_page;\n  23:\t\tpgoff_t index, last_index;\n  24:\t\tint retval = 0;\n  25:\t\tint err = 0;\n  26:\t\n  27:\t\tend_offset = min(offset + length, vi-\u003etree_params.tree_size);\n  28:\t\tif (offset \u003e= end_offset)\n  29:\t\t\treturn 0;\n  30:\t\toffs_in_page = offset_in_page(offset);\n  31:\t\tindex = offset \u003e\u003e PAGE_SHIFT;\n  32:\t\tlast_index = (end_offset - 1) \u003e\u003e PAGE_SHIFT;\n  33:\t\n  34:\t\t/*\n  35:\t\t * Kick off readahead for the range we are going to read to ensure a\n  36:\t\t * single large sequential read instead of lots of small ones.\n  37:\t\t */\n  38:\t\tif (inode-\u003ei_sb-\u003es_vop-\u003ereadahead_merkle_tree) {\n  39:\t\t\tfilemap_invalidate_lock_shared(inode-\u003ei_mapping);\n  40:\t\t\tinode-\u003ei_sb-\u003es_vop-\u003ereadahead_merkle_tree(\n  41:\t\t\t\tinode, index, last_index - index + 1);\n  42:\t\t\tfilemap_invalidate_unlock_shared(inode-\u003ei_mapping);\n  43:\t\t}\n  44:\t\n  45:\t\t/*\n  46:\t\t * Iterate through each Merkle tree page in the requested range and copy\n  47:\t\t * the requested portion to userspace.  Note that the Merkle tree block\n  48:\t\t * size isn't important here, as we are returning a byte stream; i.e.,\n  49:\t\t * we can just work with pages even if the tree block size != PAGE_SIZE.\n  50:\t\t */\n  51:\t\tfor (; index \u003c= last_index; index++) {\n  52:\t\t\tunsigned int bytes_to_copy = min_t(u64, end_offset - offset,\n  53:\t\t\t\t\t\t\t   PAGE_SIZE - offs_in_page);\n  54:\t\t\tstruct page *page;\n  55:\t\t\tconst void *virt;\n  56:\t\n  57:\t\t\tpage = vops-\u003eread_merkle_tree_page(inode, index);\n  58:\t\t\tif (IS_ERR(page)) {\n  59:\t\t\t\terr = PTR_ERR(page);\n  60:\t\t\t\tfsverity_err(inode,\n  61:\t\t\t\t\t     \"Error %d reading Merkle tree page %lu\",\n  62:\t\t\t\t\t     err, index);\n  63:\t\t\t\tbreak;\n  64:\t\t\t}\n  65:\t\n  66:\t\t\tvirt = kmap_local_page(page);\n  67:\t\t\tif (copy_to_user(buf, virt + offs_in_page, bytes_to_copy)) {\n  68:\t\t\t\tkunmap_local(virt);\n  69:\t\t\t\tput_page(page);\n  70:\t\t\t\terr = -EFAULT;\n  71:\t\t\t\tbreak;\n  72:\t\t\t}\n  73:\t\t\tkunmap_local(virt);\n  74:\t\t\tput_page(page);\n  75:\t\n  76:\t\t\tretval += bytes_to_copy;\n  77:\t\t\tbuf += bytes_to_copy;\n  78:\t\t\toffset += bytes_to_copy;\n  79:\t\n  80:\t\t\tif (fatal_signal_pending(current))  {\n  81:\t\t\t\terr = -EINTR;\n  82:\t\t\t\tbreak;\n  83:\t\t\t}\n  84:\t\t\tcond_resched();\n  85:\t\t\toffs_in_page = 0;\n  86:\t\t}\n  87:\t\treturn retval ? retval : err;\n  88:\t}\n  89:\t\n  90:\t/* Copy the requested portion of the buffer to userspace. */\n  91:\tstatic int fsverity_read_buffer(void __user *dst, u64 offset, int length,\n  92:\t\t\t\t\tconst void *src, size_t src_length)\n  93:\t{\n  94:\t\tif (offset \u003e= src_length)\n  95:\t\t\treturn 0;\n  96:\t\tsrc += offset;\n  97:\t\tsrc_length -= offset;\n  98:\t\n  99:\t\tlength = min_t(size_t, length, src_length);\n"
}

37/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 43946
							output: 24
							thoughts: 225
						

Thoughts:
Okay, let's break this down.

**Investigating the XFS Implementation of `read_merkle_tree_page`**

Right, so I'm tracing the data flow for `fsverity_read_merkle_tree` and I can see that it's calling `vops->read_merkle_tree_page(inode, index)` and then copying data to userspace using `copy_to_user`. I need to figure out how XFS actually implements that critical `read_merkle_tree_page` function. 

Let's see, what does XFS do? Ah, it looks like `xfs_fsverity_read_merkle` is the function I want. Okay, so `xfs_fsverity_read_merkle` takes the inode and index. It's doing some offset calculation with `xfs_fsverity_metadata_offset(XFS_I(inode)) >> PAGE_SHIFT` and then it calls `generic_read_merkle_tree_page(inode, index)`.

Now, that's interesting. It looks like it delegates the actual merkle tree page reading to `generic_read_merkle_tree_page`. I need to dig into that now to understand what it's actually doing. Time to check `fs/verity/pagecache.c` or wherever `generic_read_merkle_tree_page` is defined. This should give me the core logic.



38/3 2026/11/03 04:05 tool grepper
0m Args:
{
  "Expression": "generic_read_merkle_tree_page"
}

Results:
{
  "Output": "fs/ext4/verity.c=336=static struct page *ext4_read_merkle_tree_page(struct inode *inode,\n--\nfs/ext4/verity.c-339-\tindex += ext4_verity_metadata_pos(inode) \u003e\u003e PAGE_SHIFT;\nfs/ext4/verity.c:340:\treturn generic_read_merkle_tree_page(inode, index);\nfs/ext4/verity.c-341-}\n--\nfs/f2fs/verity.c=234=static struct page *f2fs_read_merkle_tree_page(struct inode *inode,\n--\nfs/f2fs/verity.c-237-\tindex += f2fs_verity_metadata_pos(inode) \u003e\u003e PAGE_SHIFT;\nfs/f2fs/verity.c:238:\treturn generic_read_merkle_tree_page(inode, index);\nfs/f2fs/verity.c-239-}\n--\nfs/verity/pagecache.c-11-/**\nfs/verity/pagecache.c:12: * generic_read_merkle_tree_page - generic -\u003eread_merkle_tree_page helper\nfs/verity/pagecache.c-13- * @inode:\tinode containing the Merkle tree\n--\nfs/verity/pagecache.c-19- */\nfs/verity/pagecache.c:20:struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index)\nfs/verity/pagecache.c-21-{\n--\nfs/verity/pagecache.c-28-}\nfs/verity/pagecache.c:29:EXPORT_SYMBOL_GPL(generic_read_merkle_tree_page);\nfs/verity/pagecache.c-30-\n--\nfs/xfs/xfs_fsverity.c=388=xfs_fsverity_read_merkle(\n--\nfs/xfs/xfs_fsverity.c-393-\nfs/xfs/xfs_fsverity.c:394:\treturn generic_read_merkle_tree_page(inode, index);\nfs/xfs/xfs_fsverity.c-395-}\n--\ninclude/linux/fsverity.h=326=void fsverity_cleanup_inode(struct inode *inode);\ninclude/linux/fsverity.h-327-\ninclude/linux/fsverity.h:328:struct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index);\ninclude/linux/fsverity.h-329-void generic_readahead_merkle_tree(struct inode *inode, pgoff_t index,\n"
}

39/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45219
							output: 36
							thoughts: 28
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into Verity Pagecache**

Alright, let's zero in on `generic_read_merkle_tree_page` within `fs/verity/pagecache.c`. I'm specifically thinking about this function because it's central to how we're dealing with verifying the integrity of data within the pagecache for Verity. This means I need to refresh my understanding of *precisely* how it fetches and validates merkle tree nodes during reads. I'm assuming, of course, that the caller is handling the locking properly, but I want to verify the implications and constraints. I'm wondering if there's any room for optimization here, perhaps in pre-fetching or re-using entries under heavy load. Also, I need to check for potential edge cases, error handling, and security considerations, such as malicious modification attempts, as well as concurrency issues. In short, let's deconstruct the core mechanics here to ensure it's rock solid.



40/3 2026/11/03 04:05 tool read-file
0m Args:
{
  "File": "fs/verity/pagecache.c",
  "FirstLine": 12,
  "LineCount": 40
}

Results:
{
  "Contents": "  12:\t * generic_read_merkle_tree_page - generic -\u003eread_merkle_tree_page helper\n  13:\t * @inode:\tinode containing the Merkle tree\n  14:\t * @index:\t0-based index of the Merkle tree page in the inode\n  15:\t *\n  16:\t * The caller needs to adjust @index from the Merkle-tree relative index passed\n  17:\t * to -\u003eread_merkle_tree_page to the actual index where the Merkle tree is\n  18:\t * stored in the page cache for @inode.\n  19:\t */\n  20:\tstruct page *generic_read_merkle_tree_page(struct inode *inode, pgoff_t index)\n  21:\t{\n  22:\t\tstruct folio *folio;\n  23:\t\n  24:\t\tfolio = read_mapping_folio(inode-\u003ei_mapping, index, NULL);\n  25:\t\tif (IS_ERR(folio))\n  26:\t\t\treturn ERR_CAST(folio);\n  27:\t\treturn folio_file_page(folio, index);\n  28:\t}\n  29:\tEXPORT_SYMBOL_GPL(generic_read_merkle_tree_page);\n  30:\t\n  31:\t/**\n  32:\t * generic_readahead_merkle_tree() - generic -\u003ereadahead_merkle_tree helper\n  33:\t * @inode:\tinode containing the Merkle tree\n  34:\t * @index:\t0-based index of the first Merkle tree page to read ahead in the\n  35:\t *\t\tinode\n  36:\t * @nr_pages:\tthe number of Merkle tree pages that should be read ahead\n  37:\t *\n  38:\t * The caller needs to adjust @index from the Merkle-tree relative index passed\n  39:\t * to -\u003eread_merkle_tree_page to the actual index where the Merkle tree is\n  40:\t * stored in the page cache for @inode.\n  41:\t */\n  42:\tvoid generic_readahead_merkle_tree(struct inode *inode, pgoff_t index,\n  43:\t\t\t\t\t   unsigned long nr_pages)\n  44:\t{\n  45:\t\tstruct folio *folio;\n  46:\t\n  47:\t\tlockdep_assert_held(\u0026inode-\u003ei_mapping-\u003einvalidate_lock);\n  48:\t\n  49:\t\tfolio = __filemap_get_folio(inode-\u003ei_mapping, index, FGP_ACCESSED, 0);\n  50:\t\tif (folio == ERR_PTR(-ENOENT) ||\n  51:\t\t    (!IS_ERR(folio) \u0026\u0026 !folio_test_uptodate(folio))) {\n"
}

41/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46197
							output: 23
							thoughts: 692
						

Thoughts:
**Investigating XFS and Beyond EOF Reads**

Okay, so I'm curious about how XFS handles pagecache reads that go beyond the end-of-file (EOF). Specifically, I'm thinking about how the Merkle tree used by XFS, similar to ext4 and f2fs, is stored in the inode's pagecache and disk blocks *past* EOF. This is where things get interesting, how does this actually work?

My first instinct is to dig into the XFS source code and see how reads and writes that go past EOF are handled. I need to understand what's changed and how they're handling this case. Let me check the patch changes related to XFS read/write paths, and also IOMAP, and see if there are any hints.

I see several modifications:

1.  In `xfs_bmapi_convert_one_delalloc`, there's a check for `XFS_VERITY_CONSTRUCTION`. If that flag is set *and* the offset is beyond the `xfs_fsverity_metadata_offset`, it sets the `IOMAP_F_FSVERITY` flag. This seems to be the entry point for handling this, but what is it used for?
2.  `xfs_map_blocks` also includes the `IOMAP_F_FSVERITY` flag based on the same `XFS_VERITY_CONSTRUCTION` flag.
3.  `xfs_iomap_writepages` explicitly notes that writeback doesn't work for folios past EOF, but it allows I/O when `XFS_VERITY_CONSTRUCTION` is set by setting `IOMAP_F_FSVERITY`. This tells the writepath to be careful.
4.  `xfs_read_iomap_begin` also checks `fsverity_active()` and offset to set `IOMAP_F_FSVERITY` as well.

Okay, so the `IOMAP_F_FSVERITY` flag is clearly central to handling reads and writes past EOF, at least when related to fsverity metadata. I need to understand what that flag *actually* does within the iomap framework. Let me run a grep on `IOMAP_F_FSVERITY` in the codebase and see how it is handled in `iomap`.



42/3 2026/11/03 04:05 tool grepper
0m Args:
{
  "Expression": "IOMAP_F_FSVERITY"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=382=static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-402-\t */\nfs/iomap/buffered-io.c:403:\tif (srcmap-\u003eflags \u0026 IOMAP_F_FSVERITY)\nfs/iomap/buffered-io.c-404-\t\treturn false;\n--\nfs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-603-\t\t */\nfs/iomap/buffered-io.c:604:\t\tif ((iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026\nfs/iomap/buffered-io.c-605-\t\t    iomap-\u003etype == IOMAP_HOLE) {\n--\nfs/iomap/buffered-io.c=1188=static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i,\n--\nfs/iomap/buffered-io.c-1258-\t\tif (pos + written \u003e old_size \u0026\u0026\nfs/iomap/buffered-io.c:1259:\t\t    !(iter-\u003eiomap.flags \u0026 IOMAP_F_FSVERITY)) {\nfs/iomap/buffered-io.c-1260-\t\t\ti_size_write(iter-\u003einode, pos + written);\n--\nfs/iomap/buffered-io.c-1264-\nfs/iomap/buffered-io.c:1265:\t\tif (old_size \u003c pos \u0026\u0026 !(iter-\u003eiomap.flags \u0026 IOMAP_F_FSVERITY))\nfs/iomap/buffered-io.c-1266-\t\t\tpagecache_isize_extended(iter-\u003einode, old_size, pos);\n--\nfs/iomap/buffered-io.c=1926=static bool iomap_writeback_handle_eof(struct folio *folio,\n--\nfs/iomap/buffered-io.c-1931-\nfs/iomap/buffered-io.c:1932:\tif (wpc-\u003eiomap.flags \u0026 IOMAP_F_FSVERITY) {\nfs/iomap/buffered-io.c-1933-\t\tWARN_ON_ONCE(folio_pos(folio) \u003c isize);\n--\nfs/iomap/trace.h=87=DEFINE_RANGE_EVENT(iomap_zero_iter);\n--\nfs/iomap/trace.h-121-\t{ IOMAP_F_STALE,\t\"STALE\" }, \\\nfs/iomap/trace.h:122:\t{ IOMAP_F_FSVERITY,\t\"FSVERITY\" }, \\\nfs/iomap/trace.h-123-\t{ IOMAP_F_ZERO_TAIL,\t\"ZERO TAIL\" }\n--\nfs/xfs/libxfs/xfs_bmap.c=4356=xfs_bmapi_convert_one_delalloc(\n--\nfs/xfs/libxfs/xfs_bmap.c-4409-\t\t    offset \u003e= xfs_fsverity_metadata_offset(ip))\nfs/xfs/libxfs/xfs_bmap.c:4410:\t\t\tflags |= IOMAP_F_FSVERITY;\nfs/xfs/libxfs/xfs_bmap.c-4411-\t\txfs_bmbt_to_iomap(ip, iomap, \u0026bma.got, 0, flags,\n--\nfs/xfs/libxfs/xfs_bmap.c-4459-\t    offset \u003e= xfs_fsverity_metadata_offset(ip))\nfs/xfs/libxfs/xfs_bmap.c:4460:\t\tflags |= IOMAP_F_FSVERITY;\nfs/xfs/libxfs/xfs_bmap.c-4461-\n--\nfs/xfs/xfs_aops.c=159=xfs_map_blocks(\n--\nfs/xfs/xfs_aops.c-183-\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_aops.c:184:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_aops.c-185-\n--\nfs/xfs/xfs_aops.c=409=xfs_zoned_map_blocks(\n--\nfs/xfs/xfs_aops.c-428-\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_aops.c:429:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_aops.c-430-\n--\nfs/xfs/xfs_aops.c=521=xfs_iomap_writepages(\n--\nfs/xfs/xfs_aops.c-530-\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_aops.c:531:\t\tctx-\u003eiomap.flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_aops.c-532-\n--\nfs/xfs/xfs_iomap.c=850=xfs_direct_write_iomap_begin(\n--\nfs/xfs/xfs_iomap.c-888-\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_iomap.c:889:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_iomap.c-890-\n--\nfs/xfs/xfs_iomap.c-1031-\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags,\nfs/xfs/xfs_iomap.c:1032:\t\t\t\tiomap_flags \u0026 IOMAP_F_FSVERITY, seq);\nfs/xfs/xfs_iomap.c-1033-\t\tif (error)\n--\nfs/xfs/xfs_iomap.c=1809=xfs_buffered_write_iomap_begin(\n--\nfs/xfs/xfs_iomap.c-1838-\tif (xfs_iflags_test(ip, XFS_VERITY_CONSTRUCTION))\nfs/xfs/xfs_iomap.c:1839:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_iomap.c-1840-\n--\nfs/xfs/xfs_iomap.c-2127-\t\terror = xfs_bmbt_to_iomap(ip, srcmap, \u0026imap, flags,\nfs/xfs/xfs_iomap.c:2128:\t\t\t\tiomap_flags \u0026 IOMAP_F_FSVERITY,\nfs/xfs/xfs_iomap.c-2129-\t\t\t\txfs_iomap_inode_sequence(ip, 0));\n--\nfs/xfs/xfs_iomap.c=2215=xfs_read_iomap_begin(\n--\nfs/xfs/xfs_iomap.c-2240-\t    (offset \u003e= xfs_fsverity_metadata_offset(ip)))\nfs/xfs/xfs_iomap.c:2241:\t\tiomap_flags |= IOMAP_F_FSVERITY;\nfs/xfs/xfs_iomap.c-2242-\n--\ninclude/linux/iomap.h=26=struct vm_fault;\n--\ninclude/linux/iomap.h-100- */\ninclude/linux/iomap.h:101:#define IOMAP_F_FSVERITY\t(1U \u003c\u003c 11)\ninclude/linux/iomap.h-102-\n"
}

43/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49570
							output: 39
							thoughts: 48
						

Thoughts:
Okay, let's dive into this. Here's my take on those lines of code, presented as a summary of my own thought process:

**Diving into Buffered I/O**

Alright, I'm specifically looking at `fs/iomap/buffered-io.c:604`. The context here is likely around how the kernel handles buffered I/O, which is always a critical area for performance.

I need to read lines 595 to 620, the heart of this section. I'm expecting this area to cover the mechanics of how data is staged and flushed. This segment probably includes details on how data interacts with the page cache, and potentially the details of the locking mechanisms. I'm also looking for any specific optimizations or edge-case handling around the buffering process. I'm hoping to see how the code interacts with the underlying block device. I'll be focused on things like:
*   How is data written or read from user space, and into the pages?
*   How is it made consistent?
*   What happens on flush, and what are the failure modes here?
*   Any locking/synchronization primitives used?

By analyzing this chunk of code, I hope to gain a clear view of the kernel's buffered I/O architecture and assess its efficiency and robustness, especially from a concurrency perspective.



44/3 2026/11/03 04:05 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 595,
  "LineCount": 35
}

Results:
{
  "Contents": " 595:\t\t\t/*\n 596:\t\t\t * Handling of fsverity \"holes\". We hit this for two case:\n 597:\t\t\t *   1. No need to go further, the hole after fsverity\n 598:\t\t\t *\tdescriptor is the end of the fsverity metadata.\n 599:\t\t\t *\n 600:\t\t\t *   2. This folio contains merkle tree blocks which need to be\n 601:\t\t\t *\tsynthesized. If we already have fsverity info (ctx-\u003evi)\n 602:\t\t\t *\tsynthesize these blocks.\n 603:\t\t\t */\n 604:\t\t\tif ((iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026\n 605:\t\t\t    iomap-\u003etype == IOMAP_HOLE) {\n 606:\t\t\t\tif (ctx-\u003evi)\n 607:\t\t\t\t\tfsverity_fill_zerohash(folio, poff, plen,\n 608:\t\t\t\t\t\t\t       ctx-\u003evi);\n 609:\t\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n 610:\t\t\t} else if (iomap_block_needs_zeroing(iter, pos)) {\n 611:\t\t\t\t/* zero post-eof blocks as the page may be mapped */\n 612:\t\t\t\tfolio_zero_range(folio, poff, plen);\n 613:\t\t\t\tif (ctx-\u003evi \u0026\u0026\n 614:\t\t\t\t    !fsverity_verify_blocks(ctx-\u003evi, folio, plen, poff))\n 615:\t\t\t\t\treturn -EIO;\n 616:\t\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n 617:\t\t\t} else {\n 618:\t\t\t\tif (!*bytes_submitted)\n 619:\t\t\t\t\tiomap_read_init(folio);\n 620:\t\t\t\tret = ctx-\u003eops-\u003eread_folio_range(iter, ctx, plen);\n 621:\t\t\t\tif (ret \u003c 0)\n 622:\t\t\t\t\tfserror_report_io(iter-\u003einode,\n 623:\t\t\t\t\t\t\t  FSERR_BUFFERED_READ, pos,\n 624:\t\t\t\t\t\t\t  plen, ret, GFP_NOFS);\n 625:\t\t\t\tif (ret)\n 626:\t\t\t\t\treturn ret;\n 627:\t\n 628:\t\t\t\t*bytes_submitted += plen;\n 629:\t\t\t\t/*\n"
}

45/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50564
							output: 22
							thoughts: 750
						

Thoughts:
**Analyzing XFS fsverity Implementation**

Okay, here's what I'm seeing. It appears generic fsverity support was already added or exists within iomap, which is good. Now, I need to understand how it's specifically used by XFS. Let's look at `xfs_fsverity_is_hashes_of_zeroed_blocks`. This function checks if a block contains the hashes of zeroed blocks. If it does, XFS skips writing the data, treating it like a hole. On read, this then leads to `iomap_read_folio_iter`. If the iomap entry is a hole and the `IOMAP_F_FSVERITY` flag is set, it calls `fsverity_fill_zerohash`.

Now, if data is read by `xfs_fsverity_read_merkle`, it seems it calls `generic_read_merkle_tree_page`. And, `generic_read_merkle_tree_page` then calls `read_mapping_folio`, which calls `a_ops->read_folio` -> `xfs_vm_read_folio`. In `xfs_vm_read_folio`, I see it calls `iomap_read_folio` with `xfs_read_iomap_ops` and a context struct. I noticed something. The third argument, which I believe should be my verifier info struct (my `ctx->vi`), is passed as `NULL`! But why? I'll need to double check the `iomap_read_folio` signature. 



46/3 2026/11/03 04:05 tool grepper
0m Args:
{
  "Expression": "iomap_read_folio\\("
}

Results:
{
  "Output": "fs/erofs/data.c=397=static int erofs_read_folio(struct file *file, struct folio *folio)\n--\nfs/erofs/data.c-410-\ttrace_erofs_read_folio(iter_ctx.realinode, folio, true);\nfs/erofs/data.c:411:\tiomap_read_folio(\u0026erofs_iomap_ops, \u0026read_ctx, \u0026iter_ctx);\nfs/erofs/data.c-412-\tif (need_iput)\n--\nfs/exfat/inode.c=245=static int exfat_read_folio(struct file *file, struct folio *folio)\n--\nfs/exfat/inode.c-251-\nfs/exfat/inode.c:252:\tiomap_read_folio(\u0026exfat_iomap_ops, \u0026ctx, NULL);\nfs/exfat/inode.c-253-\treturn 0;\n--\nfs/ext4/inode.c=4289=static const struct iomap_ops ext4_iomap_buffered_read_ops = {\n--\nfs/ext4/inode.c-4292-\nfs/ext4/inode.c:4293:static int ext4_iomap_read_folio(struct file *file, struct folio *folio)\nfs/ext4/inode.c-4294-{\n--\nfs/fuse/file.c=1021=static int fuse_read_folio(struct file *file, struct folio *folio)\n--\nfs/fuse/file.c-1038-\nfs/fuse/file.c:1039:\tiomap_read_folio(\u0026fuse_iomap_ops, \u0026ctx, NULL);\nfs/fuse/file.c-1040-\tfuse_invalidate_atime(inode);\n--\nfs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-650-\nfs/iomap/buffered-io.c:651:void iomap_read_folio(const struct iomap_ops *ops,\nfs/iomap/buffered-io.c-652-\t\tstruct iomap_read_folio_ctx *ctx, void *private)\n--\nfs/ntfs/aops.c=68=static int ntfs_read_folio(struct file *file, struct folio *folio)\n--\nfs/ntfs/aops.c-105-\nfs/ntfs/aops.c:106:\tiomap_read_folio(\u0026ntfs_read_iomap_ops, \u0026ctx, NULL);\nfs/ntfs/aops.c-107-\treturn 0;\n--\nfs/ntfs3/inode.c=826=static int ntfs_read_folio(struct file *file, struct folio *folio)\n--\nfs/ntfs3/inode.c-855-\nfs/ntfs3/inode.c:856:\tiomap_read_folio(\u0026ntfs_iomap_ops, \u0026ctx, NULL);\nfs/ntfs3/inode.c-857-\treturn 0;\n--\nfs/xfs/xfs_aops.c=638=xfs_vm_read_folio(\n--\nfs/xfs/xfs_aops.c-644-\tctx.ops = xfs_get_iomap_read_ops(folio-\u003emapping, folio_pos(folio));\nfs/xfs/xfs_aops.c:645:\tiomap_read_folio(\u0026xfs_read_iomap_ops, \u0026ctx, NULL);\nfs/xfs/xfs_aops.c-646-\treturn 0;\n--\ninclude/linux/iomap.h=434=int iomap_fsverity_write(struct file *file, loff_t pos, size_t length,\n--\ninclude/linux/iomap.h-436-\t\tconst struct iomap_write_ops *write_ops);\ninclude/linux/iomap.h:437:void iomap_read_folio(const struct iomap_ops *ops,\ninclude/linux/iomap.h-438-\t\tstruct iomap_read_folio_ctx *ctx, void *private);\n--\ninclude/linux/iomap.h=807=static inline void iomap_bio_read_folio(struct folio *folio,\n--\ninclude/linux/iomap.h-814-\ninclude/linux/iomap.h:815:\tiomap_read_folio(ops, \u0026ctx, NULL);\ninclude/linux/iomap.h-816-}\n"
}

47/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52895
							output: 39
							thoughts: 32
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach this task, as if I were thinking it through:

**Analyzing `iomap_read_folio` in `fs/iomap/buffered-io.c`**

Alright, I need to get my head around what's happening with buffered I/O, specifically within the `iomap_read_folio` function. I know this function is critical for how the kernel handles file reads when the `iomap` infrastructure is in play, so understanding its role and how it interacts with the folio system is paramount. I'll need to examine the flow of data, how it interacts with the underlying storage, and consider how this all plays into optimizations such as read-ahead and caching. I'll probably start by tracing the function's execution path, looking at arguments like the folio itself, the I/O mapping details (if relevant), and any other key structures it utilizes. I'm keen to see how the system is designed to handle potential errors and, of course, where it interacts with the block layer to actually fetch data. Essentially, I'm looking for the mechanism that turns an application's read request into a physical read operation – how it goes from a logical block address to actual data being pulled from storage.



48/3 2026/11/03 04:05 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 650,
  "LineCount": 40
}

Results:
{
  "Contents": " 650:\t\n 651:\tvoid iomap_read_folio(const struct iomap_ops *ops,\n 652:\t\t\tstruct iomap_read_folio_ctx *ctx, void *private)\n 653:\t{\n 654:\t\tstruct folio *folio = ctx-\u003ecur_folio;\n 655:\t\tstruct iomap_iter iter = {\n 656:\t\t\t.inode\t\t= folio-\u003emapping-\u003ehost,\n 657:\t\t\t.pos\t\t= folio_pos(folio),\n 658:\t\t\t.len\t\t= folio_size(folio),\n 659:\t\t\t.private\t= private,\n 660:\t\t};\n 661:\t\tsize_t bytes_submitted = 0;\n 662:\t\tint ret;\n 663:\t\n 664:\t\ttrace_iomap_readpage(iter.inode, 1);\n 665:\t\n 666:\t\t/*\n 667:\t\t * Fetch fsverity_info for both data and fsverity metadata, as iomap\n 668:\t\t * needs zeroed hash for merkle tree block synthesis\n 669:\t\t */\n 670:\t\tctx-\u003evi = fsverity_get_info(iter.inode);\n 671:\t\tif (ctx-\u003evi \u0026\u0026 iter.pos \u003c i_size_read(iter.inode))\n 672:\t\t\tfsverity_readahead(ctx-\u003evi, folio-\u003eindex,\n 673:\t\t\t\t\t   folio_nr_pages(folio));\n 674:\t\n 675:\t\twhile ((ret = iomap_iter(\u0026iter, ops)) \u003e 0) {\n 676:\t\t\titer.status = iomap_read_folio_iter(\u0026iter, ctx,\n 677:\t\t\t\t\t\u0026bytes_submitted);\n 678:\t\t\tif (ctx-\u003eread_ctx \u0026\u0026 ctx-\u003eops-\u003esubmit_read)\n 679:\t\t\t\tctx-\u003eops-\u003esubmit_read(\u0026iter, ctx);\n 680:\t\t}\n 681:\t\n 682:\t\tif (ctx-\u003ecur_folio)\n 683:\t\t\tiomap_read_end(ctx-\u003ecur_folio, bytes_submitted);\n 684:\t}\n 685:\tEXPORT_SYMBOL_GPL(iomap_read_folio);\n 686:\t\n 687:\tstatic int iomap_readahead_iter(struct iomap_iter *iter,\n 688:\t\t\tstruct iomap_read_folio_ctx *ctx, size_t *cur_bytes_submitted)\n 689:\t{\n"
}

49/3 2026/11/03 04:05 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53907
							output: 44
							thoughts: 1855
						

Thoughts:
**KMSAN Assessment: FS-Verity and XFS Integration**

Okay, let's break this down. My initial focus is on the `fsverity` integration within XFS, specifically the interaction with the `iomap` infrastructure and BIO completion. I see `fsverity_get_info` is being called within `iomap_read_folio` and `iomap_readahead`, and its result, `ctx->vi`, is then used in `xfs_bio_submit_read` when submitting I/O. Then, in `xfs_ioend.c` that, if FS_VERITY is enabled and there's no error on the bio, a `xfs_fsverity_ioend` is allocated from a pool, initialized, and put on the workqueue using `fsverity_enqueue_verify_work()`. This triggers `xfs_end_fsverity_io_read`.

Inside `xfs_end_fsverity_io_read`, a `xfs_fsverity_ioend` is removed from the mempool. It appears that it holds a pointer to `iomap_ioend`, and a `work_struct` that references back to `xfs_end_fsverity_io_read` itself. The `xfs_fsverity_ioend` struct itself only contains two fields, both initialized. The `ioend` and `bio` are then processed.

Now, let's apply the KMSAN criteria. My immediate concern is whether this change introduces a risk of uninitialized memory usage, particularly when dealing with FS-Verity's interaction with the kernel.

**KMSAN Evaluation Criteria:**

The key is to determine whether any of the four KMSAN criteria are met:

1.  **Kernel structures sent to user space:** I need to verify no new kernel structures are sent to userspace via `copy_to_user`, `put_user`, netlink, ioctl, socket options, or BPF buffers where fields or padding might be uninitialized. My first investigation is ioctls and bulkstat:
    *   I've reviewed the ioctl handling. `FS_IOC_ENABLE_VERITY`, `FS_IOC_MEASURE_VERITY`, and `FS_IOC_READ_VERITY_METADATA`, are generic FS-verity ioctls (existing code, already used by multiple filesystems like ext4 and btrfs). They don't appear to be new or expose any new uninitialized memory vulnerabilities.
    *   Bulkstat is next, which checks `xfs_bulkstat_health` and adds `XFS_BS_SICK_FSVERITY` as a flag. `bs->bs_sick` and `bs->bs_checked` are zeroed, and not uninitialized.
    *   The geometry `XFS_FSOP_GEOM_FLAGS_VERITY` added to geo->flags. The next step is to examine how xfs_fs_geometry is handled, and if the geo variable is zeroed at any point.

2.  **Conditional logic based on potentially uninitialized variables:** I need to look for any new conditional branches that rely on potentially uninitialized variables or structure fields.

3.  **Complex data structures with uninitialized fields:** I need to check for any new allocations of complex data structures where uninitialized fields could be read later. The `xfs_fsverity_ioend` structure seems to be the critical area to check, but since it's allocated from a mempool and the members are explicitly initialized, this seems unlikely.

4.  **Bounds checks exposing uninitialized bytes:** Check for any changes to bounds checks or lengths that would expose uninitialized bytes.

So far, based on the initial assessment of the ioctl paths and the structure initializations, I'm not seeing any immediate red flags. I need to complete the investigation of `xfs_fs_geometry` to be certain. Given these preliminary findings, I'm leaning toward a `NeedsKMSAN=false` assessment, but I must fully explore the existing code to confirm that no uninitialized memory risks are introduced, as this would be a high priority for review.



50/3 2026/11/03 04:06 tool read-file
0m Args:
{
  "File": "fs/xfs/libxfs/xfs_sb.c",
  "FirstLine": 1510,
  "LineCount": 40
}

Results:
{
  "Contents": "1510:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_DALIGN;\n1511:\t\tif (xfs_has_asciici(mp))\n1512:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_DIRV2CI;\n1513:\t\tif (xfs_has_lazysbcount(mp))\n1514:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_LAZYSB;\n1515:\t\tif (xfs_has_projid32(mp))\n1516:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_PROJID32;\n1517:\t\tif (xfs_has_crc(mp))\n1518:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_V5SB;\n1519:\t\tif (xfs_has_ftype(mp))\n1520:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_FTYPE;\n1521:\t\tif (xfs_has_finobt(mp))\n1522:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_FINOBT;\n1523:\t\tif (xfs_has_sparseinodes(mp))\n1524:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_SPINODES;\n1525:\t\tif (xfs_has_rmapbt(mp))\n1526:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_RMAPBT;\n1527:\t\tif (xfs_has_reflink(mp))\n1528:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_REFLINK;\n1529:\t\tif (xfs_has_bigtime(mp))\n1530:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_BIGTIME;\n1531:\t\tif (xfs_has_inobtcounts(mp))\n1532:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_INOBTCNT;\n1533:\t\tif (xfs_has_parent(mp))\n1534:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_PARENT;\n1535:\t\tif (xfs_has_sector(mp)) {\n1536:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_SECTOR;\n1537:\t\t\tgeo-\u003elogsectsize = sbp-\u003esb_logsectsize;\n1538:\t\t} else {\n1539:\t\t\tgeo-\u003elogsectsize = BBSIZE;\n1540:\t\t}\n1541:\t\tif (xfs_has_large_extent_counts(mp))\n1542:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_NREXT64;\n1543:\t\tif (xfs_has_exchange_range(mp))\n1544:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE;\n1545:\t\tif (xfs_has_metadir(mp))\n1546:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_METADIR;\n1547:\t\tif (xfs_has_zoned(mp))\n1548:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_ZONED;\n1549:\t\tif (xfs_has_verity(mp))\n"
}

51/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57599
							output: 44
							thoughts: 26
						

Thoughts:
Okay, here's my attempt at summarizing that thought process, keeping in mind the expert user:

**Deep Dive into `xfs_fs_geometry`**

Alright, let's get down to brass tacks. I'm focusing on the `geo` variable within `xfs_fs_geometry`. It's a critical structure, obviously – likely holding the core filesystem geometry information. I want to see *exactly* what's going on with it *before* line 1510. This feels like a pivotal moment, or perhaps a problematic point in the code. I need to understand the state of the geometry at that point. I'll need to trace back from that line to see how `geo` is initialized, potentially modified, and validated. This could be about a specific partition, a raid config or a potential geometry inconsistency. Ultimately I want to know if everything is as it should be, or if there is a lurking issue. My intuition tells me there is something important occurring.



52/3 2026/11/03 04:06 tool read-file
0m Args:
{
  "File": "fs/xfs/libxfs/xfs_sb.c",
  "FirstLine": 1480,
  "LineCount": 30
}

Results:
{
  "Contents": "1480:\t\tgeo-\u003einodesize = sbp-\u003esb_inodesize;\n1481:\t\tgeo-\u003eimaxpct = sbp-\u003esb_imax_pct;\n1482:\t\tgeo-\u003edatablocks = sbp-\u003esb_dblocks;\n1483:\t\tgeo-\u003ertblocks = sbp-\u003esb_rblocks;\n1484:\t\tgeo-\u003ertextents = sbp-\u003esb_rextents;\n1485:\t\tgeo-\u003elogstart = sbp-\u003esb_logstart;\n1486:\t\tBUILD_BUG_ON(sizeof(geo-\u003euuid) != sizeof(sbp-\u003esb_uuid));\n1487:\t\tmemcpy(geo-\u003euuid, \u0026sbp-\u003esb_uuid, sizeof(sbp-\u003esb_uuid));\n1488:\t\n1489:\t\tif (struct_version \u003c 2)\n1490:\t\t\treturn;\n1491:\t\n1492:\t\tgeo-\u003esunit = sbp-\u003esb_unit;\n1493:\t\tgeo-\u003eswidth = sbp-\u003esb_width;\n1494:\t\n1495:\t\tif (struct_version \u003c 3)\n1496:\t\t\treturn;\n1497:\t\n1498:\t\tgeo-\u003eversion = XFS_FSOP_GEOM_VERSION;\n1499:\t\tgeo-\u003eflags = XFS_FSOP_GEOM_FLAGS_NLINK |\n1500:\t\t\t     XFS_FSOP_GEOM_FLAGS_DIRV2 |\n1501:\t\t\t     XFS_FSOP_GEOM_FLAGS_EXTFLG |\n1502:\t\t\t     XFS_FSOP_GEOM_FLAGS_ATTR2;\n1503:\t\tif (xfs_has_attr(mp))\n1504:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_ATTR;\n1505:\t\tif (xfs_has_quota(mp))\n1506:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_QUOTA;\n1507:\t\tif (xfs_has_align(mp))\n1508:\t\t\tgeo-\u003eflags |= XFS_FSOP_GEOM_FLAGS_IALIGN;\n1509:\t\tif (xfs_has_dalign(mp))\n"
}

53/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58452
							output: 20
							thoughts: 95
						

Thoughts:
Okay, here's my breakdown of this snippet.

**Analyzing XFS Filesystem Geometry and Verity Descriptors**

Alright, so `xfs_fs_geometry` is responsible for either clearing or writing all those fields – I need to keep that in mind. Now, I have to consider another point, how does `xfs_fsverity_get_descriptor` fit into this? Does it simply read data, or is it going to write to user space? I should probably check that first before I jump to any conclusions. Ah wait, isn't it called from `fsverity_read_descriptor`? Let me see how `get_verity_descriptor` is actually *called* within the kernel; I need to trace its usage to understand the context.



54/3 2026/11/03 04:06 tool grepper
0m Args:
{
  "Expression": "get_verity_descriptor"
}

Results:
{
  "Output": "fs/btrfs/send.c=5095=static int process_verity(struct send_ctx *sctx)\n--\nfs/btrfs/send.c-5104-\nfs/btrfs/send.c:5105:\tret = btrfs_get_verity_descriptor(\u0026inode-\u003evfs_inode, NULL, 0);\nfs/btrfs/send.c-5106-\tif (ret \u003c 0)\n--\nfs/btrfs/send.c-5121-\nfs/btrfs/send.c:5122:\tret = btrfs_get_verity_descriptor(\u0026inode-\u003evfs_inode, sctx-\u003everity_descriptor, ret);\nfs/btrfs/send.c-5123-\tif (ret \u003c 0)\n--\nfs/btrfs/verity.c=628=static int btrfs_end_enable_verity(struct file *filp, const void *desc,\n--\nfs/btrfs/verity.c-665- */\nfs/btrfs/verity.c:666:int btrfs_get_verity_descriptor(struct inode *inode, void *buf, size_t buf_size)\nfs/btrfs/verity.c-667-{\n--\nfs/btrfs/verity.c=815=const struct fsverity_operations btrfs_verityops = {\n--\nfs/btrfs/verity.c-817-\t.end_enable_verity       = btrfs_end_enable_verity,\nfs/btrfs/verity.c:818:\t.get_verity_descriptor   = btrfs_get_verity_descriptor,\nfs/btrfs/verity.c-819-\t.read_merkle_tree_page   = btrfs_read_merkle_tree_page,\n--\nfs/btrfs/verity.h=15=int btrfs_drop_verity_items(struct btrfs_inode *inode);\nfs/btrfs/verity.h:16:int btrfs_get_verity_descriptor(struct inode *inode, void *buf, size_t buf_size);\nfs/btrfs/verity.h-17-\n--\nfs/btrfs/verity.h=22=static inline int btrfs_drop_verity_items(struct btrfs_inode *inode)\n--\nfs/btrfs/verity.h-26-\nfs/btrfs/verity.h:27:static inline int btrfs_get_verity_descriptor(struct inode *inode, void *buf,\nfs/btrfs/verity.h-28-\t\t\t\t\t      size_t buf_size)\n--\nfs/ext4/verity.c=165=static int ext4_end_enable_verity(struct file *filp, const void *desc,\n--\nfs/ext4/verity.c-244-\nfs/ext4/verity.c:245:static int ext4_get_verity_descriptor_location(struct inode *inode,\nfs/ext4/verity.c-246-\t\t\t\t\t       size_t *desc_size_ret,\n--\nfs/ext4/verity.c-314-\nfs/ext4/verity.c:315:static int ext4_get_verity_descriptor(struct inode *inode, void *buf,\nfs/ext4/verity.c-316-\t\t\t\t      size_t buf_size)\n--\nfs/ext4/verity.c-321-\nfs/ext4/verity.c:322:\terr = ext4_get_verity_descriptor_location(inode, \u0026desc_size, \u0026desc_pos);\nfs/ext4/verity.c-323-\tif (err)\n--\nfs/ext4/verity.c=360=const struct fsverity_operations ext4_verityops = {\n--\nfs/ext4/verity.c-362-\t.end_enable_verity\t= ext4_end_enable_verity,\nfs/ext4/verity.c:363:\t.get_verity_descriptor\t= ext4_get_verity_descriptor,\nfs/ext4/verity.c-364-\t.read_merkle_tree_page\t= ext4_read_merkle_tree_page,\n--\nfs/f2fs/verity.c=120=static int f2fs_end_enable_verity(struct file *filp, const void *desc,\n--\nfs/f2fs/verity.c-192-\nfs/f2fs/verity.c:193:static int f2fs_get_verity_descriptor(struct inode *inode, void *buf,\nfs/f2fs/verity.c-194-\t\t\t\t      size_t buf_size)\n--\nfs/f2fs/verity.c=258=const struct fsverity_operations f2fs_verityops = {\n--\nfs/f2fs/verity.c-260-\t.end_enable_verity\t= f2fs_end_enable_verity,\nfs/f2fs/verity.c:261:\t.get_verity_descriptor\t= f2fs_get_verity_descriptor,\nfs/f2fs/verity.c-262-\t.read_merkle_tree_page\t= f2fs_read_merkle_tree_page,\n--\nfs/verity/open.c=314=int fsverity_get_descriptor(struct inode *inode,\n--\nfs/verity/open.c-319-\nfs/verity/open.c:320:\tres = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, NULL, 0);\nfs/verity/open.c-321-\tif (res \u003c 0) {\n--\nfs/verity/open.c-333-\t\treturn -ENOMEM;\nfs/verity/open.c:334:\tres = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, desc, res);\nfs/verity/open.c-335-\tif (res \u003c 0) {\n--\nfs/xfs/xfs_fsverity.c=475=const struct fsverity_operations xfs_fsverity_ops = {\n--\nfs/xfs/xfs_fsverity.c-477-\t.end_enable_verity\t\t= xfs_fsverity_end_enable,\nfs/xfs/xfs_fsverity.c:478:\t.get_verity_descriptor\t\t= xfs_fsverity_get_descriptor,\nfs/xfs/xfs_fsverity.c-479-\t.read_merkle_tree_page\t\t= xfs_fsverity_read_merkle,\n--\ninclude/linux/fsverity.h=32=struct fsverity_operations {\n--\ninclude/linux/fsverity.h-84-\t */\ninclude/linux/fsverity.h:85:\tint (*get_verity_descriptor)(struct inode *inode, void *buf,\ninclude/linux/fsverity.h-86-\t\t\t\t     size_t bufsize);\n"
}

55/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60582
							output: 36
							thoughts: 103
						

Thoughts:
Okay, let's break this down.

**Verifying the Verity Descriptor Retrieval**

Alright, I'm digging into the fs-verity code, specifically in `fs/verity/open.c`. I'm trying to follow how the descriptor size is obtained. Looks like `fsverity_get_descriptor` is the key. It calls `inode->i_sb->s_vop->get_verity_descriptor(inode, NULL, 0)`. That call is what's returning `desc_size`. Good. That's the first critical piece. Then, I see the code using either `kzalloc` or `kmalloc` to allocate memory for the descriptor itself. That makes sense – we need to allocate based on the size we just retrieved. Now, I need to check around line 314 of `fs/verity/open.c` to see how this `desc_size` is being handled, especially in relation to the allocation. I'm guessing there's a check there. I expect that I will likely see more details on how the size is used to prevent potential buffer overflows. I'll need to double check the allocation type based on what is returned to me.



56/3 2026/11/03 04:06 tool read-file
0m Args:
{
  "File": "fs/verity/open.c",
  "FirstLine": 314,
  "LineCount": 40
}

Results:
{
  "Contents": " 314:\tint fsverity_get_descriptor(struct inode *inode,\n 315:\t\t\t\t    struct fsverity_descriptor **desc_ret)\n 316:\t{\n 317:\t\tint res;\n 318:\t\tstruct fsverity_descriptor *desc;\n 319:\t\n 320:\t\tres = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, NULL, 0);\n 321:\t\tif (res \u003c 0) {\n 322:\t\t\tfsverity_err(inode,\n 323:\t\t\t\t     \"Error %d getting verity descriptor size\", res);\n 324:\t\t\treturn res;\n 325:\t\t}\n 326:\t\tif (res \u003e FS_VERITY_MAX_DESCRIPTOR_SIZE) {\n 327:\t\t\tfsverity_err(inode, \"Verity descriptor is too large (%d bytes)\",\n 328:\t\t\t\t     res);\n 329:\t\t\treturn -EMSGSIZE;\n 330:\t\t}\n 331:\t\tdesc = kmalloc(res, GFP_KERNEL);\n 332:\t\tif (!desc)\n 333:\t\t\treturn -ENOMEM;\n 334:\t\tres = inode-\u003ei_sb-\u003es_vop-\u003eget_verity_descriptor(inode, desc, res);\n 335:\t\tif (res \u003c 0) {\n 336:\t\t\tfsverity_err(inode, \"Error %d reading verity descriptor\", res);\n 337:\t\t\tkfree(desc);\n 338:\t\t\treturn res;\n 339:\t\t}\n 340:\t\n 341:\t\tif (!validate_fsverity_descriptor(inode, desc, res)) {\n 342:\t\t\tkfree(desc);\n 343:\t\t\treturn -EINVAL;\n 344:\t\t}\n 345:\t\n 346:\t\t*desc_ret = desc;\n 347:\t\treturn 0;\n 348:\t}\n 349:\t\n 350:\t/**\n 351:\t * fsverity_ensure_verity_info() - cache verity info if it's not already cached\n 352:\t * @inode: the inode for which verity info should be cached\n 353:\t *\n"
}

57/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61581
							output: 38
							thoughts: 75
						

Thoughts:
Here's my understanding of the situation, presented as a summary of my internal thought process:

**Diving into the fsverity Pagecache Read**

Okay, so we're looking at the core of the `fsverity` read operation. Specifically, I see `fsverity_pagecache_read(inode, buf, desc_size, desc_pos);`. This function is pivotal; it's responsible for fetching the data into the buffer `buf` directly from the pagecache. This is the initial data retrieval stage. We need to follow where it's reading from and how, to grasp the performance and behaviour.

Now, that brings up the question of **where** and **what** it's getting, and that leads me to examining `fsverity_read_descriptor`. Let's dig into that and trace it, specifically in `fs/verity/read_metadata.c`. I need to figure out what data the descriptor is reading. That should tell me how it is working.



58/3 2026/11/03 04:06 tool read-file
0m Args:
{
  "File": "fs/verity/read_metadata.c",
  "FirstLine": 100,
  "LineCount": 40
}

Results:
{
  "Contents": " 100:\t\n 101:\t\tif (copy_to_user(dst, src, length))\n 102:\t\t\treturn -EFAULT;\n 103:\t\n 104:\t\treturn length;\n 105:\t}\n 106:\t\n 107:\tstatic int fsverity_read_descriptor(struct inode *inode,\n 108:\t\t\t\t\t    void __user *buf, u64 offset, int length)\n 109:\t{\n 110:\t\tstruct fsverity_descriptor *desc;\n 111:\t\tsize_t desc_size;\n 112:\t\tint res;\n 113:\t\n 114:\t\tres = fsverity_get_descriptor(inode, \u0026desc);\n 115:\t\tif (res)\n 116:\t\t\treturn res;\n 117:\t\n 118:\t\t/* don't include the builtin signature */\n 119:\t\tdesc_size = offsetof(struct fsverity_descriptor, signature);\n 120:\t\tdesc-\u003esig_size = 0;\n 121:\t\n 122:\t\tres = fsverity_read_buffer(buf, offset, length, desc, desc_size);\n 123:\t\n 124:\t\tkfree(desc);\n 125:\t\treturn res;\n 126:\t}\n 127:\t\n 128:\tstatic int fsverity_read_signature(struct inode *inode,\n 129:\t\t\t\t\t   void __user *buf, u64 offset, int length)\n 130:\t{\n 131:\t\tstruct fsverity_descriptor *desc;\n 132:\t\tint res;\n 133:\t\n 134:\t\tres = fsverity_get_descriptor(inode, \u0026desc);\n 135:\t\tif (res)\n 136:\t\t\treturn res;\n 137:\t\n 138:\t\tif (desc-\u003esig_size == 0) {\n 139:\t\t\tres = -ENODATA;\n"
}

59/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62446
							output: 36
							thoughts: 152
						

Thoughts:
Okay, let me break this down.

**Verifying Descriptor Initialization**

Right, so `fsverity_get_descriptor` is grabbing a descriptor, `desc`, and filling it with `res` bytes.  That much is clear. The key thing is, `desc` was allocated with `kmalloc`. Now, the critical question pops up: **is the *entire* `desc` buffer initialized before it's used?**  That's where potential security vulnerabilities lurk, and I always have to be vigilant about that kind of thing. Uninitialized memory is a classic source of issues.

Now, looking deeper within `xfs_fsverity_get_descriptor`, it appears the initialization happens via `fsverity_pagecache_read`, where:
`error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);`

If that read *fails*, well, it returns an error and we're done; no problem. But, if it *succeeds*, it has purportedly read `desc_size` bytes into `desc`. That's good, but does that guarantee *complete* initialization? It better! Otherwise, we could have a partial initialization, and then potentially expose sensitive information.

Okay, let's take a closer look at `fsverity_pagecache_read`. Time to dive into the code! I'll need to inspect the `fs/verity/pagecache.c` file to be completely certain.



60/3 2026/11/03 04:06 tool read-file
0m Args:
{
  "File": "fs/verity/pagecache.c",
  "FirstLine": 80,
  "LineCount": 40
}

Results:
{
  "Contents": "  80:\tEXPORT_SYMBOL_GPL(fsverity_fill_zerohash);\n  81:\t\n  82:\t/**\n  83:\t * fsverity_pagecache_read() - read verity metadata via the pagecache\n  84:\t * @inode:\tcopy from this inode's address space\n  85:\t * @buf:\tbuffer to copy to\n  86:\t * @count:\tnumber of bytes to copy\n  87:\t * @pos:\tbyte offset in the file to copy from\n  88:\t *\n  89:\t * Read some verity metadata from the inode.  __vfs_read() can't be used because\n  90:\t * we need to read beyond i_size.\n  91:\t */\n  92:\tint fsverity_pagecache_read(struct inode *inode, void *buf, size_t count,\n  93:\t\t\t\t  loff_t pos)\n  94:\t{\n  95:\t\twhile (count) {\n  96:\t\t\tstruct folio *folio;\n  97:\t\t\tsize_t n;\n  98:\t\n  99:\t\t\tfolio = read_mapping_folio(inode-\u003ei_mapping, pos \u003e\u003e PAGE_SHIFT,\n 100:\t\t\t\t\t\t NULL);\n 101:\t\t\tif (IS_ERR(folio))\n 102:\t\t\t\treturn PTR_ERR(folio);\n 103:\t\n 104:\t\t\tn = memcpy_from_file_folio(buf, folio, pos, count);\n 105:\t\t\tfolio_put(folio);\n 106:\t\n 107:\t\t\tbuf += n;\n 108:\t\t\tpos += n;\n 109:\t\t\tcount -= n;\n 110:\t\t}\n 111:\t\treturn 0;\n 112:\t}\n 113:\tEXPORT_SYMBOL_GPL(fsverity_pagecache_read);\n"
}

61/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63442
							output: 36
							thoughts: 1384
						

Thoughts:
**Analyzing Potential Data Leakage in XFS with fs-verity**

Okay, so I'm diving into how XFS handles reads that extend past the end-of-file, specifically when fs-verity metadata is involved. My initial focus is on `memcpy_from_file_folio`, the function that actually copies the data.

I'm trying to figure out if there's a risk of uninitialized data being returned in certain scenarios. Specifically, I'm thinking about what happens when reading blocks beyond the file's defined end, where the fs-verity metadata resides. How is that mapping handled?

I've homed in on `xfs_read_iomap_begin` in `fs/xfs/xfs_iomap.c`. I can see that if `fsverity_active(inode)` and the offset is beyond the metadata region, the `IOMAP_F_FSVERITY` flag is set. Then it uses `xfs_bmapi_read` to figure out the block mapping.  `xfs_bmapi_read` returns a 'hole' if there's no extent mapped for that block. If that happens,  `xfs_bmbt_to_iomap` sets the `iomap->type = IOMAP_HOLE`.

Then, I'm looking at `iomap_read_folio_iter` and this is where it gets interesting. If `IOMAP_F_FSVERITY` is set *and* the `iomap` is a hole, there's a conditional check: If `ctx->vi` is not NULL, `fsverity_fill_zerohash` is called. Regardless,  `iomap_set_range_uptodate` is called, which means the page is marked as "uptodate". However, if `ctx->vi` is NULL it looks like nothing happens, which means that the page might contain uninitialized data!

Then it hits me! What's `ctx->vi`? It's not initialized yet at the time! `ctx->vi` is not yet valid! `fsverity_ensure_verity_info` and `fsverity_file_open` are *reading* the descriptor to construct `ctx->vi`. During the *reading* of `desc_size` or `buf` the code calls `read_mapping_folio`, which calls `iomap_read_folio` where we find `ctx->vi = fsverity_get_info(...)` is NULL because the `vi` is not constructed yet!

So, the critical question becomes: What happens when `xfs_read_iomap_begin` is called *during* `xfs_fsverity_get_descriptor`? This is where the vulnerability exists!

During the descriptor read, `inode->i_flags & S_VERITY` *is* true, `fsverity_active(inode)` is true, and the offset condition is met.  So, `IOMAP_F_FSVERITY` is set, and the `iomap_read_folio_iter` logic is executed. Crucially, the code that fills the hash is not called. If the `iomap` is a hole *and*  `ctx->vi == NULL`, the page *isn't* zeroed! Instead, it is marked as 'uptodate'.  That's my concern.

I have to verify that the code that marks as uptodate isn't just a separate code path, but that this code is introduced in the first place or is existing. I have to verify that code: `if ((iomap->flags & IOMAP_F_FSVERITY) && iomap->type == IOMAP_HOLE)`  is indeed part of this patch or is existing.
I'm checking if that's even possible: Can there be a hole where the descriptor is? Is this code from the current patch? I have to look for that code in `fs/iomap/buffered-io.c` and use `git log` to confirm that this is not an entirely new code.



62/3 2026/11/03 04:06 tool grepper
0m Args:
{
  "Expression": "fsverity_fill_zerohash",
  "PathPrefixes": [
    "fs/iomap/"
  ]
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-606-\t\t\tif (ctx-\u003evi)\nfs/iomap/buffered-io.c:607:\t\t\t\tfsverity_fill_zerohash(folio, poff, plen,\nfs/iomap/buffered-io.c-608-\t\t\t\t\t\t       ctx-\u003evi);\n"
}

63/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65901
							output: 39
							thoughts: 100
						

Thoughts:
Okay, let's dive into this. Here's how I'd approach understanding the context surrounding this specific code in `fs/iomap/buffered-io.c`:

**Initial Thoughts on Investigating `fs/iomap/buffered-io.c`**

Alright, I need to get a better handle on what's happening within `fs/iomap/buffered-io.c`. My initial thought is to quickly leverage my usual workflow. Ideally, I'd check the recent history using `git log` to get a sense of recent changes and the rationale behind them. Specifically, I'd run `git log -n 5 fs/iomap/buffered-io.c` to see the last five commits. Alternatively, I could dig deeper directly into `iomap_read_folio_iter`.

However, no `git log` tool? That's fine; it happens. Since I can't check the commit history easily, let's skip the history and I can dive directly into the code and focus on lines 580 through 620 in `fs/iomap/buffered-io.c`. This should give me a specific context, allowing me to understand the flow and logic surrounding that section.



64/3 2026/11/03 04:06 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 580,
  "LineCount": 40
}

Results:
{
  "Contents": " 580:\t\twhile (length) {\n 581:\t\t\tiomap_adjust_read_range(iter-\u003einode, folio, \u0026pos, length, \u0026poff,\n 582:\t\t\t\t\t\u0026plen);\n 583:\t\n 584:\t\t\tpos_diff = pos - iter-\u003epos;\n 585:\t\t\tif (WARN_ON_ONCE(pos_diff + plen \u003e length))\n 586:\t\t\t\treturn -EIO;\n 587:\t\n 588:\t\t\tret = iomap_iter_advance(iter, pos_diff);\n 589:\t\t\tif (ret)\n 590:\t\t\t\treturn ret;\n 591:\t\n 592:\t\t\tif (plen == 0)\n 593:\t\t\t\treturn 0;\n 594:\t\n 595:\t\t\t/*\n 596:\t\t\t * Handling of fsverity \"holes\". We hit this for two case:\n 597:\t\t\t *   1. No need to go further, the hole after fsverity\n 598:\t\t\t *\tdescriptor is the end of the fsverity metadata.\n 599:\t\t\t *\n 600:\t\t\t *   2. This folio contains merkle tree blocks which need to be\n 601:\t\t\t *\tsynthesized. If we already have fsverity info (ctx-\u003evi)\n 602:\t\t\t *\tsynthesize these blocks.\n 603:\t\t\t */\n 604:\t\t\tif ((iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026\n 605:\t\t\t    iomap-\u003etype == IOMAP_HOLE) {\n 606:\t\t\t\tif (ctx-\u003evi)\n 607:\t\t\t\t\tfsverity_fill_zerohash(folio, poff, plen,\n 608:\t\t\t\t\t\t\t       ctx-\u003evi);\n 609:\t\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n 610:\t\t\t} else if (iomap_block_needs_zeroing(iter, pos)) {\n 611:\t\t\t\t/* zero post-eof blocks as the page may be mapped */\n 612:\t\t\t\tfolio_zero_range(folio, poff, plen);\n 613:\t\t\t\tif (ctx-\u003evi \u0026\u0026\n 614:\t\t\t\t    !fsverity_verify_blocks(ctx-\u003evi, folio, plen, poff))\n 615:\t\t\t\t\treturn -EIO;\n 616:\t\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n 617:\t\t\t} else {\n 618:\t\t\t\tif (!*bytes_submitted)\n 619:\t\t\t\t\tiomap_read_init(folio);\n"
}

65/3 2026/11/03 04:06 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 66987
							output: 21
							thoughts: 1799
						

Thoughts:
**Uncovering a Potential Security Vulnerability in fs-verity with Hole Handling**

Okay, here's what I'm seeing. I've been digging into the `fs/iomap/buffered-io.c` file and have noticed a potential issue around lines 604-609, specifically regarding how fs-verity interacts with holes in the file system.  The critical point is that if a file marked with `IOMAP_F_FSVERITY` has a hole (`iomap->type == IOMAP_HOLE`) and the context `ctx->vi` is `NULL`, then a certain range `[poff, poff + plen)` is *not* zeroed as it would normally be with `fsverity_fill_zerohash`.  Crucially, it is then marked as "uptodate" with `iomap_set_range_uptodate`.

This got me thinking, under what conditions does `iomap->type == IOMAP_HOLE`, `iomap->flags & IOMAP_F_FSVERITY`, and `ctx->vi == NULL` happen together? The trigger seems to be in XFS when `xfs_read_iomap_begin` is called, and `fsverity_active(inode)` is true. If a malicious user or a corrupted filesystem presents a file with the `S_VERITY` flag or uses an ioctl, this can be triggered. When opening a file, a chain of calls starts, from `xfs_file_open` down to `fsverity_get_descriptor`.

Now, if a hole exists *before* the location of the fs-verity metadata, things get interesting.  In `xfs_fsverity_get_descriptor`, `xfs_bmap_last_extent` is called to find the last extent and the last block offset. Let's say that the extent from `xfs_bmap_last_extent` contains the metadata descriptor. What if a hole exists before this `last_block_offset`? Specifically, if the descriptor size and the descriptor itself are in that hole? This means `desc_pos` ends up within a HOLE.

The subsequent `fsverity_pagecache_read` allocates a folio.  I need to check how folios allocated for pagecache are handled. Are they zeroed on allocation?  A quick check of the code for `filemap_alloc_folio` reveals that, no, they are *not* zeroed because of the `mapping_gfp_mask(mapping)` used for allocation.  The read path or iomap is supposed to handle initializing the contents.

Back to the original problem in buffered I/O, if we have a hole, but `ctx->vi` is `NULL`, the `fsverity_fill_zerohash` step is skipped.  The folio remains uninitialized, and `iomap_set_range_uptodate` still marks it as up to date. Then a `memcpy_from_file_folio` happens, copying the *uninitialized* folio memory to a buffer. This buffer, `desc`, is then used in `fsverity_get_descriptor`. This is a clear path to returning uninitialized memory.

This uninitialized `desc` is then passed to `copy_to_user` and *copied to userspace*!  I then need to figure out how this `desc` is populated.  I need to confirm if this `desc` variable is validated prior to being copied.

I can see that `fsverity_read_merkle_tree` requires a non-NULL `vi`, so the merkle tree is safe.

But, the ioctl `FS_IOC_READ_VERITY_METADATA` with `FS_VERITY_METADATA_TYPE_DESCRIPTOR` calls `fsverity_read_descriptor`. In `fsverity_read_descriptor`,  `fsverity_get_descriptor` returns `desc`, and `fsverity_read_buffer` is called to return the memory to user space.  *This* is the critical path where the uninitialized memory could be leaked. The fact that the call flow is `fsverity_read_descriptor` -> `fsverity_get_descriptor` -> `copy_to_user` is a strong indication that this is the vulnerability. I'll need to check if `validate_fsverity_descriptor` is called prior to returning this descriptor, and that the validation ensures that any uninitialized memory is caught.



66/3 2026/11/03 04:07 tool grepper
0m Args:
{
  "Expression": "validate_fsverity_descriptor"
}

Results:
{
  "Output": "fs/verity/open.c=267=EXPORT_SYMBOL_GPL(__fsverity_get_info);\nfs/verity/open.c-268-\nfs/verity/open.c:269:static bool validate_fsverity_descriptor(struct inode *inode,\nfs/verity/open.c-270-\t\t\t\t\t const struct fsverity_descriptor *desc,\n--\nfs/verity/open.c=314=int fsverity_get_descriptor(struct inode *inode,\n--\nfs/verity/open.c-340-\nfs/verity/open.c:341:\tif (!validate_fsverity_descriptor(inode, desc, res)) {\nfs/verity/open.c-342-\t\tkfree(desc);\n"
}

67/3 2026/11/03 04:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 70000
							output: 36
							thoughts: 13
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Analyzing the `validate_fsverity_descriptor` Function**

Alright, let's dive into this `validate_fsverity_descriptor` function. I need to understand its role in verifying the integrity of the FS-Verity descriptor. This is critical because a compromised descriptor would completely undermine the security guarantees we're trying to achieve with FS-Verity. We need to ascertain that the descriptor itself is authentic and hasn't been tampered with, which ultimately guarantees the integrity of the file it describes.

I'm thinking about the key checks it probably performs. It’s likely ensuring the descriptor's format is correct, checking for version compatibility, verifying the signature (probably using a public key), and validating the cryptographic hashes against a known root or trusted authority, or at least against some internally consistent structure. I expect it's also handling edge cases and error conditions gracefully—malformed descriptors, invalid signatures, incorrect hash values, perhaps even preventing replay attacks. It *has* to.

I'll be looking specifically for potential vulnerabilities. Are there any integer overflows that could be exploited? Buffer overflows? Could an attacker craft a descriptor that appears valid but directs us to the wrong data, or bypasses the verifications? What about timing attacks—could an attacker glean information about the key or hash computation through careful manipulation of input and observation of response times? The subtle details will be the key here.



68/3 2026/11/03 04:07 tool read-file
0m Args:
{
  "File": "fs/verity/open.c",
  "FirstLine": 268,
  "LineCount": 45
}

Results:
{
  "Contents": " 268:\t\n 269:\tstatic bool validate_fsverity_descriptor(struct inode *inode,\n 270:\t\t\t\t\t\t const struct fsverity_descriptor *desc,\n 271:\t\t\t\t\t\t size_t desc_size)\n 272:\t{\n 273:\t\tif (desc_size \u003c sizeof(*desc)) {\n 274:\t\t\tfsverity_err(inode, \"Unrecognized descriptor size: %zu bytes\",\n 275:\t\t\t\t     desc_size);\n 276:\t\t\treturn false;\n 277:\t\t}\n 278:\t\n 279:\t\tif (desc-\u003eversion != 1) {\n 280:\t\t\tfsverity_err(inode, \"Unrecognized descriptor version: %u\",\n 281:\t\t\t\t     desc-\u003eversion);\n 282:\t\t\treturn false;\n 283:\t\t}\n 284:\t\n 285:\t\tif (memchr_inv(desc-\u003e__reserved, 0, sizeof(desc-\u003e__reserved))) {\n 286:\t\t\tfsverity_err(inode, \"Reserved bits set in descriptor\");\n 287:\t\t\treturn false;\n 288:\t\t}\n 289:\t\n 290:\t\tif (desc-\u003esalt_size \u003e sizeof(desc-\u003esalt)) {\n 291:\t\t\tfsverity_err(inode, \"Invalid salt_size: %u\", desc-\u003esalt_size);\n 292:\t\t\treturn false;\n 293:\t\t}\n 294:\t\n 295:\t\tif (le64_to_cpu(desc-\u003edata_size) != inode-\u003ei_size) {\n 296:\t\t\tfsverity_err(inode,\n 297:\t\t\t\t     \"Wrong data_size: %llu (desc) != %lld (inode)\",\n 298:\t\t\t\t     le64_to_cpu(desc-\u003edata_size), inode-\u003ei_size);\n 299:\t\t\treturn false;\n 300:\t\t}\n 301:\t\n 302:\t\tif (le32_to_cpu(desc-\u003esig_size) \u003e desc_size - sizeof(*desc)) {\n 303:\t\t\tfsverity_err(inode, \"Signature overflows verity descriptor\");\n 304:\t\t\treturn false;\n 305:\t\t}\n 306:\t\n 307:\t\treturn true;\n 308:\t}\n 309:\t\n 310:\t/*\n 311:\t * Read the inode's fsverity_descriptor (with optional appended builtin\n 312:\t * signature) from the filesystem, and do basic validation of it.\n"
}

69/3 2026/11/03 04:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 71033
							output: 35
							thoughts: 627
						

Thoughts:
**Uncovering Potential Vulnerabilities in XFS's fs-verity Implementation**

Okay, let's break this down. First, I see that `validate_fsverity_descriptor` is checking `desc->version`. If that `desc` struct is coming straight from uninitialized pagecache memory, `desc->version` will be whatever garbage happened to be there. And if it branches on that, KMSAN is going to catch it, which is great. 

But wait! Even before we get to the validation, there's a potential issue in `xfs_fsverity_get_descriptor`. We're reading `d_desc_size` using `fsverity_pagecache_read`, and that's reading a `__be32` from the pagecache. I need to be careful with the source of this value. 

Now, what if the `desc_size_pos` calculation in `xfs_fsverity_get_descriptor` ends up reading from a hole or a partial block? That's another avenue for potential problems. Let's see... the `last_block_offset - sizeof(__be32)` calculation... can that put us in a hole? I need to look into this more closely.

Right, let's trace through `xfs_fsverity_get_descriptor`. Okay, it calls `xfs_bmap_last_extent` to find the last extent. Then, it calculates `last_block_offset`, subtracting `sizeof(__be32)` to get `desc_size_pos`. Then, it reads `d_desc_size` from that position.

But hold on! What if the `rec` we get from `xfs_bmap_last_extent` is an unwritten extent? That would mean `rec.br_state == XFS_EXT_UNWRITTEN`. Now *that* is an interesting point. In XFS, what actually happens when you try to read from an UNWRITTEN extent? I need to know how iomap handles `XFS_EXT_UNWRITTEN` in `xfs_bmbt_to_iomap`, that is the next critical step. This is where the vulnerability might lie.



70/3 2026/11/03 04:07 tool grepper
0m Args:
{
  "Expression": "XFS_EXT_UNWRITTEN",
  "PathPrefixes": [
    "fs/xfs/"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 242 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (18 files in total):\nfs/xfs/libxfs/xfs_bmap.c:16\nfs/xfs/libxfs/xfs_bmap.h:1\nfs/xfs/libxfs/xfs_bmap_btree.c:2\nfs/xfs/libxfs/xfs_iext_tree.c:2\nfs/xfs/libxfs/xfs_rmap.c:1\nfs/xfs/libxfs/xfs_types.h:1\nfs/xfs/scrub/bmap.c:3\nfs/xfs/scrub/bmap_repair.c:1\nfs/xfs/scrub/quota_repair.c:1\nfs/xfs/scrub/rmap_repair.c:1\nfs/xfs/scrub/rtbitmap_repair.c:2\nfs/xfs/scrub/rtrmap_repair.c:1\nfs/xfs/xfs_bmap_item.c:2\nfs/xfs/xfs_bmap_util.c:1\nfs/xfs/xfs_iomap.c:5\nfs/xfs/xfs_pnfs.c:1\nfs/xfs/xfs_reflink.c:3\nfs/xfs/xfs_rmap_item.c:2\n\nfs/xfs/libxfs/xfs_bmap.c=510=xfs_bmap_validate_ret(\n--\nfs/xfs/libxfs/xfs_bmap.c-539-\t\tASSERT(mval[i].br_state == XFS_EXT_NORM ||\nfs/xfs/libxfs/xfs_bmap.c:540:\t\t       mval[i].br_state == XFS_EXT_UNWRITTEN);\nfs/xfs/libxfs/xfs_bmap.c-541-\t}\n--\nfs/xfs/libxfs/xfs_bmap.c=3898=xfs_bmapi_allocate(\n--\nfs/xfs/libxfs/xfs_bmap.c-3972-\tif (bma-\u003eflags \u0026 XFS_BMAPI_PREALLOC)\nfs/xfs/libxfs/xfs_bmap.c:3973:\t\tbma-\u003egot.br_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.c-3974-\n--\nfs/xfs/libxfs/xfs_bmap.c-3994-\tASSERT(bma-\u003egot.br_state == XFS_EXT_NORM ||\nfs/xfs/libxfs/xfs_bmap.c:3995:\t       bma-\u003egot.br_state == XFS_EXT_UNWRITTEN);\nfs/xfs/libxfs/xfs_bmap.c-3996-\treturn 0;\n--\nfs/xfs/libxfs/xfs_bmap.c=4000=xfs_bmapi_convert_unwritten(\n--\nfs/xfs/libxfs/xfs_bmap.c-4011-\t/* check if we need to do unwritten-\u003ereal conversion */\nfs/xfs/libxfs/xfs_bmap.c:4012:\tif (mval-\u003ebr_state == XFS_EXT_UNWRITTEN \u0026\u0026\nfs/xfs/libxfs/xfs_bmap.c-4013-\t    (flags \u0026 XFS_BMAPI_PREALLOC))\n--\nfs/xfs/libxfs/xfs_bmap.c-4029-\t}\nfs/xfs/libxfs/xfs_bmap.c:4030:\tmval-\u003ebr_state = (mval-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/libxfs/xfs_bmap.c:4031:\t\t\t\t? XFS_EXT_NORM : XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.c-4032-\n--\nfs/xfs/libxfs/xfs_bmap.c=4521=xfs_bmapi_remap(\n--\nfs/xfs/libxfs/xfs_bmap.c-4575-\tif (flags \u0026 XFS_BMAPI_PREALLOC)\nfs/xfs/libxfs/xfs_bmap.c:4576:\t\tgot.br_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.c-4577-\telse\n--\nfs/xfs/libxfs/xfs_bmap.c=4917=xfs_bmap_del_extent_real(\n--\nfs/xfs/libxfs/xfs_bmap.c-5133-\t\t\tif ((bflags \u0026 XFS_BMAPI_NODISCARD) ||\nfs/xfs/libxfs/xfs_bmap.c:5134:\t\t\t    del-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/libxfs/xfs_bmap.c-5135-\t\t\t\tefi_flags |= XFS_FREE_EXTENT_SKIP_DISCARD;\n--\nfs/xfs/libxfs/xfs_bmap.c=5179=__xfs_bunmapi(\n--\nfs/xfs/libxfs/xfs_bmap.c-5282-\t\tif ((flags \u0026 XFS_BMAPI_UNWRITTEN) \u0026\u0026\nfs/xfs/libxfs/xfs_bmap.c:5283:\t\t    del.br_state != XFS_EXT_UNWRITTEN)\nfs/xfs/libxfs/xfs_bmap.c-5284-\t\t\tgoto skip;\n--\nfs/xfs/libxfs/xfs_bmap.c-5298-\t\t\t */\nfs/xfs/libxfs/xfs_bmap.c:5299:\t\t\tif (del.br_state == XFS_EXT_UNWRITTEN) {\nfs/xfs/libxfs/xfs_bmap.c-5300-\t\t\t\t/*\n--\nfs/xfs/libxfs/xfs_bmap.c-5328-\t\t\t}\nfs/xfs/libxfs/xfs_bmap.c:5329:\t\t\tdel.br_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.c-5330-\t\t\terror = xfs_bmap_add_extent_unwritten_real(tp, ip,\n--\nfs/xfs/libxfs/xfs_bmap.c-5351-\t\t\t} else if (del.br_startoff == start \u0026\u0026\nfs/xfs/libxfs/xfs_bmap.c:5352:\t\t\t\t   (del.br_state == XFS_EXT_UNWRITTEN ||\nfs/xfs/libxfs/xfs_bmap.c-5353-\t\t\t\t    tp-\u003et_blk_res == 0)) {\n--\nfs/xfs/libxfs/xfs_bmap.c-5365-\t\t\t\tcontinue;\nfs/xfs/libxfs/xfs_bmap.c:5366:\t\t\t} else if (del.br_state == XFS_EXT_UNWRITTEN) {\nfs/xfs/libxfs/xfs_bmap.c-5367-\t\t\t\tstruct xfs_bmbt_irec\tprev;\n--\nfs/xfs/libxfs/xfs_bmap.c-5388-\t\t\t\tprev.br_blockcount -= mod;\nfs/xfs/libxfs/xfs_bmap.c:5389:\t\t\t\tprev.br_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.c-5390-\t\t\t\terror = xfs_bmap_add_extent_unwritten_real(tp,\n--\nfs/xfs/libxfs/xfs_bmap.c-5397-\t\t\t\tASSERT(del.br_state == XFS_EXT_NORM);\nfs/xfs/libxfs/xfs_bmap.c:5398:\t\t\t\tdel.br_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.c-5399-\t\t\t\terror = xfs_bmap_add_extent_unwritten_real(tp,\n--\nfs/xfs/libxfs/xfs_bmap.c=6056=xfs_bmap_finish_one(\n--\nfs/xfs/libxfs/xfs_bmap.c-6075-\tcase XFS_BMAP_MAP:\nfs/xfs/libxfs/xfs_bmap.c:6076:\t\tif (bi-\u003ebi_bmap.br_state == XFS_EXT_UNWRITTEN)\nfs/xfs/libxfs/xfs_bmap.c-6077-\t\t\tflags |= XFS_BMAPI_PREALLOC;\n--\nfs/xfs/libxfs/xfs_bmap.h=169=static inline bool xfs_bmap_is_written_extent(const struct xfs_bmbt_irec *irec)\n--\nfs/xfs/libxfs/xfs_bmap.h-171-\treturn xfs_bmap_is_real_extent(irec) \u0026\u0026\nfs/xfs/libxfs/xfs_bmap.h:172:\t       irec-\u003ebr_state != XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap.h-173-}\n--\nfs/xfs/libxfs/xfs_bmap_btree.c=78=xfs_bmbt_disk_get_all(\n--\nfs/xfs/libxfs/xfs_bmap_btree.c-88-\tif (l0 \u003e\u003e (64 - BMBT_EXNTFLAG_BITLEN))\nfs/xfs/libxfs/xfs_bmap_btree.c:89:\t\tirec-\u003ebr_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_bmap_btree.c-90-\telse\n--\nfs/xfs/libxfs/xfs_bmap_btree.c=119=xfs_bmbt_disk_set_all(\n--\nfs/xfs/libxfs/xfs_bmap_btree.c-124-\nfs/xfs/libxfs/xfs_bmap_btree.c:125:\tASSERT(s-\u003ebr_state == XFS_EXT_NORM || s-\u003ebr_state == XFS_EXT_UNWRITTEN);\nfs/xfs/libxfs/xfs_bmap_btree.c-126-\tASSERT(!(s-\u003ebr_startoff \u0026 xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)));\n--\nfs/xfs/libxfs/xfs_iext_tree.c=53=xfs_iext_set(\n--\nfs/xfs/libxfs/xfs_iext_tree.c-66-\nfs/xfs/libxfs/xfs_iext_tree.c:67:\tif (irec-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/libxfs/xfs_iext_tree.c-68-\t\trec-\u003ehi |= (1 \u003c\u003c 21);\n--\nfs/xfs/libxfs/xfs_iext_tree.c=72=xfs_iext_get(\n--\nfs/xfs/libxfs/xfs_iext_tree.c-82-\tif (rec-\u003ehi \u0026 (1 \u003c\u003c 21))\nfs/xfs/libxfs/xfs_iext_tree.c:83:\t\tirec-\u003ebr_state = XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_iext_tree.c-84-\telse\n--\nfs/xfs/libxfs/xfs_rmap.c=2679=xfs_rmap_finish_one(\n--\nfs/xfs/libxfs/xfs_rmap.c-2713-\t\t\tri-\u003eri_bmap.br_startoff);\nfs/xfs/libxfs/xfs_rmap.c:2714:\tunwritten = ri-\u003eri_bmap.br_state == XFS_EXT_UNWRITTEN;\nfs/xfs/libxfs/xfs_rmap.c-2715-\n--\nfs/xfs/libxfs/xfs_types.h=150=typedef enum {\nfs/xfs/libxfs/xfs_types.h:151:\tXFS_EXT_NORM, XFS_EXT_UNWRITTEN,\nfs/xfs/libxfs/xfs_types.h-152-} xfs_exntst_t;\n--\nfs/xfs/scrub/bmap.c=145=xchk_bmap_get_rmap(\n--\nfs/xfs/scrub/bmap.c-165-\t\trflags |= XFS_RMAP_ATTR_FORK;\nfs/xfs/scrub/bmap.c:166:\tif (irec-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/scrub/bmap.c-167-\t\trflags |= XFS_RMAP_UNWRITTEN;\n--\nfs/xfs/scrub/bmap.c=201=xchk_bmap_xref_rmap(\n--\nfs/xfs/scrub/bmap.c-251-\t */\nfs/xfs/scrub/bmap.c:252:\tif (!!(irec-\u003ebr_state == XFS_EXT_UNWRITTEN) !=\nfs/xfs/scrub/bmap.c-253-\t    !!(rmap.rm_flags \u0026 XFS_RMAP_UNWRITTEN))\n--\nfs/xfs/scrub/bmap.c=471=xchk_bmap_iextent(\n--\nfs/xfs/scrub/bmap.c-503-\t/* We don't allow unwritten extents on attr forks. */\nfs/xfs/scrub/bmap.c:504:\tif (irec-\u003ebr_state == XFS_EXT_UNWRITTEN \u0026\u0026\nfs/xfs/scrub/bmap.c-505-\t    info-\u003ewhichfork == XFS_ATTR_FORK)\n--\nfs/xfs/scrub/bmap_repair.c=130=xrep_bmap_from_rmap(\n--\nfs/xfs/scrub/bmap_repair.c-139-\t\t.br_startblock\t= startblock,\nfs/xfs/scrub/bmap_repair.c:140:\t\t.br_state\t= unwritten ? XFS_EXT_UNWRITTEN : XFS_EXT_NORM,\nfs/xfs/scrub/bmap_repair.c-141-\t};\n--\nfs/xfs/scrub/quota_repair.c=421=xrep_quota_data_fork(\n--\nfs/xfs/scrub/quota_repair.c-457-\t\t/* Convert unwritten extents to real ones. */\nfs/xfs/scrub/quota_repair.c:458:\t\tif (irec.br_state == XFS_EXT_UNWRITTEN) {\nfs/xfs/scrub/quota_repair.c-459-\t\t\tstruct xfs_bmbt_irec\tnrec;\n--\nfs/xfs/scrub/rmap_repair.c=334=xrep_rmap_visit_bmbt(\n--\nfs/xfs/scrub/rmap_repair.c-352-\t\trmap_flags |= XFS_RMAP_ATTR_FORK;\nfs/xfs/scrub/rmap_repair.c:353:\tif (rec-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/scrub/rmap_repair.c-354-\t\trmap_flags |= XFS_RMAP_UNWRITTEN;\n--\nfs/xfs/scrub/rtbitmap_repair.c=397=xrep_rtbitmap_data_mappings(\n--\nfs/xfs/scrub/rtbitmap_repair.c-440-\t\t/* Make sure we're really converting an unwritten extent. */\nfs/xfs/scrub/rtbitmap_repair.c:441:\t\tif (map.br_state != XFS_EXT_UNWRITTEN) {\nfs/xfs/scrub/rtbitmap_repair.c:442:\t\t\tASSERT(map.br_state == XFS_EXT_UNWRITTEN);\nfs/xfs/scrub/rtbitmap_repair.c-443-\t\t\treturn -EFSCORRUPTED;\n--\nfs/xfs/scrub/rtrmap_repair.c=217=xrep_rtrmap_visit_bmbt(\n--\nfs/xfs/scrub/rtrmap_repair.c-232-\nfs/xfs/scrub/rtrmap_repair.c:233:\tif (rec-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/scrub/rtrmap_repair.c-234-\t\trmap_flags |= XFS_RMAP_UNWRITTEN;\n--\nfs/xfs/xfs_bmap_item.c=253=xfs_bmap_update_log_item(\n--\nfs/xfs/xfs_bmap_item.c-281-\t}\nfs/xfs/xfs_bmap_item.c:282:\tif (bi-\u003ebi_bmap.br_state == XFS_EXT_UNWRITTEN)\nfs/xfs/xfs_bmap_item.c-283-\t\tmap-\u003eme_flags |= XFS_BMAP_EXTENT_UNWRITTEN;\n--\nfs/xfs/xfs_bmap_item.c=455=xfs_bui_recover_work(\n--\nfs/xfs/xfs_bmap_item.c-476-\tbi-\u003ebi_bmap.br_state = (map-\u003eme_flags \u0026 XFS_BMAP_EXTENT_UNWRITTEN) ?\nfs/xfs/xfs_bmap_item.c:477:\t\t\tXFS_EXT_UNWRITTEN : XFS_EXT_NORM;\nfs/xfs/xfs_bmap_item.c-478-\tbi-\u003ebi_owner = *ipp;\n--\nfs/xfs/xfs_bmap_util.c=146=xfs_getbmap_report_one(\n--\nfs/xfs/xfs_bmap_util.c-177-\nfs/xfs/xfs_bmap_util.c:178:\tif (got-\u003ebr_state == XFS_EXT_UNWRITTEN \u0026\u0026\nfs/xfs/xfs_bmap_util.c-179-\t    (bmv-\u003ebmv_iflags \u0026 BMV_IF_PREALLOC))\n--\nfs/xfs/xfs_iomap.c=102=xfs_bmbt_to_iomap(\n--\nfs/xfs/xfs_iomap.c-132-\nfs/xfs/xfs_iomap.c:133:\t\tif (imap-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/xfs_iomap.c-134-\t\t\tiomap-\u003etype = IOMAP_UNWRITTEN;\n--\nfs/xfs/xfs_iomap.c=270=xfs_iomap_write_direct(\n--\nfs/xfs/xfs_iomap.c-318-\t\tbmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;\nfs/xfs/xfs_iomap.c:319:\t\tif (imap-\u003ebr_state == XFS_EXT_UNWRITTEN) {\nfs/xfs/xfs_iomap.c-320-\t\t\tforce = true;\n--\nfs/xfs/xfs_iomap.c=733=imap_needs_alloc(\n--\nfs/xfs/xfs_iomap.c-746-\t/* we convert unwritten extents before copying the data for DAX */\nfs/xfs/xfs_iomap.c:747:\tif ((flags \u0026 IOMAP_DAX) \u0026\u0026 imap-\u003ebr_state == XFS_EXT_UNWRITTEN)\nfs/xfs/xfs_iomap.c-748-\t\treturn true;\n--\n\n"
}

71/3 2026/11/03 04:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 77458
							output: 24
							thoughts: 110
						

Thoughts:
**Analyzing Unwritten Extents in XFS and IOMAP**

Okay, let's dive into this. I'm looking at `xfs_bmbt_to_iomap` and specifically focusing on the handling of unwritten extents. If the `br_state` in the `imap` structure is `XFS_EXT_UNWRITTEN`, the code correctly sets `iomap->type` to `IOMAP_UNWRITTEN`. Now, my main question is how `IOMAP_UNWRITTEN` is subsequently processed within the `iomap_read_folio_iter` function. The key lies in understanding how this `iomap` type impacts the read path.

To answer that, I need to check the logic behind `iomap_block_needs_zeroing(iter, pos)`. This function is likely the one determining whether or not unwritten blocks need to be zeroed during the read operation. I'll need to analyze that function call closely to see how it uses the `IOMAP_UNWRITTEN` flag and how it affects the data returned to the user. I'm assuming there's some sort of zeroing optimization or bypassing that will be revealed in that call.



72/3 2026/11/03 04:07 tool grepper
0m Args:
{
  "Expression": "iomap_block_needs_zeroing"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=318=static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,\n--\nfs/iomap/buffered-io.c-381-\nfs/iomap/buffered-io.c:382:static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\nfs/iomap/buffered-io.c-383-\t\tloff_t pos)\n--\nfs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-609-\t\t\tiomap_set_range_uptodate(folio, poff, plen);\nfs/iomap/buffered-io.c:610:\t\t} else if (iomap_block_needs_zeroing(iter, pos)) {\nfs/iomap/buffered-io.c-611-\t\t\t/* zero post-eof blocks as the page may be mapped */\n--\nfs/iomap/buffered-io.c=875=static int __iomap_write_begin(const struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-919-\nfs/iomap/buffered-io.c:920:\t\tif (iomap_block_needs_zeroing(iter, block_start)) {\nfs/iomap/buffered-io.c-921-\t\t\tif (WARN_ON_ONCE(iter-\u003eflags \u0026 IOMAP_UNSHARE))\n"
}

73/3 2026/11/03 04:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 78277
							output: 39
							thoughts: 31
						

Thoughts:
Okay, here's my summary, tailored for an expert audience, presented as if it were my own thought process:

**Diving into `iomap_block_needs_zeroing`**

Alright, time to crack open `fs/iomap/buffered-io.c` and specifically, that `iomap_block_needs_zeroing` function. Given my background, I'm already anticipating some of the nuances this is going to deal with. This has got to be a core piece dealing with buffered I/O, which, as we know, can get incredibly complex when you're trying to optimize performance while maintaining data integrity. I'm guessing this function is central to determining if a block needs zeroing before being written, likely because it's either uninitialized on disk, or perhaps the buffered write hasn't completely overwritten some previous data. It's probably considering factors like the file's current state, the write offset and length, and possibly metadata related to the block allocation strategy of the underlying filesystem. I'm keen to see how they handle partial block writes – that's often where the real cleverness hides. Let's see how they deal with any potential race conditions and concurrency challenges.



74/3 2026/11/03 04:07 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 380,
  "LineCount": 35
}

Results:
{
  "Contents": " 380:\t}\n 381:\t\n 382:\tstatic inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\n 383:\t\t\tloff_t pos)\n 384:\t{\n 385:\t\tconst struct iomap *srcmap = iomap_iter_srcmap(iter);\n 386:\t\n 387:\t\t/*\n 388:\t\t * If this block has not been written, there's nothing to read\n 389:\t\t */\n 390:\t\tif (srcmap-\u003etype != IOMAP_MAPPED)\n 391:\t\t\treturn true;\n 392:\t\n 393:\t\t/*\n 394:\t\t * Newly allocated blocks have not been written\n 395:\t\t */\n 396:\t\tif (srcmap-\u003eflags \u0026 IOMAP_F_NEW)\n 397:\t\t\treturn true;\n 398:\t\n 399:\t\t/*\n 400:\t\t * fsverity metadata is stored past i_size, we need to read it instead\n 401:\t\t * of zeroing\n 402:\t\t */\n 403:\t\tif (srcmap-\u003eflags \u0026 IOMAP_F_FSVERITY)\n 404:\t\t\treturn false;\n 405:\t\n 406:\t\treturn pos \u003e= i_size_read(iter-\u003einode);\n 407:\t}\n 408:\t\n 409:\t/**\n 410:\t * iomap_read_inline_data - copy inline data into the page cache\n 411:\t * @iter: iteration structure\n 412:\t * @folio: folio to copy to\n 413:\t *\n 414:\t * Copy the inline data in @iter into @folio and zero out the rest of the folio.\n"
}

75/3 2026/11/03 04:07 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 79088
							output: 23
							thoughts: 6622
						

Thoughts:
**Vulnerability Deep Dive: fsverity and Uninitialized Memory in XFS**

Alright, I've got a critical issue here. I've been dissecting the interaction between fsverity, the iomap layer, and specifically the XFS filesystem. It seems there's a serious flaw that can lead to reading uninitialized memory, potentially controllable by an attacker, and ultimately resulting in information leaks or corruption. The crux of the problem lies in how XFS handles "holes" in conjunction with fsverity metadata.

Here's the breakdown: XFS, when fsverity is enabled, uses the iomap infrastructure to manage block mapping. It sets `IOMAP_F_FSVERITY` to identify the blocks in the file that contain verity metadata.  Now, the `iomap_block_needs_zeroing` function is crucial. Its job is to determine if a block needs to be zeroed before being read, to prevent information disclosure from previously written data. If a block is an unwritten extent or a hole (`IOMAP_UNWRITTEN` or `IOMAP_HOLE` type), it *should* return TRUE. However, it *does* return `true` if it's not mapped. The problem is that the next code in `iomap_read_folio_iter` does not zero the block if the file is a hole, if fsverity is enabled and if `ctx->vi` is NULL.

Crucially, there's a conditional branch that bypasses the zeroing mechanism under specific circumstances. If a block is a hole and flagged for fsverity and when `ctx->vi` is NULL, the code doesn't zero the page and sets the page to UPTODATE. `ctx->vi` is the verity information for the file. This can be NULL when fsverity is being activated, or the metadata is being accessed for the first time. For example, during initial setup, or when the file is opened for scrubbing, or when reading the descriptor. This then leads to uninitialized memory being marked as UPTODATE in the page cache.  This can occur during the initial stages of checking and enabling fsverity, or during the reading of the metadata descriptor. This also occurs during the reading of a Merkle tree that may contain holes, and when `FS_IOC_READ_VERITY_METADATA` is called.

The vulnerability comes from the potential for the *fsverity_pagecache_read* function, when reading verity metadata, to copy this uninitialized memory into a user-provided buffer. This is because the code skips zeroing when reading a hole in the verity metadata region if it does not have the verity info for the file. For example, a crafted file, which has a hole in the region that contains its metadata, will result in an attack vector where uninitialized memory is read. This memory can then be used in a conditional jump in the kernel.

Specifically, during fsverity metadata reading, when the system encounters a hole within the metadata region, the related page within the file is not zeroed.  The Merkle tree may have holes. When the metadata is requested by ioctl calls such as `FS_IOC_READ_VERITY_METADATA`, or when the descriptor is read, the file region is mapped and copied into a buffer directly accessible by the kernel or indirectly by userspace.

The implications are serious. This uninitialized memory could contain sensitive kernel data or lead to exploitable behavior when used later in calculations within the kernel, for example, within the `validate_fsverity_descriptor` function which accesses this data directly. In the corrupted XFS filesystem, a version check, or other checks, may depend on the uninitialized data.



76/3 2026/11/03 04:08 tool grepper
0m Args:
{
  "Expression": "fsverity_fill_zerohash"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-606-\t\t\tif (ctx-\u003evi)\nfs/iomap/buffered-io.c:607:\t\t\t\tfsverity_fill_zerohash(folio, poff, plen,\nfs/iomap/buffered-io.c-608-\t\t\t\t\t\t       ctx-\u003evi);\n--\nfs/verity/pagecache.c=59=EXPORT_SYMBOL_GPL(generic_readahead_merkle_tree);\n--\nfs/verity/pagecache.c-61-/**\nfs/verity/pagecache.c:62: * fsverity_fill_zerohash() - fill folio with hashes of zero data block\nfs/verity/pagecache.c-63- * @folio:\tfolio to fill\n--\nfs/verity/pagecache.c-67- */\nfs/verity/pagecache.c:68:void fsverity_fill_zerohash(struct folio *folio, size_t offset, size_t len,\nfs/verity/pagecache.c-69-\t\t\t      struct fsverity_info *vi)\n--\nfs/verity/pagecache.c-79-}\nfs/verity/pagecache.c:80:EXPORT_SYMBOL_GPL(fsverity_fill_zerohash);\nfs/verity/pagecache.c-81-\n--\ninclude/linux/fsverity.h=207=void fsverity_enqueue_verify_work(struct work_struct *work);\ninclude/linux/fsverity.h:208:void fsverity_fill_zerohash(struct folio *folio, size_t offset, size_t len,\ninclude/linux/fsverity.h-209-\t\t\t    struct fsverity_info *vi);\n--\ninclude/linux/fsverity.h=285=static inline void fsverity_enqueue_verify_work(struct work_struct *work)\n--\ninclude/linux/fsverity.h-289-\ninclude/linux/fsverity.h:290:static inline void fsverity_fill_zerohash(struct folio *folio, size_t offset,\ninclude/linux/fsverity.h-291-\t\tsize_t len, struct fsverity_info *vi)\n"
}

77/3 2026/11/03 04:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 87137
							output: 36
							thoughts: 27
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `fsverity_fill_zerohash`**

Alright, let's get into the nitty-gritty of `fsverity_fill_zerohash` within `fs/verity/pagecache.c`. I'm curious to see how they handle the zero-hash scenarios. Presumably, this is where the magic happens for handling blocks that either aren't present or are intentionally zeroed out in the verified data stream. I expect a good implementation here should be efficient and robust because this routine's performance impacts overall verified file access. I'm keen to understand the interactions with the page cache. I imagine they're probably leveraging the page cache to minimize redundant calculations, but I'll need to check the exact implementation details. Specifically, I'm thinking about aspects like page locking, error handling (especially in the face of underlying I/O problems), and how this function integrates with the overall fs-verity data flow. I also want to see if any optimization strategies are employed for handling large blocks of zeros, since that's a common case for padding and uninitialized data. Finally, I'm interested to see how they handle potential race conditions, if any, that could arise when multiple threads are requesting zero-hash pages simultaneously. So, let's take a look.



78/3 2026/11/03 04:08 tool read-file
0m Args:
{
  "File": "fs/verity/pagecache.c",
  "FirstLine": 60,
  "LineCount": 25
}

Results:
{
  "Contents": "  60:\t\n  61:\t/**\n  62:\t * fsverity_fill_zerohash() - fill folio with hashes of zero data block\n  63:\t * @folio:\tfolio to fill\n  64:\t * @offset:\toffset in the folio to start\n  65:\t * @len:\tlength of the range to fill with hashes\n  66:\t * @vi:\t\tfsverity info\n  67:\t */\n  68:\tvoid fsverity_fill_zerohash(struct folio *folio, size_t offset, size_t len,\n  69:\t\t\t\t      struct fsverity_info *vi)\n  70:\t{\n  71:\t\tsize_t off = offset;\n  72:\t\n  73:\t\tWARN_ON_ONCE(!IS_ALIGNED(offset, vi-\u003etree_params.digest_size));\n  74:\t\tWARN_ON_ONCE(!IS_ALIGNED(len, vi-\u003etree_params.digest_size));\n  75:\t\n  76:\t\tfor (; off \u003c (offset + len); off += vi-\u003etree_params.digest_size)\n  77:\t\t\tmemcpy_to_folio(folio, off, vi-\u003etree_params.zero_digest,\n  78:\t\t\t\t\tvi-\u003etree_params.digest_size);\n  79:\t}\n  80:\tEXPORT_SYMBOL_GPL(fsverity_fill_zerohash);\n  81:\t\n  82:\t/**\n  83:\t * fsverity_pagecache_read() - read verity metadata via the pagecache\n  84:\t * @inode:\tcopy from this inode's address space\n"
}

79/3 2026/11/03 04:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 87914
							output: 23
							thoughts: 1633
						

Thoughts:
**XFS Verity and Buffered Reads: A Deep Dive**

Okay, let's break this down. First, I'm looking at `fsverity_fill_zerohash`. This is pretty straightforward: it fills with `zero_digest`. But hang on... what if the `offset + len` doesn't cover the whole folio? That's a potential area for concern.

Next, I'm diving into `iomap_read_folio_iter`. I see the `iomap_adjust_read_range` call, and then the critical check: `if ((iomap->flags & IOMAP_F_FSVERITY) && iomap->type == IOMAP_HOLE)`. If it's a verity hole, we call `fsverity_fill_zerohash`. But wait, again, what if the Merkle tree ends before our requested range or if `len` is smaller than a page? Furthermore, Merkle tree blocks are block-aligned, right? So how does the code deal with `poff` and `plen` being processed?

Then, the focus shifts to `xfs_fsverity_is_hashes_of_zeroed_blocks`. This is interesting. It checks if a block contains all hashes of zeroed blocks. It only does this check if the Merkle tree block equals the filesystem block size. This makes sense. Iomap synthesizes these blocks based on holes in the merkle tree. So, for example, a 4k filesystem block that contains: `[ 1k | zero hashes | zero hashes | 1k ]` would cause an issue. Iomap would not know about the zero-hash blocks.

Now the code's checking `memcmp(buf + digest_size, buf, size - digest_size) == 0`. What if `size < digest_size`? Oh, wait, no, `size` is always at least the block size and digest sizes are much smaller, so that's not a concern.

Looking at `xfs_file_dio_read` and the fallback to `xfs_file_buffered_read`. The code *first* locks the inode, then checks for verity. If verity is active, it *unlocks* and falls back to buffered I/O. So, the lock is released when falling back to the buffered path. And, the buffered path locks the inode again, which is good.

But wait, what's happening with `xfs_dio_read_bounce_submit_io` and `xfs_bio_submit_read`? The `vi` field is now being passed as `NULL` in `xfs_dio_read_bounce_submit_io`. What's the context here? And, where does this `ctx->vi` come from in `xfs_bio_submit_read`? Let's check `xfs_get_iomap_read_ops`.

Ah! If it's *not* file data (e.g., metadata past `xfs_fsverity_metadata_offset(ip)`), then `xfs_fsverity_is_file_data(ip, pos)` is FALSE. So `xfs_get_iomap_read_ops` returns `&iomap_bio_read_ops`.

So, for metadata reads (like the Merkle tree or descriptor pages), the read operations come from `&iomap_bio_read_ops`, not verity-specific code. Okay, need to check `iomap_bio_read_ops` in `fs/iomap/buffered-io.c` to see how those pages are read.



80/3 2026/11/03 04:08 tool grepper
0m Args:
{
  "Expression": "iomap_bio_read_ops"
}

Results:
{
  "Output": "fs/erofs/data.c=397=static int erofs_read_folio(struct file *file, struct folio *folio)\n--\nfs/erofs/data.c-405-\t\t.ops = erofs_is_fileio_mode(sbi) ?\nfs/erofs/data.c:406:\t\t\t\u0026erofs_fileio_iomap_read_ops : \u0026iomap_bio_read_ops,\nfs/erofs/data.c-407-\t\t.cur_folio = folio,\n--\nfs/erofs/data.c=417=static void erofs_readahead(struct readahead_control *rac)\n--\nfs/erofs/data.c-425-\t\t.ops = erofs_is_fileio_mode(sbi) ?\nfs/erofs/data.c:426:\t\t\t\u0026erofs_fileio_iomap_read_ops : \u0026iomap_bio_read_ops,\nfs/erofs/data.c-427-\t\t.rac = rac,\n--\nfs/exfat/inode.c=245=static int exfat_read_folio(struct file *file, struct folio *folio)\n--\nfs/exfat/inode.c-248-\t\t.cur_folio = folio,\nfs/exfat/inode.c:249:\t\t.ops = \u0026exfat_iomap_bio_read_ops,\nfs/exfat/inode.c-250-\t};\n--\nfs/exfat/inode.c=256=static void exfat_readahead(struct readahead_control *rac)\n--\nfs/exfat/inode.c-263-\tstruct iomap_read_folio_ctx ctx = {\nfs/exfat/inode.c:264:\t\t.ops = \u0026exfat_iomap_bio_read_ops,\nfs/exfat/inode.c-265-\t\t.rac = rac,\n--\nfs/exfat/iomap.c=314=static void exfat_iomap_bio_submit_read(const struct iomap_iter *iter,\n--\nfs/exfat/iomap.c-319-\nfs/exfat/iomap.c:320:const struct iomap_read_ops exfat_iomap_bio_read_ops = {\nfs/exfat/iomap.c-321-\t.read_folio_range\t= iomap_bio_read_folio_range,\n--\nfs/exfat/iomap.h=12=extern const struct iomap_writeback_ops exfat_writeback_ops;\nfs/exfat/iomap.h:13:extern const struct iomap_read_ops exfat_iomap_bio_read_ops;\nfs/exfat/iomap.h-14-\n--\nfs/iomap/bio.c=117=EXPORT_SYMBOL_GPL(iomap_bio_read_folio_range);\nfs/iomap/bio.c-118-\nfs/iomap/bio.c:119:const struct iomap_read_ops iomap_bio_read_ops = {\nfs/iomap/bio.c-120-\t.read_folio_range\t= iomap_bio_read_folio_range,\n--\nfs/iomap/bio.c-122-};\nfs/iomap/bio.c:123:EXPORT_SYMBOL_GPL(iomap_bio_read_ops);\nfs/iomap/bio.c-124-\n--\nfs/ntfs/aops.c=40=static void ntfs_iomap_bio_submit_read(const struct iomap_iter *iter,\n--\nfs/ntfs/aops.c-45-\nfs/ntfs/aops.c:46:static const struct iomap_read_ops ntfs_iomap_bio_read_ops = {\nfs/ntfs/aops.c-47-\t.read_folio_range\t= iomap_bio_read_folio_range,\n--\nfs/ntfs/aops.c=68=static int ntfs_read_folio(struct file *file, struct folio *folio)\n--\nfs/ntfs/aops.c-72-\t\t.cur_folio = folio,\nfs/ntfs/aops.c:73:\t\t.ops = \u0026ntfs_iomap_bio_read_ops,\nfs/ntfs/aops.c-74-\t};\n--\nfs/ntfs/aops.c=232=static void ntfs_readahead(struct readahead_control *rac)\n--\nfs/ntfs/aops.c-237-\tstruct iomap_read_folio_ctx ctx = {\nfs/ntfs/aops.c:238:\t\t.ops = \u0026ntfs_iomap_bio_read_ops,\nfs/ntfs/aops.c-239-\t\t.rac = rac,\n--\nfs/ntfs3/inode.c=813=static void ntfs_iomap_bio_submit_read(const struct iomap_iter *iter,\n--\nfs/ntfs3/inode.c-819-// clang-format off\nfs/ntfs3/inode.c:820:static const struct iomap_read_ops ntfs_iomap_bio_read_ops = {\nfs/ntfs3/inode.c-821-\t.read_folio_range\t= iomap_bio_read_folio_range,\n--\nfs/ntfs3/inode.c=826=static int ntfs_read_folio(struct file *file, struct folio *folio)\n--\nfs/ntfs3/inode.c-834-\t\t.cur_folio = folio,\nfs/ntfs3/inode.c:835:\t\t.ops = \u0026ntfs_iomap_bio_read_ops,\nfs/ntfs3/inode.c-836-\t};\n--\nfs/ntfs3/inode.c=860=static void ntfs_readahead(struct readahead_control *rac)\n--\nfs/ntfs3/inode.c-865-\tstruct iomap_read_folio_ctx ctx = {\nfs/ntfs3/inode.c:866:\t\t.ops = \u0026ntfs_iomap_bio_read_ops,\nfs/ntfs3/inode.c-867-\t\t.rac = rac,\n--\nfs/xfs/xfs_aops.c=625=xfs_get_iomap_read_ops(\n--\nfs/xfs/xfs_aops.c-633-\t\treturn \u0026xfs_iomap_read_ops;\nfs/xfs/xfs_aops.c:634:\treturn \u0026iomap_bio_read_ops;\nfs/xfs/xfs_aops.c-635-}\n--\ninclude/linux/iomap.h=802=void iomap_bio_submit_read_endio(const struct iomap_iter *iter,\n--\ninclude/linux/iomap.h-804-\ninclude/linux/iomap.h:805:extern const struct iomap_read_ops iomap_bio_read_ops;\ninclude/linux/iomap.h-806-\ninclude/linux/iomap.h=807=static inline void iomap_bio_read_folio(struct folio *folio,\n--\ninclude/linux/iomap.h-810-\tstruct iomap_read_folio_ctx ctx = {\ninclude/linux/iomap.h:811:\t\t.ops\t\t= \u0026iomap_bio_read_ops,\ninclude/linux/iomap.h-812-\t\t.cur_folio\t= folio,\n--\ninclude/linux/iomap.h=818=static inline void iomap_bio_readahead(struct readahead_control *rac,\n--\ninclude/linux/iomap.h-821-\tstruct iomap_read_folio_ctx ctx = {\ninclude/linux/iomap.h:822:\t\t.ops\t\t= \u0026iomap_bio_read_ops,\ninclude/linux/iomap.h-823-\t\t.rac\t\t= rac,\n"
}

81/3 2026/11/03 04:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 92465
							output: 23
							thoughts: 6525
						

Thoughts:
**Uninitialized Memory Vulnerability in XFS Filesystem with fs-verity Enabled**

Okay, here's the breakdown of my concerns, as I see it. It looks like there's a serious potential for an uninitialized memory leak when fs-verity is used with XFS, particularly in how the descriptor and metadata are handled during reads, and it appears the KMSAN checks should be enabled.

The problem centers around the interaction between `iomap`, fs-verity's data integrity checks, and how the file system handles "holes" within a file. When a file with fs-verity is read, the system uses different I/O paths based on whether it's file data, Merkle tree metadata, etc. The switch to fs-verity is driven via the `xfs_get_iomap_read_ops`, which returns different `read_ops` for integrity/verity data vs buffered-io read-ops. I've noted that while reading the merkle tree metadata during file verification, if a "hole" is encountered (where there's no allocated data), and the context's fsverity info, `ctx->vi`, is NULL, the folio is marked `uptodate` WITHOUT zeroing it.  `folio_zero_range` is skipped due to conditional logic.

This is the core of the issue:
1.  **Uninitialized Folio:** The `read_mapping_folio` allocates a pagecache folio, which, when it falls into a hole, contains uninitialized memory.
2.  **`IOMAP_F_FSVERITY`:** XFS specifically sets this flag when fs-verity is active.
3.  **Hole Handling:**  When a hole is encountered in the metadata (or after the fsverity descriptor), and `ctx->vi` is absent (due to the `get_verity_descriptor` phase), the `iomap_read_folio_iter` code skips zeroing the folio via `folio_zero_range`, and marks the uninitialized folio as `uptodate`.
4.  **Data Copy:**  `memcpy_from_file_folio`, in `fsverity_pagecache_read`, copies from this *uptodate*, yet uninitialized folio, potentially to a kernel-space buffer.

From there, this uninitialized memory can leak into user-space via several pathways:

*   **Descriptor Reads:** The `fsverity_get_descriptor` function calculates `desc_size_pos` and `desc_pos`. If those positions fall into a hole (and they can, given the layout of the descriptor and the last extent of a file), the uninitialized data from the folio is copied into stack memory (`d_desc_size`) or a buffer allocated with `kmalloc`. The uninitialized `desc_size` can then cause problems in subsequent logic. Also, if `FS_IOC_READ_VERITY_METADATA` is called to read descriptor, then uninitialized values can be directly copied via `copy_to_user` to a user-space buffer!
*   **Descriptor Validation:** Even if the read is successful, the data then may be validated by `validate_fsverity_descriptor`. This may branch on uninitialized values.  If a valid descriptor is read from an uninitialized area it also copies to user space.
*   **Metadata Reads:** `FS_IOC_READ_VERITY_METADATA` is used for Merkle tree reads. `generic_read_merkle_tree_page` copies an *uptodate*, but potentially uninitialized page, to user space. `fsverity_fill_zerohash` can potentially lead to partially initialized writes.

The issue stems from the fact that `xfs_fsverity_get_descriptor` reads from a position determined by the *last* extent of the file, and then backs up to read the descriptor. There is no check to see if the read is within an allocated extent.

Moreover, if there are unwritten extents or the file is being read past the EOF or via `readahead` or `xfs_file_buffered_read` etc, there may be `IOMAP_HOLE`s that get marked as uptodate without zeroing, leaking uninitialized values.

Crucially, the code responsible for marking the folio `uptodate` *skips* the zeroing step when it encounters a hole.  This means that the system *expects* valid, zeroed data where uninitialized data may reside, depending on what happened before.  This is because `IOMAP_F_FSVERITY` is set for this data, even though there is no explicit check to call `folio_zero_range` to zero this memory.

**In summary:**


82/3 2026/11/03 04:09 tool grepper
0m Args:
{
  "Expression": "iomap_fsverity_write"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=1325=EXPORT_SYMBOL_GPL(iomap_file_buffered_write);\nfs/iomap/buffered-io.c-1326-\nfs/iomap/buffered-io.c:1327:int iomap_fsverity_write(struct file *file, loff_t pos, size_t length,\nfs/iomap/buffered-io.c-1328-\t\tconst void *buf, const struct iomap_ops *ops,\n--\nfs/iomap/buffered-io.c-1349-}\nfs/iomap/buffered-io.c:1350:EXPORT_SYMBOL_GPL(iomap_fsverity_write);\nfs/iomap/buffered-io.c-1351-\n--\nfs/xfs/xfs_fsverity.c=143=xfs_fsverity_write_descriptor(\n--\nfs/xfs/xfs_fsverity.c-162-\nfs/xfs/xfs_fsverity.c:163:\terror = iomap_fsverity_write(file, desc_size_pos, sizeof(__be32),\nfs/xfs/xfs_fsverity.c-164-\t\t\t(const void *)\u0026desc_size_disk,\n--\nfs/xfs/xfs_fsverity.c-169-\nfs/xfs/xfs_fsverity.c:170:\treturn iomap_fsverity_write(file, desc_pos, desc_size, desc,\nfs/xfs/xfs_fsverity.c-171-\t\t\t\u0026xfs_buffered_write_iomap_ops,\n--\nfs/xfs/xfs_fsverity.c=450=xfs_fsverity_write_merkle(\n--\nfs/xfs/xfs_fsverity.c-469-\nfs/xfs/xfs_fsverity.c:470:\treturn iomap_fsverity_write(file, position, size, buf,\nfs/xfs/xfs_fsverity.c-471-\t\t\t\u0026xfs_buffered_write_iomap_ops,\n--\ninclude/linux/iomap.h=431=ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,\n--\ninclude/linux/iomap.h-433-\t\tconst struct iomap_write_ops *write_ops, void *private);\ninclude/linux/iomap.h:434:int iomap_fsverity_write(struct file *file, loff_t pos, size_t length,\ninclude/linux/iomap.h-435-\t\tconst void *buf, const struct iomap_ops *ops,\n"
}

83/3 2026/11/03 04:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 100765
							output: 40
							thoughts: 30
						

Thoughts:
Okay, here's my summary, taking on the persona you requested:

**Deconstructing `iomap_fsverity_write`**

Alright, let's dive into the guts of this `iomap_fsverity_write` function. The name itself suggests we're dealing with writes, specifically within the iomap framework, and, oh yes, we're definitely talking about fs-verity. I need to understand how the iomap layer interacts with and supports fs-verity's integrity checks during write operations. I need to trace the data flow; how does the write data get handled? Where are integrity calculations performed (if any)? Are metadata updates integrated into the process or separate steps? I need to understand how this function fits into the bigger picture. Is it called directly by VFS? Does it interact with block device drivers? Does it somehow hook into the block layer or maybe even the page cache? I need to figure out where the `fs/iomap/buffered-io.c` file is doing the bulk of its work.



84/3 2026/11/03 04:09 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 1325,
  "LineCount": 30
}

Results:
{
  "Contents": "1325:\tEXPORT_SYMBOL_GPL(iomap_file_buffered_write);\n1326:\t\n1327:\tint iomap_fsverity_write(struct file *file, loff_t pos, size_t length,\n1328:\t\t\tconst void *buf, const struct iomap_ops *ops,\n1329:\t\t\tconst struct iomap_write_ops *write_ops)\n1330:\t{\n1331:\t\tint\t\t\tret;\n1332:\t\tstruct iov_iter\t\tiiter;\n1333:\t\tstruct kvec\t\tkvec = {\n1334:\t\t\t.iov_base\t= (void *)buf,\n1335:\t\t\t.iov_len\t= length,\n1336:\t\t};\n1337:\t\tstruct kiocb\t\tiocb = {\n1338:\t\t\t.ki_filp\t= file,\n1339:\t\t\t.ki_ioprio\t= get_current_ioprio(),\n1340:\t\t\t.ki_pos\t\t= pos,\n1341:\t\t};\n1342:\t\n1343:\t\tiov_iter_kvec(\u0026iiter, WRITE, \u0026kvec, 1, length);\n1344:\t\n1345:\t\tret = iomap_file_buffered_write(\u0026iocb, \u0026iiter, ops, write_ops, NULL);\n1346:\t\tif (ret \u003c 0)\n1347:\t\t\treturn ret;\n1348:\t\treturn ret == length ? 0 : -EIO;\n1349:\t}\n1350:\tEXPORT_SYMBOL_GPL(iomap_fsverity_write);\n1351:\t\n1352:\tstatic void iomap_write_delalloc_ifs_punch(struct inode *inode,\n1353:\t\t\tstruct folio *folio, loff_t start_byte, loff_t end_byte,\n1354:\t\t\tstruct iomap *iomap, iomap_punch_t punch)\n"
}

85/3 2026/11/03 04:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 101588
							output: 39
							thoughts: 54
						

Thoughts:
Okay, let's dive into this `iomap_file_buffered_write` scenario involving a partial block write. I need to understand the nuances here, so my first stop is going to be `__iomap_write_begin` in `fs/iomap/buffered-io.c`. I expect this function will provide the initial setup and handle the intricacies of how this buffered I/O operates. I'm especially interested in how it deals with the partial block, as that's where things can get interesting – and potentially tricky – with I/O alignment and cache coherency. What kind of metadata management happens when only part of a block needs modification? I hope it's not needlessly complex, and it should be efficient. I’m thinking there will be read-modify-write operations happening under the covers, but I need to see the details of how it’s implemented.



86/3 2026/11/03 04:09 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 900,
  "LineCount": 45
}

Results:
{
  "Contents": " 900:\t\tif ((iter-\u003eflags \u0026 IOMAP_NOWAIT) \u0026\u0026 !ifs \u0026\u0026 nr_blocks \u003e 1)\n 901:\t\t\treturn -EAGAIN;\n 902:\t\n 903:\t\tif (folio_test_uptodate(folio))\n 904:\t\t\treturn 0;\n 905:\t\n 906:\t\tdo {\n 907:\t\t\tiomap_adjust_read_range(iter-\u003einode, folio, \u0026block_start,\n 908:\t\t\t\t\tblock_end - block_start, \u0026poff, \u0026plen);\n 909:\t\t\tif (plen == 0)\n 910:\t\t\t\tbreak;\n 911:\t\n 912:\t\t\t/*\n 913:\t\t\t * If the read range will be entirely overwritten by the write,\n 914:\t\t\t * we can skip having to zero/read it in.\n 915:\t\t\t */\n 916:\t\t\tif (!(iter-\u003eflags \u0026 IOMAP_UNSHARE) \u0026\u0026 from \u003c= poff \u0026\u0026\n 917:\t\t\t    to \u003e= poff + plen)\n 918:\t\t\t\tcontinue;\n 919:\t\n 920:\t\t\tif (iomap_block_needs_zeroing(iter, block_start)) {\n 921:\t\t\t\tif (WARN_ON_ONCE(iter-\u003eflags \u0026 IOMAP_UNSHARE))\n 922:\t\t\t\t\treturn -EIO;\n 923:\t\t\t\tfolio_zero_segments(folio, poff, from, to, poff + plen);\n 924:\t\t\t} else {\n 925:\t\t\t\tconst struct iomap *iomap = iomap_iter_srcmap(iter);\n 926:\t\t\t\tint status;\n 927:\t\n 928:\t\t\t\tif (iter-\u003eflags \u0026 IOMAP_NOWAIT)\n 929:\t\t\t\t\treturn -EAGAIN;\n 930:\t\n 931:\t\t\t\tif (write_ops \u0026\u0026 write_ops-\u003eread_folio_range)\n 932:\t\t\t\t\tstatus = write_ops-\u003eread_folio_range(iter,\n 933:\t\t\t\t\t\t\tfolio, block_start, plen);\n 934:\t\t\t\telse\n 935:\t\t\t\t\tstatus = iomap_bio_read_folio_range_sync(iter,\n 936:\t\t\t\t\t\t\tfolio, block_start, plen);\n 937:\t\t\t\tif (status \u003c 0)\n 938:\t\t\t\t\tfserror_report_io(iter-\u003einode,\n 939:\t\t\t\t\t\t\t  FSERR_BUFFERED_READ, pos,\n 940:\t\t\t\t\t\t\t  plen, status, GFP_NOFS);\n 941:\t\t\t\tif (status)\n 942:\t\t\t\t\treturn status;\n 943:\t\n 944:\t\t\t\tif (iomap-\u003eflags \u0026 IOMAP_F_ZERO_TAIL)\n"
}

87/3 2026/11/03 04:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 102594
							output: 23
							thoughts: 6646
						

Thoughts:
**XFS fs-verity Vulnerability: Uninitialized Memory Disclosure**

Okay, so I've been dissecting the fs-verity implementation in XFS and have identified a critical vulnerability. It hinges on how XFS handles metadata blocks for fs-verity files, specifically during the file open process *after* fs-verity has been enabled and the Merkle tree and descriptor have been written. The core issue revolves around uninitialized memory, which could lead to an information leak.

Here's the breakdown: When a fs-verity file is opened on XFS (after enabling), the kernel retrieves the descriptor, and reads the Merkle tree, but because of the way the Merkle tree is structured and holes can occur during its construction, a critical window for memory disclosure exists.  This can happen because of skipped zeroed blocks in the Merkle tree which means the page cache is not initialized and the IOMAP will return a hole which is normally zeroed, but in our case of `ctx->vi == NULL`, will be marked uptodate. This, combined with the fact that `kmalloc` is used instead of `kzalloc` for `desc` means the descriptor, which comes from page cache, contains uninitialized memory!

Now, the steps to enable are: (1) `xfs_fsverity_begin_enable`:  sets a construction flag and deletes old metadata. (2) `fsverity_ioctl_enable`: builds the Merkle tree, potentially skipping blocks of zeroed hashes. (3) `xfs_fsverity_end_enable`: writes the file descriptor.

Crucially, in `xfs_fsverity_end_enable`, `xfs_fsverity_write_descriptor` is called. It aligns the descriptor to a 64KB boundary, leaving a potentially large "hole" between the end of the Merkle tree data and the start of the descriptor. This hole can contain uninitialized memory, which is normal for XFS. Further during enabling `xfs_free_eofblocks` will truncate all unwritten extents, this means the Merkle tree and the descriptor extents, which are *written*, are not removed, and so they remain on disk for later.

Later, when the file is re-opened (e.g., `open(path, O_RDONLY)`), `fsverity_file_open` is called to ensure verity info, and this includes calling `fsverity_get_descriptor`. `xfs_fsverity_get_descriptor` is where things go wrong: it reads the descriptor size, and then reads the descriptor data from the page cache. `fsverity_pagecache_read` is used to get the data, but critically `iomap_read_folio` is called, which may return a hole. 

Here's the problem: The XFS filesystem *deliberately* avoids zeroing the gap between the Merkle tree and the descriptor. The result is that when a Merkle tree block is missing (e.g. all zero-hashes), `ctx->vi` will be NULL during the descriptor load. This means `fsverity_fill_zerohash` will *not* be called.

So, in the case of a Merkle tree hole and `ctx->vi == NULL`, the pagecache folio won't be initialized to zero. Instead, it gets marked as "uptodate" with whatever random data was in memory (which could be leftovers from another unrelated write). `fsverity_pagecache_read` then copies this uninitialized memory into the `buf` that will be used for the descriptor, and then later in a user process the `buf` is copied to the user as part of the `read` or ioctl operation.

The vulnerability:

1.  **Uninitialized Memory in Descriptor:**  The descriptor that's read can contain uninitialized memory, which is then returned to userspace.
2.  **Information Leak:**  The `validate_fsverity_descriptor` may branch based on uninitialized data, and the `fsverity_read_descriptor` call (`copy_to_user`) may leak this memory.

This is a classic uninitialized memory bug, it's NOT detected by KASAN because the memory is correctly allocated and within bounds; KMSAN is needed to find this vulnerability.



88/3 2026/11/03 04:10 tool grepper
0m Args:
{
  "Expression": "xfs_bmap_last_extent"
}

Results:
{
  "Output": "fs/xfs/libxfs/xfs_bmap.c=1314=int\nfs/xfs/libxfs/xfs_bmap.c:1315:xfs_bmap_last_extent(\nfs/xfs/libxfs/xfs_bmap.c-1316-\tstruct xfs_trans\t*tp,\n--\nfs/xfs/libxfs/xfs_bmap.c=1348=xfs_bmap_isaeof(\n--\nfs/xfs/libxfs/xfs_bmap.c-1356-\tbma-\u003eaeof = false;\nfs/xfs/libxfs/xfs_bmap.c:1357:\terror = xfs_bmap_last_extent(NULL, bma-\u003eip, whichfork, \u0026rec,\nfs/xfs/libxfs/xfs_bmap.c-1358-\t\t\t\t     \u0026is_empty);\n--\nfs/xfs/libxfs/xfs_bmap.c=1383=xfs_bmap_last_offset(\n--\nfs/xfs/libxfs/xfs_bmap.c-1402-\nfs/xfs/libxfs/xfs_bmap.c:1403:\terror = xfs_bmap_last_extent(NULL, ip, whichfork, \u0026rec, \u0026is_empty);\nfs/xfs/libxfs/xfs_bmap.c-1404-\tif (error || is_empty)\n--\nfs/xfs/libxfs/xfs_bmap.c=5757=xfs_bmap_can_insert_extents(\n--\nfs/xfs/libxfs/xfs_bmap.c-5771-\txfs_ilock(ip, XFS_ILOCK_EXCL);\nfs/xfs/libxfs/xfs_bmap.c:5772:\terror = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, \u0026got, \u0026is_empty);\nfs/xfs/libxfs/xfs_bmap.c-5773-\tif (!error \u0026\u0026 !is_empty \u0026\u0026 got.br_startoff \u003e= off \u0026\u0026\n--\nfs/xfs/xfs_bmap_util.h=52=bool\txfs_bmap_adjacent(struct xfs_bmalloca *ap);\nfs/xfs/xfs_bmap_util.h:53:int\txfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,\nfs/xfs/xfs_bmap_util.h-54-\t\t\t     int whichfork, struct xfs_bmbt_irec *rec,\n--\nfs/xfs/xfs_fsverity.c=61=xfs_fsverity_get_descriptor(\n--\nfs/xfs/xfs_fsverity.c-86-\t}\nfs/xfs/xfs_fsverity.c:87:\terror = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, \u0026rec, \u0026is_empty);\nfs/xfs/xfs_fsverity.c-88-\txfs_iunlock(ip, XFS_ILOCK_EXCL);\n"
}

89/3 2026/11/03 04:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 111027
							output: 45
							thoughts: 17
						

Thoughts:
Here's a first-person summary, tailored for an expert audience, based on the prompt:

**Diving into `xfs_bmap_last_extent`**

Okay, so I need to refresh my memory on the `xfs_bmap_last_extent` implementation. It's been a while since I last really scrutinized the intricacies of how XFS handles block mapping, specifically the "last extent" scenario. I know the core idea, of course: it's about efficiently locating the final extent of a file, especially in cases where we're dealing with sparse files or large, fragmented blocks. But, I need to get back into the details - I want to verify I understand the edge cases, potential bottlenecks, and any subtle optimizations used to avoid unnecessary I/O. I need to make sure I understand the interaction with the allocation structures, and the implications for performance under concurrent access. Let's see how they handled the potential race conditions and locking strategies within that function, and how those specifically relate to the other bmap functions that depend on or may call it. I want to specifically look at how the buffer cache is used or bypassed, and how the implementation handles the potential for block prefetching. Let's start with the code itself and see what surprises it might have in store.



90/3 2026/11/03 04:10 tool read-file
0m Args:
{
  "File": "fs/xfs/libxfs/xfs_bmap.c",
  "FirstLine": 1314,
  "LineCount": 35
}

Results:
{
  "Contents": "1314:\tint\n1315:\txfs_bmap_last_extent(\n1316:\t\tstruct xfs_trans\t*tp,\n1317:\t\tstruct xfs_inode\t*ip,\n1318:\t\tint\t\t\twhichfork,\n1319:\t\tstruct xfs_bmbt_irec\t*rec,\n1320:\t\tint\t\t\t*is_empty)\n1321:\t{\n1322:\t\tstruct xfs_ifork\t*ifp = xfs_ifork_ptr(ip, whichfork);\n1323:\t\tstruct xfs_iext_cursor\ticur;\n1324:\t\tint\t\t\terror;\n1325:\t\n1326:\t\terror = xfs_iread_extents(tp, ip, whichfork);\n1327:\t\tif (error)\n1328:\t\t\treturn error;\n1329:\t\n1330:\t\txfs_iext_last(ifp, \u0026icur);\n1331:\t\tif (!xfs_iext_get_extent(ifp, \u0026icur, rec))\n1332:\t\t\t*is_empty = 1;\n1333:\t\telse\n1334:\t\t\t*is_empty = 0;\n1335:\t\treturn 0;\n1336:\t}\n1337:\t\n1338:\t/*\n1339:\t * Check the last inode extent to determine whether this allocation will result\n1340:\t * in blocks being allocated at the end of the file. When we allocate new data\n1341:\t * blocks at the end of the file which do not start at the previous data block,\n1342:\t * we will try to align the new blocks at stripe unit boundaries.\n1343:\t *\n1344:\t * Returns 1 in bma-\u003eaeof if the file (fork) is empty as any new write will be\n1345:\t * at, or past the EOF.\n1346:\t */\n1347:\tSTATIC int\n1348:\txfs_bmap_isaeof(\n"
}

91/3 2026/11/03 04:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 111902
							output: 695
							thoughts: 1211
						

Thoughts:
**KMSAN Justification for XFS fs-verity Patch Series**

Okay, so `xfs_bmap_last_extent` correctly sets `*is_empty`, which is good. Now, I need to meticulously review the criteria for setting `NeedsKMSAN=true`. It's all about whether this patch introduces or modifies code that could lead to information leaks or issues related to uninitialized memory. Let's revisit the four criteria:

1.  Kernel structures sent to userspace – definitely something to keep an eye on.
2.  Conditional logic based on uninitialized variables – this is a major red flag!
3.  Allocation and initialization of complex data structures – also potentially problematic.
4.  Bounds checks or logic that could expose uninitialized bytes – another critical area.

Focusing on criteria 2 and 4, this patch series introduces fs-verity support in XFS. It integrates XFS with iomap's `IOMAP_F_FSVERITY` flag and provides `xfs_fsverity_ops`. Here's the core issue, as I see it:

The patch introduces this interaction: During `xfs_fsverity_get_descriptor`:

1.  `desc_pos` is calculated as `round_down(desc_size_pos - desc_size, blocksize)`.
2.  When reading `desc_pos` using `fsverity_pagecache_read`, `xfs_read_iomap_begin` sets `IOMAP_F_FSVERITY` because `fsverity_active(inode)` and `offset >= xfs_fsverity_metadata_offset(ip)`.
3.  If `desc_pos` falls into a hole (which it can, due to sparse metadata, crafted images, or gaps in alignment, creating a hole), the iomap type is `IOMAP_HOLE`.
4.  In `iomap_read_folio_iter`, the code specifically checks for `IOMAP_F_FSVERITY` and `IOMAP_HOLE`. Because `ctx->vi` is NULL during descriptor activation, the code bypasses the zeroing and uptodate path and directly marks the newly allocated pagecache folio as uptodate via `iomap_set_range_uptodate(folio, poff, plen)`.
5.  This means uninitialized folio memory is directly copied into a user-facing buffer (`buf`).
6.  `validate_fsverity_descriptor` then immediately branches based on uninitialized fields like `desc->version`, `desc->salt_size`, `desc->data_size`, etc.
7.  Furthermore, userspace can trigger reads of this uninitialized memory via `ioctl(FS_IOC_READ_VERITY_METADATA)` or just by opening the file, which copies it back to userspace via `fsverity_read_descriptor` and `copy_to_user`.

Here's the critical point: **KASAN cannot catch this!** KASAN deals with out-of-bounds access and use-after-free, but it doesn't track uninitialized memory reads or detect branching on uninitialized data. All the memory accesses in this scenario are within the bounds of allocated buffers. **Only KMSAN detects these uninitialized memory reads and potential information leaks.**

Therefore, I'm completely confident that this patch series *absolutely* requires `NeedsKMSAN=true`. We're dealing with conditional logic (branching) on potentially uninitialized data (criterion 2), and a situation where uninitialized memory can be accessed because of logic (holes) (criterion 4).

Let's do a final review to confirm this is ironclad:

*   We've highlighted the crucial difference between KASAN and KMSAN.
*   We've explained the exact mechanism by which uninitialized memory ends up in user space: XFS with `IOMAP_F_FSVERITY`, hole handling in post-EOF metadata blocks, the NULL `ctx->vi` case, the skipped zeroing, and the critical `desc` field branching.
*   We noted kernel info-leaks.

Perfect. Let's call `set-results` now.



92/3 2026/11/03 04:11 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series introduces fs-verity support to XFS, hooking up XFS to fs-verity operations and the iomap subsystem with the IOMAP_F_FSVERITY flag. This change exposes significant uninitialized memory risks that can only be detected by KMSAN:\n\n1. Hole handling in post-EOF fs-verity metadata during descriptor lookup:\nIn `xfs_fsverity_get_descriptor()`, the descriptor location `desc_pos` is calculated as `round_down(desc_size_pos - desc_size, blocksize)`. Because fs-verity metadata is spaced out past EOF with `XFS_FSVERITY_START_ALIGN` (64KB alignment) and zero-digest blocks can be omitted, holes can exist between the Merkle tree and descriptor, or across corrupted/crafted metadata extents.\nWhen `fsverity_pagecache_read()` reads from `desc_pos`, `xfs_read_iomap_begin()` sets `IOMAP_F_FSVERITY`. In `iomap_read_folio_iter()`, if `(iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026 iomap-\u003etype == IOMAP_HOLE`:\n```c\nif (ctx-\u003evi)\n    fsverity_fill_zerohash(folio, poff, plen, ctx-\u003evi);\niomap_set_range_uptodate(folio, poff, plen);\n```\nDuring descriptor reading (`xfs_fsverity_get_descriptor()` called from `fsverity_ensure_verity_info()`), `ctx-\u003evi` is NULL because the `fsverity_info` structure has not yet been instantiated. Consequently, `fsverity_fill_zerohash()` is skipped, `folio_zero_range()` is bypassed, and the newly allocated folio is marked uptodate while still containing uninitialized memory.\n\n2. Branching on uninitialized memory and user info-leaks:\nThe uninitialized bytes from the folio are copied into the `desc` buffer (allocated with `kmalloc()` in `fsverity_get_descriptor()`). Immediately thereafter, `validate_fsverity_descriptor()` evaluates conditional branches depending directly on these uninitialized struct fields (`desc-\u003eversion`, `desc-\u003esalt_size`, `desc-\u003edata_size`). Furthermore, through `FS_IOC_READ_VERITY_METADATA` or descriptor reads, uninitialized buffer data can be leaked to userspace via `copy_to_user()`.\n\n3. KASAN vs KMSAN applicability:\nKASAN only monitors memory bounds and life cycle events (out-of-bounds accesses, use-after-free, double-free). Because all folio and descriptor buffer accesses remain within their legitimate allocation bounds, KASAN is blind to uninitialized memory being marked valid, copied, and evaluated in conditional logic. Only KMSAN tracks uninitialized shadow memory and catches uninitialized variable reads and kernel-to-user info-leaks.\n\nTherefore, running a dedicated KMSAN fuzzing session is justified.",
  "NeedsKMSAN": true
}

Results:
{
  "KMSANReasoning": "The patch series introduces fs-verity support to XFS, hooking up XFS to fs-verity operations and the iomap subsystem with the IOMAP_F_FSVERITY flag. This change exposes significant uninitialized memory risks that can only be detected by KMSAN:\n\n1. Hole handling in post-EOF fs-verity metadata during descriptor lookup:\nIn `xfs_fsverity_get_descriptor()`, the descriptor location `desc_pos` is calculated as `round_down(desc_size_pos - desc_size, blocksize)`. Because fs-verity metadata is spaced out past EOF with `XFS_FSVERITY_START_ALIGN` (64KB alignment) and zero-digest blocks can be omitted, holes can exist between the Merkle tree and descriptor, or across corrupted/crafted metadata extents.\nWhen `fsverity_pagecache_read()` reads from `desc_pos`, `xfs_read_iomap_begin()` sets `IOMAP_F_FSVERITY`. In `iomap_read_folio_iter()`, if `(iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026 iomap-\u003etype == IOMAP_HOLE`:\n```c\nif (ctx-\u003evi)\n    fsverity_fill_zerohash(folio, poff, plen, ctx-\u003evi);\niomap_set_range_uptodate(folio, poff, plen);\n```\nDuring descriptor reading (`xfs_fsverity_get_descriptor()` called from `fsverity_ensure_verity_info()`), `ctx-\u003evi` is NULL because the `fsverity_info` structure has not yet been instantiated. Consequently, `fsverity_fill_zerohash()` is skipped, `folio_zero_range()` is bypassed, and the newly allocated folio is marked uptodate while still containing uninitialized memory.\n\n2. Branching on uninitialized memory and user info-leaks:\nThe uninitialized bytes from the folio are copied into the `desc` buffer (allocated with `kmalloc()` in `fsverity_get_descriptor()`). Immediately thereafter, `validate_fsverity_descriptor()` evaluates conditional branches depending directly on these uninitialized struct fields (`desc-\u003eversion`, `desc-\u003esalt_size`, `desc-\u003edata_size`). Furthermore, through `FS_IOC_READ_VERITY_METADATA` or descriptor reads, uninitialized buffer data can be leaked to userspace via `copy_to_user()`.\n\n3. KASAN vs KMSAN applicability:\nKASAN only monitors memory bounds and life cycle events (out-of-bounds accesses, use-after-free, double-free). Because all folio and descriptor buffer accesses remain within their legitimate allocation bounds, KASAN is blind to uninitialized memory being marked valid, copied, and evaluated in conditional logic. Only KMSAN tracks uninitialized shadow memory and catches uninitialized variable reads and kernel-to-user info-leaks.\n\nTherefore, running a dedicated KMSAN fuzzing session is justified.",
  "NeedsKMSAN": true
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)