|
|
@@ -630,6 +630,8 @@ static void userfaultfd_event_wait_completion(struct userfaultfd_ctx *ctx,
|
|
|
|
|
|
/* the various vma->vm_userfaultfd_ctx still points to it */
|
|
|
down_write(&mm->mmap_sem);
|
|
|
+ /* no task can run (and in turn coredump) yet */
|
|
|
+ VM_WARN_ON(!mmget_still_valid(mm));
|
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next)
|
|
|
if (vma->vm_userfaultfd_ctx.ctx == release_new_ctx) {
|
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
|
@@ -884,6 +886,8 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
|
|
|
* taking the mmap_sem for writing.
|
|
|
*/
|
|
|
down_write(&mm->mmap_sem);
|
|
|
+ if (!mmget_still_valid(mm))
|
|
|
+ goto skip_mm;
|
|
|
prev = NULL;
|
|
|
for (vma = mm->mmap; vma; vma = vma->vm_next) {
|
|
|
cond_resched();
|
|
|
@@ -906,6 +910,7 @@ static int userfaultfd_release(struct inode *inode, struct file *file)
|
|
|
vma->vm_flags = new_flags;
|
|
|
vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
|
|
|
}
|
|
|
+skip_mm:
|
|
|
up_write(&mm->mmap_sem);
|
|
|
mmput(mm);
|
|
|
wakeup:
|
|
|
@@ -1334,6 +1339,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
|
|
|
goto out;
|
|
|
|
|
|
down_write(&mm->mmap_sem);
|
|
|
+ if (!mmget_still_valid(mm))
|
|
|
+ goto out_unlock;
|
|
|
vma = find_vma_prev(mm, start, &prev);
|
|
|
if (!vma)
|
|
|
goto out_unlock;
|
|
|
@@ -1521,6 +1528,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
|
|
|
goto out;
|
|
|
|
|
|
down_write(&mm->mmap_sem);
|
|
|
+ if (!mmget_still_valid(mm))
|
|
|
+ goto out_unlock;
|
|
|
vma = find_vma_prev(mm, start, &prev);
|
|
|
if (!vma)
|
|
|
goto out_unlock;
|