Skip to contentSkip to conversation

scsi: qla2xxx avoid a panic due to BUG() if a WRITE_SAME command is sent to a device that has no protection

PATCH In review Laurence Oberman 4 participants 9 messages Jun 28, 2023 – Jul 31, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: qla2xxx avoid a panic due to BUG() if a WRITE_SAME command is sent to a device that has no protection

In the current code, If a device does not have protection, qla2xx will land up defaulting to a BUG() and will panic the system when sg_write_same is sent.This is because SCSI_PROT_NORMAL is matched and falls through to the BUG() call.
The write_same command to a device without protection is not handled safely.

Fix this by making two changes:
Set the bundling variable also to 0 for SCSI_PROT_NORMAL Modify the switch statement to match on SCSI_PROT_NORMAL and handle it appropriately removing the call to BUG()

Supersedes prior suggested patch.

---
 drivers/scsi/qla2xxx/qla_iocb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/scsi/qla2xxx/qla_iocb.c
index b9b3e6f80ea9..82a5d195e401 100644

drivers/scsi/qla2xxx/qla_iocb.c +0 -0
@@ -1381,7 +1381,8 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct

cmd_type_crc_2 *cmd_pkt,

 	if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
 	    (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP) ||
 	    (scsi_get_prot_op(cmd) == SCSI_PROT_READ_STRIP) ||
-	    (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT))
+	    (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT) ||
+	    (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL))

bundling = 0;

/* Allocate CRC context from global pool */
@@ -1443,6 +1444,9 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
dif_bytes = (data_bytes / blk_size) * 8;

switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
+ case SCSI_PROT_NORMAL:
+ total_bytes = data_bytes;
+ break;
case SCSI_PROT_READ_INSERT:
case SCSI_PROT_WRITE_STRIP:
total_bytes = data_bytes;

Signature · 1 line
2.39.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Laurence,

Quoted 9 lines · Laurence Oberman

In the current code, If a device does not have protection, qla2xx will land up defaulting to a BUG() and will panic the system when sg_write_same is sent.This is because SCSI_PROT_NORMAL is matched and falls through to the BUG() call.
The write_same command to a device without protection is not handled safely.

Quoted 5 lines

Fix this by making two changes:
Set the bundling variable also to 0 for SCSI_PROT_NORMAL Modify the switch statement to match on SCSI_PROT_NORMAL and handle it appropriately removing the call to BUG()

This should go to stable kernel as well.

Quoted 33 lines

Supersedes prior suggested patch.

---
drivers/scsi/qla2xxx/qla_iocb.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_iocb.c +0 -0
index b9b3e6f80ea9..82a5d195e401 100644
@@ -1381,7 +1381,8 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct
 cmd_type_crc_2 *cmd_pkt,

if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
(scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP) || (scsi_get_prot_op(cmd) == SCSI_PROT_READ_STRIP) ||

drivers/scsi/qla2xxx/qla_iocb.c +2 -1
-    (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT))
+    (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT) ||
+    (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL))

bundling = 0;

/* Allocate CRC context from global pool */

drivers/scsi/qla2xxx/qla_iocb.c +3 -0
@@ -1443,6 +1444,9 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct
 cmd_type_crc_2 *cmd_pkt,
 dif_bytes = (data_bytes / blk_size) * 8;
 
 switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
+ case SCSI_PROT_NORMAL:
+ total_bytes = data_bytes;
+ break;
Quoted 5 lines

case SCSI_PROT_READ_INSERT:
case SCSI_PROT_WRITE_STRIP:
total_bytes = data_bytes;

Signature · 1 line
2.39.3

The change itself looks good.

Reviewed-by Himanshu Madhani <[email protected] <mailto:[email protected]>>
Signature · 1 line
Himanshu Madhani Oracle Linux Engineering
#2 lore raw
In reply to Laurence Oberman

Laurence,

Quoted 5 lines

In the current code, If a device does not have protection, qla2xx will land up defaulting to a BUG() and will panic the system when sg_write_same is sent.This is because SCSI_PROT_NORMAL is matched and falls through to the BUG() call. The write_same command to a device without protection is not handled safely.

I would like to understand why the driver PI code path was chosen for a SCSI_PROT_NORMAL cmnd. That doesn't seem right.

Review

Quoted 6 lines
(quoted diff) +3 -0
+	case SCSI_PROT_NORMAL:
+		total_bytes = data_bytes;
+		break;
 	case SCSI_PROT_READ_INSERT:
 	case SCSI_PROT_WRITE_STRIP:
 		total_bytes = data_bytes;

All this transfer size wrangling in the driver should be removed and replaced with a call to scsi_transfer_length() which takes the PI size into account.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw
Quoted 22 lines · Martin K. Petersen

Laurence,

Quoted 7 lines

In the current code, If a device does not have protection, qla2xx will
land up defaulting to a BUG() and will panic the system when sg_write_same is sent.This is because SCSI_PROT_NORMAL is matched and
falls through to the BUG() call. The write_same command to a device without protection is not handled safely.

I would like to understand why the driver PI code path was chosen for a
SCSI_PROT_NORMAL cmnd. That doesn't seem right.

Quoted 6 lines

+       case SCSI_PROT_NORMAL:
+               total_bytes = data_bytes;
+               break;
        case SCSI_PROT_READ_INSERT:
        case SCSI_PROT_WRITE_STRIP:
                total_bytes = data_bytes;

Quoted 4 lines

All this transfer size wrangling in the driver should be removed and replaced with a call to scsi_transfer_length() which takes the PI size
into account.

Martin, good questions

I am waiting on Marvell to decide what to do about all this.

