Skip to contentSkip to conversation

userfaultfd: avoid the duplicated release for userfaultfd_ctx

PATCH In review [email protected] 3 participants 6 messages Jul 14, 2020 – Jul 22, 2020 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 userfaultfd: avoid the duplicated release for userfaultfd_ctx

From: Yanfei Xu <[email protected]>

when get_unused_fd_flags gets failure, userfaultfd_ctx_cachep will be freed by userfaultfd_fops's release function which is the userfaultfd_release. So we could return directly after fput().

userfaultfd_release()->userfaultfd_ctx_put(ctx)

Fixes d08ac70b1e0d (Wire UFFD up to SELinux)
Reported-by [email protected]
---
 fs/userfaultfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/userfaultfd.c +1 -1
index 3a4d6ac5a81a..e98317c15530 100644
@@ -2049,7 +2049,7 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)
 	fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
 	if (fd < 0) {
 		fput(file);
-		goto out;
+		return fd;
 	}
 
 	ctx->owner = file_inode(file);
Signature · 1 line
2.18.2
author
#1 lore raw

Add maintainer Alexander Viro :)

Quoted 29 lines · On 7/15/20 12:12 AM, [email protected] wrote:

From: Yanfei Xu <[email protected]>

when get_unused_fd_flags gets failure, userfaultfd_ctx_cachep will be freed by userfaultfd_fops's release function which is the userfaultfd_release. So we could return directly after fput().

userfaultfd_release()->userfaultfd_ctx_put(ctx)

Fixes d08ac70b1e0d (Wire UFFD up to SELinux)
Reported-by [email protected]
---
  fs/userfaultfd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/userfaultfd.c +1 -1
index 3a4d6ac5a81a..e98317c15530 100644
@@ -2049,7 +2049,7 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)
  	fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
  	if (fd < 0) {
  		fput(file);
-		goto out;
+		return fd;
  	}
 
  	ctx->owner = file_inode(file);
author
#2 lore raw
In reply to [email protected]

ping Al Viro

Could you please help to review this patch? Thanks a lot.

Yanfei

Quoted 29 lines · On 7/15/20 12:12 AM, [email protected] wrote:

From: Yanfei Xu <[email protected]>

when get_unused_fd_flags gets failure, userfaultfd_ctx_cachep will be freed by userfaultfd_fops's release function which is the userfaultfd_release. So we could return directly after fput().

userfaultfd_release()->userfaultfd_ctx_put(ctx)

Fixes d08ac70b1e0d (Wire UFFD up to SELinux)
Reported-by [email protected]
---
  fs/userfaultfd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/userfaultfd.c +1 -1
index 3a4d6ac5a81a..e98317c15530 100644
@@ -2049,7 +2049,7 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)
  	fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
  	if (fd < 0) {
  		fput(file);
-		goto out;
+		return fd;
  	}
 
  	ctx->owner = file_inode(file);
maintainer
#3 lore raw
Quoted 3 lines · Yanfei

ping Al Viro

Could you please help to review this patch? Thanks a lot.

That's -next, right? As for the patch itself... Frankly, Daniel's patch looks seriously wrong.
* why has O_CLOEXEC been quietly smuggled in? It's
a userland ABI change, for fsck sake...

	* the double-put you've spotted
	* the whole out: thing - just make it
	if (IS_ERR(file)) {
		userfaultfd_ctx_put(ctx);
		return PTR_ERR(file);
	}
	and be done with that.
author
#4 lore raw
Quoted 6 lines · Al Viro
Quoted 3 lines · Yanfei

ping Al Viro

Could you please help to review this patch? Thanks a lot.

That's -next, right? As for the patch itself... Frankly,

Yes, it's -next.

Quoted 1 line

Daniel's patch looks seriously wrong.

Get it.

Regards,
Yanfei

Quoted 10 lines

* why has O_CLOEXEC been quietly smuggled in? It's
a userland ABI change, for fsck sake...

	* the double-put you've spotted
	* the whole out: thing - just make it
	if (IS_ERR(file)) {
		userfaultfd_ctx_put(ctx);
		return PTR_ERR(file);
	}
	and be done with that.
#5 lore raw
Quoted 9 lines · Yanfei
Quoted 5 lines · Al Viro
Quoted 3 lines · Yanfei

ping Al Viro

Could you please help to review this patch? Thanks a lot.

Quoted 17 lines
Quoted 1 line

That's -next, right? As for the patch itself... Frankly,

Yes, it's -next.

Quoted 1 line

Daniel's patch looks seriously wrong.

Get it.

Regards,
Yanfei

Quoted 10 lines

* why has O_CLOEXEC been quietly smuggled in? It's
a userland ABI change, for fsck sake...

      * the double-put you've spotted
      * the whole out: thing - just make it
      if (IS_ERR(file)) {
              userfaultfd_ctx_put(ctx);
              return PTR_ERR(file);
      }
      and be done with that.

Adding Lokesh to take a look.