Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] mm/hmm: refuse secretmem VMAs in hmm_range_fault()
@ 2026-11-29  8:47 David Hildenbrand (Arm)
  2026-11-29 16:01 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-29  8:47 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky, Andrew Morton, Mike Rapoport,
	James Bottomley, Hagen Paul Pfeifer
  Cc: linux-mm, Chris Mason, stable, David Hildenbrand (Arm)

From: Chris Mason <mason@kernel.org>

secretmem folios are removed from the directmap. GUP refuses secretmem
VMAs for that reason, but hmm_range_fault() hands out secretmem folios
to drivers.

Consequently, drivers that are not aware of this might access these
folios through the directmap, resulting in a kernel page fault. For
example, the rxe ODP code accesses the folios through kmap_local_page()
when copying data or performing atomic operations on a memory region.

Let's fix it by refusing secretmem VMAs in hmm_range_fault(), just like
GUP does.

This has low urgency, as it requires registering secretmem with a driver
that uses hmm_range_fault(), such as rxe ODP.

Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ david: adjust description and comment ]
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
On top of akpm/mm-unstable.
---
 mm/hmm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/hmm.c b/mm/hmm.c
index 6b9def3c06879..12e2033604d27 100644
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -28,6 +28,7 @@
 #include <linux/pci-p2pdma.h>
 #include <linux/mmu_notifier.h>
 #include <linux/memory_hotplug.h>
+#include <linux/secretmem.h>
 
 #include "internal.h"
 
@@ -598,7 +599,7 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,
 
 	if (!vma_test_any(vma, VMA_IO_BIT, VMA_PFNMAP_BIT) &&
 	    !vma_test_single_mask(vma, VMA_SHADOW_STACK) &&
-	    vma_test(vma, VMA_READ_BIT))
+	    !vma_is_secretmem(vma) && vma_test(vma, VMA_READ_BIT))
 		return 0;
 
 	/*
@@ -611,6 +612,9 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,
 	 *
 	 * Devices must not gain ordinary write access to shadow stacks.
 	 *
+	 * secretmem folios have no directmap and drivers are not aware of
+	 * that; refuse such mappings, just like GUP does.
+	 *
 	 * If a fault is requested for an unsupported range then it is a hard
 	 * failure.
 	 */

---
base-commit: c5941b1abeffba401f7f9cbc8c4f0c5da75dcba5
change-id: 20261129-hmm_secretmem-383cc374615b

Best regards,
--  
David Hildenbrand (Arm) <david@kernel.org>


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

* Re: [PATCH] mm/hmm: refuse secretmem VMAs in hmm_range_fault()
  2026-11-29  8:47 [PATCH] mm/hmm: refuse secretmem VMAs in hmm_range_fault() David Hildenbrand (Arm)
@ 2026-11-29 16:01 ` Mike Rapoport
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Rapoport @ 2026-11-29 16:01 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: Jason Gunthorpe, Leon Romanovsky, Andrew Morton, James Bottomley,
	Hagen Paul Pfeifer, linux-mm, Chris Mason, stable

On Sun, Nov 29, 2026 at 09:47:02AM +0100, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@kernel.org>
> 
> secretmem folios are removed from the directmap. GUP refuses secretmem

Nit: usually direct map is two words :)

> VMAs for that reason, but hmm_range_fault() hands out secretmem folios
> to drivers.
> 
> Consequently, drivers that are not aware of this might access these
> folios through the directmap, resulting in a kernel page fault. For
> example, the rxe ODP code accesses the folios through kmap_local_page()
> when copying data or performing atomic operations on a memory region.
> 
> Let's fix it by refusing secretmem VMAs in hmm_range_fault(), just like
> GUP does.
> 
> This has low urgency, as it requires registering secretmem with a driver
> that uses hmm_range_fault(), such as rxe ODP.
> 
> Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chris Mason <mason@kernel.org>
> [ david: adjust description and comment ]
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> ---
> On top of akpm/mm-unstable.
>
> @@ -611,6 +612,9 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end,
>  	 *
>  	 * Devices must not gain ordinary write access to shadow stacks.
>  	 *
> +	 * secretmem folios have no directmap and drivers are not aware of

Ditto.

I believe Andrew can fix it up while applying.

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> +	 * that; refuse such mappings, just like GUP does.
> +	 *
>  	 * If a fault is requested for an unsupported range then it is a hard
>  	 * failure.
>  	 */

-- 
Sincerely yours,
Mike.

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

end of thread, other threads:[~2026-11-29 16:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  8:47 [PATCH] mm/hmm: refuse secretmem VMAs in hmm_range_fault() David Hildenbrand (Arm)
2026-11-29 16:01 ` Mike Rapoport

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