Skip to contentSkip to conversation

smartpqi fix static checker issues

PATCH Applied Don Brace 2 participants 5 messages Apr 15, 2021 – Apr 20, 2021

Subsystems (2)
lore
Share & tools
lore

Don Brace

author maintainer
#0 lore raw

cover smartpqi fix static checker issues

These patches are based on Martin Peterson's 5.13/scsi-queue tree

This set corrects two static checker warnings found by Dan Carpenter <[email protected]>

smartpqi-fix-blocks_per_row-static-checker-issue

Fixes 6702d2c40f31 ("scsi: smartpqi: Add support for RAID5 and RAID6 writes")

Using rmd->blocks_per_row as a divisor without checking it for 0 first.
The variable blocks_per_row is used as a divisor in many raid_map calculations. This can lead to a divide by 0. This patch prevents a possible divide by 0. If the member is 0, return PQI_RAID_BYPASS_INELIGIBLE before any division is performed. The current check for a non-0 value was after multiple divisions were performed.

smartpqi-fix-device-pointer-variable-reference

Link ("https://www.mail-archive.com/[email protected]/msg06329.html")
Fixes ec504b23df9d ("[304/324] scsi: smartpqi: Add phy ID support for the physical drives")

drivers/scsi/smartpqi/smartpqi_sas_transport.c:97 pqi_sas_port_add_rphy() warn: variable dereferenced before check 'pqi_sas_port->device' (see line 95)
In function pqi_sas_port_add_rphy there is a pointer dereference without a check for NULL value. Correct this by moving the pointer dereference after the check for non-NULL value.

Note: I could not find the e-mail for
smartpqi-fix-device-pointer-variable-reference issue in lore.kernel.org so I used mail-archive.com.
It may have not been forwarded to lore.kernel.org. Not sure.

---

Don Brace (2):
smartpqi: fix blocks_per_row static checker issue
smartpqi: fix device pointer variable reference static checker issue

 drivers/scsi/smartpqi/smartpqi_sas_transport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
Signature

author maintainer
#1 lore raw

PATCH 1/2 smartpqi: fix blocks_per_row static checker issue

Dan Carpenter found a possible divide by 0 issue in the smartpqi driver in functions pci_get_aio_common_raid_map_values and pqi_calc_aio_r5_or_r6. The variable rmd->blocks_per_row is used as a divisor and could be 0.

Fixes 6702d2c40f31 ("scsi: smartpqi: Add support for RAID5 and RAID6 writes")

Using rmd->blocks_per_row as a divisor without checking it for 0 first.

Correct these possible divide by 0 conditions by insuring that rmd->blocks_per_row is not zero before usage.
The check for non-0 was too late to prevent a divide by 0 condition. Add in a comment to explain why the check for non-zero
is necessary. If the member is 0, return PQI_RAID_BYPASS_INELIGIBLE before any division is performed.

---
 drivers/scsi/smartpqi/smartpqi_init.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/scsi/smartpqi/smartpqi_init.c +6 -2
index 3b0f281daa2b..797ac699b7ff 100644
@@ -2510,6 +2510,8 @@ static int pci_get_aio_common_raid_map_values(struct pqi_ctrl_info *ctrl_info,
 
 	/* Calculate stripe information for the request. */
 	rmd->blocks_per_row = rmd->data_disks_per_row * rmd->strip_size;
+	if (rmd->blocks_per_row == 0) /* Used as a divisor in many calculations */
+		return PQI_RAID_BYPASS_INELIGIBLE;
 #if BITS_PER_LONG == 32
 	tmpdiv = rmd->first_block;
 	do_div(tmpdiv, rmd->blocks_per_row);
@@ -2559,6 +2561,10 @@ static int pqi_calc_aio_r5_or_r6(struct pqi_scsi_dev_raid_map_data *rmd,
 #if BITS_PER_LONG == 32
 	u64 tmpdiv;
 #endif
+
+	if (rmd->blocks_per_row == 0) /* Used as a divisor in many calculations */
+		return PQI_RAID_BYPASS_INELIGIBLE;
+
 	/* RAID 50/60 */
 	/* Verify first and last block are in same RAID group. */
 	rmd->stripesize = rmd->blocks_per_row * rmd->layout_map_count;
@@ -2662,8 +2668,6 @@ static int pqi_calc_aio_r5_or_r6(struct pqi_scsi_dev_raid_map_data *rmd,
 			rmd->q_parity_it_nexus = raid_map->disk_data[index + 1].aio_handle;
 			rmd->xor_mult = raid_map->disk_data[rmd->map_index].xor_mult[1];
 		}
-		if (rmd->blocks_per_row == 0)
-			return PQI_RAID_BYPASS_INELIGIBLE;
 #if BITS_PER_LONG == 32
 		tmpdiv = rmd->first_block;
 		do_div(tmpdiv, rmd->blocks_per_row);
author maintainer
#2 lore raw

PATCH 2/2 smartpqi: fix device pointer variable reference static checker issue

In reply to Don Brace

Dan Carpenter found a possible NULL pointer dereference issue in function pqi_sas_port_add_rphy.

Link ("https://www.mail-archive.com/[email protected]/msg06329.html")
Fixes ec504b23df9d ("[304/324] scsi: smartpqi: Add phy ID support for the physical drives")

drivers/scsi/smartpqi/smartpqi_sas_transport.c:97 pqi_sas_port_add_rphy() warn: variable dereferenced before check 'pqi_sas_port->device' (see line 95)

Correct issue by moving reference of pqi_sas_port->device after the check for the device pointer being non-NULL.

---
 drivers/scsi/smartpqi/smartpqi_sas_transport.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/smartpqi/smartpqi_sas_transport.c +1 -1
index dd9b784792ef..dd628cc87f78 100644
@@ -92,12 +92,12 @@ static int pqi_sas_port_add_rphy(struct pqi_sas_port *pqi_sas_port,
 
 	identify = &rphy->identify;
 	identify->sas_address = pqi_sas_port->sas_address;
-	identify->phy_identifier = pqi_sas_port->device->phy_id;
 
 	identify->initiator_port_protocols = SAS_PROTOCOL_ALL;
 	identify->target_port_protocols = SAS_PROTOCOL_STP;
 
 	if (pqi_sas_port->device) {
+		identify->phy_identifier = pqi_sas_port->device->phy_id;
 		switch (pqi_sas_port->device->device_type) {
 		case SA_DEVICE_TYPE_SAS:
 		case SA_DEVICE_TYPE_SES:
#4 lore raw
In reply to Don Brace
Quoted 17 lines · Don Brace

These patches are based on Martin Peterson's 5.13/scsi-queue tree

This set corrects two static checker warnings found by Dan Carpenter <[email protected]>

smartpqi-fix-blocks_per_row-static-checker-issue

Fixes 6702d2c40f31 ("scsi: smartpqi: Add support for RAID5 and RAID6 writes")

Using rmd->blocks_per_row as a divisor without checking it for 0 first.
The variable blocks_per_row is used as a divisor in many raid_map calculations. This can lead to a divide by 0. This patch prevents a possible divide by 0. If the member is 0, return PQI_RAID_BYPASS_INELIGIBLE before any division is performed. The current check for a non-0 value was after multiple divisions were performed.

Quoted 1 line

[...]

Applied to 5.13/scsi-queue, thanks!

[1/2] smartpqi: fix blocks_per_row static checker issue

      https://git.kernel.org/mkp/scsi/c/667298ceaf04
[2/2] smartpqi: fix device pointer variable reference static checker issue
      https://git.kernel.org/mkp/scsi/c/5cad5a507241
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering