linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mm/madvise: Always set ptes via arch helpers
@ 2025-03-07 12:33 Ryan Roberts
  2025-03-07 13:04 ` Lorenzo Stoakes
  0 siblings, 1 reply; 9+ messages in thread
From: Ryan Roberts @ 2025-03-07 12:33 UTC (permalink / raw)
  To: Andrew Morton, Lorenzo Stoakes
  Cc: Ryan Roberts, linux-mm, linux-kernel, stable

Instead of writing a pte directly into the table, use the set_pte_at()
helper, which gives the arch visibility of the change.

In this instance we are guaranteed that the pte was originally none and
is being modified to a not-present pte, so there was unlikely to be a
bug in practice (at least not on arm64). But it's bad practice to write
the page table memory directly without arch involvement.

Cc: <stable@vger.kernel.org>
Fixes: 662df3e5c376 ("mm: madvise: implement lightweight guard page mechanism")
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
 mm/madvise.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 388dc289b5d1..6170f4acc14f 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1101,7 +1101,7 @@ static int guard_install_set_pte(unsigned long addr, unsigned long next,
 	unsigned long *nr_pages = (unsigned long *)walk->private;

 	/* Simply install a PTE marker, this causes segfault on access. */
-	*ptep = make_pte_marker(PTE_MARKER_GUARD);
+	set_pte_at(walk->mm, addr, ptep, make_pte_marker(PTE_MARKER_GUARD));
 	(*nr_pages)++;

 	return 0;
--
2.43.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-03-07 18:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-07 12:33 [PATCH v1] mm/madvise: Always set ptes via arch helpers Ryan Roberts
2025-03-07 13:04 ` Lorenzo Stoakes
2025-03-07 13:42   ` Ryan Roberts
2025-03-07 13:59     ` Lorenzo Stoakes
2025-03-07 14:35       ` Ryan Roberts
2025-03-07 14:55         ` Lorenzo Stoakes
2025-03-07 15:57           ` Ryan Roberts
2025-03-07 17:43           ` David Hildenbrand
2025-03-07 18:04             ` Lorenzo Stoakes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox