Skip to contentSkip to conversation

userfaultfd: non-cooperative: fix fork fctx->new memleak

PATCH New [email protected] 1 participant 1 message Mar 10, 2017 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 15/26 userfaultfd: non-cooperative: fix fork fctx->new memleak

From: Mike Rapoport <[email protected]>
Subject: userfaultfd: non-cooperative: fix fork fctx->new memleak

We have a memleak in the ->new ctx if the uffd of the parent is closed before the fork event is read, nothing frees the new context.

---

 fs/userfaultfd.c |    9 +++++++++
 1 file changed, 9 insertions(+)
fs/userfaultfd.c renamed from fs/userfaultfd.c~userfaultfd-non-cooperative-fix-fork-fctx-new-memleak +9 -0
diff -puN fs/userfaultfd.c~userfaultfd-non-cooperative-fix-fork-fctx-new-memleak fs/userfaultfd.c
@@ -549,6 +549,15 @@ static void userfaultfd_event_wait_compl
 		if (ACCESS_ONCE(ctx->released) ||
 		    fatal_signal_pending(current)) {
 			__remove_wait_queue(&ctx->event_wqh, &ewq->wq);
+			if (ewq->msg.event == UFFD_EVENT_FORK) {
+				struct userfaultfd_ctx *new;
+
+				new = (struct userfaultfd_ctx *)
+					(unsigned long)
+					ewq->msg.arg.reserved.reserved1;
+
+				userfaultfd_ctx_put(new);
+			}
 			break;
 		}
 

_