scsi: check set_identify result in update_links
Subsystems (4)
cover scsi: check set_identify result in update_links
update_links() in mpt3sas, mpi3mr and leapraid all ignore the return value of their set_identify helper. On firmware query failure the identify struct is left untouched, and the phy is then attached using a stale sas_address from before the failed query.
This series fixes all three the same way: fold the call into the if condition so a failed query takes the existing zeroing else path, the same "no valid identify" state as an invalid handle or link rate. The next successful link event re-fills the identify.
All three were verified against scsi.git fixes (469fa055664b): each applies cleanly, passes checkpatch --strict with no warnings, and its transport object builds warning-free before and after the change.
Shirong Zhao (3):
scsi: mpt3sas: check set_identify result in update_links
scsi: mpi3mr: check set_identify result in update_links
scsi: leapraid: check set_identify result in update_links
drivers/scsi/leapraid/leapraid_transport.c | 6 +++--- drivers/scsi/mpi3mr/mpi3mr_transport.c | 6 +++--- drivers/scsi/mpt3sas/mpt3sas_transport.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-)
PATCH 1/3 scsi: mpt3sas: check set_identify result in update_links
mpt3sas_transport_update_links() ignores the return value of _transport_set_identify(), which leaves the identify struct untouched on FW query failure (host/PCI recovery, config page error, bad IOC status). The phy is then attached using a stale remote_identify.sas_address from before the failed query.
Fold the call into the if condition so a failed query takes the existing zeroing else path (same "no valid identify" state as an invalid handle/rate) instead of attaching with stale data. The next successful link event re-fills the identify.
Verified against scsi.git fixes (469fa055664b), the current SCSI fixes tree.
--- drivers/scsi/mpt3sas/mpt3sas_transport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/mpt3sas/mpt3sas_transport.c +3 -3
@@ -1179,9 +1179,9 @@ mpt3sas_transport_update_links(struct MPT3SAS_ADAPTER *ioc, mpt3sas_phy = &sas_node->phy[phy_number]; mpt3sas_phy->attached_handle = handle;spin_unlock_irqrestore (&ioc->sas_node_lock, flags); -if (handle && (link_rate >=MPI2_SAS_NEG_LINK_RATE_1_5 )) { -_transport_set_identify (ioc, handle, - &mpt3sas_phy->remote_identify); +if (handle && link_rate >=MPI2_SAS_NEG_LINK_RATE_1_5 && + !_transport_set_identify (ioc, handle, + &mpt3sas_phy->remote_identify)) {if ((sas_node->handle <= ioc->sas_hba.num_phys) && (ioc->multipath_on_hba)) { list_for_each_entry(hba_port,
PATCH 2/3 scsi: mpi3mr: check set_identify result in update_links
In reply to Shirong Zhaompi3mr_update_links() ignores the return value of mpi3mr_set_identify(), which leaves the identify struct untouched on FW query failure (recovery in progress, config page error, bad IOC status). The phy is then attached using a stale mr_sas_phy->remote_identify.sas_address from before the failed query.
Fold the call into the if condition so a failed query takes the existing zeroing else path (same "no valid identify" state as an invalid handle/rate) instead of attaching with stale data. The next successful link event re-fills the identify.
Verified against scsi.git fixes (469fa055664b), the current SCSI fixes tree.
--- drivers/scsi/mpi3mr/mpi3mr_transport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_transport.c +3 -3
@@ -1093,9 +1093,9 @@ void mpi3mr_update_links(struct mpi3mr_ioc *mrioc, mr_sas_phy = &mr_sas_node->phy[phy_number]; mr_sas_phy->attached_handle = handle;spin_unlock_irqrestore (&mrioc->sas_node_lock, flags); -if (handle && (link_rate >=MPI3_SAS_NEG_LINK_RATE_1_5 )) { -mpi3mr_set_identify (mrioc, handle, - &mr_sas_phy->remote_identify); +if (handle && link_rate >=MPI3_SAS_NEG_LINK_RATE_1_5 && + !mpi3mr_set_identify (mrioc, handle, + &mr_sas_phy->remote_identify)) {mpi3mr_add_phy_to_an_existing_port (mrioc, mr_sas_node, mr_sas_phy, mr_sas_phy->remote_identify.sas_address, hba_port);
PATCH 3/3 scsi: leapraid: check set_identify result in update_links
In reply to Shirong Zhaoleapraid_transport_update_links() ignores the return value of leapraid_transport_set_identify(), which leaves the identify struct untouched on FW query failure (recovery in progress, config page error). The phy is then attached using a stale card_phy->remote_identify.sas_address from before the failed query.
Fold the call into the if condition so a failed query takes the existing zeroing else path (same "no valid identify" state as an invalid handle/rate) instead of attaching with stale data. The next successful link event re-fills the identify.
Verified against scsi.git fixes (469fa055664b), the current SCSI fixes tree.
--- drivers/scsi/leapraid/leapraid_transport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/leapraid/leapraid_transport.c +3 -3
@@ -1150,9 +1150,9 @@ void leapraid_transport_update_links( card_phy->attached_hdl = hdl;spin_unlock_irqrestore (&adapter->dev_topo.topo_node_lock, flags); -if (hdl && link_rate >=LEAPRAID_SAS_NEG_LINK_RATE_1_5 ) { -leapraid_transport_set_identify (adapter, hdl, - &card_phy->remote_identify); +if (hdl && link_rate >=LEAPRAID_SAS_NEG_LINK_RATE_1_5 && + !leapraid_transport_set_identify (adapter, hdl, + &card_phy->remote_identify)) {if (topo_node->hdl <= adapter->dev_topo.card.phys_num && adapter->adapter_attr.enable_mp) { list_for_each_entry(card_port,
[email protected]
AI reviewRe: [PATCH 3/3] scsi: leapraid: check set_identify result in update_links
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] scsi: leapraid: UAF on card_phy after dropping topo_node_lock - [High] scsi: leapraid…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] scsi: leapraid: UAF on card_phy after dropping topo_node_lock
- [High] scsi: leapraid: out-of-bounds array access via unvalidated phy_index
- [High] scsi: leapraid: lockless traversal of card_port_list causes UAF
--
commit 4abc139d948d5c745212e888718ff5b93bc978e0
Author: Shirong Zhao <[email protected]>
scsi: leapraid: check set_identify result in update_links
leapraid_transport_update_links() ignores the return value of leapraid_transport_set_identify(), which leaves the identify struct untouched on FW query failure. Fold the call into the if condition so a failed query takes the existing zeroing else path instead of attaching with stale data.
drivers/scsi/leapraid/leapraid_transport.c void leapraid_transport_update_links( · line 1150
Quoted 6 lines
drivers/scsi/leapraid/leapraid_transport.c +0
-0@@ -1150,9 +1150,9 @@ void leapraid_transport_update_links( card_phy->attached_hdl = hdl;
[Severity: High]
Does this code overflow the topo_node->card_phy array in leapraid_transport_update_links() in drivers/scsi/leapraid/leapraid_transport.c?
Callers like leapraid_sas_pd_add() and leapraid_scan_sas_dev_after_reset() pass the hardware-provided sas_dev_p0.phy_num directly as phy_index without validating it against topo_node->phys_num. A malicious or malfunctioning HBA returning an unexpectedly large phy_num could cause an out-of-bounds write on card_phy->attached_hdl here.
drivers/scsi/leapraid/leapraid_transport.c void leapraid_transport_update_links( · line 1155
Quoted 8 lines
drivers/scsi/leapraid/leapraid_transport.c +3
-3spin_unlock_irqrestore (&adapter->dev_topo.topo_node_lock, flags); -if (hdl && link_rate >=LEAPRAID_SAS_NEG_LINK_RATE_1_5 ) { -leapraid_transport_set_identify (adapter, hdl, - &card_phy->remote_identify); +if (hdl && link_rate >=LEAPRAID_SAS_NEG_LINK_RATE_1_5 && + !leapraid_transport_set_identify (adapter, hdl, + &card_phy->remote_identify)) {
[Severity: High]
Can this dereference a freed card_phy pointer?
By dropping adapter->dev_topo.topo_node_lock before calling the blocking hardware query leapraid_transport_set_identify(), the safe lifetime of topo_node and card_phy ends.
Concurrently, teardown paths like leapraid_exp_rm() can acquire the topo_node_lock, remove the node, drop the lock, and call kfree() on both topo_node_exp->card_phy and topo_node_exp. When leapraid_transport_set_identify() executes, it would write to the freed card_phy->remote_identify.
drivers/scsi/leapraid/leapraid_transport.c void leapraid_transport_update_links( · line 1158
Quoted 3 lines
drivers/scsi/leapraid/leapraid_transport.c +0
-0if (topo_node->hdl <= adapter->dev_topo.card.phys_num && adapter->adapter_attr.enable_mp) { list_for_each_entry(card_port,
[Severity: High]
Is it safe to iterate adapter->dev_topo.card_port_list without holding the topo_node_lock?
Since the lock was dropped earlier in this function, this list is traversed locklessly. Concurrently, leapraid_cleanup_card_port_and_vphys() can be called (e.g. from leapraid_transport_port_remove()), which removes and calls kfree() on elements from this same list, potentially causing a use-after-free in this iterator.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3