Skip to content

Commit 3d32aaa

Browse files
author
Mike Snitzer
committed
dm ioctl: fix nested locking in table_clear() to remove deadlock concern
syzkaller found the following problematic rwsem locking (with write lock already held): down_read+0x9d/0x450 kernel/locking/rwsem.c:1509 dm_get_inactive_table+0x2b/0xc0 drivers/md/dm-ioctl.c:773 __dev_status+0x4fd/0x7c0 drivers/md/dm-ioctl.c:844 table_clear+0x197/0x280 drivers/md/dm-ioctl.c:1537 In table_clear, it first acquires a write lock https://elixir.bootlin.com/linux/v6.2/source/drivers/md/dm-ioctl.c#L1520 down_write(&_hash_lock); Then before the lock is released at L1539, there is a path shown above: table_clear -> __dev_status -> dm_get_inactive_table -> down_read https://elixir.bootlin.com/linux/v6.2/source/drivers/md/dm-ioctl.c#L773 down_read(&_hash_lock); It tries to acquire the same read lock again, resulting in the deadlock problem. Fix this by moving table_clear()'s __dev_status() call to after its up_write(&_hash_lock); Cc: [email protected] Reported-by: Zheng Zhang <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent f799508 commit 3d32aaa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/md/dm-ioctl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,11 +1556,12 @@ static int table_clear(struct file *filp, struct dm_ioctl *param, size_t param_s
15561556
has_new_map = true;
15571557
}
15581558

1559-
param->flags &= ~DM_INACTIVE_PRESENT_FLAG;
1560-
1561-
__dev_status(hc->md, param);
15621559
md = hc->md;
15631560
up_write(&_hash_lock);
1561+
1562+
param->flags &= ~DM_INACTIVE_PRESENT_FLAG;
1563+
__dev_status(md, param);
1564+
15641565
if (old_map) {
15651566
dm_sync_table(md);
15661567
dm_table_destroy(old_map);

0 commit comments

Comments
 (0)