Skip to content

Commit d484740

Browse files
committed
Merge: CVE-2025-37958 mm/huge_memory: fix dereferencing invalid pmd migration entry
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7001 JIRA: https://issues.redhat.com/browse/RHEL-96372 CVE: CVE-2025-37958 ``` When migrating a THP, concurrent access to the PMD migration entry during a deferred split scan can lead to an invalid address access, as illustrated below. To prevent this invalid access, it is necessary to check the PMD migration entry and return early. In this context, there is no need to use pmd_to_swp_entry and pfn_swap_entry_to_page to verify the equality of the target folio. Since the PMD migration entry is locked, it cannot be served as the target. ``` Signed-off-by: Rafael Aquini <raquini@redhat.com> Approved-by: Donald Dutile <ddutile@redhat.com> Approved-by: Luiz Capitulino <luizcap@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents c6f1ea1 + 29119a5 commit d484740

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

mm/huge_memory.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,7 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
23122312
{
23132313
spinlock_t *ptl;
23142314
struct mmu_notifier_range range;
2315+
bool pmd_migration;
23152316

23162317
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma->vm_mm,
23172318
address & HPAGE_PMD_MASK,
@@ -2326,13 +2327,13 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
23262327
VM_BUG_ON(freeze && !folio);
23272328
VM_WARN_ON_ONCE(folio && !folio_test_locked(folio));
23282329

2329-
if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) ||
2330-
is_pmd_migration_entry(*pmd)) {
2330+
pmd_migration = is_pmd_migration_entry(*pmd);
2331+
if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) || pmd_migration) {
23312332
/*
2332-
* It's safe to call pmd_page when folio is set because it's
2333-
* guaranteed that pmd is present.
2333+
* Do not apply pmd_folio() to a migration entry; and folio lock
2334+
* guarantees that it must be of the wrong folio anyway.
23342335
*/
2335-
if (folio && folio != page_folio(pmd_page(*pmd)))
2336+
if (folio && (pmd_migration || folio != page_folio(pmd_page(*pmd))))
23362337
goto out;
23372338
__split_huge_pmd_locked(vma, pmd, range.start, freeze);
23382339
}

0 commit comments

Comments
 (0)