lkml.org 
[lkml]   [2024]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 2/3] userfaultfd: convert to ->read_iter()
From
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


\
 
 \ /
  Last update: 2024-05-27 16:22    [W:0.143 / U:0.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site