From: "Zhao Gongyi" <zhaogongyi@bytedance.com>
To: <xu.xin@linux.dev>
Cc: <aarcange@redhat.com>, <akpm@linux-foundation.org>,
<chengming.zhou@linux.dev>, <david@kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<riel@redhat.com>
Subject: Re: [PATCH] mm/ksm: avoid anon_vma UAF during page merging
Date: Mon, 2 Nov 2026 19:14:04 +0800 [thread overview]
Message-ID: <b208b102-81b6-4e39-9be3-202fc0519e07@bytedance.com> (raw)
In-Reply-To: <20261102101831.218090-1-xu.xin@linux.dev>
Hi Xu,
Thanks for the review.
On 11/2/26 6:18 PM, xu.xin@linux.dev wrote:
>
> I’d like to ask whether this issue is easy to reproduce on 6.18 since
> I suspect the accuracy of the “fixes” tag in the commit description.
>
> Besides, adding an extra folio_test_ksm() check is unneeded, see reasons below.
>
I reproduced the issue twice on v6.18
(7d0a66e4bb90, CONFIG_KSM=y, CONFIG_KASAN=y and
CONFIG_KASAN_GENERIC=y).
The exact invocation from my previous email:
/tmp/ksm_fixed_pool_static 4 2048 1 100000 64
reproduced the issue after about 220 seconds:
BUG: KASAN: slab-use-after-free in page_address_in_vma+0x292/0x2b0
Read of size 8 by task ksmd
page_address_in_vma
write_protect_page
try_to_merge_one_page
try_to_merge_with_ksm_page
ksm_scan_thread
The corresponding free path included:
__put_anon_vma
unlink_anon_vmas
...
mremap_to
do_mremap
A second run with 4096 slots reproduced the same UAF after about
142 seconds. This confirms that the issue is present in v6.18.
I also rechecked the Fixes tag. Before 21d0d443cdc1
("rmap: resurrect page_address_in_vma anon_vma check"), the anonymous
page path in page_address_in_vma() computed the address without
dereferencing the page-side anon_vma. That commit added the comparison
between vma->anon_vma->root and page_anon_vma(page)->root.
At that time, the KSM scan path already retained a page reference,
dropped mmap_sem, and later called page_address_in_vma() from
write_protect_page() or replace_page(). The page reference does not
pin the page-side anon_vma.
Commit 4829b906cc06 ("ksm: fix page_address_in_vma anon_vma oops")
added a NULL check, but the helper still dereferences the anon_vma
when it is non-NULL but stale.
MREMAP_DONTUNMAP, especially commit 1583aa278f5f
("mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP
success"), makes this race easy to reproduce and explains the
unlink_anon_vmas() free path. However, it did not introduce the
unpinned anon_vma dereference that this patch removes. Based on that,
I think 21d0d443cdc1 remains the earliest appropriate Fixes commit.
Please let me know if I am missing a lifetime guarantee that made the
dereference safe before the MREMAP_DONTUNMAP changes.
You are also right that the folio_test_ksm() check is unnecessary.
cmp_and_merge_page() already checks folio_stable_node(), and a KSM
fork page that continues through this path is handled by the
page == kpage check in try_to_merge_one_page(). I will drop that hunk
and the corresponding commit-message text in v2.
Thanks,
Gongyi
next prev parent reply other threads:[~2026-11-02 11:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 18:22 Zhao Gongyi
2026-11-01 18:11 ` David Hildenbrand (Arm)
2026-11-02 3:32 ` Zhao Gongyi
2026-11-02 11:23 ` Lorenzo Stoakes (ARM)
2026-11-02 10:18 ` xu.xin
2026-11-02 11:14 ` Zhao Gongyi [this message]
2026-11-02 12:14 ` Lorenzo Stoakes (ARM)
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=b208b102-81b6-4e39-9be3-202fc0519e07@bytedance.com \
--to=zhaogongyi@bytedance.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@redhat.com \
--cc=xu.xin@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
all inboxes | Powered by JetHome®