All of lore.kernel.org
 help / color / mirror / Atom feed
* + mm-ksm-fix-pte_unmap_unlock-of-wrong-address-in-break_ksm_pmd_entry.patch added to mm-hotfixes-unstable branch
@ 2025-12-21  0:17 Andrew Morton
  0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2025-12-21  0:17 UTC (permalink / raw)
  To: mm-commits, xu.xin16, pedrodemargomes, david, chengming.zhou,
	sashal, akpm


The patch titled
     Subject: mm/ksm: fix pte_unmap_unlock of wrong address in break_ksm_pmd_entry
has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
     mm-ksm-fix-pte_unmap_unlock-of-wrong-address-in-break_ksm_pmd_entry.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-ksm-fix-pte_unmap_unlock-of-wrong-address-in-break_ksm_pmd_entry.patch

This patch will later appear in the mm-hotfixes-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Sasha Levin <sashal@kernel.org>
Subject: mm/ksm: fix pte_unmap_unlock of wrong address in break_ksm_pmd_entry
Date: Sat, 20 Dec 2025 15:29:26 -0500

On ARM32 with HIGHMEM/HIGHPTE, break_ksm_pmd_entry() triggers a BUG during
KSM unmerging because pte_unmap_unlock() is passed a pointer that may be
beyond the mapped PTE page.

The issue occurs when the PTE iteration loop completes without finding a
KSM page.  After the loop, 'ptep' has been incremented past the last PTE
entry.  On ARM32 LPAE with 512 PTEs per page (512 * 8 = 4096 bytes), this
means ptep points to the next page, outside the kmap'd region.

When pte_unmap_unlock(ptep, ptl) calls kunmap_local(ptep), it unmaps the
wrong page address, leaving the original kmap slot still mapped.  The next
kmap_local then finds this slot unexpectedly occupied:

  WARNING: mm/highmem.c:622 kunmap_local_indexed  (address mismatch)
  kernel BUG at mm/highmem.c:564  __kmap_local_pfn_prot  (slot not empty)

Fix this by passing start_ptep to pte_unmap_unlock(), which always points
within the originally mapped PTE page.

Reproducer: Run LTP ksm03 test on ARM32 with HIGHMEM enabled.  The test
triggers KSM merging followed by unmerging (writing 0 then 2 to
/sys/kernel/mm/ksm/run), which exercises break_ksm_pmd_entry().

Link: https://lkml.kernel.org/r/20251220202926.318366-1-sashal@kernel.org
Fixes: 5d4939fc2258 ("ksm: perform a range-walk in break_ksm")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Assisted-by: claude-opus-4-5-20251101
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: "David Hildenbrand (Red Hat)" <david@kernel.org>
Cc: Pedro Demarchi Gomes <pedrodemargomes@gmail.com>
Cc: xu xin <xu.xin16@zte.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/ksm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/mm/ksm.c~mm-ksm-fix-pte_unmap_unlock-of-wrong-address-in-break_ksm_pmd_entry
+++ a/mm/ksm.c
@@ -650,7 +650,7 @@ static int break_ksm_pmd_entry(pmd_t *pm
 		}
 	}
 out_unlock:
-	pte_unmap_unlock(ptep, ptl);
+	pte_unmap_unlock(start_ptep, ptl);
 	return found;
 }
 
_

Patches currently in -mm which might be from sashal@kernel.org are

mm-ksm-fix-pte_unmap_unlock-of-wrong-address-in-break_ksm_pmd_entry.patch


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-12-21  0:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-21  0:17 + mm-ksm-fix-pte_unmap_unlock-of-wrong-address-in-break_ksm_pmd_entry.patch added to mm-hotfixes-unstable branch Andrew Morton

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.