Linux fsverity development list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrey Albershteyn" <aalbersh@kernel.org>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Christoph Hellwig" <hch@lst.de>,
	"Carlos Maiolino" <cem@kernel.org>,
	fsverity <fsverity@lists.linux.dev>
Cc: david@fromorbit.com
Subject: Re: [PATCH v19 09/15] xfs: add fs-verity support
Date: Fri, 20 Nov 2026 16:51:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-225600@kernel.org> (raw)
In-Reply-To: <20261120155752.192025-10-aalbersh@kernel.org>

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] xfs: skipped post-EOF verity writeback in
  xfs_fsverity_end_enable()
- [High] xfs: undeclared fsverity_is_building() and missing verity
  building state
- [Medium] xfs: missing extent bounds check in
  xfs_fsverity_get_descriptor()
- [Medium] xfs: missing verity di_size check in xfs_dinode_verify()
  causes overflow
- [Medium] xfs: broken error rollback in xfs_fsverity_reset_inode()
- [Low] xfs: bogus corruption check and bounds checks in
  xfs_fsverity_get_descriptor()
- [Low] xfs: duplicate inclusion of xfs_fsverity.h in fs/xfs/xfs_super.c
--

commit e657f01948f31434d0a0fecaa28699dd1636b20c
Author: Andrey Albershteyn <aalbersh@kernel.org>

xfs: add fs-verity support

This commit integrates XFS with fs-verity by implementing the
fsverity_operations callbacks to read and write the Merkle tree and verity
descriptor in the inode data fork past EOF.

> diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
> index 13042e1eaf351..fdcfc1f3f472b 100644
> --- a/fs/xfs/libxfs/xfs_inode_buf.c
> +++ b/fs/xfs/libxfs/xfs_inode_buf.c
> @@ -764,6 +764,17 @@ xfs_dinode_verify(
>  			return __this_address;
>  		if (!S_ISREG(mode))
>  			return __this_address;
> +		/*
> +		 * fs-verity stores the Merkle tree past EOF, so it cannot
> +		 * coexist with a realtime allocation unit larger than a single
> +		 * filesystem block. This is because we remove any unwritten
> +		 * extents beyond EOF for fs-verity inodes. The realtime inode
> +		 * with larger extents could have EOF in the middle of the
> +		 * extent. Enabling fsverity on such inode could lead to removal
> +		 * of data before EOF.
> +		 */
> +		if ((flags & XFS_DIFLAG_REALTIME) && mp->m_sb.sb_rextsize > 1)
> +			return __this_address;
>  	}

[Severity: Medium]
Should xfs_dinode_verify() also reject XFS_DIFLAG2_VERITY inodes whose
di_size exceeds XFS_FSVERITY_LARGEST_FILE_FSB(mp), matching the check in
xfs_fsverity_begin_enable()?

Without an upper bound check on di_size, an on-disk verity inode with
di_size > LLONG_MAX - XFS_FSVERITY_START_ALIGN + 1 passes verification and
overflows signed loff_t to LLONG_MIN in xfs_fsverity_metadata_offset():

fs/xfs/libxfs/xfs_verity.c:xfs_fsverity_metadata_offset() {
	return round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN);
}

With a negative metadata offset, xfs_fsverity_is_file_data() returns false
and xfs_iomap_is_fsverity_metadata() returns true for all non-negative
file offsets, causing normal file data reads to be treated as unverified
verity metadata.

> diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
> index 8fc3e763c017b..ec4006729e757 100644
> --- a/fs/xfs/xfs_fsverity.c
> +++ b/fs/xfs/xfs_fsverity.c
[ ... ]
> +static int
> +xfs_fsverity_get_descriptor(
> +	struct inode		*inode,
> +	void			*buf,
> +	size_t			buf_size)
> +{
[ ... ]
> +	/*
> +	 * Make sure we can open large file on a 32-bit kernel
> +	 */
> +	if (rec.br_startoff + rec.br_blockcount >
> +			XFS_B_TO_FSB(mp, inode->i_sb->s_maxbytes))
> +		return -EFBIG;
> +
> +	last_block_offset =
> +		XFS_FSB_TO_B(mp, rec.br_startoff + rec.br_blockcount);
> +	if (last_block_offset <= xfs_fsverity_metadata_offset(ip))
> +		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))
> +		return -ERANGE;
> +	if (XFS_IS_CORRUPT(mp, desc_size > desc_size_pos))
> +		return -ERANGE;
> +
> +	if (!buf_size)
> +		return desc_size;
> +
> +	if (XFS_IS_CORRUPT(mp, desc_size > buf_size))
> +		return -ERANGE;

