The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs
@ 2026-11-12 17:38 Lorenzo Stoakes (ARM)
  2026-11-12 20:59 ` Liam R. Howlett
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-12 17:38 UTC (permalink / raw)
  To: Andrew Morton, Liam R. Howlett, David Hildenbrand,
	Vlastimil Babka, Jann Horn, Mike Rapoport, Suren Baghdasaryan,
	Michal Hocko, Shuah Khan
  Cc: linux-mm, linux-kernel, linux-kselftest, ljs, Tal Zussman, stable

In order to establish guard regions, guard markers are installed in the
page tables of a mapped VMA.

However, problems arise when one tries to combine this with registering a
VMA for userfaultfd, as such operations may themselves need to install page
table markers such as uffd-wp.

When this installation is attempted the guard marker prevents these markers
being applied, which can lead to unexpected results (especially if the
guard regions are later removed.)

This is especially problematic because guard region installation causes the
regions to be zapped first, meaning that the removal of userfaultfd-tracked
ranges will not be logged in this case.

Therefore, disallow this.

This makes sense as conceptually, guard regions mark a part of a VMA as
effectively unmapped at the page table level, and removing the markers is
like mapping the VMA again, over which operation uffd markers would in any
case be lost.

Only check for this on installation, as a VMA can be registered for
userfaultfd after guard regions are established.

In this case, the guard regions cannot have new markers installed, and no
faults can occur in the guard regions, until they are removed, at which
point everything should function normally.

A survey of open source users indicates nobody is relying on installing
guard regions in uffd-armed VMAs. Software including glibc, android,
tcmalloc and CRIU were checked.

Fix the selftest to reflect the change.

Fixes: 662df3e5c376 ("mm: madvise: implement lightweight guard page mechanism")
Reported-by: Tal Zussman <tz2294@columbia.edu>
Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-9-00713d368976@columbia.edu/
Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-10-00713d368976@columbia.edu/
Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-11-00713d368976@columbia.edu/
Cc: stable@vger.kernel.org
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
 mm/madvise.c                               |  4 ++++
 tools/testing/selftests/mm/guard-regions.c | 12 ++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 0214efd2a014..268731e90f12 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1156,6 +1156,10 @@ static long madvise_guard_install(struct madvise_behavior *madv_behavior)
 	if (!is_valid_guard_vma(vma, /* allow_locked = */false))
 		return -EINVAL;
 
+	/* Guard markers are incompatible with UFFD markers. */
+	if (userfaultfd_armed(vma))
+		return -EINVAL;
+
 	/*
 	 * Set atomically under read lock. All pertinent readers will need to
 	 * acquire an mmap/VMA write lock to read it. All remaining readers may
diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
index 02f69244f9a4..97da54dcf3a4 100644
--- a/tools/testing/selftests/mm/guard-regions.c
+++ b/tools/testing/selftests/mm/guard-regions.c
@@ -1476,7 +1476,7 @@ TEST_F(guard_regions, cold_pageout)
 	ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
 }
 
-/* Ensure that guard pages do not break userfaultd. */
+/* Ensure that guard regions cannot be installed in uffd-armed VMAs. */
 TEST_F(guard_regions, uffd)
 {
 	const unsigned long page_size = self->page_size;
@@ -1526,10 +1526,15 @@ TEST_F(guard_regions, uffd)
 	reg.mode = UFFDIO_REGISTER_MODE_MISSING;
 	ASSERT_EQ(ioctl(uffd, UFFDIO_REGISTER, &reg), 0);
 
-	/* Guard the range. This should not trigger the uffd. */
+	/* Now try to guard, should fail with EINVAL. */
+	ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), -1);
+	ASSERT_EQ(errno, EINVAL);
+
+	/* Once unregistered, we should be able to guard the range. */
+	ASSERT_EQ(ioctl(uffd, UFFDIO_UNREGISTER, &range), 0);
 	ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), 0);
 
-	/* The guarding should behave as usual with no uffd intervention. */
+	/* The guarding should behave as usual. */
 	for (i = 0; i < 10; i++) {
 		char *curr = &ptr[i * page_size];
 
@@ -1537,7 +1542,6 @@ TEST_F(guard_regions, uffd)
 	}
 
 	/* Cleanup. */
-	ASSERT_EQ(ioctl(uffd, UFFDIO_UNREGISTER, &range), 0);
 	close(uffd);
 	ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
 }

---
base-commit: 4318887a3efa4c53d6f083ccfd7105b809a3ac65
change-id: 20261112-disallow-uffd-guard-install-a5294129ad7b

Cheers,
-- 
Lorenzo Stoakes (ARM) <ljs@kernel.org>


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

* Re: [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs
  2026-11-12 17:38 [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs Lorenzo Stoakes (ARM)
@ 2026-11-12 20:59 ` Liam R. Howlett
  2026-11-12 23:59 ` David Hildenbrand (Arm)
  2026-11-13  8:58 ` Vlastimil Babka (SUSE)
  2 siblings, 0 replies; 5+ messages in thread
