Commit 36e8169
RDMA/ucma: Protect mc during concurrent multicast leaves
Partially revert the commit mentioned in the Fixes line to make sure that
allocation and erasing multicast struct are locked.
BUG: KASAN: use-after-free in ucma_cleanup_multicast drivers/infiniband/core/ucma.c:491 [inline]
BUG: KASAN: use-after-free in ucma_destroy_private_ctx+0x914/0xb70 drivers/infiniband/core/ucma.c:579
Read of size 8 at addr ffff88801bb74b00 by task syz-executor.1/25529
CPU: 0 PID: 25529 Comm: syz-executor.1 Not tainted 5.16.0-rc7-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description.constprop.0.cold+0x8d/0x320 mm/kasan/report.c:247
__kasan_report mm/kasan/report.c:433 [inline]
kasan_report.cold+0x83/0xdf mm/kasan/report.c:450
ucma_cleanup_multicast drivers/infiniband/core/ucma.c:491 [inline]
ucma_destroy_private_ctx+0x914/0xb70 drivers/infiniband/core/ucma.c:579
ucma_destroy_id+0x1e6/0x280 drivers/infiniband/core/ucma.c:614
ucma_write+0x25c/0x350 drivers/infiniband/core/ucma.c:1732
vfs_write+0x28e/0xae0 fs/read_write.c:588
ksys_write+0x1ee/0x250 fs/read_write.c:643
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
Currently the xarray search can touch a concurrently freeing mc as the
xa_for_each() is not surrounded by any lock. Rather than hold the lock for
a full scan hold it only for the effected items, which is usually an empty
list.
Fixes: 95fe510 ("RDMA/ucma: Remove mc_list and rely on xarray")
Link: https://lore.kernel.org/r/1cda5fabb1081e8d16e39a48d3a4f8160cea88b8.1642491047.git.leonro@nvidia.com
Reported-by: syzbot+e3f96c43d19782dd14a7@syzkaller.appspotmail.com
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Maor Gottlieb <maorg@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>1 parent d9e410e commit 36e8169
1 file changed
Lines changed: 23 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
| |||
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
| 203 | + | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
| |||
484 | 487 | | |
485 | 488 | | |
486 | 489 | | |
487 | | - | |
488 | | - | |
| 490 | + | |
489 | 491 | | |
490 | | - | |
491 | | - | |
492 | | - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
493 | 495 | | |
494 | 496 | | |
495 | 497 | | |
496 | 498 | | |
497 | | - | |
| 499 | + | |
498 | 500 | | |
499 | 501 | | |
| 502 | + | |
500 | 503 | | |
501 | 504 | | |
502 | 505 | | |
| |||
1469 | 1472 | | |
1470 | 1473 | | |
1471 | 1474 | | |
1472 | | - | |
| 1475 | + | |
| 1476 | + | |
1473 | 1477 | | |
1474 | 1478 | | |
1475 | 1479 | | |
1476 | 1480 | | |
1477 | 1481 | | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
1478 | 1485 | | |
1479 | 1486 | | |
1480 | 1487 | | |
| |||
1500 | 1507 | | |
1501 | 1508 | | |
1502 | 1509 | | |
1503 | | - | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
1504 | 1513 | | |
| 1514 | + | |
1505 | 1515 | | |
1506 | 1516 | | |
1507 | 1517 | | |
| |||
1569 | 1579 | | |
1570 | 1580 | | |
1571 | 1581 | | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | 1582 | | |
1576 | 1583 | | |
| 1584 | + | |
1577 | 1585 | | |
1578 | 1586 | | |
1579 | 1587 | | |
1580 | 1588 | | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
1581 | 1593 | | |
1582 | 1594 | | |
1583 | 1595 | | |
| |||
0 commit comments