]> git.baikalelectronics.ru Git - kernel.git/commit
io_uring: fix race in unified task_work running
authorJens Axboe <axboe@kernel.dk>
Mon, 26 Jul 2021 16:42:56 +0000 (10:42 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 26 Jul 2021 16:42:56 +0000 (10:42 -0600)
commit2a7bffc9bddff6c273509a1bd92074933f6c2e9c
treed44e394878d2d3dbd3fd0aafa1555e0ff4c8034b
parent572478267c8f03f604f553399e58d94e14df982a
io_uring: fix race in unified task_work running

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>
fs/io_uring.c