From: Liam R. Howlett @ 2026-11-12 20:59 UTC (permalink / raw)
  To: Lorenzo Stoakes (ARM)
  Cc: Andrew Morton, David Hildenbrand, Vlastimil Babka, Jann Horn,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
	linux-mm, linux-kernel, linux-kselftest, Tal Zussman, stable

On 26/11/12 05:38PM, Lorenzo Stoakes (ARM) wrote:
> In order to establish guard regions, guard markers are installed in the
> page tables of a mapped VMA.
> 
> However, problems arise when one tries to combine this with registering a
> VMA for userfaultfd, as such operations may themselves need to install page
> table markers such as uffd-wp.
> 
> When this installation is attempted the guard marker prevents these markers
> being applied, which can lead to unexpected results (especially if the
> guard regions are later removed.)
> 
> This is especially problematic because guard region installation causes the
> regions to be zapped first, meaning that the removal of userfaultfd-tracked
> ranges will not be logged in this case.
> 
> Therefore, disallow this.
> 
> This makes sense as conceptually, guard regions mark a part of a VMA as
> effectively unmapped at the page table level, and removing the markers is
> like mapping the VMA again, over which operation uffd markers would in any
> case be lost.
> 
> Only check for this on installation, as a VMA can be registered for
> userfaultfd after guard regions are established.
> 
> In this case, the guard regions cannot have new markers installed, and no
> faults can occur in the guard regions, until they are removed, at which
> point everything should function normally.
> 
> A survey of open source users indicates nobody is relying on installing
> guard regions in uffd-armed VMAs. Software including glibc, android,
> tcmalloc and CRIU were checked.
> 
> Fix the selftest to reflect the change.
> 
> Fixes: 662df3e5c376 ("mm: madvise: implement lightweight guard page mechanism")
> Reported-by: Tal Zussman <tz2294@columbia.edu>
> Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-9-00713d368976@columbia.edu/
> Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-10-00713d368976@columbia.edu/
> Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-11-00713d368976@columbia.edu/
> Cc: stable@vger.kernel.org
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

Reviewed-by: Liam R. Howlett (Google) <liam@infradead.org>

