Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx
@ 2020-07-14 16:12 yanfei.xu
  2020-07-15  1:41 ` Xu, Yanfei
  2020-07-19 13:58 ` Xu, Yanfei
  0 siblings, 2 replies; 6+ messages in thread
From: yanfei.xu @ 2020-07-14 16:12 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel

From: Yanfei Xu <yanfei.xu@windriver.com>

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: syzbot+75867c44841cb6373570@syzkaller.appspotmail.com
Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
---
 fs/userfaultfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 3a4d6ac5a81a..e98317c15530 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -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);
-- 
2.18.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx
  2020-07-14 16:12 [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx yanfei.xu
@ 2020-07-15  1:41 ` Xu, Yanfei
  2020-07-19 13:58 ` Xu, Yanfei
  1 sibling, 0 replies; 6+ messages in thread
From: Xu, Yanfei @ 2020-07-15  1:41 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel, Alexander Viro

Add maintainer Alexander Viro  :)

On 7/15/20 12:12 AM, yanfei.xu@windriver.com wrote:
> From: Yanfei Xu <yanfei.xu@windriver.com>
> 
> 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: syzbot+75867c44841cb6373570@syzkaller.appspotmail.com
> Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
> ---
>   fs/userfaultfd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index 3a4d6ac5a81a..e98317c15530 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -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);
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx
  2020-07-14 16:12 [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx yanfei.xu
  2020-07-15  1:41 ` Xu, Yanfei
@ 2020-07-19 13:58 ` Xu, Yanfei
  2020-07-19 16:57   ` Al Viro
  1 sibling, 1 reply; 6+ messages in thread
From: Xu, Yanfei @ 2020-07-19 13:58 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel, Alexander Viro

ping Al Viro

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

Yanfei

On 7/15/20 12:12 AM, yanfei.xu@windriver.com wrote:
> From: Yanfei Xu <yanfei.xu@windriver.com>
> 
> 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: syzbot+75867c44841cb6373570@syzkaller.appspotmail.com
> Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
> ---
>   fs/userfaultfd.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index 3a4d6ac5a81a..e98317c15530 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -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);
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx
  2020-07-19 13:58 ` Xu, Yanfei
@ 2020-07-19 16:57   ` Al Viro
  2020-07-20  1:34     ` Xu, Yanfei
  0 siblings, 1 reply; 6+ messages in thread
From: Al Viro @ 2020-07-19 16:57 UTC (permalink / raw)
  To: Xu, Yanfei; +Cc: linux-fsdevel, linux-kernel

On Sun, Jul 19, 2020 at 09:58:34PM +0800, Xu, Yanfei wrote:
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx
  2020-07-19 16:57   ` Al Viro
@ 2020-07-20  1:34     ` Xu, Yanfei
  2020-07-22  0:09       ` Suren Baghdasaryan
  0 siblings, 1 reply; 6+ messages in thread
From: Xu, Yanfei @ 2020-07-20  1:34 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel, linux-kernel



On 7/20/20 12:57 AM, Al Viro wrote:
> On Sun, Jul 19, 2020 at 09:58:34PM +0800, Xu, Yanfei wrote:
>> 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.
> Daniel's patch looks seriously wrong.
Get it.

Regards,
Yanfei
> 	* 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.
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx
  2020-07-20  1:34     ` Xu, Yanfei
@ 2020-07-22  0:09       ` Suren Baghdasaryan
  0 siblings, 0 replies; 6+ messages in thread
From: Suren Baghdasaryan @ 2020-07-22  0:09 UTC (permalink / raw)
  To: Xu, Yanfei, Lokesh Gidra; +Cc: Al Viro, linux-fsdevel, LKML

On Sun, Jul 19, 2020 at 6:34 PM Xu, Yanfei <yanfei.xu@windriver.com> wrote:
>
>
>
> On 7/20/20 12:57 AM, Al Viro wrote:
> > On Sun, Jul 19, 2020 at 09:58:34PM +0800, Xu, Yanfei wrote:
> >> 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.
> > Daniel's patch looks seriously wrong.
> Get it.
>
> Regards,
> Yanfei
> >       * 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-22  0:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14 16:12 [PATCH] userfaultfd: avoid the duplicated release for userfaultfd_ctx yanfei.xu
2020-07-15  1:41 ` Xu, Yanfei
2020-07-19 13:58 ` Xu, Yanfei
2020-07-19 16:57   ` Al Viro
2020-07-20  1:34     ` Xu, Yanfei
2020-07-22  0:09       ` Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).