From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796233753; b=0HGJROP2UjfiKp1X28vPDknZEVWNpuRXxVoGduTwaX8LNdOSRE8H/5+uDUro+DqSFQfy KhcAZTsd6Ou4SkBKHHBoT9OfieX7a1iVVy1QKs97WIW97dzUW/lh1TzCQGOn3/76EwY/T 0JYY0J1HNoWg1+Jd+e3ncN4nj6kKaMcdmSuFfUeu5Se8sYDyyHLJ2wknOs/Jkne4/nyo3 O7Aalku3tl7c1m97pzl3Y7YPs8iIUFomMmPyYenp37/c++4tey4kaUPLiVWgFhpMqjQVq 57zyXxptPae85jdEis1g4TeLVNtxHeCPQFqz920svScW8g14UDGF7UZ45i3MVYNcEyg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796233753; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=aTPXZdeXfJWPQSAvmKbnm2hGgDSWXQ6p9UaiKeL1ung=; b=qh5Q7DDfnw6ktO5Bs9gqRbNkVQYeOxb/3Eh6JItys+by8SO71kq7AnAED7ohcAIZ1mAX 9BAyf5m4Zd7C7IJSifaPHrTZJPwdgZCeom9Cvm9Z9rnc6w22BQqlmfXU5wqflKXI52pZn SXuaM0lQqLN3VkXniZPHRufRq7UUj94ODG6zWbFNtnxL6Kc5/Uiom3Wn1glisOaYMTHkv lJssYOvOwDb+2a9rHWKQddJU66WXH2POf/4XQ183ZMVHfdwOtWEycXFoJTnhBhvHCrWe0 6SF/LL6eGAXKWWA+Wdqz2OZke4qSH6Ndm2C6Ft3smmF7QL2DSglF2VYXWJ60shpqQfA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=E8wX+kIH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E772606A322; Wed, 2 Dec 2026 17:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=E8wX+kIH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91FB71F000C1; Wed, 2 Dec 2026 17:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796233753; bh=aTPXZdeXfJWPQSAvmKbnm2hGgDSWXQ6p9UaiKeL1ung=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=E8wX+kIHczDTnEpXDKvPEiARl9nkY/G2uLZ9WZciU95cXaq/H3R2UeA9ymdsllFht OJtMoV4fc+htho0TqqkdkuyjlTAokuQXcoSY2LpVK8GReTzLwVNRtD14o6sBV/fobC Cf8RZ197yYE/2xlOGrvLA9JzOoTBoZgMCd0tM3qjybnbb1uBxJgRi9z+xF5pb2XDZl JNG8JdcGJ9kvogsga3/KFZSKGyC9YwNMTAs6WmqDvU6dj5MlGlOvLrq4Q15m7V0i85 IQZJZZ3NPQSAEB8TwuZ2VYHSqlv8m0GqKQkKYI6YFvq90hzG1rj4ujPIcKgDxwcEsh aBIjQFYdveW7Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [f2fs-dev] [PATCH v20 17/23] xfs: add fs-verity support Reply-To: sashiko-reviews@lists.linux.dev To: "Andrey Albershteyn via Linux-f2fs-devel" , linux-ext4 , "Eric Biggers" , "Christoph Hellwig" , "Carlos Maiolino" , fsverity Cc: david@fromorbit.com, "Christian Brauner" , "Andrey Albershteyn" , dsterba@suse.cz, tytso@mit.edu In-Reply-To: <20261202165653.767961-18-aalbersh@kernel.org> References: <20261202165653.767961-1-aalbersh@kernel.org> <20261202165653.767961-18-aalbersh@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 17:49:12 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D > + 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 <=3D xfs_fsverity_metadata_offset(ip)) > + return -ENODATA; > + > + desc_size_pos =3D last_block_offset - sizeof(__be32); > + error =3D fsverity_pagecache_read(inode, (char *)&d_desc_size, > + sizeof(d_desc_size), desc_size_pos); > + if (error) > + return error; > + > + desc_size =3D 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 =3D 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 =3D=3D 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 =3D 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 =3D=3D XFS_EXT_NORM and desc_pos >=3D 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 =3D=3D 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 =3D=3D 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 =3D ip->i_mount; > + struct xfs_trans *tp; > + > + error =3D 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 =3D xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange, > + 0, 0, false, &tp); > + if (error) > + return error; > + > + ip->i_diflags2 &=3D ~XFS_DIFLAG2_VERITY; > + > + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); > + xfs_trans_set_sync(tp); > + > + error =3D 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 =3D 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 |=3D XFS_DIFLAG2_VERITY; > + > + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); > + xfs_trans_set_sync(tp); > + > + error =3D 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 =3D 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 =3D=3D 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 =3D file_inode(file); > + struct xfs_inode *ip =3D XFS_I(inode); > + loff_t position =3D 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; > =20 > + /* > + * 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; > } > =20 > + /* > + * 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 =3D xfs_aligned_fsb_count(..., xfs_get_extsz_hint(ip)) xfs_fileattr_set() xfs_ioctl_setattr_check_extsize() /* xfs_inode_has_filedata(ip) =3D= =3D 0 */ ip->i_extsize =3D ...; /* larger */ xfs_trans_alloc_inode(...) xfs_bmapi_write() /* allocates with new i_extsize, overrunning tp->t_blk_res */ --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202165653.7679= 61-1-aalbersh@kernel.org?part=3D17