> ---
>  mm/madvise.c                               |  4 ++++
>  tools/testing/selftests/mm/guard-regions.c | 12 ++++++++----
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 0214efd2a014..268731e90f12 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -1156,6 +1156,10 @@ static long madvise_guard_install(struct madvise_behavior *madv_behavior)
>  	if (!is_valid_guard_vma(vma, /* allow_locked = */false))
>  		return -EINVAL;
>  
> +	/* Guard markers are incompatible with UFFD markers. */
> +	if (userfaultfd_armed(vma))
> +		return -EINVAL;
> +
>  	/*
>  	 * Set atomically under read lock. All pertinent readers will need to
>  	 * acquire an mmap/VMA write lock to read it. All remaining readers may
> diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
> index 02f69244f9a4..97da54dcf3a4 100644
> --- a/tools/testing/selftests/mm/guard-regions.c
> +++ b/tools/testing/selftests/mm/guard-regions.c
> @@ -1476,7 +1476,7 @@ TEST_F(guard_regions, cold_pageout)
>  	ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
>  }
>  
> -/* Ensure that guard pages do not break userfaultd. */
> +/* Ensure that guard regions cannot be installed in uffd-armed VMAs. */
>  TEST_F(guard_regions, uffd)
>  {
>  	const unsigned long page_size = self->page_size;
> @@ -1526,10 +1526,15 @@ TEST_F(guard_regions, uffd)
>  	reg.mode = UFFDIO_REGISTER_MODE_MISSING;
>  	ASSERT_EQ(ioctl(uffd, UFFDIO_REGISTER, &reg), 0);
>  
> -	/* Guard the range. This should not trigger the uffd. */
> +	/* Now try to guard, should fail with EINVAL. */
> +	ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), -1);
> +	ASSERT_EQ(errno, EINVAL);
> +
> +	/* Once unregistered, we should be able to guard the range. */
> +	ASSERT_EQ(ioctl(uffd, UFFDIO_UNREGISTER, &range), 0);
>  	ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), 0);
>  
> -	/* The guarding should behave as usual with no uffd intervention. */
> +	/* The guarding should behave as usual. */
>  	for (i = 0; i < 10; i++) {
>  		char *curr = &ptr[i * page_size];
>  
> @@ -1537,7 +1542,6 @@ TEST_F(guard_regions, uffd)
>  	}
>  
>  	/* Cleanup. */
> -	ASSERT_EQ(ioctl(uffd, UFFDIO_UNREGISTER, &range), 0);
>  	close(uffd);
>  	ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
>  }
> 
> ---
> base-commit: 4318887a3efa4c53d6f083ccfd7105b809a3ac65
> change-id: 20261112-disallow-uffd-guard-install-a5294129ad7b
> 
> Cheers,
> -- 
> Lorenzo Stoakes (ARM) <ljs@kernel.org>
> 

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

