userfaultfd: ensure mremap_userfaultfd_fail() releases mmap_changing
Subsystems (2)
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().
---
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
@@ -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