Skip to contentSkip to conversation

userfaultfd: ensure mremap_userfaultfd_fail() releases mmap_changing

PATCH Applied Mike Rapoport 1 participant 1 message May 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 userfaultfd: ensure mremap_userfaultfd_fail() releases mmap_changing

From: "Mike Rapoport (Microsoft)" <[email protected]>

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().

Fixes df2cc96e7701 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races")

---

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/[email protected]
(patch 1/3)

 fs/userfaultfd.c | 2 ++
 1 file changed, 2 insertions(+)
fs/userfaultfd.c +2 -0
index 4b53dc4a3266..390e4b7d9cb9 100644
@@ -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

Signature · 1 line
2.53.0