* Re: [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs
  2026-11-12 17:38 [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs Lorenzo Stoakes (ARM)
  2026-11-12 20:59 ` Liam R. Howlett
@ 2026-11-12 23:59 ` David Hildenbrand (Arm)
  2026-11-13 13:59   ` Lorenzo Stoakes (ARM)
  2026-11-13  8:58 ` Vlastimil Babka (SUSE)
  2 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-12 23:59 UTC (permalink / raw)
  To: Lorenzo Stoakes (ARM), Andrew Morton, Liam R. Howlett,
	Vlastimil Babka, Jann Horn, Mike Rapoport, Suren Baghdasaryan,
	Michal Hocko, Shuah Khan
  Cc: linux-mm, linux-kernel, linux-kselftest, Tal Zussman, stable

On 11/12/26 18:38, Lorenzo Stoakes (ARM) wrote:
> In order to establish guard regions, guard markers are installed in the
> page tables of a mapped VMA.
> 
> However, problems arise when one tries to combine this with registering a
> VMA for userfaultfd, as such operations may themselves need to install page
> table markers such as uffd-wp.

How does this interact with UFFDIO_POISON markers that can outlive even
userfaultfd registration?

I'd assume it's just the same thing, just like having proper hwpoison marker in
anon mappings, so it just works (uffd-wp will skip, guard installation will zap).

> 
> When this installation is attempted the guard marker prevents these markers
> being applied, which can lead to unexpected results (especially if the
> guard regions are later removed.)
> 
> This is especially problematic because guard region installation causes the
> regions to be zapped first, meaning that the removal of userfaultfd-tracked
> ranges will not be logged in this case.

Again, similar to trying to uffd-wp-protect'ing a hwpoison marker (which will be
ignored), and then zapping that.

Isn't guard marker installation/removal just another form of zapping?

So to me this all sounds like "if user space does something stupid, it's user
space's fault".

> 
> Therefore, disallow this.
> 
> This makes sense as conceptually, guard regions mark a part of a VMA as
> effectively unmapped at the page table level, and removing the markers is
> like mapping the VMA again, over which operation uffd markers would in any
> case be lost.

Right, but that to me just says "on the parts of the VMA where you mess with
guard markers, your uffd-wp protection is similarly ignored".

So disallowing it entirely for a VMA, I am not sure. I could see use cases for
that, although you might argue that user space should then register uffd-wp on
the separate pieces. But then you get multiple VMAs again.


-- 
Cheers,

David

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

* Re: [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs
  2026-11-12 17:38 [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs Lorenzo Stoakes (ARM)
  2026-11-12 20:59 ` Liam R. Howlett
  2026-11-12 23:59 ` David Hildenbrand (Arm)
@ 2026-11-13  8:58 ` Vlastimil Babka (SUSE)
  2 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-11-13  8:58 UTC (permalink / raw)
  To: Lorenzo Stoakes (ARM), Andrew Morton, Liam R. Howlett,
	David Hildenbrand, Jann Horn, Mike Rapoport, Suren Baghdasaryan,
	Michal Hocko, Shuah Khan
  Cc: linux-mm, linux-kernel, linux-kselftest, Tal Zussman, stable

On 11/12/26 18:38, Lorenzo Stoakes (ARM) wrote:
> In order to establish guard regions, guard markers are installed in the
> page tables of a mapped VMA.
> 
> However, problems arise when one tries to combine this with registering a
> VMA for userfaultfd, as such operations may themselves need to install page
> table markers such as uffd-wp.
> 
> When this installation is attempted the guard marker prevents these markers
> being applied, which can lead to unexpected results (especially if the
> guard regions are later removed.)
> 
> This is especially problematic because guard region installation causes the
> regions to be zapped first, meaning that the removal of userfaultfd-tracked
> ranges will not be logged in this case.
> 
> Therefore, disallow this.
> 
> This makes sense as conceptually, guard regions mark a part of a VMA as
> effectively unmapped at the page table level, and removing the markers is
> like mapping the VMA again, over which operation uffd markers would in any
> case be lost.
> 
> Only check for this on installation, as a VMA can be registered for
> userfaultfd after guard regions are established.
> 
> In this case, the guard regions cannot have new markers installed, and no
> faults can occur in the guard regions, until they are removed, at which
> point everything should function normally.

So IIUC this means the other order of operations (first guard regions, then
uffd) already prevents the two co-existing. Makes sense to prevent the same
in the order of uffd and then guard regions then.

> A survey of open source users indicates nobody is relying on installing
> guard regions in uffd-armed VMAs. Software including glibc, android,
> tcmalloc and CRIU were checked.
> 
> Fix the selftest to reflect the change.
> 
> Fixes: 662df3e5c376 ("mm: madvise: implement lightweight guard page mechanism")
> Reported-by: Tal Zussman <tz2294@columbia.edu>
> Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-9-00713d368976@columbia.edu/
> Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-10-00713d368976@columbia.edu/
> Closes: https://lore.kernel.org/all/20261111-uffd-state-fixes-v1-11-00713d368976@columbia.edu/
> Cc: stable@vger.kernel.org
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

> ---
>  mm/madvise.c                               |  4 ++++
>  tools/testing/selftests/mm/guard-regions.c | 12 ++++++++----
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 0214efd2a014..268731e90f12 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -1156,6 +1156,10 @@ static long madvise_guard_install(struct madvise_behavior *madv_behavior)
>  	if (!is_valid_guard_vma(vma, /* allow_locked = */false))
>  		return -EINVAL;
>  
> +	/* Guard markers are incompatible with UFFD markers. */
> +	if (userfaultfd_armed(vma))
> +		return -EINVAL;
> +
>  	/*
>  	 * Set atomically under read lock. All pertinent readers will need to
>  	 * acquire an mmap/VMA write lock to read it. All remaining readers may
> diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/selftests/mm/guard-regions.c
> index 02f69244f9a4..97da54dcf3a4 100644
> --- a/tools/testing/selftests/mm/guard-regions.c
> +++ b/tools/testing/selftests/mm/guard-regions.c
> @@ -1476,7 +1476,7 @@ TEST_F(guard_regions, cold_pageout)
>  	ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
>  }
>  
> -/* Ensure that guard pages do not break userfaultd. */
> +/* Ensure that guard regions cannot be installed in uffd-armed VMAs. */
>  TEST_F(guard_regions, uffd)
>  {
>  	const unsigned long page_size = self->page_size;
> @@ -1526,10 +1526,15 @@ TEST_F(guard_regions, uffd)
>  	reg.mode = UFFDIO_REGISTER_MODE_MISSING;
>  	ASSERT_EQ(ioctl(uffd, UFFDIO_REGISTER, &reg), 0);
>  
> -	/* Guard the range. This should not trigger the uffd. */
> +	/* Now try to guard, should fail with EINVAL. */
> +	ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), -1);
> +	ASSERT_EQ(errno, EINVAL);
> +
> +	/* Once unregistered, we should be able to guard the range. */
> +	ASSERT_EQ(ioctl(uffd, UFFDIO_UNREGISTER, &range), 0);
>  	ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), 0);
>  
> -	/* The guarding should behave as usual with no uffd intervention. */
> +	/* The guarding should behave as usual. */
>  	for (i = 0; i < 10; i++) {
>  		char *curr = &ptr[i * page_size];
>  
> @@ -1537,7 +1542,6 @@ TEST_F(guard_regions, uffd)
>  	}
>  
>  	/* Cleanup. */
> -	ASSERT_EQ(ioctl(uffd, UFFDIO_UNREGISTER, &range), 0);
>  	close(uffd);
>  	ASSERT_EQ(munmap(ptr, 10 * page_size), 0);
>  }
> 
> ---
> base-commit: 4318887a3efa4c53d6f083ccfd7105b809a3ac65
> change-id: 20261112-disallow-uffd-guard-install-a5294129ad7b
> 
> Cheers,


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

* Re: [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs
  2026-11-12 23:59 ` David Hildenbrand (Arm)
@ 2026-11-13 13:59   ` Lorenzo Stoakes (ARM)
  0 siblings, 0 replies; 5+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-13 13:59 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: Andrew Morton, Liam R. Howlett, Vlastimil Babka, Jann Horn,
	Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Shuah Khan,
	linux-mm, linux-kernel, linux-kselftest, Tal Zussman, stable

On Fri, Nov 13, 2026 at 12:59:00AM +0100, David Hildenbrand (Arm) wrote:
> On 11/12/26 18:38, Lorenzo Stoakes (ARM) wrote:
> > In order to establish guard regions, guard markers are installed in the
> > page tables of a mapped VMA.
> >
> > However, problems arise when one tries to combine this with registering a
> > VMA for userfaultfd, as such operations may themselves need to install page
> > table markers such as uffd-wp.
>
> How does this interact with UFFDIO_POISON markers that can outlive even
> userfaultfd registration?

The zap clears poison markers, as is standard. It's really horrible this logic.

So the code path for zap used by the guard install (via zap_vma_range()) is:

zap_vma_range()
  -> zap_vma_range_batched() with NULL zap_details
    -> __zap_vma_range()
      -> zap_p4d_range()
        ...
        -> zap_pte_range()
          -> do_zap_pte_range()
            -> zap_nonpresent_ptes()

And zap_details is NULL.

In zap_non_present_ptes():

	...
	} else if (softleaf_is_uffd_wp_marker(entry)) {
		if (... !zap_drop_markers(details))
			return 1;
	} else if (softleaf_is_guard_marker(entry)) {
		...
		if (!zap_drop_markers(details))
			return 1;
	} else if (softleaf_is_hwpoison(entry) ||
		   softleaf_is_poison_marker(entry)) {
		if (!should_zap_cows(details))
			return 1;
	} ...

And zap_drop_markers() checks zap_details && zap_details->flags &
ZAP_FLAG_DROP_MARKER.

However the poison markers only guards against !should_zap_cows(), which
returns true if NULL details.

What a mess...!

But obviously this patch doesn't change any of that.

>
> I'd assume it's just the same thing, just like having proper hwpoison marker in
> anon mappings, so it just works (uffd-wp will skip, guard installation will zap).

For poison markers yes, as per above.

>
> >
> > When this installation is attempted the guard marker prevents these markers
> > being applied, which can lead to unexpected results (especially if the
> > guard regions are later removed.)
> >
> > This is especially problematic because guard region installation causes the
> > regions to be zapped first, meaning that the removal of userfaultfd-tracked
> > ranges will not be logged in this case.
>
> Again, similar to trying to uffd-wp-protect'ing a hwpoison marker (which will be
> ignored), and then zapping that.
>
> Isn't guard marker installation/removal just another form of zapping?

I mean users being weird could decide to use it for that rather than
MADV_DONTNEED, but zapping is a side effect really.

Really the idea is that you might have users who, for whatever reason,
faulted in some range, and now want to make that a guard range, so for
convenience we zap it for them :)

>
> So to me this all sounds like "if user space does something stupid, it's user
> space's fault".

Unfortunately, as per Tal's series, there's more to it than that (linked in
Closes: tags).

You can get an infinite syscall restart (ugh) if you do this on a shmem
range (Tal's 9/12) so it's a kernel bug that _has_ to be fixed.

The other bits are just about a user losing track of uffd stuff if they
guard/unguard, as you say.

But every other zap code path does the uffd remove event stuff, so this is
still an exception.

If you support uffd, you have to add a whole bunch of horrifying, awful,
terrible open-coded uffd crap, e.g. the userfaultfd_remove() etc. And you
have to drop the bloody lock and reacquire it too and make sure all that
works correctly (...!)

Anyway there's basically 3 options here:

1. do something like what Tal's series does - add a TON of complexity for a
   use case that nobody uses to get behaviour on something nobody sane
   should care about (i.e. uffd/guard/unguard/expect uffd correctness).

2. Zap with ZAP_FLAG_DROP_MARKER, and silently lose uffd-wp state but
  'support' uffd. It does fix the 9/12 bug but then subtly breaks uffd.

3. Disallow uffd.

1 is totally unacceptable + will likely expose us to new bugs (dropping the
lock is just... yeah no thanks), 2 just seems broken, so 3 (which is what
this does) seems the right way to do things.

Basically, right now, anybody using uffd + guard regions in this way is
experiencing silent bugs.

So option 3 is by far the best course of action. And no action isn't an
option.

>
> >
> > Therefore, disallow this.
> >
> > This makes sense as conceptually, guard regions mark a part of a VMA as
> > effectively unmapped at the page table level, and removing the markers is
> > like mapping the VMA again, over which operation uffd markers would in any
> > case be lost.
>
> Right, but that to me just says "on the parts of the VMA where you mess with
> guard markers, your uffd-wp protection is similarly ignored".

As per above on unfortunate need to do something here.

>
> So disallowing it entirely for a VMA, I am not sure. I could see use cases for
> that, although you might argue that user space should then register uffd-wp on
> the separate pieces. But then you get multiple VMAs again.

I did a survey of open source software out there - glibc, android,
tcmalloc, CRIU - and none of them rely on this.

So in general there's no signs that anybody actually does this, and if they
do, it's literally currently broken. And we've had no bug reports for some
time now.

So I think it's fine (IOW this patch is fine :P)

If you're really concerned though, we could go with option 2, which will
just make UFFD behave differently for guard regions.

(I regret, obviously, ever allowing this for uffd ranges. And we _all_
 regret that uffd was _ever_ allowed to be merged in this state...)

--
Cheers, Lorenzo

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

end of thread, other threads:[~2026-11-13 14:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 17:38 [PATCH] mm/madvise: disallow guard region installation in uffd-armed VMAs Lorenzo Stoakes (ARM)
2026-11-12 20:59 ` Liam R. Howlett
2026-11-12 23:59 ` David Hildenbrand (Arm)
2026-11-13 13:59   ` Lorenzo Stoakes (ARM)
2026-11-13  8:58 ` Vlastimil Babka (SUSE)

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