SAS device page 0 provides phy_num, which leapraid passes straight into leapraid_transport_update_links() as the index into topo_node->card_phy[]. That array holds phys_num entries from the IO-unit or expander page, and nothing compares the two. A controller that reports a larger phy_num in the device page than the parent topology node has makes the driver write past the card_phy[] array: attached_hdl and the fields filled by leapraid_transport_set_identify() land in unrelated slab memory. Reject the update when the index does not fit the target topology node. Fixes: 5597088c9e79 ("scsi: leapraid: Add new SCSI driver") Cc: stable@vger.kernel.org Cc: Dongdong Hao Signed-off-by: Hongyu Guo --- drivers/scsi/leapraid/leapraid_transport.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/scsi/leapraid/leapraid_transport.c b/drivers/scsi/leapraid/leapraid_transport.c index 77ffbd6ddce4..7468276b4a10 100644 --- a/drivers/scsi/leapraid/leapraid_transport.c +++ b/drivers/scsi/leapraid/leapraid_transport.c @@ -1146,6 +1146,15 @@ void leapraid_transport_update_links( return; } + if (phy_index >= topo_node->phys_num) { + spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, + flags); + dev_warn(&adapter->pdev->dev, + "%s: phy index %u out of range, max %u\n", + __func__, phy_index, topo_node->phys_num); + return; + } + card_phy = &topo_node->card_phy[phy_index]; card_phy->attached_hdl = hdl; spin_unlock_irqrestore(&adapter->dev_topo.topo_node_lock, flags); -- 2.43.0