Skip to contentSkip to conversation

mm: prepare anon_vma before swapin rmap

PATCH In review ZhengYuan Huang 5 participants 13 messages Apr 17 – Apr 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: prepare anon_vma before swapin rmap

[BUG]
madvise(MADV_HWPOISON) can fault a swap entry back in through get_user_pages_fast() and hit:

kernel BUG at mm/rmap.c:1364!

Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:__folio_set_anon mm/rmap.c:1364 [inline]
RIP: 0010:folio_add_new_anon_rmap+0x41d/0xc10 mm/rmap.c:1553
Call Trace:
 do_swap_page+0x14c5/0x5c30 mm/memory.c:4963
 handle_pte_fault mm/memory.c:6198 [inline]
 __handle_mm_fault+0x1512/0x22f0 mm/memory.c:6336
 handle_mm_fault+0x42f/0x820 mm/memory.c:6505
 faultin_page mm/gup.c:1126 [inline]
 __get_user_pages+0x4b3/0x3400 mm/gup.c:1428
 __get_user_pages_locked mm/gup.c:1692 [inline]
 __gup_longterm_locked+0x945/0x14b0 mm/gup.c:2476
 gup_fast_fallback+0x8a3/0x2440 mm/gup.c:3220
 get_user_pages_fast+0x64/0xb0 mm/gup.c:3298
 madvise_inject_error mm/madvise.c:1456 [inline]
 madvise_do_behavior+0x503/0x860 mm/madvise.c:1875
 do_madvise+0x17e/0x210 mm/madvise.c:1978
 __do_sys_madvise mm/madvise.c:1987 [inline]
 __se_sys_madvise mm/madvise.c:1985 [inline]
 __x64_sys_madvise+0xae/0x120 mm/madvise.c:1985
 ...

[CAUSE]
Commit a373baed5a9d ("mm: delay the check for a NULL anon_vma") moved anon_vma preparation out of the generic fault path and into the fault handlers that actually need to install anonymous rmap state.

do_swap_page() was left behind. It can still restore anonymous mappings via folio_add_new_anon_rmap() or folio_add_anon_rmap_ptes(), but it does not call vmf_anon_prepare() first. On a VMA-lock fault this can leave vma->anon_vma NULL all the way down to __folio_set_anon(), which BUG_ONs on that violated invariant.

[FIX]
Prepare the faulting VMA's anon_vma once do_swap_page() has confirmed it is handling a real swap entry, before any swapin path can install anonymous rmap state.

vmf_anon_prepare() already handles the retry rules for VMA-lock faults, and when anon_vma is already present this stays a single likely branch in the swap fault hot path.

Fixes a373baed5a9d ("mm: delay the check for a NULL anon_vma")

---
I can reproduce this issue deterministically on v6.18, but I have not been able to reproduce it with the same setup on next-20260415.

However, I have not identified a change that clearly explains the difference. From code inspection, do_swap_page() still appears able to reach folio_add_new_anon_rmap()/folio_add_anon_rmap_ptes() without a prior vmf_anon_prepare(), while __folio_set_anon() still BUG_ONs if vma->anon_vma is NULL. So although I could not reproduce the issue on next-20260415, I also could not confirm that it has been fixed there. Recent changes around the swap fault path may have affected the reproduction conditions, but I may also be missing another relevant change.
---
mm/memory.c | 5 +++++

1 file changed, 5 insertions(+)
mm/memory.c +5 -0
index ea6568571131..a64bc9826cc5 100644
@@ -4850,6 +4850,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
 		goto out;
 	}
 
+	/* Swapin installs anonymous rmap state into the faulting VMA. */
+	ret = vmf_anon_prepare(vmf);
+	if (ret)
+		goto out;
+
 	/* Prevent swapoff from happening to us. */
 	si = get_swap_device(entry);
 	if (unlikely(!si))
Signature · 1 line
2.49.0
#1 lore raw
Quoted 9 lines · ZhengYuan Huang

