Skip to content

Commit e95d994

Browse files
axboegregkh
authored andcommitted
io_uring: fix race in unified task_work running
commit 110aa25 upstream. We use a bit to manage if we need to add the shared task_work, but a list + lock for the pending work. Before aborting a current run of the task_work we check if the list is empty, but we do so without grabbing the lock that protects it. This can lead to races where we think we have nothing left to run, where in practice we could be racing with a task adding new work to the list. If we do hit that race condition, we could be left with work items that need processing, but the shared task_work is not active. Ensure that we grab the lock before checking if the list is empty, so we know if it's safe to exit the run or not. Link: https://lore.kernel.org/io-uring/c6bd5987-e9ae-cd02-49d0-1b3ac1ef65b1@tnonline.net/ Cc: stable@vger.kernel.org # 5.11+ Reported-by: Forza <forza@tnonline.net> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ee6d50c commit e95d994

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎fs/io_uring.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ static void tctx_task_work(struct callback_head *cb)
18991899

19001900
clear_bit(0, &tctx->task_state);
19011901

1902-
while (!wq_list_empty(&tctx->task_list)) {
1902+
while (true) {
19031903
struct io_ring_ctx *ctx = NULL;
19041904
struct io_wq_work_list list;
19051905
struct io_wq_work_node *node;
@@ -1909,6 +1909,9 @@ static void tctx_task_work(struct callback_head *cb)
19091909
INIT_WQ_LIST(&tctx->task_list);
19101910
spin_unlock_irq(&tctx->task_lock);
19111911

1912+
if (wq_list_empty(&list))
1913+
break;
1914+
19121915
node = list.first;
19131916
while (node) {
19141917
struct io_wq_work_node *next = node->next;

0 commit comments

Comments
 (0)