From: Andrew Morton <akpm@linux-foundation.org>
To: Vernon Yang <vernon2gm@gmail.com>
Cc: david@kernel.org, ljs@kernel.org, nico.pache@linux.dev,
ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org,
lance.yang@linux.dev, usama.arif@linux.dev, zokeefe@google.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
stable@vger.kernel.org, Vernon Yang <yanglincheng@kylinos.cn>
Subject: Re: [PATCH v5 0/3] mm: khugepaged: fix tracepoint UAF
Date: Tue, 8 Sep 2026 23:58:36 -0700 [thread overview]
Message-ID: <20260908235836.43865421771074b81eadd127@linux-foundation.org> (raw)
In-Reply-To: <20260909025804.3233645-1-vernon2gm@gmail.com>
On Wed, 9 Sep 2026 10:58:00 +0800 Vernon Yang <vernon2gm@gmail.com> wrote:
> From: Vernon Yang <yanglincheng@kylinos.cn>
>
> The khugepaged tracepoints take a folio pointer and call folio_pfn(),
> but by then the folio may no longer be valid: freed after folio_put(),
> folio_unlock() or pte_unmap_unlock(), or not a folio at all but an
> xarray-encoded swap entry. On classic SPARSEMEM, dereferencing it oopses
> khugepaged as soon as the trace event is enabled; on other memory models
> it merely prints a bogus pfn.
>
> Pass the pfn to the tracepoints directly, captured while the folio is
> still pinned, closing the use-after-free windows in
> mm_khugepaged_scan_file(), mm_khugepaged_scan_pmd() and
> mm_khugepaged_collapse_file().
Thanks, I've updated mm.git to this version.
> V4 -> V5:
> - Use a single trace statement.
> - Collect Acked-by.
Here's how v5 altered mm.git:
mm/khugepaged.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
--- a/mm/khugepaged.c~b
+++ a/mm/khugepaged.c
@@ -1790,13 +1790,10 @@ out_unmap:
unmapped, cc, enabled_orders);
/* mmap_lock was released above, set lock_dropped */
*lock_dropped = true;
- trace_mm_khugepaged_scan_pmd(mm, -1, referenced, none_or_zero,
- SCAN_SUCCEED, unmapped);
- } else {
-out:
- trace_mm_khugepaged_scan_pmd(mm, failed_pfn, referenced,
- none_or_zero, result, unmapped);
}
+out:
+ trace_mm_khugepaged_scan_pmd(mm, failed_pfn, referenced,
+ none_or_zero, result, unmapped);
return result;
}
@@ -2789,13 +2786,9 @@ static enum scan_result collapse_scan_fi
} else {
result = collapse_file(mm, addr, file, start, cc);
}
- trace_mm_khugepaged_scan_file(mm, -1, file, present, swap,
- SCAN_SUCCEED);
- } else {
- trace_mm_khugepaged_scan_file(mm, failed_pfn, file, present,
- swap, result);
}
+ trace_mm_khugepaged_scan_file(mm, failed_pfn, file, present, swap, result);
return result;
}
_
prev parent reply other threads:[~2026-09-09 6:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 2:58 [PATCH v5 0/3] mm: khugepaged: fix tracepoint UAF Vernon Yang
2026-09-09 2:58 ` [PATCH v5 1/3] mm: khugepaged: fix swap entry value to folio_pfn() Vernon Yang
2026-09-09 2:58 ` [PATCH v5 2/3] mm: khugepaged: fix folio is used after pte_unmap_unlock() Vernon Yang
2026-09-09 2:58 ` [PATCH v5 3/3] mm: khugepaged: fix folio is used after folio_put/unlock() Vernon Yang
2026-09-09 6:58 ` Andrew Morton [this message]
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=20260908235836.43865421771074b81eadd127@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=nico.pache@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=usama.arif@linux.dev \
--cc=vernon2gm@gmail.com \
--cc=yanglincheng@kylinos.cn \
--cc=zokeefe@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.