Skip to content

Commit 4b70cf9

Browse files
committed
io_uring: ensure consistent view of original task ->mm from SQPOLL
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>
1 parent fdaf083 commit 4b70cf9

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

fs/io_uring.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,20 +995,33 @@ static void io_sq_thread_drop_mm(void)
995995
if (mm) {
996996
kthread_unuse_mm(mm);
997997
mmput(mm);
998+
current->mm = NULL;
998999
}
9991000
}
10001001

10011002
static int __io_sq_thread_acquire_mm(struct io_ring_ctx *ctx)
10021003
{
1003-
if (!current->mm) {
1004-
if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
1005-
!ctx->sqo_task->mm ||
1006-
!mmget_not_zero(ctx->sqo_task->mm)))
1007-
return -EFAULT;
1008-
kthread_use_mm(ctx->sqo_task->mm);
1004+
struct mm_struct *mm;
1005+
1006+
if (current->mm)
1007+
return 0;
1008+
1009+
/* Should never happen */
1010+
if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL)))
1011+
return -EFAULT;
1012+
1013+
task_lock(ctx->sqo_task);
1014+
mm = ctx->sqo_task->mm;
1015+
if (unlikely(!mm || !mmget_not_zero(mm)))
1016+
mm = NULL;
1017+
task_unlock(ctx->sqo_task);
1018+
1019+
if (mm) {
1020+
kthread_use_mm(mm);
1021+
return 0;
10091022
}
10101023

1011-
return 0;
1024+
return -EFAULT;
10121025
}
10131026

10141027
static int io_sq_thread_acquire_mm(struct io_ring_ctx *ctx,

0 commit comments

Comments
 (0)