Commit d434ab6d authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe
Browse files

io_uring: drop mm and files after task_work_run



__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: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent d9d05217
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -7056,6 +7056,7 @@ static int io_sq_thread(void *data)


		if (sqt_spin || !time_after(jiffies, timeout)) {
		if (sqt_spin || !time_after(jiffies, timeout)) {
			io_run_task_work();
			io_run_task_work();
			io_sq_thread_drop_mm_files();
			cond_resched();
			cond_resched();
			if (sqt_spin)
			if (sqt_spin)
				timeout = jiffies + sqd->sq_thread_idle;
				timeout = jiffies + sqd->sq_thread_idle;
@@ -7093,6 +7094,7 @@ static int io_sq_thread(void *data)
	}
	}


	io_run_task_work();
	io_run_task_work();
	io_sq_thread_drop_mm_files();


	if (cur_css)
	if (cur_css)
		io_sq_thread_unassociate_blkcg();
		io_sq_thread_unassociate_blkcg();