From: sashiko-bot@kernel.org
To: "Andrey Albershteyn" <aalbersh@kernel.org>,
ebiggers@kernel.org, hch@lst.de,
"Carlos Maiolino" <cem@kernel.org>,
fsverity@lists.linux.dev
Cc: david@fromorbit.com, "Darrick J. Wong" <djwong@kernel.org>
Subject: Re: [PATCH v18 07/15] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi()
Date: Mon, 02 Nov 2026 15:02:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-193622@kernel.org> (raw)
In-Reply-To: <20261102144147.2393369-8-aalbersh@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] xfs: __xfs_bunmapi() with XFS_BMAPI_UNWRITTEN unmaps written rt extents
--
commit 823f5c04cb0ac218e733c0788aa8567888bdc3de
Author: Andrey Albershteyn <aalbersh@kernel.org>
xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi()
This commit adds the XFS_BMAPI_UNWRITTEN flag to __xfs_bunmapi() so callers
can unmap only unwritten extents while leaving written extents in place.
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index a35a44cf8c635..706f2ead42f58 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -5279,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;
[Severity: High]
As reported by Darrick J. Wong on v16 [1], when __xfs_bunmapi() is called
with XFS_BMAPI_UNWRITTEN on a realtime inode with sb_rextsize > 1, can an
unwritten tail of a partially written realtime extent cause the written left
neighbor to be converted to unwritten and freed?
Specifically, if del is an unwritten extent (del.br_state ==
XFS_EXT_UNWRITTEN) at the end of a realtime allocation unit whose head
extent prev is written (prev.br_state == XFS_EXT_NORM), it passes this check
and enters the realtime alignment logic in __xfs_bunmapi():
mod = xfs_rtb_to_rtxoff(mp, del.br_startblock);
if (mod) {
...
} else if (del.br_startoff == start &&
(del.br_state == XFS_EXT_UNWRITTEN ||
tp->t_blk_res == 0)) {
...
continue;
} else if (del.br_state == XFS_EXT_UNWRITTEN) {
...
if (!xfs_iext_prev_extent(ifp, &icur, &prev))
ASSERT(0);
ASSERT(prev.br_state == XFS_EXT_NORM);
...
prev.br_state = XFS_EXT_UNWRITTEN;
error = xfs_bmap_add_extent_unwritten_real(tp,
ip, whichfork, &icur, &cur,
&prev, &logflags);
if (error)
goto error0;
goto nodelete;
}
When del.br_startoff > start and del.br_blockcount <= off, this branch
assumes the caller is also unmapping the preceding range. It converts the
written left neighbor prev to XFS_EXT_UNWRITTEN (merging it with del) and
jumps to nodelete. On the next loop iteration, the newly merged extent is
both unwritten and aligned to the realtime extent boundary, so
__xfs_bunmapi() jumps to delete and frees the written blocks as well.
Although xfs_fsverity_begin_enable() in the subsequent fs-verity patch
checks xfs_inode_has_bigrtalloc(ip), enable_verity() drops inode_lock()
after begin_enable_verity() while building the Merkle tree. On an empty or
sparse file where xfs_inode_has_filedata(ip) is false, a concurrent
FS_IOC_FSSETXATTR ioctl via xfs_ioctl_setattr_xflags() (which does not check
XFS_VERITY_CONSTRUCTION) can set XFS_DIFLAG_REALTIME before
xfs_fsverity_end_enable() writes the verity descriptor and calls
xfs_free_eofblocks(). Additionally, xfs_dinode_verify() does not reject
on-disk inodes that have both XFS_DIFLAG2_VERITY and XFS_DIFLAG_REALTIME
when sb_rextsize > 1.
Should __xfs_bunmapi() skip partial unwritten realtime extents when
XFS_BMAPI_UNWRITTEN is set instead of converting the written left neighbor?
[1] https://lore.kernel.org/r/20260922044911.GA6239@frogsfrogsfrogs
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102144147.2393369-1-aalbersh@kernel.org?part=7
next prev parent reply other threads:[~2026-11-02 15:02 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 14:41 [PATCH v18 00/15] fs-verity support for XFS with post EOF merkle tree Andrey Albershteyn
2026-11-02 14:41 ` [PATCH v18 01/15] xfs: introduce fsverity on-disk changes Andrey Albershteyn
2026-11-02 15:08 ` sashiko-bot
2026-11-02 14:41 ` [PATCH v18 02/15] xfs: don't allow to enable DAX on fs-verity sealed inode Andrey Albershteyn
2026-11-02 14:41 ` [PATCH v18 03/15] xfs: disable direct read path for fs-verity files Andrey Albershteyn
2026-11-02 14:41 ` [PATCH v18 04/15] xfs: don't report dio_mem_align and dio_offset_align for fsverity files Andrey Albershteyn
2026-11-03 9:23 ` Christoph Hellwig
2026-11-02 14:41 ` [PATCH v18 05/15] xfs: handle fsverity I/O in write/read path Andrey Albershteyn
2026-11-02 15:13 ` sashiko-bot
2026-11-03 9:37 ` Christoph Hellwig
2026-11-03 13:55 ` Andrey Albershteyn
2026-11-03 14:53 ` Christoph Hellwig
2026-11-03 15:26 ` Andrey Albershteyn
2026-11-03 22:03 ` Eric Biggers
2026-11-02 14:41 ` [PATCH v18 06/15] xfs: use read ioend for fsverity data verification Andrey Albershteyn
2026-11-02 14:57 ` sashiko-bot
2026-11-03 9:39 ` Christoph Hellwig
2026-11-02 14:41 ` [PATCH v18 07/15] xfs: add XFS_BMAPI_UNWRITTEN to unmap unwritten extents in __xfs_bunmapi() Andrey Albershteyn
2026-11-02 15:02 ` sashiko-bot [this message]
2026-11-03 9:41 ` Christoph Hellwig
2026-11-03 14:31 ` Andrey Albershteyn
2026-11-03 14:39 ` Christoph Hellwig
2026-11-03 14:45 ` Andrey Albershteyn
2026-11-03 14:49 ` Christoph Hellwig
2026-11-03 15:17 ` Andrey Albershteyn
2026-11-02 14:41 ` [PATCH v18 08/15] xfs: don't remove written extents past EOF on fsverity inodes Andrey Albershteyn
2026-11-02 15:11 ` sashiko-bot
2026-11-03 9:42 ` Christoph Hellwig
2026-11-02 14:41 ` [PATCH v18 09/15] xfs: add fs-verity support Andrey Albershteyn
2026-11-02 15:34 ` sashiko-bot
2026-11-03 18:23 ` Eric Biggers
2026-11-02 14:41 ` [PATCH v18 10/15] xfs: initialize fs-verity on file open Andrey Albershteyn
2026-11-02 14:41 ` [PATCH v18 11/15] xfs: add fs-verity ioctls Andrey Albershteyn
2026-11-02 15:24 ` sashiko-bot
2026-11-02 14:41 ` [PATCH v18 12/15] xfs: advertise fs-verity being available on filesystem Andrey Albershteyn
2026-11-02 14:41 ` [PATCH v18 13/15] xfs: check and repair the verity inode flag state Andrey Albershteyn
2026-11-02 15:28 ` sashiko-bot
2026-11-02 14:41 ` [PATCH v18 14/15] xfs: introduce health state for corrupted fsverity metadata Andrey Albershteyn
2026-11-02 15:16 ` sashiko-bot
2026-11-02 14:41 ` [PATCH v18 15/15] xfs: enable ro-compat fs-verity flag Andrey Albershteyn
2026-11-02 15:35 ` sashiko-bot
2026-11-03 9:44 ` Christoph Hellwig
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-193622@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aalbersh@kernel.org \
--cc=cem@kernel.org \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--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