Skip to content

Commit

Permalink
io_uring: fix ltout double free on completion race
Browse files Browse the repository at this point in the history
[ Upstream commit 447c19f ]

Always remove linked timeout on io_link_timeout_fn() from the master
request link list, otherwise we may get use-after-free when first
io_link_timeout_fn() puts linked timeout in the fail path, and then
will be found and put on master's free.

Cc: stable@vger.kernel.org # 5.10+
Fixes: 90cd7e4 ("io_uring: track link timeout's master explicitly")
Reported-and-tested-by: syzbot+5a864149dd970b546223@syzkaller.appspotmail.com
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/69c46bf6ce37fec4fdcd98f0882e18eb07ce693a.1620990121.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
isilence authored and gregkh committed Jun 10, 2021
1 parent 9e44293 commit 1f64f5e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fs/io_uring.c
Expand Up @@ -6289,10 +6289,11 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer)
* We don't expect the list to be empty, that will only happen if we
* race with the completion of the linked work.
*/
if (prev && req_ref_inc_not_zero(prev))
if (prev) {
io_remove_next_linked(prev);
else
prev = NULL;
if (!req_ref_inc_not_zero(prev))
prev = NULL;
}
spin_unlock_irqrestore(&ctx->completion_lock, flags);

if (prev) {
Expand Down

0 comments on commit 1f64f5e

Please sign in to comment.