From: Carlos Maiolino <cem@kernel.org>
To: jianyungao89@gmail.com
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
"Darrick J. Wong" <djwong@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Eric Sandeen <sandeen@redhat.com>,
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
Yuzuki Ishiyama <ishiyama@hpc.is.uec.ac.jp>,
Dave Chinner <dchinner@redhat.com>,
"open list:XFS FILESYSTEM" <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH] xfs: fix spurious len double-counting in rmap three-way merge check
Date: Tue, 3 Nov 2026 16:32:54 +0100 [thread overview]
Message-ID: <aun6-mywXYg2VTL4@nidhogg.toxiclabs.cc> (raw)
In-Reply-To: <20261103144148.14430-1-jianyungao89@gmail.com>
On Tue, Nov 03, 2026 at 10:41:44PM +0800, jianyungao89@gmail.com wrote:
> From: Jianyun Gao <jianyungao89@gmail.com>
>
> In xfs_rmap_map, the left-edge merge path already executes
> ltrec.rm_blockcount += len at line 1119 before checking whether the
> right record is also contiguous and can be merged. The subsequent
> overflow guard therefore must compare the already-incremented
> ltrec.rm_blockcount plus gtrec.rm_blockcount against XFS_RMAP_LEN_MAX,
> but it incorrectly adds len a second time:
>
> (unsigned long)ltrec.rm_blockcount + len +
> gtrec.rm_blockcount <= XFS_RMAP_LEN_MAX
>
> The extra len makes the check too strict: when the real merged length
> does not overflow but the inflated value exceeds XFS_RMAP_LEN_MAX, the
> three-way merge is rejected and the code falls back to a two-way merge,
> leaving the right record unmerged. This produces rmap btree
> fragmentation but does not corrupt on-disk metadata.
>
> Remove the spurious len from the overflow check.
>
> Fixes: 0a1b0b3855cf7 ("xfs: add an extent to the rmap btree")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Jianyun Gao <jianyungao89@gmail.com>
Hi, even though this looks reasonably correct, how did you find this
issue?
Did you test this at all against any regressions (i.e. running it
against xfstests)? This is touching critical logic on the rmap trees
which can potentially end really bad.
Cheers.
> ---
> fs/xfs/libxfs/xfs_rmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c
> index 14aef87837a9..c2b2f8e7502d 100644
> --- a/fs/xfs/libxfs/xfs_rmap.c
> +++ b/fs/xfs/libxfs/xfs_rmap.c
> @@ -1120,7 +1120,7 @@ xfs_rmap_map(
> if (have_gt &&
> bno + len == gtrec.rm_startblock &&
> (ignore_off || offset + len == gtrec.rm_offset) &&
> - (unsigned long)ltrec.rm_blockcount + len +
> + (unsigned long)ltrec.rm_blockcount +
> gtrec.rm_blockcount <= XFS_RMAP_LEN_MAX) {
> /*
> * right edge also contiguous, delete right record
> --
> 2.34.1
>
>
next prev parent reply other threads:[~2026-11-03 15:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 14:41 jianyungao89
2026-11-03 15:32 ` Carlos Maiolino [this message]
2026-11-04 3:27 ` Jianyun Gao
2026-11-04 15:00 ` Carlos Maiolino
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=aun6-mywXYg2VTL4@nidhogg.toxiclabs.cc \
--to=cem@kernel.org \
--cc=ast@kernel.org \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=ishiyama@hpc.is.uec.ac.jp \
--cc=jianyungao89@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mykyta.yatsenko5@gmail.com \
--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®