[Severity: Low]
Is desc_size > buf_size an on-disk corruption condition?  buf_size is the
caller-supplied buffer length and desc_size has already been checked
against FS_VERITY_MAX_DESCRIPTOR_SIZE, so a caller passing a smaller
buffer triggers a false XFS_IS_CORRUPT() report.

Also, returning early when !buf_size skips the desc_pos >=
xfs_fsverity_metadata_offset(ip) check below, so the initial size probe in
fsverity_get_descriptor() accepts a corrupt desc_size that overlaps the
file data region.  Finally, XFS_B_TO_FSB(mp, inode->i_sb->s_maxbytes)
rounds LLONG_MAX up to 1ULL << (63 - sb_blocklog), which overflows signed
xfs_fsize_t in XFS_FSB_TO_B(); using XFS_B_TO_FSBT() avoids that overflow.

> +	desc_pos = round_down(desc_size_pos - desc_size, blocksize);
> +	if (desc_pos < xfs_fsverity_metadata_offset(ip))
> +		return -ERANGE;
> +
> +	error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
> +	if (error)
> +		return error;
> +
> +	return desc_size;
> +}

[Severity: Medium]
Can fsverity_pagecache_read() read across a hole in [desc_pos,
last_block_offset) and expose uninitialized pagecache memory?

xfs_fsverity_get_descriptor() checks desc_pos against
xfs_fsverity_metadata_offset(ip), but does not verify that rec.br_state ==
XFS_EXT_NORM or that desc_pos >= XFS_FSB_TO_B(mp, rec.br_startoff) so that
the entire descriptor lives within the last written extent.

When xfs_fsverity_get_descriptor() is called from
fsverity_ensure_verity_info(), S_VERITY is already set on the inode (so
xfs_bmbt_to_iomap() sets IOMAP_F_FSVERITY), while fsverity_get_info(inode)
is still NULL.  If [desc_pos, desc_pos + desc_size) hits a hole,
iomap_read_folio_iter() skips fsverity_fill_zerohash() because ctx->vi is
NULL and marks the newly allocated folio uptodate without zeroing it:

fs/iomap/buffered-io.c:iomap_read_folio_iter() {
    ...
		if ((iomap->flags & IOMAP_F_FSVERITY) &&
		    iomap->type == IOMAP_HOLE) {
			if (ctx->vi)
				fsverity_fill_zerohash(folio, poff, plen,
						       ctx->vi);
			iomap_set_range_uptodate(folio, poff, plen);
		}
    ...
}

That leaves uninitialized kernel page memory cached in inode->i_mapping
and readable via FS_IOC_READ_VERITY_METADATA.

[ ... ]

> +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;
> +}

[Severity: Medium]
Does xfs_fsverity_reset_inode() leave XFS_DIFLAG2_VERITY set on the
in-core inode if xfs_trans_commit() fails in xfs_fsverity_end_enable(),
while running an unnecessary synchronous transaction on earlier errors?

In xfs_fsverity_end_enable(), S_VERITY is only set after
xfs_trans_commit() succeeds, and ip->i_diflags2 |= XFS_DIFLAG2_VERITY is
only set inside that final transaction.  If xfs_trans_commit() fails, the
filesystem shuts down without persisting XFS_DIFLAG2_VERITY, and
xfs_fsverity_delete_metadata() fails immediately in xfs_trans_alloc() and
returns before clearing ip->i_diflags2.  Conversely, if
xfs_fsverity_end_enable() fails before the final transaction,
XFS_DIFLAG2_VERITY was never set, so allocating and committing a
synchronous tr_ichange transaction here is unnecessary.

[ ... ]

