All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] smartpqi fix static checker issues
@ 2021-04-15 16:41 Don Brace
  2021-04-15 16:42 ` [PATCH 1/2] smartpqi: fix blocks_per_row static checker issue Don Brace
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Don Brace @ 2021-04-15 16:41 UTC (permalink / raw)
  To: Kevin.Barnett, scott.teel, Justin.Lindley, scott.benesh,
	gerry.morong, mahesh.rajashekhara, mike.mcgowen, murthy.bhat,
	hch, jejb, joseph.szczypek, POSWALD
  Cc: linux-scsi

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

This set corrects two static checker warnings found by
Dan Carpenter <dan.carpenter@oracle.com>

smartpqi-fix-blocks_per_row-static-checker-issue
 Link: https://lore.kernel.org/linux-scsi/YG%2F5kWHHAr7w5dU5@mwanda/
 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/kbuild@lists.01.org/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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reported-by: kernel test robot <lkp@intel.com>

---

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] smartpqi: fix blocks_per_row static checker issue
  2021-04-15 16:41 [PATCH 0/2] smartpqi fix static checker issues Don Brace
@ 2021-04-15 16:42 ` Don Brace
  2021-04-15 16:42 ` [PATCH 2/2] smartpqi: fix device pointer variable reference " Don Brace
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Don Brace @ 2021-04-15 16:42 UTC (permalink / raw)
  To: Kevin.Barnett, scott.teel, Justin.Lindley, scott.benesh,
	gerry.morong, mahesh.rajashekhara, mike.mcgowen, murthy.bhat,
	hch, jejb, joseph.szczypek, POSWALD
  Cc: linux-scsi

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.

Link: https://lore.kernel.org/linux-scsi/YG%2F5kWHHAr7w5dU5@mwanda/
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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Scott Benesh <scott.benesh@microchip.com>
Reviewed-by: Scott Teel <scott.teel@microchip.com>
Reviewed-by: Mike McGowen <mike.mcgowen@microchip.com>
Reviewed-by: Kevin Barnett <kevin.barnett@microchip.com>
Signed-off-by: Don Brace <don.brace@microchip.com>
---
 drivers/scsi/smartpqi/smartpqi_init.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 3b0f281daa2b..797ac699b7ff 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -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);


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] smartpqi: fix device pointer variable reference static checker issue
  2021-04-15 16:41 [PATCH 0/2] smartpqi fix static checker issues Don Brace
  2021-04-15 16:42 ` [PATCH 1/2] smartpqi: fix blocks_per_row static checker issue Don Brace
@ 2021-04-15 16:42 ` Don Brace
  2021-04-16  2:03 ` [PATCH 0/2] smartpqi fix static checker issues Martin K. Petersen
  2021-04-20  2:29 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Don Brace @ 2021-04-15 16:42 UTC (permalink / raw)
  To: Kevin.Barnett, scott.teel, Justin.Lindley, scott.benesh,
	gerry.morong, mahesh.rajashekhara, mike.mcgowen, murthy.bhat,
	hch, jejb, joseph.szczypek, POSWALD
  Cc: linux-scsi

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

Link: ("https://www.mail-archive.com/kbuild@lists.01.org/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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Scott Benesh <scott.benesh@microchip.com>
Reviewed-by: Scott Teel <scott.teel@microchip.com>
Reviewed-by: Mike McGowen <mike.mcgowen@microchip.com>
Reviewed-by: Kevin Barnett <kevin.barnett@microchip.com>
Signed-off-by: Don Brace <don.brace@microchip.com>
---
 drivers/scsi/smartpqi/smartpqi_sas_transport.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/smartpqi/smartpqi_sas_transport.c b/drivers/scsi/smartpqi/smartpqi_sas_transport.c
index dd9b784792ef..dd628cc87f78 100644
--- a/drivers/scsi/smartpqi/smartpqi_sas_transport.c
+++ b/drivers/scsi/smartpqi/smartpqi_sas_transport.c
@@ -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:


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] smartpqi fix static checker issues
  2021-04-15 16:41 [PATCH 0/2] smartpqi fix static checker issues Don Brace
  2021-04-15 16:42 ` [PATCH 1/2] smartpqi: fix blocks_per_row static checker issue Don Brace
  2021-04-15 16:42 ` [PATCH 2/2] smartpqi: fix device pointer variable reference " Don Brace
@ 2021-04-16  2:03 ` Martin K. Petersen
  2021-04-20  2:29 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-04-16  2:03 UTC (permalink / raw)
  To: Don Brace
  Cc: Kevin.Barnett, scott.teel, Justin.Lindley, scott.benesh,
	gerry.morong, mahesh.rajashekhara, mike.mcgowen, murthy.bhat,
	hch, jejb, joseph.szczypek, POSWALD, linux-scsi


Don,

> This set corrects two static checker warnings found by Dan Carpenter
> <dan.carpenter@oracle.com>

Applied to 5.13/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] smartpqi fix static checker issues
  2021-04-15 16:41 [PATCH 0/2] smartpqi fix static checker issues Don Brace
                   ` (2 preceding siblings ...)
  2021-04-16  2:03 ` [PATCH 0/2] smartpqi fix static checker issues Martin K. Petersen
@ 2021-04-20  2:29 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-04-20  2:29 UTC (permalink / raw)
  To: POSWALD, mahesh.rajashekhara, Don Brace, mike.mcgowen,
	Kevin.Barnett, scott.teel, joseph.szczypek, scott.benesh,
	gerry.morong, jejb, hch, murthy.bhat, Justin.Lindley
  Cc: Martin K . Petersen, linux-scsi

On Thu, 15 Apr 2021 11:41:58 -0500, Don Brace wrote:

> These patches are based on Martin Peterson's 5.13/scsi-queue tree
> 
> This set corrects two static checker warnings found by
> Dan Carpenter <dan.carpenter@oracle.com>
> 
> smartpqi-fix-blocks_per_row-static-checker-issue
>  Link: https://lore.kernel.org/linux-scsi/YG%2F5kWHHAr7w5dU5@mwanda/
>  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.
> 
> [...]

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

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-20  2:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-15 16:41 [PATCH 0/2] smartpqi fix static checker issues Don Brace
2021-04-15 16:42 ` [PATCH 1/2] smartpqi: fix blocks_per_row static checker issue Don Brace
2021-04-15 16:42 ` [PATCH 2/2] smartpqi: fix device pointer variable reference " Don Brace
2021-04-16  2:03 ` [PATCH 0/2] smartpqi fix static checker issues Martin K. Petersen
2021-04-20  2:29 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.