public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] userfaultfd: convert to ->read_iter()
Date: Wed, 3 Apr 2024 07:44:51 -0600	[thread overview]
Message-ID: <8fc38d0e-4138-4624-800e-b503bbd744e1@kernel.dk> (raw)
In-Reply-To: <20240403-plant-narren-2bbfb61f19f0@brauner>

On 4/3/24 4:09 AM, Christian Brauner wrote:
>> @@ -2215,16 +2216,25 @@ static int new_userfaultfd(int flags)
>>  	init_rwsem(&ctx->map_changing_lock);
>>  	atomic_set(&ctx->mmap_changing, 0);
>>  	ctx->mm = current->mm;
>> -	/* prevent the mm struct to be freed */
>> -	mmgrab(ctx->mm);
>> +
>> +	fd = get_unused_fd_flags(O_RDONLY | (flags & UFFD_SHARED_FCNTL_FLAGS));
>> +	if (fd < 0)
>> +		goto err_out;
>>  
>>  	/* Create a new inode so that the LSM can block the creation.  */
>> -	fd = anon_inode_create_getfd("[userfaultfd]", &userfaultfd_fops, ctx,
>> +	file = anon_inode_create_getfile("[userfaultfd]", &userfaultfd_fops, ctx,
>>  			O_RDONLY | (flags & UFFD_SHARED_FCNTL_FLAGS), NULL);
>> -	if (fd < 0) {
>> -		mmdrop(ctx->mm);
>> -		kmem_cache_free(userfaultfd_ctx_cachep, ctx);
>> +	if (IS_ERR(file)) {
>> +		fd = PTR_ERR(file);
>> +		goto err_out;
> 
> You're leaking the fd you allocated above.

Oops yes - thanks, fixed.

-- 
Jens Axboe


  reply	other threads:[~2024-04-03 13:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 20:18 [PATCHSET 0/3] Convert fs drivers to ->read_iter() Jens Axboe
2024-04-02 20:18 ` [PATCH 1/3] timerfd: convert " Jens Axboe
2024-04-02 20:18 ` [PATCH 2/3] userfaultfd: " Jens Axboe
2024-04-03 10:09   ` Christian Brauner
2024-04-03 13:44     ` Jens Axboe [this message]
2024-04-02 20:18 ` [PATCH 3/3] signalfd: " Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2024-04-03 14:02 [PATCHSET v2 0/3] Convert fs drivers " Jens Axboe
2024-04-03 14:02 ` [PATCH 2/3] userfaultfd: convert " Jens Axboe
2024-04-03 22:45   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fc38d0e-4138-4624-800e-b503bbd744e1@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox