From: sashiko-bot@kernel.org
To: "Andrey Albershteyn via Linux-f2fs-devel"
<linux-f2fs-devel@lists.sourceforge.net>,
linux-ext4 <linux-ext4@vger.kernel.org>,
"Eric Biggers" <ebiggers@kernel.org>,
"Christoph Hellwig" <hch@lst.de>,
"Carlos Maiolino" <cem@kernel.org>,
fsverity <fsverity@lists.linux.dev>
Cc: david@fromorbit.com, "Christian Brauner" <brauner@kernel.org>,
"Andrey Albershteyn" <aalbersh@kernel.org>,
dsterba@suse.cz, tytso@mit.edu
Subject: Re: [f2fs-dev] [PATCH v20 17/23] xfs: add fs-verity support
Date: Wed, 02 Dec 2026 17:49:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-246390@kernel.org> (raw)
In-Reply-To: <20261202165653.767961-18-aalbersh@kernel.org>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] xfs: unlocked iomap_fsverity_write() in
xfs_fsverity_write_merkle()
- [Medium] xfs: broken error rollback in xfs_fsverity_reset_inode()
- [Medium] xfs: missing verity di_size check in xfs_dinode_verify()
causes overflow
- [Medium] xfs: missing extent bounds check in
xfs_fsverity_get_descriptor()
- [Medium] xfs: xfs_ioctl_setattr_xflags() allows setting RT flag on
extentless verity inode
- [Medium] xfs: race changing i_extsize in
xfs_ioctl_setattr_check_extsize() during verity
- [Low] xfs: !buf_size return in xfs_fsverity_get_descriptor() skips
checks
- [Low] xfs: off-by-one s_maxbytes check in
xfs_fsverity_get_descriptor()
--
commit b9564e67a9b1a0520488741ca90d7b445b9145e2
Author: Andrey Albershteyn <aalbersh@kernel.org>
xfs: add fs-verity support
This commit integrates XFS with fs-verity, storing the Merkle tree and
verity descriptor in the inode data fork at 64k-aligned offsets past EOF
and wiring up the fsverity_operations callbacks.
> 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 verify that XFS_B_TO_FSB(mp, di_size) does
not exceed XFS_FSVERITY_LARGEST_FILE_FSB(mp), matching
xfs_fsverity_begin_enable()?
Without that check on disk, a corrupted or crafted verity inode with
di_size > LLONG_MAX - XFS_FSVERITY_START_ALIGN + 1 passes verification and
causes round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN) in
xfs_fsverity_metadata_offset() to overflow signed loff_t to LLONG_MIN.
xfs_fsverity_is_file_data() then returns false for all non-negative file
offsets, treating all file data reads as unverified metadata.
> diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
> index 8fc3e763c017b..1c1cc5a6462bb 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);
[Severity: Low]
Should this bound check use XFS_B_TO_FSBT() instead of XFS_B_TO_FSB()?
On 64-bit systems s_maxbytes is LLONG_MAX, which XFS_B_TO_FSB() rounds up
to 1ULL << (63 - sb_blocklog). An extent ending at that block passes the
check, and XFS_FSB_TO_B() then overflows signed xfs_fsize_t to LLONG_MIN
(s_maxbytes + 1).
> + 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 (desc_size > buf_size)
> + return -ERANGE;
> +
> + if (XFS_IS_CORRUPT(mp,
> + desc_size < sizeof(struct fsverity_descriptor)))
> + return -ERANGE;
> +
> + desc_pos = round_down(desc_size_pos - desc_size, blocksize);
> + if (desc_pos < xfs_fsverity_metadata_offset(ip))
> + return -ERANGE;
[Severity: Low]
Does returning early on !buf_size make the
desc_size < sizeof(struct fsverity_descriptor) corruption check
unreachable from fsverity_get_descriptor()?
fsverity_get_descriptor() always calls ->get_verity_descriptor() with
buf_size == 0 first and aborts with -EMSGSIZE if the returned size is
smaller than sizeof(struct fsverity_descriptor), so it never makes the
second call that reaches XFS_IS_CORRUPT() (or the XFS_SICK_INO_FSVERITY
health update added later in commit "xfs: introduce health state for
corrupted fsverity metadata"). Checking desc_size and desc_pos before
if (!buf_size) would also avoid allocating a buffer and re-reading
desc_size when desc_pos < xfs_fsverity_metadata_offset(ip).
> +
> + error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
> + if (error)
> + return error;
> +
> + return desc_size;
> +}
[Severity: Medium]
What happens if the descriptor range [desc_pos, last_block_offset) on a
corrupted image starts before rec.br_startoff or spans a hole?
xfs_bmap_last_extent() only returns the last extent, and
xfs_fsverity_get_descriptor() does not check that
rec.br_state == XFS_EXT_NORM and
desc_pos >= XFS_FSB_TO_B(mp, rec.br_startoff). When
fsverity_pagecache_read() reads a hole in the verity metadata region while
fsverity_info is not yet set on the inode (ctx->vi == NULL),
iomap_read_folio_iter() skips fsverity_fill_zerohash() without zeroing the
folio and marks the uninitialized folio range uptodate:
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 as uptodate in
inode->i_mapping, where FS_IOC_READ_VERITY_METADATA can read it.
[ ... ]
> +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;
> +}
[ ... ]
> +static int
> +xfs_fsverity_end_enable(
> + struct file *file,
> + const void *desc,
> + size_t desc_size,
> + u64 merkle_tree_size)
> +{
[ ... ]
> + /*
> + * 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);
> + return error;
> +
> +out:
> + 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);
> +
> + return error;
> +}
[Severity: Medium]
Does xfs_fsverity_reset_inode() ever need to run a transaction to clear
XFS_DIFLAG2_VERITY on disk, and can it leave XFS_DIFLAG2_VERITY set in
memory when xfs_trans_commit() fails?
Every goto out before xfs_trans_commit() runs before XFS_DIFLAG2_VERITY or
S_VERITY has been set in memory or on disk, so xfs_fsverity_reset_inode()
commits an unnecessary synchronous tr_ichange transaction on every failed
enablement (such as desc == NULL). Conversely, if xfs_trans_commit() in
xfs_fsverity_end_enable() fails, the transaction aborts without persisting
XFS_DIFLAG2_VERITY and shuts down the mount; xfs_fsverity_delete_metadata()
then fails at xfs_trans_alloc() and returns early from
xfs_fsverity_reset_inode(), leaving XFS_DIFLAG2_VERITY set in
ip->i_diflags2 while S_VERITY is clear.
[ ... ]
> +/*
> + * 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_next,
> + &xfs_iomap_write_ops);
> +}
[Severity: High]
Is it safe to call iomap_fsverity_write() here without holding
XFS_IOLOCK_EXCL?
enable_verity() drops inode_lock() across build_merkle_tree(), and
deny_write_access() only blocks FMODE_WRITE opens. Other XFS paths rely
on XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL to serialize against buffered writes
and do not check fsverity_is_building(), including background blockgc
(xfs_inode_free_cowblocks()), O_RDONLY ioctls (FS_IOC_FSSETXATTR, FICLONE,
FIDEDUPERANGE), and path-based file_setattr():
CPU0 CPU1
enable_verity()
build_merkle_tree()
xfs_fsverity_write_merkle()
iomap_fsverity_write()
xfs_buffered_write_iomap_begin()
/* allocates COW delalloc */
iomap_write_begin()
xfs_iomap_valid()
xfs_inode_free_cowblocks()
xfs_ilock(ip, XFS_IOLOCK_EXCL |
XFS_MMAPLOCK_EXCL)
xfs_reflink_cancel_cow_range()
/* cancels COW delalloc */
xfs_iunlock(...)
iomap_write_end()
/* dirties folio over canceled reservation;
writeback maps a hole and drops the Merkle block */
Acquiring XFS_IOLOCK_EXCL around iomap_fsverity_write() (or checking
fsverity_is_building() in the racing paths) would prevent concurrent COW
block freeing, reflink remapping, and fileattr changes from racing with
Merkle tree writes.
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index c76e36dadf952..c4199c5f90794 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -562,6 +563,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;
[Severity: Medium]
Should this also reject changing the realtime flag when verity is already
enabled on the inode (IS_VERITY(VFS_IC(ip)) or
(ip->i_diflags2 & XFS_DIFLAG2_VERITY))?
If a corrupted on-disk inode has XFS_DIFLAG2_VERITY set with zero extents,
xfs_inode_has_filedata(ip) is false, and the path-based file_setattr()
syscall can reach xfs_ioctl_setattr_xflags() without opening the file.
Setting FS_XFLAG_REALTIME on a filesystem with sb_rextsize > 1 then logs an
inode with both XFS_DIFLAG_REALTIME and XFS_DIFLAG2_VERITY, which trips
xfs_dinode_verify() on writeback and shuts down the filesystem.
> /*
> * If S_DAX is enabled on this file, we can only switch the
> * device if both support fsdax, and the zoned code does not.
> @@ -576,6 +585,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: Medium]
Should xfs_ioctl_setattr_check_extsize() also reject changing ip->i_extsize
when fsverity_is_building(VFS_IC(ip)) is true?
On a sparse file where i_size > 0 but xfs_inode_has_filedata(ip) is still
false before the first Merkle tree extent is allocated,
xfs_iomap_write_direct() computes the transaction block reservation from
xfs_get_extsz_hint(ip) before acquiring XFS_ILOCK_EXCL. A concurrent
FS_IOC_FSSETXATTR or file_setattr() increasing ip->i_extsize in that window
causes xfs_bmapi_write() to allocate using the larger extent size hint,
overrunning tp->t_blk_res and shutting down the filesystem:
CPU0 CPU1
xfs_fsverity_write_merkle()
iomap_fsverity_write()
...
xfs_iomap_write_direct()
resaligned = xfs_aligned_fsb_count(...,
xfs_get_extsz_hint(ip))
xfs_fileattr_set()
xfs_ioctl_setattr_check_extsize()
/* xfs_inode_has_filedata(ip) == 0 */
ip->i_extsize = ...; /* larger */
xfs_trans_alloc_inode(...)
xfs_bmapi_write()
/* allocates with new i_extsize,
overrunning tp->t_blk_res */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202165653.767961-1-aalbersh@kernel.org?part=17
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot--- via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: "Andrey Albershteyn via Linux-f2fs-devel"
<linux-f2fs-devel@lists.sourceforge.net>,
linux-ext4 <linux-ext4@vger.kernel.org>,
"Eric Biggers" <ebiggers@kernel.org>,
"Christoph Hellwig" <hch@lst.de>,
"Carlos Maiolino" <cem@kernel.org>,
fsverity <fsverity@lists.linux.dev>
Cc: sashiko-bot@kernel.org, tytso@mit.edu,
Andrey Albershteyn <aalbersh@kernel.org>,
Christian Brauner <brauner@kernel.org>,
david@fromorbit.com, dsterba@suse.cz
Subject: Re: [f2fs-dev] [PATCH v20 17/23] xfs: add fs-verity support
Date: Wed, 02 Dec 2026 17:49:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-246390@kernel.org> (raw)
In-Reply-To: <20261202165653.767961-18-aalbersh@kernel.org>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] xfs: unlocked iomap_fsverity_write() in
xfs_fsverity_write_merkle()
- [Medium] xfs: broken error rollback in xfs_fsverity_reset_inode()
- [Medium] xfs: missing verity di_size check in xfs_dinode_verify()
causes overflow
- [Medium] xfs: missing extent bounds check in
xfs_fsverity_get_descriptor()
- [Medium] xfs: xfs_ioctl_setattr_xflags() allows setting RT flag on
extentless verity inode
- [Medium] xfs: race changing i_extsize in
xfs_ioctl_setattr_check_extsize() during verity
- [Low] xfs: !buf_size return in xfs_fsverity_get_descriptor() skips
checks
- [Low] xfs: off-by-one s_maxbytes check in
xfs_fsverity_get_descriptor()
--
commit b9564e67a9b1a0520488741ca90d7b445b9145e2
Author: Andrey Albershteyn <aalbersh@kernel.org>
xfs: add fs-verity support
This commit integrates XFS with fs-verity, storing the Merkle tree and
verity descriptor in the inode data fork at 64k-aligned offsets past EOF
and wiring up the fsverity_operations callbacks.
> 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 verify that XFS_B_TO_FSB(mp, di_size) does
not exceed XFS_FSVERITY_LARGEST_FILE_FSB(mp), matching
xfs_fsverity_begin_enable()?
Without that check on disk, a corrupted or crafted verity inode with
di_size > LLONG_MAX - XFS_FSVERITY_START_ALIGN + 1 passes verification and
causes round_up(i_size_read(VFS_IC(ip)), XFS_FSVERITY_START_ALIGN) in
xfs_fsverity_metadata_offset() to overflow signed loff_t to LLONG_MIN.
xfs_fsverity_is_file_data() then returns false for all non-negative file
offsets, treating all file data reads as unverified metadata.
> diff --git a/fs/xfs/xfs_fsverity.c b/fs/xfs/xfs_fsverity.c
> index 8fc3e763c017b..1c1cc5a6462bb 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);
[Severity: Low]
Should this bound check use XFS_B_TO_FSBT() instead of XFS_B_TO_FSB()?
On 64-bit systems s_maxbytes is LLONG_MAX, which XFS_B_TO_FSB() rounds up
to 1ULL << (63 - sb_blocklog). An extent ending at that block passes the
check, and XFS_FSB_TO_B() then overflows signed xfs_fsize_t to LLONG_MIN
(s_maxbytes + 1).
> + 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 (desc_size > buf_size)
> + return -ERANGE;
> +
> + if (XFS_IS_CORRUPT(mp,
> + desc_size < sizeof(struct fsverity_descriptor)))
> + return -ERANGE;
> +
> + desc_pos = round_down(desc_size_pos - desc_size, blocksize);
> + if (desc_pos < xfs_fsverity_metadata_offset(ip))
> + return -ERANGE;
[Severity: Low]
Does returning early on !buf_size make the
desc_size < sizeof(struct fsverity_descriptor) corruption check
unreachable from fsverity_get_descriptor()?
fsverity_get_descriptor() always calls ->get_verity_descriptor() with
buf_size == 0 first and aborts with -EMSGSIZE if the returned size is
smaller than sizeof(struct fsverity_descriptor), so it never makes the
second call that reaches XFS_IS_CORRUPT() (or the XFS_SICK_INO_FSVERITY
health update added later in commit "xfs: introduce health state for
corrupted fsverity metadata"). Checking desc_size and desc_pos before
if (!buf_size) would also avoid allocating a buffer and re-reading
desc_size when desc_pos < xfs_fsverity_metadata_offset(ip).
> +
> + error = fsverity_pagecache_read(inode, buf, desc_size, desc_pos);
> + if (error)
> + return error;
> +
> + return desc_size;
> +}
[Severity: Medium]
What happens if the descriptor range [desc_pos, last_block_offset) on a
corrupted image starts before rec.br_startoff or spans a hole?
xfs_bmap_last_extent() only returns the last extent, and
xfs_fsverity_get_descriptor() does not check that
rec.br_state == XFS_EXT_NORM and
desc_pos >= XFS_FSB_TO_B(mp, rec.br_startoff). When
fsverity_pagecache_read() reads a hole in the verity metadata region while
fsverity_info is not yet set on the inode (ctx->vi == NULL),
iomap_read_folio_iter() skips fsverity_fill_zerohash() without zeroing the
folio and marks the uninitialized folio range uptodate:
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 as uptodate in
inode->i_mapping, where FS_IOC_READ_VERITY_METADATA can read it.
[ ... ]
> +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;
> +}
[ ... ]
> +static int
> +xfs_fsverity_end_enable(
> + struct file *file,
> + const void *desc,
> + size_t desc_size,
> + u64 merkle_tree_size)
> +{
[ ... ]
> + /*
> + * 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);
> + return error;
> +
> +out:
> + 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);
> +
> + return error;
> +}
[Severity: Medium]
Does xfs_fsverity_reset_inode() ever need to run a transaction to clear
XFS_DIFLAG2_VERITY on disk, and can it leave XFS_DIFLAG2_VERITY set in
memory when xfs_trans_commit() fails?
Every goto out before xfs_trans_commit() runs before XFS_DIFLAG2_VERITY or
S_VERITY has been set in memory or on disk, so xfs_fsverity_reset_inode()
commits an unnecessary synchronous tr_ichange transaction on every failed
enablement (such as desc == NULL). Conversely, if xfs_trans_commit() in
xfs_fsverity_end_enable() fails, the transaction aborts without persisting
XFS_DIFLAG2_VERITY and shuts down the mount; xfs_fsverity_delete_metadata()
then fails at xfs_trans_alloc() and returns early from
xfs_fsverity_reset_inode(), leaving XFS_DIFLAG2_VERITY set in
ip->i_diflags2 while S_VERITY is clear.
[ ... ]
> +/*
> + * 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_next,
> + &xfs_iomap_write_ops);
> +}
[Severity: High]
Is it safe to call iomap_fsverity_write() here without holding
XFS_IOLOCK_EXCL?
enable_verity() drops inode_lock() across build_merkle_tree(), and
deny_write_access() only blocks FMODE_WRITE opens. Other XFS paths rely
on XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL to serialize against buffered writes
and do not check fsverity_is_building(), including background blockgc
(xfs_inode_free_cowblocks()), O_RDONLY ioctls (FS_IOC_FSSETXATTR, FICLONE,
FIDEDUPERANGE), and path-based file_setattr():
CPU0 CPU1
enable_verity()
build_merkle_tree()
xfs_fsverity_write_merkle()
iomap_fsverity_write()
xfs_buffered_write_iomap_begin()
/* allocates COW delalloc */
iomap_write_begin()
xfs_iomap_valid()
xfs_inode_free_cowblocks()
xfs_ilock(ip, XFS_IOLOCK_EXCL |
XFS_MMAPLOCK_EXCL)
xfs_reflink_cancel_cow_range()
/* cancels COW delalloc */
xfs_iunlock(...)
iomap_write_end()
/* dirties folio over canceled reservation;
writeback maps a hole and drops the Merkle block */
Acquiring XFS_IOLOCK_EXCL around iomap_fsverity_write() (or checking
fsverity_is_building() in the racing paths) would prevent concurrent COW
block freeing, reflink remapping, and fileattr changes from racing with
Merkle tree writes.
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index c76e36dadf952..c4199c5f90794 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -562,6 +563,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;
[Severity: Medium]
Should this also reject changing the realtime flag when verity is already
enabled on the inode (IS_VERITY(VFS_IC(ip)) or
(ip->i_diflags2 & XFS_DIFLAG2_VERITY))?
If a corrupted on-disk inode has XFS_DIFLAG2_VERITY set with zero extents,
xfs_inode_has_filedata(ip) is false, and the path-based file_setattr()
syscall can reach xfs_ioctl_setattr_xflags() without opening the file.
Setting FS_XFLAG_REALTIME on a filesystem with sb_rextsize > 1 then logs an
inode with both XFS_DIFLAG_REALTIME and XFS_DIFLAG2_VERITY, which trips
xfs_dinode_verify() on writeback and shuts down the filesystem.
> /*
> * If S_DAX is enabled on this file, we can only switch the
> * device if both support fsdax, and the zoned code does not.
> @@ -576,6 +585,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: Medium]
Should xfs_ioctl_setattr_check_extsize() also reject changing ip->i_extsize
when fsverity_is_building(VFS_IC(ip)) is true?
On a sparse file where i_size > 0 but xfs_inode_has_filedata(ip) is still
false before the first Merkle tree extent is allocated,
xfs_iomap_write_direct() computes the transaction block reservation from
xfs_get_extsz_hint(ip) before acquiring XFS_ILOCK_EXCL. A concurrent
FS_IOC_FSSETXATTR or file_setattr() increasing ip->i_extsize in that window
causes xfs_bmapi_write() to allocate using the larger extent size hint,
overrunning tp->t_blk_res and shutting down the filesystem:
CPU0 CPU1
xfs_fsverity_write_merkle()
iomap_fsverity_write()
...
xfs_iomap_write_direct()
resaligned = xfs_aligned_fsb_count(...,
xfs_get_extsz_hint(ip))
xfs_fileattr_set()
xfs_ioctl_setattr_check_extsize()
/* xfs_inode_has_filedata(ip) == 0 */
ip->i_extsize = ...; /* larger */
xfs_trans_alloc_inode(...)
xfs_bmapi_write()
/* allocates with new i_extsize,
overrunning tp->t_blk_res */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202165653.767961-1-aalbersh@kernel.org?part=17
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2026-12-02 17:49 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 16:56 [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 01/23] fs: constify inode argument of inode_state_read_once() Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 02/23] fs: strip FS_VERITY_FL from FS_IOC_SETFLAGS Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 03/23] fs,fsverity: add I_VERITY_BUILDING inode state flag Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] [PATCH v20 03/23] fs, fsverity: " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 04/23] fs,fsverity: reject S_APPEND on fsverity inodes Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] [PATCH v20 04/23] fs, fsverity: " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 05/23] iomap: use fsverity_is_building() to check for fsverity IO Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:09 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 06/23] btrfs: use I_VERITY_BUILDING instead of private flags Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 07/23] ext4: " Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 08/23] f2fs: " Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 09/23] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 10/23] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 11/23] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 12/23] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 13/23] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:28 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 14/23] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:15 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 15/23] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:09 ` sashiko-bot
2026-12-02 16:56 ` [PATCH v20 16/23] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 17/23] xfs: add fs-verity support Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:49 ` sashiko-bot [this message]
2026-12-02 17:49 ` sashiko-bot--- via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 18/23] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 19/23] xfs: add fs-verity ioctls Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 20/23] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 21/23] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:35 ` sashiko-bot
2026-12-02 17:35 ` sashiko-bot--- via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 22/23] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:17 ` sashiko-bot
2026-12-02 17:17 ` sashiko-bot--- via Linux-f2fs-devel
2026-12-02 16:56 ` [PATCH v20 23/23] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-12-02 16:56 ` [f2fs-dev] " Andrey Albershteyn via Linux-f2fs-devel
2026-12-02 17:17 ` sashiko-bot
2026-12-02 17:17 ` sashiko-bot--- via Linux-f2fs-devel
2026-12-02 17:49 ` [PATCH v20 00/23] fs-verity support for XFS with post EOF merkle tree sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-246390@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aalbersh@kernel.org \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=dsterba@suse.cz \
--cc=ebiggers@kernel.org \
--cc=fsverity@lists.linux.dev \
--cc=hch@lst.de \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.