Commit a373baed5a9d ("mm: delay the check for a NULL anon_vma") moved anon_vma preparation out of the generic fault path and into the fault handlers that actually need to install anonymous rmap state.

do_swap_page() was left behind. It can still restore anonymous mappings via folio_add_new_anon_rmap() or folio_add_anon_rmap_ptes(), but it does not call vmf_anon_prepare() first. On a VMA-lock fault this can leave vma->anon_vma NULL all the way down to __folio_set_anon(), which BUG_ONs on that violated invariant.

Huh. Can you share your reproducer? I wonder if there's an equivalent problem with do_numa_fault(). And maybe the right solution might be to put the call to vmf_anon_prepare() in handle_pte_fault() instead.

I'm asking because I don't quite understand how we get to this point without an anon_vma being assigned to this VMA. We should allocate one on the first fault ... so we cannot have ever faulted, but if we've never faulted, how does madvise() manage to swap out a page if none has been allocated?

(also if you share your reproducer, perhaps someone will add it to the self-tests and maybe it'll prevent another bug in the future)

#2 lore raw
Quoted 15 lines · Matthew Wilcox
Quoted 9 lines · ZhengYuan Huang

Commit a373baed5a9d ("mm: delay the check for a NULL anon_vma") moved anon_vma preparation out of the generic fault path and into the fault handlers that actually need to install anonymous rmap state.

do_swap_page() was left behind. It can still restore anonymous mappings via folio_add_new_anon_rmap() or folio_add_anon_rmap_ptes(), but it does not call vmf_anon_prepare() first. On a VMA-lock fault this can leave vma->anon_vma NULL all the way down to __folio_set_anon(), which BUG_ONs on that violated invariant.

Huh. Can you share your reproducer? I wonder if there's an equivalent problem with do_numa_fault(). And maybe the right solution might be to put the call to vmf_anon_prepare() in handle_pte_fault() instead.

Quoted 5 lines

I'm asking because I don't quite understand how we get to this point without an anon_vma being assigned to this VMA. We should allocate one on the first fault ... so we cannot have ever faulted, but if we've never faulted, how does madvise() manage to swap out a page if none has been allocated?

Yeah there really isn't any way this should be possible unless something else is causing a bug here.

My recent anon_vma changes are too new for them to be the culprit I think :))

Quoted 3 lines

