Re: [PATCH] xarray: fix index jumping backwards in xas_find()
From: Krystian Kaniewski
Date: Fri Sep 04 2026 - 09:18:21 EST
I have fixed the test issue and submitted patch as v2. I'm sorry about issue v1 caused, hopefully v2 is going to be fully correct now.
On 9/4/2026 10:41 AM, Krystian Kaniewski wrote:
Hello,
Thanks for running tests on my patch. I've quickly looked into the test
result and the problem seems to be related to check_multi_find_4() test and
not the fix itself. I'll send a v2 patch once I get the test fixed.
pt., 4 wrz 2026 o 10:22 Mike Rapoport <rppt@xxxxxxxxxx> napisał(a):
On Thu, Sep 03, 2026 at 11:22:51AM -0700, Andrew Morton wrote:
On Thu, 3 Sep 2026 13:48:55 +0000 (UTC) "syzbot" <syzbot@xxxxxxxxxx>wrote:
entryFrom: Krystian Kaniewski <krystianmkaniewski@xxxxxxxxx>
A bug in the XArray iterator xas_find() causes the iterator's index
(xas->xa_index) to jump backwards when iterating over a multi-index
sets(like a THP) that resides in a non-leaf node and is concurrently split.
When iterating over a multi-index entry in a non-leaf node, xas_load()
xas->xa_index atxas->xa_offset to the base offset of the entry, but leaves
thethe requested index. When the caller subsequently wants to advance to
recalculatesnext entry, xas_find() is called. xas_find() attempts to synchronize
xas->xa_offset with xas->xa_index before advancing. However, the fixup
logic was incorrectly restricted to leaf nodes (!xas->xa_node->shift).
Because the THP resides in a non-leaf node, the fixup is skipped.
As a result, xas_find() simply increments xas->xa_offset and
jumpxas->xa_index based on this new offset. This causes xas->xa_index to
offsetbackwards. If the THP was concurrently split, the entry at the new
folio atis a node pointer, so xas_find() descends into it and returns the
thethe backwards index. The caller (filemap_map_pages()) then calculates
memoryPTE pointer based on this backwards index, resulting in an invalid
pageaccess such as an out-of-bounds read or use-after-free on a page-table
advancing.freed via tlb_remove_table_rcu().
To fix this, check if xas->xa_offset matches get_offset(xas->xa_index,
xas->xa_node). If it does not and the node is a non-leaf node, set
xas->xa_offset to get_offset(xas->xa_index, xas->xa_node) before
The testing shows there are issues with this patch:Also add test cases in test_xarray to verify xas_find() behavior whenThanks. But the changelog omits vital information: a description of
iterating over and splitting multi-index entries.
the userspace-visible runtime effects of the bug.
Fixes: b803b42823d0 ("xarray: Add XArray iterators")I see from there that it was a use-after-free, detected by KASAN. I'll
Assisted-by: Gemini:gemini-3.7-flash syzbot
Reported-by: syzbot+b72767277f29b6407083@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=b72767277f29b6407083
update the changelog and I'll add cc:stable.
I'll queue the patch for testing while awaiting review input.
https://github.com/linux-mm/linux-mm/actions/runs/33815757662/job/100847425973
And since it's in mm-unstable now it breaks all CI jobs :(
https://syzkaller.appspot.com/ai_job?id=a01c56bd-74d0-411c-afb4-ee6f0cb6cb61Link:
--
Sincerely yours,
Mike.