io_uring: drop mm and files after task_work_run
authorPavel Begunkov <asml.silence@gmail.com>
Mon, 11 Jan 2021 04:00:30 +0000 (04:00 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Jan 2021 17:27:23 +0000 (18:27 +0100)
[ Upstream commit d434ab6db524ab1efd0afad4ffa1ee65ca6ac097 ]

__io_req_task_submit() run by task_work can set mm and files, but
io_sq_thread() in some cases, and because __io_sq_thread_acquire_mm()
and __io_sq_thread_acquire_files() do a simple current->mm/files check
it may end up submitting IO with mm/files of another task.

We also need to drop it after in the end to drop potentially grabbed
references to them.

Cc: stable@vger.kernel.org # 5.9+
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/io_uring.c

index 6c356b9e87b39126710c89bb6c341e2b00a68fb7..cab640c10bc0fcc63c93ec2350b36c0f480ac3e9 100644 (file)
@@ -6841,6 +6841,7 @@ static int io_sq_thread(void *data)
 
                if (ret & SQT_SPIN) {
                        io_run_task_work();
+                       io_sq_thread_drop_mm();
                        cond_resched();
                } else if (ret == SQT_IDLE) {
                        if (kthread_should_park())
@@ -6855,6 +6856,7 @@ static int io_sq_thread(void *data)
        }
 
        io_run_task_work();
+       io_sq_thread_drop_mm();
 
        if (cur_css)
                io_sq_thread_unassociate_blkcg();