The patch was focused only on avoiding the nasty effect of what you mention happens in that code path, causing customers to have system panics.

The patch is to avoid the panic at this point with minimal impact to prior code functionality.

Regards
Laurence

Quoted 1 line
#4 lore raw
Quoted 40 lines · Laurence Oberman
Quoted 24 lines · Martin K. Petersen

Laurence,

Quoted 8 lines

In the current code, If a device does not have protection, qla2xx will
land up defaulting to a BUG() and will panic the system when sg_write_same is sent.This is because SCSI_PROT_NORMAL is matched and
falls through to the BUG() call. The write_same command to a device
without protection is not handled safely.

I would like to understand why the driver PI code path was chosen for
a
SCSI_PROT_NORMAL cmnd. That doesn't seem right.

Quoted 6 lines

+       case SCSI_PROT_NORMAL:
+               total_bytes = data_bytes;
+               break;
        case SCSI_PROT_READ_INSERT:
        case SCSI_PROT_WRITE_STRIP:
                total_bytes = data_bytes;

Quoted 5 lines

All this transfer size wrangling in the driver should be removed and
replaced with a call to scsi_transfer_length() which takes the PI size
into account.

Martin, good questions

I am waiting on Marvell to decide what to do about all this.

The patch was focused only on avoiding the nasty effect of what you mention happens in that code path, causing customers to have system panics.

Quoted 10 lines

The patch is to avoid the panic at this point with minimal impact to prior code functionality.

Regards
Laurence

Quoted 1 line

Hello Nilesh and Marvell

Any chance to get comments/eyes on this please.
Given its causing system crashes we need to decide how best to deal with it.

regards
Laurence

#5 lore raw

Hello Nilesh and Marvell

Any chance to get comments/eyes on this please.
Given its causing system crashes we need to decide how best to deal with it.

QT: Laurence,
In understanding the severity, Does end customer uses sg_write_same as the mechanism to move data?
Other than the sg_write_same utility, how common is end customer uses 32Byte CDB? It seems like upper layer doesn't have support for 32Bytes CDB at this time.

The code path you're modifying is for the T10-PI disk. This disk is "non-T10-PI" where it may create some confusion for next reader n Martin on why we've wander down this code path.

Will queue up a patch that plug this hole.

#6 lore raw
Quoted 13 lines · Quinn Tran

Hello Nilesh and Marvell

Any chance to get comments/eyes on this please.
Given its causing system crashes we need to decide how best to deal with it.

QT:  Laurence,
In understanding the severity,  Does end customer uses sg_write_same as the mechanism to move data?
Other than the sg_write_same utility, how common is end customer uses 32Byte CDB?   It seems like upper layer doesn't  have support for 32Bytes CDB at this time.

Quoted 8 lines

The code path you're modifying is for the T10-PI disk.  This disk is "non-T10-PI" where it may create some confusion for next reader n Martin on why we've wander down this code path.

Will queue up a patch that plug this hole.

OK, Thank you
In this case the customer was specifically using sg_write_same. I am not sure if it was part of a script or some other use case. They were of the opinion it was severe enough of an issue to warrant fixing so they logged a case with us.
Thanks for looking into this.

Regards
Laurence

#7 lore raw
Quoted 33 lines · Laurence Oberman
Quoted 15 lines · Quinn Tran

Hello Nilesh and Marvell

Any chance to get comments/eyes on this please.
Given its causing system crashes we need to decide how best to deal with it.

QT:  Laurence,
In understanding the severity,  Does end customer uses sg_write_same
as the mechanism to move data?
Other than the sg_write_same utility, how common is end customer uses
32Byte CDB?   It seems like upper layer doesn't  have support for 32Bytes CDB at this time.

Quoted 9 lines

The code path you're modifying is for the T10-PI disk.  This disk is
"non-T10-PI" where it may create some confusion for next reader n Martin on why we've wander down this code path.

Will queue up a patch that plug this hole.

OK, Thank you
In this case the customer was specifically using sg_write_same. I am not sure if it was part of a script or some other use case. They were of the opinion it was severe enough of an issue to warrant fixing so they logged a case with us.
Thanks for looking into this.

Quoted 2 lines

Regards
Laurence

Hello QT

Did I miss an update to this. Was another fix sent.
We need to deal with this at Red Hat as soon as possible please.

Regards
Laurence

#8 lore raw
Quoted 39 lines · Laurence Oberman
Quoted 36 lines · Laurence Oberman
Quoted 16 lines · Quinn Tran

Hello Nilesh and Marvell

Any chance to get comments/eyes on this please. Given its causing system crashes we need to decide how best to deal
with it.

QT:  Laurence,
In understanding the severity,  Does end customer uses sg_write_same
as the mechanism to move data?
Other than the sg_write_same utility, how common is end customer uses
32Byte CDB?   It seems like upper layer doesn't  have support for 32Bytes CDB at this time.

Quoted 9 lines

The code path you're modifying is for the T10-PI disk.  This disk is
"non-T10-PI" where it may create some confusion for next reader n Martin on why we've wander down this code path.

Will queue up a patch that plug this hole.

OK, Thank you
In this case the customer was specifically using sg_write_same. I am
not sure if it was part of a script or some other use case. They were of the opinion it was severe enough of an issue to warrant
fixing so they logged a case with us.
Thanks for looking into this.

Quoted 2 lines

Regards
Laurence

Quoted 7 lines

Hello QT

Did I miss an update to this. Was another fix sent.
We need to deal with this at Red Hat as soon as possible please.

Regards
Laurence

QT
WStillw aiting on you guys and we need to get thjis fixed, Please send the fix upstream that you were thinking of today. Regards
Laurence