Skip to content

Commit 47fa301

Browse files
davidhildenbrandakpm00
authored andcommitted
mm/huge_memory: check pmd_special() only after pmd_present()
We should only check for pmd_special() after we made sure that we have a present PMD. For example, if we have a migration PMD, pmd_special() might indicate that we have a special PMD although we really don't. This fixes confusing migration entries as PFN mappings, and not doing what we are supposed to do in the "is_swap_pmd()" case further down in the function -- including messing up COW, page table handling and accounting. Link: https://lkml.kernel.org/r/20240926154234.2247217-1-david@redhat.com Fixes: bc02afb ("mm/fork: accept huge pfnmap entries") Signed-off-by: David Hildenbrand <david@redhat.com> Reported-by: syzbot+bf2c35fa302ebe3c7471@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/66f15c8d.050a0220.c23dd.000f.GAE@google.com/ Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 0665d7a commit 47fa301

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

mm/huge_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm,
15861586
int ret = -ENOMEM;
15871587

15881588
pmd = pmdp_get_lockless(src_pmd);
1589-
if (unlikely(pmd_special(pmd))) {
1589+
if (unlikely(pmd_present(pmd) && pmd_special(pmd))) {
15901590
dst_ptl = pmd_lock(dst_mm, dst_pmd);
15911591
src_ptl = pmd_lockptr(src_mm, src_pmd);
15921592
spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);

0 commit comments

Comments
 (0)