From: jianyungao89@gmail.com
To: linux-kernel@vger.kernel.org
Cc: Jianyun Gao <jianyungao89@gmail.com>,
stable@vger.kernel.org, Carlos Maiolino <cem@kernel.org>,
"Darrick J. Wong" <djwong@kernel.org>,
Eric Sandeen <sandeen@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Brian Foster <bfoster@redhat.com>,
Yuzuki Ishiyama <ishiyama@hpc.is.uec.ac.jp>,
linux-xfs@vger.kernel.org (open list:XFS FILESYSTEM)
Subject: [PATCH] xfs: fix log flag cleanup in xfs_bmapi_remap error path for attr fork
Date: Fri, 27 Nov 2026 11:04:55 +0800 [thread overview]
Message-ID: <20261127030501.1618-1-jianyungao89@gmail.com> (raw)
From: Jianyun Gao <jianyungao89@gmail.com>
xfs_bmapi_remap() was originally a data-fork-only helper, so its error0
cleanup block hardcoded ip->i_df.if_format and the D-series log flags
(XFS_ILOG_DEXT / XFS_ILOG_DBROOT). commit 7cf199ba5a70d ("xfs: make
xfs_bmapi_remapi work with attribute forks") extended the function to
support XFS_BMAPI_ATTRFORK and converted almost the entire body to use
whichfork, but the error0 cleanup was left untouched; a later mechanical
conversion in commit f7e67b20ecbbc ("xfs: move the fork format fields
into struct xfs_ifork") preserved the bug.
When called for the attr fork, the cleanup is a complete no-op: it
checks the data fork's format and clears D-series flags that were never
set, while the A-series flags (XFS_ILOG_AEXT / XFS_ILOG_ABROOT) set by
xfs_bmap_add_extent_hole_real() are never stripped. This is reachable
on the success path too, since error0 is a fall-through target: if the
attr fork starts in BTREE format and a three-way merge drops
if_nextents below the threshold, xfs_bmap_btree_to_extents() frees
if_broot but a stale XFS_ILOG_ABROOT remains in logflags.
In practice this does not crash or corrupt data -- the inode item
format and flush helpers dispatch on if_format and clear stale ABROOT
before if_broot is dereferenced. But the code is logically inconsistent
and relies on downstream defensive checks; fix it now to avoid future
trouble if those checks are refactored.
Make the cleanup fork-aware, mirroring xfs_bmapi_finish(): use
xfs_ilog_fext/fbroot(whichfork) and check ifp->if_format.
Fixes: 7cf199ba5a70d ("xfs: make xfs_bmapi_remapi work with attribute forks")
Cc: stable@vger.kernel.org
Signed-off-by: Jianyun Gao <jianyungao89@gmail.com>
---
fs/xfs/libxfs/xfs_bmap.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index dcd5faf3428e..9236aa80838e 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4520,10 +4520,12 @@ xfs_bmapi_remap(
error = xfs_bmap_btree_to_extents(tp, ip, cur, &logflags, whichfork);
error0:
- if (ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS)
- logflags &= ~XFS_ILOG_DEXT;
- else if (ip->i_df.if_format != XFS_DINODE_FMT_BTREE)
- logflags &= ~XFS_ILOG_DBROOT;
+ if ((logflags & xfs_ilog_fext(whichfork)) &&
+ ifp->if_format != XFS_DINODE_FMT_EXTENTS)
+ logflags &= ~xfs_ilog_fext(whichfork);
+ else if ((logflags & xfs_ilog_fbroot(whichfork)) &&
+ ifp->if_format != XFS_DINODE_FMT_BTREE)
+ logflags &= ~xfs_ilog_fbroot(whichfork);
if (logflags)
xfs_trans_log_inode(tp, ip, logflags);
--
2.34.1
reply other threads:[~2026-11-27 3:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261127030501.1618-1-jianyungao89@gmail.com \
--to=jianyungao89@gmail.com \
--cc=ast@kernel.org \
--cc=bfoster@redhat.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=ishiyama@hpc.is.uec.ac.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®