(also if you share your reproducer, perhaps someone will add it to the self-tests and maybe it'll prevent another bug in the future)

Yes, if this is a real bug we really need to see how this is happening.

Thanks, Lorenzo

#3 lore raw
In reply to ZhengYuan Huang
Quoted 49 lines · ZhengYuan Huang

[BUG]
madvise(MADV_HWPOISON) can fault a swap entry back in through get_user_pages_fast() and hit:

kernel BUG at mm/rmap.c:1364!

Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:__folio_set_anon mm/rmap.c:1364 [inline]
RIP: 0010:folio_add_new_anon_rmap+0x41d/0xc10 mm/rmap.c:1553
Call Trace:
 do_swap_page+0x14c5/0x5c30 mm/memory.c:4963
 handle_pte_fault mm/memory.c:6198 [inline]
 __handle_mm_fault+0x1512/0x22f0 mm/memory.c:6336
 handle_mm_fault+0x42f/0x820 mm/memory.c:6505
 faultin_page mm/gup.c:1126 [inline]
 __get_user_pages+0x4b3/0x3400 mm/gup.c:1428
 __get_user_pages_locked mm/gup.c:1692 [inline]
 __gup_longterm_locked+0x945/0x14b0 mm/gup.c:2476
 gup_fast_fallback+0x8a3/0x2440 mm/gup.c:3220
 get_user_pages_fast+0x64/0xb0 mm/gup.c:3298
 madvise_inject_error mm/madvise.c:1456 [inline]
 madvise_do_behavior+0x503/0x860 mm/madvise.c:1875
 do_madvise+0x17e/0x210 mm/madvise.c:1978
 __do_sys_madvise mm/madvise.c:1987 [inline]
 __se_sys_madvise mm/madvise.c:1985 [inline]
 __x64_sys_madvise+0xae/0x120 mm/madvise.c:1985
 ...

[CAUSE]
Commit a373baed5a9d ("mm: delay the check for a NULL anon_vma") moved anon_vma preparation out of the generic fault path and into the fault handlers that actually need to install anonymous rmap state.

do_swap_page() was left behind. It can still restore anonymous mappings via folio_add_new_anon_rmap() or folio_add_anon_rmap_ptes(), but it does not call vmf_anon_prepare() first. On a VMA-lock fault this can leave vma->anon_vma NULL all the way down to __folio_set_anon(), which BUG_ONs on that violated invariant.

[FIX]
Prepare the faulting VMA's anon_vma once do_swap_page() has confirmed it is handling a real swap entry, before any swapin path can install anonymous rmap state.

vmf_anon_prepare() already handles the retry rules for VMA-lock faults, and when anon_vma is already present this stays a single likely branch in the swap fault hot path.

Fixes a373baed5a9d ("mm: delay the check for a NULL anon_vma")
Quoted 8 lines

---
I can reproduce this issue deterministically on v6.18, but I have not been able to reproduce it with the same setup on next-20260415.

However, I have not identified a change that clearly explains the difference. From code inspection, do_swap_page() still appears able to reach folio_add_new_anon_rmap()/folio_add_anon_rmap_ptes() without a prior vmf_anon_prepare()

If there is an anon page swapped out, certainly at the allocation time of that anon folio, there would have to be a anon_rmap allocated.

During fork, the anon_rmap would have to be created as well.

Something is off here.

Signature · 3 lines
Cheers,

David
#4 lore raw
Quoted 60 lines · David Hildenbrand (Arm)
Quoted 49 lines · ZhengYuan Huang

[BUG]
madvise(MADV_HWPOISON) can fault a swap entry back in through get_user_pages_fast() and hit:

kernel BUG at mm/rmap.c:1364!

Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:__folio_set_anon mm/rmap.c:1364 [inline]
RIP: 0010:folio_add_new_anon_rmap+0x41d/0xc10 mm/rmap.c:1553
Call Trace:
 do_swap_page+0x14c5/0x5c30 mm/memory.c:4963
 handle_pte_fault mm/memory.c:6198 [inline]
 __handle_mm_fault+0x1512/0x22f0 mm/memory.c:6336
 handle_mm_fault+0x42f/0x820 mm/memory.c:6505
 faultin_page mm/gup.c:1126 [inline]
 __get_user_pages+0x4b3/0x3400 mm/gup.c:1428
 __get_user_pages_locked mm/gup.c:1692 [inline]
 __gup_longterm_locked+0x945/0x14b0 mm/gup.c:2476
 gup_fast_fallback+0x8a3/0x2440 mm/gup.c:3220
 get_user_pages_fast+0x64/0xb0 mm/gup.c:3298
 madvise_inject_error mm/madvise.c:1456 [inline]
 madvise_do_behavior+0x503/0x860 mm/madvise.c:1875
 do_madvise+0x17e/0x210 mm/madvise.c:1978
 __do_sys_madvise mm/madvise.c:1987 [inline]
 __se_sys_madvise mm/madvise.c:1985 [inline]
 __x64_sys_madvise+0xae/0x120 mm/madvise.c:1985
 ...

[CAUSE]
Commit a373baed5a9d ("mm: delay the check for a NULL anon_vma") moved anon_vma preparation out of the generic fault path and into the fault handlers that actually need to install anonymous rmap state.

do_swap_page() was left behind. It can still restore anonymous mappings via folio_add_new_anon_rmap() or folio_add_anon_rmap_ptes(), but it does not call vmf_anon_prepare() first. On a VMA-lock fault this can leave vma->anon_vma NULL all the way down to __folio_set_anon(), which BUG_ONs on that violated invariant.

[FIX]
Prepare the faulting VMA's anon_vma once do_swap_page() has confirmed it is handling a real swap entry, before any swapin path can install anonymous rmap state.

vmf_anon_prepare() already handles the retry rules for VMA-lock faults, and when anon_vma is already present this stays a single likely branch in the swap fault hot path.

Fixes a373baed5a9d ("mm: delay the check for a NULL anon_vma")
Quoted 8 lines

---
I can reproduce this issue deterministically on v6.18, but I have not been able to reproduce it with the same setup on next-20260415.

However, I have not identified a change that clearly explains the difference. From code inspection, do_swap_page() still appears able to reach folio_add_new_anon_rmap()/folio_add_anon_rmap_ptes() without a prior vmf_anon_prepare()

Quoted 7 lines

If there is an anon page swapped out, certainly at the allocation time of that anon folio, there would have to be a anon_rmap allocated.

During fork, the anon_rmap would have to be created as well.

Something is off here.

Just speculating, we had

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

Go into v6.19.

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

If this cannot be reproduced on 6.19+,there is nothing to worry about.

Signature · 3 lines
Cheers,

David
#5 lore raw
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 4 lines · David Hildenbrand (Arm)
Quoted 3 lines · ZhengYuan Huang

[BUG]
madvise(MADV_HWPOISON) can fault a swap entry back in through get_user_pages_fast() and hit:

...

Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

I can reproduce this issue deterministically on v6.18, but I have not been able to reproduce it with the same setup on next-20260415.

Just speculating, we had

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000
Quoted 8 lines

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

Go into v6.19.

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

If this cannot be reproduced on 6.19+,there is nothing to worry about.

... except that 6.18 is LTS so we need a fix for that kernel version. And maybe 6.12 as well (a373baed5a9d went into 6.9, so no need to go further back than that)

#6 lore raw
Quoted 18 lines · Matthew Wilcox
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 4 lines · David Hildenbrand (Arm)
Quoted 3 lines · ZhengYuan Huang

[BUG]
madvise(MADV_HWPOISON) can fault a swap entry back in through get_user_pages_fast() and hit:

...

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

I can reproduce this issue deterministically on v6.18, but I have not been able to reproduce it with the same setup on next-20260415.

Just speculating, we had

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

Quoted 8 lines
Quoted 6 lines

Go into v6.19.

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

If this cannot be reproduced on 6.19+,there is nothing to worry about.

... except that 6.18 is LTS so we need a fix for that kernel version.

It's there: https://kernel.dance/#3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Quoted 2 lines

And maybe 6.12 as well (a373baed5a9d went into 6.9, so no need to go further back than that)

Not there (yet?) but it was tagged stable.

#7 lore raw
Quoted 17 lines · Vlastimil Babka (SUSE)
Quoted 16 lines · Matthew Wilcox
Quoted 14 lines · David Hildenbrand (Arm)

Just speculating, we had

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

Go into v6.19.

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

If this cannot be reproduced on 6.19+,there is nothing to worry about.

Quoted 8 lines
Quoted 1 line

... except that 6.18 is LTS so we need a fix for that kernel version.

It's there: https://kernel.dance/#3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Quoted 2 lines

And maybe 6.12 as well (a373baed5a9d went into 6.9, so no need to go further back than that)

Not there (yet?) but it was tagged stable.

879bca0a2c4f (the commit fixed by 3b617fd3d317) went into 6.15, so if that's the problem then there's no need to backport 3b617fd3d317 to 6.12. Unless someone backported 879bca0a2c4f to 6.12 which they might have since it was a fix for a 2011 commit. But so far nobody seems to have done that, and since it's only a performance bug (right?), probably nobody will bother.

#8 lore raw
In reply to David Hildenbrand (Arm)
Quoted 2 lines · David Hildenbrand (Arm)

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

Unless there's a bug (and correct me if I'm misinterpreting), VMA merge requires vma->anon_vma to either be equal for merged adjacent VMAs, or one or the other VMA to have NULL vma->anon_vma, in which case we set vma->anon_vma in the merged VMA.

