* [PATCH v2] userfaultfd: ensure mremap_userfaultfd_fail() releases mmap_changing
@ 2026-05-13 8:14 Mike Rapoport
0 siblings, 0 replies; only message in thread
From: Mike Rapoport @ 2026-05-13 8:14 UTC (permalink / raw)
To: Andrew Morton
Cc: Alexander Viro, Christian Brauner, David Hildenbrand, Jan Kara,
Mike Rapoport, Peter Xu, linux-fsdevel, linux-kernel, linux-mm
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Sashiko says:
mremap_userfaultfd_prep() increments ctx->mmap_changing to stall
concurrent operations, but mremap_userfaultfd_fail() does not
decrement it before dropping the context reference.
If an mremap operation fails, ctx->mmap_changing remains elevated. This
will causes subsequent userfaultfd operations like a UFFDIO_COPY to fail
with -EAGAIN.
Decrement ctx->mmap_changing in mremap_userfaultfd_fail().
Link: https://sashiko.dev/#/patchset/20260430113512.115938-1-rppt@kernel.org
Fixes: df2cc96e7701 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races")
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
I split the fix from the code movement series, will be easier to
everyone :)
v2 changes:
* VM_WARN() if mmap_changing is going negative
v1: https://lore.kernel.org/all/20260501145433.156211-1-rppt@kernel.org
(patch 1/3)
fs/userfaultfd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 4b53dc4a3266..390e4b7d9cb9 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -786,6 +786,8 @@ void mremap_userfaultfd_fail(struct vm_userfaultfd_ctx *vm_ctx)
if (!ctx)
return;
+ atomic_dec(&ctx->mmap_changing);
+ VM_WARN_ON_ONCE(atomic_read(&ctx->mmap_changing) < 0);
userfaultfd_ctx_put(ctx);
}
base-commit: 972c53e0ec3abfc6f5fe2cb503640710fb23cf95
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-13 8:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 8:14 [PATCH v2] userfaultfd: ensure mremap_userfaultfd_fail() releases mmap_changing Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox