Skip to content

Commit

Permalink
io_uring: ensure consistent view of original task ->mm from SQPOLL
Browse files Browse the repository at this point in the history
[ Upstream commit 4b70cf9 ]

Ensure we get a valid view of the task mm, by using task_lock() when
attempting to grab the original task mm.

Reported-by: syzbot+b57abf7ee60829090495@syzkaller.appspotmail.com
Fixes: 2aede0e ("io_uring: stash ctx task reference for SQPOLL")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
axboe authored and gregkh committed Nov 18, 2020
1 parent 29cd2f6 commit 9154aa2
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,20 +952,33 @@ static void io_sq_thread_drop_mm(void)
if (mm) {
kthread_unuse_mm(mm);
mmput(mm);
current->mm = NULL;
}
}

static int __io_sq_thread_acquire_mm(struct io_ring_ctx *ctx)
{
if (!current->mm) {
if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
!ctx->sqo_task->mm ||
!mmget_not_zero(ctx->sqo_task->mm)))
return -EFAULT;
kthread_use_mm(ctx->sqo_task->mm);
struct mm_struct *mm;

if (current->mm)
return 0;

/* Should never happen */
if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL)))
return -EFAULT;

task_lock(ctx->sqo_task);
mm = ctx->sqo_task->mm;
if (unlikely(!mm || !mmget_not_zero(mm)))
mm = NULL;
task_unlock(ctx->sqo_task);

if (mm) {
kthread_use_mm(mm);
return 0;
}

return 0;
return -EFAULT;
}

static int io_sq_thread_acquire_mm(struct io_ring_ctx *ctx,
Expand Down

0 comments on commit 9154aa2

Please sign in to comment.