Thanks, Lorenzo

#9 lore raw
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · David Hildenbrand (Arm)

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

Unless there's a bug (and correct me if I'm misinterpreting), VMA merge requires vma->anon_vma to either be equal for merged adjacent VMAs, or one or the other VMA to have NULL vma->anon_vma, in which case we set vma->anon_vma in the merged VMA.

I think you didn't understand what I was trying to say.

The reporter claimed that it happened on 6.18. Nobody knows on which patch version (stable tree?).

I was wondering whether your fix

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

that went into 6.19 might have resolved this problem.

Your fix stated "allow an unfaulted/faulted merge with a VMA that has been forked", so I was wondering whether that could have resulted in a situation with anon folios without vma->anon_vma (losing vma->anon_vma during the merge).

But I am not sure if 879bca0a2c4f could have triggered that. Are you aware of other fixes that went into 6.19 that could have fixed such a scenario?

Signature · 3 lines
Cheers,

David
#10 lore raw
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · David Hildenbrand (Arm)

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

Unless there's a bug (and correct me if I'm misinterpreting), VMA merge requires vma->anon_vma to either be equal for merged adjacent VMAs, or one or the other VMA to have NULL vma->anon_vma, in which case we set vma->anon_vma in the merged VMA.

I think you didn't understand what I was trying to say.