> +static int
> +xfs_fsverity_end_enable(
> +	struct file		*file,
> +	const void		*desc,
> +	size_t			desc_size,
> +	u64			merkle_tree_size)
> +{
[ ... ]
> +	/*
> +	 * Wait for Merkle tree get written to disk before setting on-disk inode
> +	 * flag and clearing I_VERITY_BUILDING
> +	 */
> +	error = filemap_write_and_wait_range(inode->i_mapping, range_start,
> +			LLONG_MAX);
> +	if (error)
> +		goto out;
> +
> +	/*
> +	 * 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);
> +	if (error)
> +		goto out;

[Severity: High]
Does filemap_write_and_wait_range() skip writing back every post-EOF
Merkle tree and descriptor folio, after which xfs_free_eofblocks() punches
out their delayed allocation extents?

xfs_vm_writepages() zero-initializes struct xfs_writepage_ctx wpc (leaving
wpc.ctx.iomap.flags == 0) before calling iomap_writepages().  For the
first folio at or past range_start (>= i_size), iomap_writeback_folio()
calls iomap_writeback_handle_eof() before calling iomap_writeback_range()
-> xfs_map_blocks():

fs/iomap/buffered-io.c:iomap_writeback_handle_eof() {
    ...
	if (wpc->iomap.flags & IOMAP_F_FSVERITY) {
		WARN_ON_ONCE(folio_pos(folio) < isize);
		return true;
	}

	if (*end_pos > isize) {
		size_t poff = offset_in_folio(folio, isize);
		pgoff_t end_index = isize >> PAGE_SHIFT;

		if (folio->index > end_index ||
		    (folio->index == end_index && poff == 0))
			return false;
    ...
}

Because IOMAP_F_FSVERITY has not been set in wpc->iomap.flags yet and
folio_pos(folio) >= round_up(isize, 65536), iomap_writeback_handle_eof()
returns false on every post-EOF folio without ever calling
xfs_map_blocks().  xfs_free_eofblocks() then punches out all post-EOF
delalloc blocks via xfs_bmap_punch_delalloc_range(), leaving the sealed
verity inode with no Merkle tree or descriptor extents on disk.

> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index f81b6e52ac403..7c7435543051a 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -562,6 +562,14 @@ xfs_ioctl_setattr_xflags(
>  		if (xfs_inode_has_filedata(ip))
>  			return -EINVAL;
>  
> +		/*
> +		 * fs-verity is incompatible with a realtime allocation unit
> +		 * larger than a single filesystem block, so don't let a file be
> +		 * converted to realtime while verity is being enabled.
> +		 */
> +		if (fsverity_is_building(VFS_IC(ip)))
> +			return -EINVAL;
> +
>  		/*
>  		 * If S_DAX is enabled on this file, we can only switch the
>  		 * device if both support fsdax.  We can't update S_DAX because
> @@ -574,6 +582,17 @@ xfs_ioctl_setattr_xflags(
>  			return -EINVAL;
>  	}
>  
> +	/*
> +	 * fs-verity is incompatible with DAX, and xfs_fsverity_begin_enable()
> +	 * verified the inode was not DAX under the inode lock.  That lock is
> +	 * dropped while the Merkle tree is built, so reject enabling DAX while
> +	 * verity is being enabled.
> +	 */
> +	if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
> +	    !(ip->i_diflags2 & XFS_DIFLAG2_DAX) &&
> +	    fsverity_is_building(VFS_IC(ip)))
> +		return -EINVAL;

[Severity: High]
Does this fail to build because fsverity_is_building() is neither declared
nor defined anywhere in the tree, and is the in-progress verity building
state missing from xfs_fsverity_begin_enable() and
xfs_fsverity_end_enable()?

The commit message notes that XFS_IVERITY_CONSTRUCTION is set while the
Merkle tree is being built, and xfs_fsverity_end_enable() mentions
clearing I_VERITY_BUILDING, but neither flag nor fsverity_is_building() is
defined, and xfs_fsverity_begin_enable() and xfs_fsverity_end_enable()
never set, test, or clear any verity-construction state on the inode.

In addition to the build failure here (and at the fsverity_is_building()
callers introduced in commit "xfs: clamp file size for reading for
fsverity" and commit "xfs: don't preallocate past descriptor block for
fsverity"), nothing returns -EBUSY if a second FS_IOC_ENABLE_VERITY starts
after enable_verity() drops inode_lock() to build the Merkle tree, and
xfs_iomap_is_fsverity_metadata() and xfs_free_eofblocks() cannot tell that
verity is being built before S_VERITY is set.

> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 532bf304a921b..890fa5727d56e 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"

[Severity: Low]
This isn't a bug, but xfs_fsverity.h is already included in
fs/xfs/xfs_super.c by commit "xfs: use read ioend for fsverity data
verification".

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120155752.192025-1-aalbersh@kernel.org?part=9

  reply	other threads:[~2026-11-20 16:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 15:57 [PATCH v19 00/15] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 01/15] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-11-20 16:26   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 02/15] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 03/15] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 04/15] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 05/15] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-11-20 16:27   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 06/15] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 07/15] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 08/15] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-11-20 16:21   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 09/15] xfs: add fs-verity support Andrey Albershteyn
2026-11-20 16:51   ` sashiko-bot [this message]
2026-11-20 15:57 ` [PATCH v19 10/15] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 11/15] xfs: add fs-verity ioctls Andrey Albershteyn
2026-11-20 16:19   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 12/15] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-11-20 15:57 ` [PATCH v19 13/15] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-11-20 16:28   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 14/15] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-11-20 16:36   ` sashiko-bot
2026-11-20 15:57 ` [PATCH v19 15/15] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-11-20 16:38   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-225600@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aalbersh@kernel.org \
    --cc=cem@kernel.org \
    --cc=david@fromorbit.com \
    --cc=ebiggers@kernel.org \
    --cc=fsverity@lists.linux.dev \
    --cc=hch@lst.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox