Skip to contentSkip to conversation

scsi: ips: Fix potential NULL pointer dereference of scb->scsi_cmd

PATCH New Zhen Ni 1 participant 1 message Sep 30, 2025

Subsystems (3)
lore
Share & tools
lore

Zhen Ni

author
#0 lore raw

PATCH 1/1 scsi: ips: Fix potential NULL pointer dereference of scb->scsi_cmd

The 'if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))' check uses an AND logic, so in the else branch (handling non-PASSTHRU commands) scb->scsi_cmd was not checked for NULL. This may lead to NULL pointer dereference and potentially cause a kernel panic when processing invalid SCSI commands.

Adding an early return if scb->scsi_cmd is NULL. Maintaining all existing functionality for valid commands.

---
 drivers/scsi/ips.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/scsi/ips.c +8 -9
index 94adb6ac02a4..091c13a21c3a 100644
@@ -3129,7 +3129,10 @@ ips_done(ips_ha_t * ha, ips_scb_t * scb)
 	if (!scb)
 		return;
 
-	if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
+	if (!scb->scsi_cmd)
+		return;
+
+	if (ips_is_passthru(scb->scsi_cmd)) {
 		ips_cleanup_passthru(ha, scb);
 		ha->num_ioctl--;
 	} else {
@@ -3184,18 +3187,14 @@ ips_done(ips_ha_t * ha, ips_scb_t * scb)
 
 			switch (ret) {
 			case IPS_FAILURE:
-				if (scb->scsi_cmd) {
-					scb->scsi_cmd->result = DID_ERROR << 16;
-					scsi_done(scb->scsi_cmd);
-				}
+				scb->scsi_cmd->result = DID_ERROR << 16;
+				scsi_done(scb->scsi_cmd);
 
 				ips_freescb(ha, scb);
 				break;
 			case IPS_SUCCESS_IMM:
-				if (scb->scsi_cmd) {
-					scb->scsi_cmd->result = DID_ERROR << 16;
-					scsi_done(scb->scsi_cmd);
-				}
+				scb->scsi_cmd->result = DID_ERROR << 16;
+				scsi_done(scb->scsi_cmd);
 
 				ips_freescb(ha, scb);
 				break;
Signature · 1 line
2.20.1