Let me take more of a look then!

Quoted 6 lines

The reporter claimed that it happened on 6.18. Nobody knows on which patch version (stable tree?).

I was wondering whether your fix

Quoted 7 lines

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

that went into 6.19 might have resolved this problem.

Ahhh, no not that one (it affects merge of VMAs that have a CoW hierarchy which we shouldn't allow) but 61f67c230a5e actually could cause this.

Can see from https://kernel.dance/#61f67c230a5e it was backported to 6.18.7 I think.

ZhengYuan - can you try seeing if it repro's with/without that?

If you're testing literally at v6.18 in Linus's tree say and NOT on a stable tree, then that's your problem - you're essentially testing a known-buggy kernel (we always find stuff later and send to stable, just how it is).

Fundmentally the bug was that copy_vma() called vma_merge_new_range(), setting vmg->middle = NULL (becuase a new merge obviously can't be modifying an existing VMA).

But, uniquely among other merge cases, it merges based on a VMA not adjacent, and unlike an ordinary new merge, the duplicated VMA might have an anon_vma associated with it.

And the merge logic had no knowledge of a vma with a vma->anon_vma to even attempt to copy...

Therefore you _can_ end up with !vma->anon_vma there incorrectly after a merge.

I misremembered that because my fix was very focused on the direct consequence of this which was a UAF for folio->mapping (!!), but yeah !vma->anon_vma is also a consequence of that.

So yeah TL;DR it's very likely 61f67c230a5e that fixes this issue (was present from 6.16 - 6.18, backport to 6.18 because was only relevant stable kernel).

Quoted 5 lines

Your fix stated "allow an unfaulted/faulted merge with a VMA that has been forked", so I was wondering whether that could have resulted in a situation with anon folios without vma->anon_vma (losing vma->anon_vma during the merge).

Yeah sorry all this logic is very fiddly. That's about cases where the vma->anon_vma_chain size is > 1 i.e. where you are a child of a fork operation, i.e. one of the 'parent' or 'child' in [0].

[0]: https://ljs.io/anon_vma_example.png

If we allow merges for those, then we propagate lock contention across the whole of the merged VMA, because anon_vma locks are held across the entire fork hierarchy, so we intentionally disallow those.

My change accidentally undid that in this one specific mremap() case, and 3b617fd3d317 fixed that.

But 61f67c230a5e is the issue here I think!

Quoted 3 lines

But I am not sure if 879bca0a2c4f could have triggered that. Are you aware of other fixes that went into 6.19 that could have fixed such a scenario?

See above!

Quoted 5 lines

--
Cheers,

David

Cheers, Lorenzo

#11 lore raw
Quoted 33 lines · Lorenzo Stoakes
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · David Hildenbrand (Arm)

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

Unless there's a bug (and correct me if I'm misinterpreting), VMA merge requires vma->anon_vma to either be equal for merged adjacent VMAs, or one or the other VMA to have NULL vma->anon_vma, in which case we set vma->anon_vma in the merged VMA.

I think you didn't understand what I was trying to say.

Let me take more of a look then!

Quoted 6 lines

The reporter claimed that it happened on 6.18. Nobody knows on which patch version (stable tree?).

I was wondering whether your fix

Quoted 7 lines

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

that went into 6.19 might have resolved this problem.

Ahhh, no not that one (it affects merge of VMAs that have a CoW hierarchy which we shouldn't allow) but 61f67c230a5e actually could cause this.

Quoted 8 lines

Can see from https://kernel.dance/#61f67c230a5e it was backported to 6.18.7 I think.

ZhengYuan - can you try seeing if it repro's with/without that?

If you're testing literally at v6.18 in Linus's tree say and NOT on a stable tree, then that's your problem - you're essentially testing a known-buggy kernel (we always find stuff later and send to stable, just how it is).

I can reproduce the issue on 6.18.7, but I can no longer reproduce it on 6.18.8. So it does look like the problem has already been fixed by commit 61f67c230a5e.

Thanks everyone for the insights and pointers.

This issue was originally found by our fuzzing tool. Unfortunately, our reproducer generation is still a bit unreliable, so I cannot provide a standalone reproducer at the moment. However, given that the issue appears to be fixed, I suppose that is no longer strictly necessary.

Let me know if further testing is needed.

Thanks,
ZhengYuan Huang

#12 lore raw
Quoted 39 lines · ZhengYuan Huang
Quoted 38 lines · Lorenzo Stoakes
Quoted 11 lines · David Hildenbrand (Arm)
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · David Hildenbrand (Arm)

Maybe there was a scenario where we could have lost vma->anon_vma during a merge, resulting in a swapped page in an anon_vma.

Unless there's a bug (and correct me if I'm misinterpreting), VMA merge requires vma->anon_vma to either be equal for merged adjacent VMAs, or one or the other VMA to have NULL vma->anon_vma, in which case we set vma->anon_vma in the merged VMA.

I think you didn't understand what I was trying to say.

Let me take more of a look then!

Quoted 6 lines

The reporter claimed that it happened on 6.18. Nobody knows on which patch version (stable tree?).

I was wondering whether your fix

Quoted 7 lines

commit 3b617fd3d317bf9dd7e2c233e56eafef05734c9d

Author: Lorenzo Stoakes <[email protected]>
Date:   Mon Jan 5 20:11:49 2026 +0000

mm/vma: enforce VMA fork limit on unfaulted,faulted mremap merge too

that went into 6.19 might have resolved this problem.

Ahhh, no not that one (it affects merge of VMAs that have a CoW hierarchy which we shouldn't allow) but 61f67c230a5e actually could cause this.

Can see from https://kernel.dance/#61f67c230a5e it was backported to 6.18.7 I think.

ZhengYuan - can you try seeing if it repro's with/without that?

Quoted 8 lines
Quoted 3 lines

If you're testing literally at v6.18 in Linus's tree say and NOT on a stable tree, then that's your problem - you're essentially testing a known-buggy kernel (we always find stuff later and send to stable, just how it is).

I can reproduce the issue on 6.18.7, but I can no longer reproduce it on 6.18.8. So it does look like the problem has already been fixed by commit 61f67c230a5e.

Thanks everyone for the insights and pointers.

Pointers always makes me think of https://xkcd.com/138/ ;)

Thanks for reporting the issue, I'm glad that the fix has that handled (mea culpa for introducing the bug! :)

Quoted 8 lines

This issue was originally found by our fuzzing tool. Unfortunately, our reproducer generation is still a bit unreliable, so I cannot provide a standalone reproducer at the moment. However, given that the issue appears to be fixed, I suppose that is no longer strictly necessary.

Let me know if further testing is needed.

No that's fine, you've confirmed the expected revisions and really I think it has to be that fix that got it.

Quoted 3 lines

Thanks,
ZhengYuan Huang

Cheers, Lorenzo