Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9176B47CA8F; Thu, 20 Aug 2026 17:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787248558; cv=none; b=A+C6S+YMb2OTkpH0Tqk2he4yF5/AiwVyk3Wuh3CwGG/tvoa49aeThMUQ5DmmfhhGExOhtv7/wKQBRqgnnHxwQCr3pmxcgxYNJ99iva5NyPQhQZ8lAA1j/lHK45HunEYsehYzDkcVWSvGFVtPUoE1xnCFS4i5uCIE2R64AU37vxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787248558; c=relaxed/simple; bh=jN3Rgku3w4q9Py99QRjexQNCVBkNEc8GgAJq1T2il0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AVIAlDyDnuLI1Ckb4TgbVmrEiiT4kPDcGBFSItMMCWGHVVfLCjhvdMQAJPID9lPT26wrHQvhWHAT0GC6WVZPzKjD50JajFq6yM3EhLyuyOgHdY88F8Xxv/z9vJrFwAq3AuRgnr4au7fXD89XoLHRPNwKKFfXO851ojFys9D0/VY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=E2KvPQtd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="E2KvPQtd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9DF31F000E9; Thu, 20 Aug 2026 17:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787248557; bh=T10LUAsH1z5achciwcQIei2hs58jJ3U2m5+q+CLu7t8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E2KvPQtdyFN3f2PW2ZzAUtwYWy/CsD49t/1sSJFPk9UbT/7kvv4VEH5FjZZvDtpzu CCXcPIZLjngYYQy7ONQ2F6qUUzEFSsvdpy8IFPgAk27FGUSWNcfJggJJT2PKMBhY0I Y4X/L1ipAfpA+o5URtqC1lxFml2rvU951XeoFha0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kefeng Wang , Balbir Singh , Zi Yan , Alistair Popple , Byungchul Park , David Hildenbrand , Gregory Price , "Huang, Ying" , Joshua Hahn , Matthew Brost , Rakie Kim , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 232/303] mm: migrate_device: fix pte_pfn/pte_dirty called on non-present PTE Date: Thu, 20 Aug 2026 16:56:08 +0200 Message-ID: <20260820145300.422196503@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145253.200766705@linuxfoundation.org> References: <20260820145253.200766705@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kefeng Wang [ Upstream commit 63867c82d0c0c2d182016a32b1cc0103116b0ea5 ] pte_pfn() and pte_dirty() have undefined behaviour when called on a non-present PTE. In migrate_vma_collect_pmd(), these functions may be invoked on non-present entries (e.g., device-private entries), leading to potential crashes from pte_pfn() or incorrect dirty folio accounting from pte_dirty(). Fix both by guarding with pte_present() checks. Link: https://lore.kernel.org/20260708003955.4024340-1-wangkefeng.wang@huawei.com Link: https://lore.kernel.org/20260706111958.3649651-1-wangkefeng.wang@huawei.com Fixes: fd35ca3d12cc ("mm/migrate_device.c: copy pte dirty bit to page") Fixes: 6c287605fd56 ("mm: remember exclusively mapped anonymous pages with PG_anon_exclusive") Signed-off-by: Kefeng Wang Reviewed-by: Balbir Singh Acked-by: Zi Yan Cc: Alistair Popple Cc: Byungchul Park Cc: David Hildenbrand Cc: Gregory Price Cc: "Huang, Ying" Cc: Joshua Hahn Cc: Matthew Brost Cc: Rakie Kim Cc: Ying Huang Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- mm/migrate_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -203,7 +203,8 @@ again: bool anon_exclusive; pte_t swp_pte; - flush_cache_page(vma, addr, pte_pfn(pte)); + if (pte_present(pte)) + flush_cache_page(vma, addr, pte_pfn(pte)); anon_exclusive = folio_test_anon(folio) && PageAnonExclusive(page); if (anon_exclusive) { @@ -223,7 +224,7 @@ again: migrate->cpages++; /* Set the dirty flag on the folio now the pte is gone. */ - if (pte_dirty(pte)) + if (pte_present(pte) && pte_dirty(pte)) folio_mark_dirty(folio); /* Setup special migration page table entry */