|
Lee Duncan |
139e22 |
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
|
|
Lee Duncan |
139e22 |
Date: Tue, 22 Mar 2022 14:57:02 +0900
|
|
Lee Duncan |
139e22 |
Subject: scsi: mpt3sas: Fix use after free in _scsih_expander_node_remove()
|
|
Lee Duncan |
139e22 |
Git-commit: 87d663d40801dffc99a5ad3b0188ad3e2b4d1557
|
|
Lee Duncan |
139e22 |
Patch-mainline: v5.18 or v5.18-rc2 (next release)
|
|
Lee Duncan |
139e22 |
References: git-fixes
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
The function mpt3sas_transport_port_remove() called in
|
|
Lee Duncan |
139e22 |
_scsih_expander_node_remove() frees the port field of the sas_expander
|
|
Lee Duncan |
139e22 |
structure, leading to the following use-after-free splat from KASAN when
|
|
Lee Duncan |
139e22 |
the ioc_info() call following that function is executed (e.g. when doing
|
|
Lee Duncan |
139e22 |
rmmod of the driver module):
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
[ 3479.371167] ==================================================================
|
|
Lee Duncan |
139e22 |
[ 3479.378496] BUG: KASAN: use-after-free in _scsih_expander_node_remove+0x710/0x750 [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.386936] Read of size 1 at addr ffff8881c037691c by task rmmod/1531
|
|
Lee Duncan |
139e22 |
[ 3479.393524]
|
|
Lee Duncan |
139e22 |
[ 3479.395035] CPU: 18 PID: 1531 Comm: rmmod Not tainted 5.17.0-rc8+ #1436
|
|
Lee Duncan |
139e22 |
[ 3479.401712] Hardware name: Supermicro Super Server/H12SSL-NT, BIOS 2.1 06/02/2021
|
|
Lee Duncan |
139e22 |
[ 3479.409263] Call Trace:
|
|
Lee Duncan |
139e22 |
[ 3479.411743] <TASK>
|
|
Lee Duncan |
139e22 |
[ 3479.413875] dump_stack_lvl+0x45/0x59
|
|
Lee Duncan |
139e22 |
[ 3479.417582] print_address_description.constprop.0+0x1f/0x120
|
|
Lee Duncan |
139e22 |
[ 3479.423389] ? _scsih_expander_node_remove+0x710/0x750 [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.429469] kasan_report.cold+0x83/0xdf
|
|
Lee Duncan |
139e22 |
[ 3479.433438] ? _scsih_expander_node_remove+0x710/0x750 [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.439514] _scsih_expander_node_remove+0x710/0x750 [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.445411] ? _raw_spin_unlock_irqrestore+0x2d/0x40
|
|
Lee Duncan |
139e22 |
[ 3479.452032] scsih_remove+0x525/0xc90 [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.458212] ? mpt3sas_expander_remove+0x1d0/0x1d0 [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.465529] ? down_write+0xde/0x150
|
|
Lee Duncan |
139e22 |
[ 3479.470746] ? up_write+0x14d/0x460
|
|
Lee Duncan |
139e22 |
[ 3479.475840] ? kernfs_find_ns+0x137/0x310
|
|
Lee Duncan |
139e22 |
[ 3479.481438] pci_device_remove+0x65/0x110
|
|
Lee Duncan |
139e22 |
[ 3479.487013] __device_release_driver+0x316/0x680
|
|
Lee Duncan |
139e22 |
[ 3479.493180] driver_detach+0x1ec/0x2d0
|
|
Lee Duncan |
139e22 |
[ 3479.498499] bus_remove_driver+0xe7/0x2d0
|
|
Lee Duncan |
139e22 |
[ 3479.504081] pci_unregister_driver+0x26/0x250
|
|
Lee Duncan |
139e22 |
[ 3479.510033] _mpt3sas_exit+0x2b/0x6cf [mpt3sas]
|
|
Lee Duncan |
139e22 |
[ 3479.516144] __x64_sys_delete_module+0x2fd/0x510
|
|
Lee Duncan |
139e22 |
[ 3479.522315] ? free_module+0xaa0/0xaa0
|
|
Lee Duncan |
139e22 |
[ 3479.527593] ? __cond_resched+0x1c/0x90
|
|
Lee Duncan |
139e22 |
[ 3479.532951] ? lockdep_hardirqs_on_prepare+0x273/0x3e0
|
|
Lee Duncan |
139e22 |
[ 3479.539607] ? syscall_enter_from_user_mode+0x21/0x70
|
|
Lee Duncan |
139e22 |
[ 3479.546161] ? trace_hardirqs_on+0x1c/0x110
|
|
Lee Duncan |
139e22 |
[ 3479.551828] do_syscall_64+0x35/0x80
|
|
Lee Duncan |
139e22 |
[ 3479.556884] entry_SYSCALL_64_after_hwframe+0x44/0xae
|
|
Lee Duncan |
139e22 |
[ 3479.563402] RIP: 0033:0x7f1fc482483b
|
|
Lee Duncan |
139e22 |
...
|
|
Lee Duncan |
139e22 |
[ 3479.943087] ==================================================================
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
Fix this by introducing the local variable port_id to store the port ID
|
|
Lee Duncan |
139e22 |
value before executing mpt3sas_transport_port_remove(). This local variable
|
|
Lee Duncan |
139e22 |
is then used in the call to ioc_info() instead of dereferencing the freed
|
|
Lee Duncan |
139e22 |
port structure.
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
Link: https://lore.kernel.org/r/20220322055702.95276-1-damien.lemoal@opensource.wdc.com
|
|
Lee Duncan |
139e22 |
Fixes: 7d310f241001 ("scsi: mpt3sas: Get device objects using sas_address & portID")
|
|
Lee Duncan |
139e22 |
Cc: stable@vger.kernel.org
|
|
Lee Duncan |
139e22 |
Acked-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
|
|
Lee Duncan |
139e22 |
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
|
|
Lee Duncan |
139e22 |
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
|
|
Lee Duncan |
139e22 |
Acked-by: Lee Duncan <lduncan@suse.com>
|
|
Lee Duncan |
139e22 |
---
|
|
Lee Duncan |
139e22 |
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 5 ++++-
|
|
Lee Duncan |
139e22 |
1 file changed, 4 insertions(+), 1 deletion(-)
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
|
|
Lee Duncan |
139e22 |
index 00792767c620..7e476f50935b 100644
|
|
Lee Duncan |
139e22 |
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
|
|
Lee Duncan |
139e22 |
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
|
|
Lee Duncan |
139e22 |
@@ -11035,6 +11035,7 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
|
|
Lee Duncan |
139e22 |
{
|
|
Lee Duncan |
139e22 |
struct _sas_port *mpt3sas_port, *next;
|
|
Lee Duncan |
139e22 |
unsigned long flags;
|
|
Lee Duncan |
139e22 |
+ int port_id;
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
/* remove sibling ports attached to this expander */
|
|
Lee Duncan |
139e22 |
list_for_each_entry_safe(mpt3sas_port, next,
|
|
Lee Duncan |
139e22 |
@@ -11055,6 +11056,8 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
|
|
Lee Duncan |
139e22 |
mpt3sas_port->hba_port);
|
|
Lee Duncan |
139e22 |
}
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
+ port_id = sas_expander->port->port_id;
|
|
Lee Duncan |
139e22 |
+
|
|
Lee Duncan |
139e22 |
mpt3sas_transport_port_remove(ioc, sas_expander->sas_address,
|
|
Lee Duncan |
139e22 |
sas_expander->sas_address_parent, sas_expander->port);
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
@@ -11062,7 +11065,7 @@ _scsih_expander_node_remove(struct MPT3SAS_ADAPTER *ioc,
|
|
Lee Duncan |
139e22 |
"expander_remove: handle(0x%04x), sas_addr(0x%016llx), port:%d\n",
|
|
Lee Duncan |
139e22 |
sas_expander->handle, (unsigned long long)
|
|
Lee Duncan |
139e22 |
sas_expander->sas_address,
|
|
Lee Duncan |
139e22 |
- sas_expander->port->port_id);
|
|
Lee Duncan |
139e22 |
+ port_id);
|
|
Lee Duncan |
139e22 |
|
|
Lee Duncan |
139e22 |
spin_lock_irqsave(&ioc->sas_node_lock, flags);
|
|
Lee Duncan |
139e22 |
list_del(&sas_expander->list);
|
|
Lee Duncan |
139e22 |
|