Skip to contentSkip to conversation

userfaultfd: add missing mmput() in error path

PATCH In review Eric Biggers 2 participants 2 messages Sep 13, 2015 – Sep 15, 2015

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

PATCH 1/1 userfaultfd: add missing mmput() in error path

---
 fs/userfaultfd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/userfaultfd.c +3 -1
index 634e676..f9aeb40 100644
@@ -1287,8 +1287,10 @@ static struct file *userfaultfd_file_create(int flags)
 
 	file = anon_inode_getfile("[userfaultfd]", &userfaultfd_fops, ctx,
 				  O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS));
-	if (IS_ERR(file))
+	if (IS_ERR(file)) {
+		mmput(ctx->mm);
 		kmem_cache_free(userfaultfd_ctx_cachep, ctx);
+	}
 out:
 	return file;
 }
Signature · 7 lines
2.4.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

Hello Eric,

Quoted 11 lines · Eric Biggers
---
 fs/userfaultfd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/userfaultfd.c +0 -0
index 634e676..f9aeb40 100644
@@ -1287,8 +1287,10 @@ static struct file *userfaultfd_file_create(int flags)
 

fs/userfaultfd.c static struct file *userfaultfd_file_create(int flags) · line 1296

Quoted 10 lines
fs/userfaultfd.c +3 -1
 	file = anon_inode_getfile("[userfaultfd]", &userfaultfd_fops, ctx,
 				  O_RDWR | (flags & UFFD_SHARED_FCNTL_FLAGS));
-	if (IS_ERR(file))
+	if (IS_ERR(file)) {
+		mmput(ctx->mm);
 		kmem_cache_free(userfaultfd_ctx_cachep, ctx);
+	}
 out:
 	return file;
 }

This bug would have generated a memleak in the error code path (which could only run if running out of files or memory, unfortunately not a condition that gets routinely exercised).

It's great you spotted it now, we can fix it before final 4.3. I'll forward it to Andrew to be sure it's not missed.

Thanks,
Andrea