Commit 6af3f48
io_uring: fix link traversal locking
WARNING: inconsistent lock state
5.16.0-rc2-syzkaller #0 Not tainted
inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage.
ffff888078e11418 (&ctx->timeout_lock
){?.+.}-{2:2}
, at: io_timeout_fn+0x6f/0x360 fs/io_uring.c:5943
{HARDIRQ-ON-W} state was registered at:
[...]
spin_unlock_irq include/linux/spinlock.h:399 [inline]
__io_poll_remove_one fs/io_uring.c:5669 [inline]
__io_poll_remove_one fs/io_uring.c:5654 [inline]
io_poll_remove_one+0x236/0x870 fs/io_uring.c:5680
io_poll_remove_all+0x1af/0x235 fs/io_uring.c:5709
io_ring_ctx_wait_and_kill+0x1cc/0x322 fs/io_uring.c:9534
io_uring_release+0x42/0x46 fs/io_uring.c:9554
__fput+0x286/0x9f0 fs/file_table.c:280
task_work_run+0xdd/0x1a0 kernel/task_work.c:164
exit_task_work include/linux/task_work.h:32 [inline]
do_exit+0xc14/0x2b40 kernel/exit.c:832
674ee8e ("io_uring: correct link-list traversal locking") fixed a
data race but introduced a possible deadlock and inconsistentcy in irq
states. E.g.
io_poll_remove_all()
spin_lock_irq(timeout_lock)
io_poll_remove_one()
spin_lock/unlock_irq(poll_lock);
spin_unlock_irq(timeout_lock)
Another type of problem is freeing a request while holding
->timeout_lock, which may leads to a deadlock in
io_commit_cqring() -> io_flush_timeouts() and other places.
Having 3 nested locks is also too ugly. Add io_match_task_safe(), which
would briefly take and release timeout_lock for race prevention inside,
so the actuall request cancellation / free / etc. code doesn't have it
taken.
Reported-by: syzbot+ff49a3059d49b0ca0eec@syzkaller.appspotmail.com
Reported-by: syzbot+847f02ec20a6609a328b@syzkaller.appspotmail.com
Reported-by: syzbot+3368aadcd30425ceb53b@syzkaller.appspotmail.com
Reported-by: syzbot+51ce8887cdef77c9ac83@syzkaller.appspotmail.com
Reported-by: syzbot+3cb756a49d2f394a9ee3@syzkaller.appspotmail.com
Fixes: 674ee8e ("io_uring: correct link-list traversal locking")
Cc: stable@kernel.org # 5.15+
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/397f7ebf3f4171f1abe41f708ac1ecb5766f0b68.1637937097.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>1 parent 617a894 commit 6af3f48
1 file changed
Lines changed: 42 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1278 | 1278 | | |
1279 | 1279 | | |
1280 | 1280 | | |
| 1281 | + | |
1281 | 1282 | | |
1282 | 1283 | | |
1283 | 1284 | | |
| |||
1293 | 1294 | | |
1294 | 1295 | | |
1295 | 1296 | | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
1296 | 1335 | | |
1297 | 1336 | | |
1298 | 1337 | | |
| |||
5699 | 5738 | | |
5700 | 5739 | | |
5701 | 5740 | | |
5702 | | - | |
5703 | 5741 | | |
5704 | 5742 | | |
5705 | 5743 | | |
5706 | 5744 | | |
5707 | 5745 | | |
5708 | | - | |
| 5746 | + | |
5709 | 5747 | | |
5710 | 5748 | | |
5711 | 5749 | | |
5712 | | - | |
5713 | 5750 | | |
5714 | 5751 | | |
5715 | 5752 | | |
| |||
9565 | 9602 | | |
9566 | 9603 | | |
9567 | 9604 | | |
9568 | | - | |
9569 | 9605 | | |
9570 | | - | |
9571 | | - | |
9572 | | - | |
9573 | | - | |
9574 | | - | |
9575 | | - | |
9576 | | - | |
9577 | | - | |
9578 | | - | |
9579 | | - | |
9580 | | - | |
| 9606 | + | |
9581 | 9607 | | |
9582 | 9608 | | |
9583 | 9609 | | |
| |||
9588 | 9614 | | |
9589 | 9615 | | |
9590 | 9616 | | |
9591 | | - | |
9592 | 9617 | | |
9593 | | - | |
| 9618 | + | |
9594 | 9619 | | |
9595 | 9620 | | |
9596 | 9621 | | |
9597 | 9622 | | |
9598 | | - | |
9599 | 9623 | | |
9600 | 9624 | | |
9601 | 9625 | | |
| |||
0 commit comments