Skip to content

Commit bc546c0

Browse files
Ye Binmartinkpetersen
authored andcommitted
scsi: scsi_dh_rdac: Avoid crash during rdac_bus_attach()
The following BUG_ON() was observed during RDAC scan: [595952.944297] kernel BUG at drivers/scsi/device_handler/scsi_dh_rdac.c:427! [595952.951143] Internal error: Oops - BUG: 0 [Rust-for-Linux#1] SMP ...... [595953.251065] Call trace: [595953.259054] check_ownership+0xb0/0x118 [595953.269794] rdac_bus_attach+0x1f0/0x4b0 [595953.273787] scsi_dh_handler_attach+0x3c/0xe8 [595953.278211] scsi_dh_add_device+0xc4/0xe8 [595953.282291] scsi_sysfs_add_sdev+0x8c/0x2a8 [595953.286544] scsi_probe_and_add_lun+0x9fc/0xd00 [595953.291142] __scsi_scan_target+0x598/0x630 [595953.295395] scsi_scan_target+0x120/0x130 [595953.299481] fc_user_scan+0x1a0/0x1c0 [scsi_transport_fc] [595953.304944] store_scan+0xb0/0x108 [595953.308420] dev_attr_store+0x44/0x60 [595953.312160] sysfs_kf_write+0x58/0x80 [595953.315893] kernfs_fop_write+0xe8/0x1f0 [595953.319888] __vfs_write+0x60/0x190 [595953.323448] vfs_write+0xac/0x1c0 [595953.326836] ksys_write+0x74/0xf0 [595953.330221] __arm64_sys_write+0x24/0x30 Code is in check_ownership: list_for_each_entry_rcu(tmp, &h->ctlr->dh_list, node) { /* h->sdev should always be valid */ BUG_ON(!tmp->sdev); tmp->sdev->access_state = access_state; } rdac_bus_attach initialize_controller list_add_rcu(&h->node, &h->ctlr->dh_list); h->sdev = sdev; rdac_bus_detach list_del_rcu(&h->node); h->sdev = NULL; Fix the race between rdac_bus_attach() and rdac_bus_detach() where h->sdev is NULL when processing the RDAC attach. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Bart Van Assche <[email protected]> Signed-off-by: Ye Bin <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 77541f7 commit bc546c0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/scsi/device_handler/scsi_dh_rdac.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ static int initialize_controller(struct scsi_device *sdev,
453453
if (!h->ctlr)
454454
err = SCSI_DH_RES_TEMP_UNAVAIL;
455455
else {
456-
list_add_rcu(&h->node, &h->ctlr->dh_list);
457456
h->sdev = sdev;
457+
list_add_rcu(&h->node, &h->ctlr->dh_list);
458458
}
459459
spin_unlock(&list_lock);
460460
err = SCSI_DH_OK;
@@ -778,11 +778,11 @@ static void rdac_bus_detach( struct scsi_device *sdev )
778778
spin_lock(&list_lock);
779779
if (h->ctlr) {
780780
list_del_rcu(&h->node);
781-
h->sdev = NULL;
782781
kref_put(&h->ctlr->kref, release_controller);
783782
}
784783
spin_unlock(&list_lock);
785784
sdev->handler_data = NULL;
785+
synchronize_rcu();
786786
kfree(h);
787787
}
788788

0 commit comments

Comments
 (0)