diff mbox series

scsi: message: fusion: Fix out-of-bounds shift in phy bitmask calculation

Message ID 20250220091436.17412-1-pchelkin@ispras.ru (mailing list archive)
State New
Headers show
Series scsi: message: fusion: Fix out-of-bounds shift in phy bitmask calculation | expand

Commit Message

Fedor Pchelkin Feb. 20, 2025, 9:14 a.m. UTC
In mptsas_setup_wide_ports() the calculation of phy bitmask is a subject
to undefined behavior when phy index exceeds the width of type 'int', but
is still less than 64.

Utilize BIT_ULL macro to fix this.

Found by Linux Verification Center (linuxtesting.org) with SVACE static
analysis tool.

Fixes: 547f9a218436 ("[SCSI] mptsas: wide port support")
Cc: stable@vger.kernel.org
Co-developed-by: Aleksandr Mishin <amishin@t-argos.ru>
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
struct mptsas_portinfo_details::phy_bitmask is used only in various
logging printks throughout the driver. Another option would be to drop
this field completely if it is considered a more appropriate solution..

 drivers/message/fusion/mptsas.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 7e79da9684ed..cd95655f1592 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -43,6 +43,7 @@ 
 */
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 
+#include <linux/bits.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
@@ -880,7 +881,7 @@  mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
 		    "%s: [%p]: deleting phy = %d\n",
 		    ioc->name, __func__, port_details, i));
 		port_details->num_phys--;
-		port_details->phy_bitmask &= ~ (1 << phy_info->phy_id);
+		port_details->phy_bitmask &= ~BIT_ULL(phy_info->phy_id);
 		memset(&phy_info->attached, 0, sizeof(struct mptsas_devinfo));
 		if (phy_info->phy) {
 			devtprintk(ioc, dev_printk(KERN_DEBUG,
@@ -915,7 +916,7 @@  mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
 			port_details->port_info = port_info;
 			if (phy_info->phy_id < 64 )
 				port_details->phy_bitmask |=
-				    (1 << phy_info->phy_id);
+					BIT_ULL(phy_info->phy_id);
 			phy_info->sas_port_add_phy=1;
 			dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "\t\tForming port\n\t\t"
 			    "phy_id=%d sas_address=0x%018llX\n",
@@ -957,7 +958,7 @@  mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
 			phy_info_cmp->port_details = port_details;
 			if (phy_info_cmp->phy_id < 64 )
 				port_details->phy_bitmask |=
-				(1 << phy_info_cmp->phy_id);
+					BIT_ULL(phy_info_cmp->phy_id);
 			port_details->num_phys++;
 		}
 	}