diff options
| -rw-r--r-- | fs/userfaultfd.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 5419e7da82ba..ef4b48d1ea42 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c | |||
| @@ -381,8 +381,26 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason) | |||
| 381 | * in __get_user_pages if userfaultfd_release waits on the | 381 | * in __get_user_pages if userfaultfd_release waits on the |
| 382 | * caller of handle_userfault to release the mmap_sem. | 382 | * caller of handle_userfault to release the mmap_sem. |
| 383 | */ | 383 | */ |
| 384 | if (unlikely(ACCESS_ONCE(ctx->released))) | 384 | if (unlikely(ACCESS_ONCE(ctx->released))) { |
| 385 | /* | ||
| 386 | * Don't return VM_FAULT_SIGBUS in this case, so a non | ||
| 387 | * cooperative manager can close the uffd after the | ||
| 388 | * last UFFDIO_COPY, without risking to trigger an | ||
| 389 | * involuntary SIGBUS if the process was starting the | ||
| 390 | * userfaultfd while the userfaultfd was still armed | ||
| 391 | * (but after the last UFFDIO_COPY). If the uffd | ||
| 392 | * wasn't already closed when the userfault reached | ||
| 393 | * this point, that would normally be solved by | ||
| 394 | * userfaultfd_must_wait returning 'false'. | ||
| 395 | * | ||
| 396 | * If we were to return VM_FAULT_SIGBUS here, the non | ||
| 397 | * cooperative manager would be instead forced to | ||
| 398 | * always call UFFDIO_UNREGISTER before it can safely | ||
| 399 | * close the uffd. | ||
| 400 | */ | ||
| 401 | ret = VM_FAULT_NOPAGE; | ||
| 385 | goto out; | 402 | goto out; |
| 403 | } | ||
| 386 | 404 | ||
| 387 | /* | 405 | /* |
| 388 | * Check that we can return VM_FAULT_RETRY. | 406 | * Check that we can return VM_FAULT_RETRY. |
