Skip to contentSkip to conversation

scsi: megaraid: Fix uninitialized mbox in mega_cmd_done

PATCH In review Maximilian Heyne 2 participants 3 messages May 31, 2023 – Jun 1, 2023

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

PATCH 1/1 scsi: megaraid: Fix uninitialized mbox in mega_cmd_done

This is similar to commit 7a2ae008a53c ("scsi: megaraid: Fix mega_cmd_done() CMDID_INT_CMDS"). When cmdid == CMDID_INT_CMDS and status != 0 then mbox is still NULL but is dereferenced below.

This bug was discovered and resolved using Coverity Static Analysis Security Testing (SAST) by Synopsys, Inc.

Fixes 0f2bb84d2a68 ("[SCSI] megaraid: simplify internal command handling")

---
Note: I have only compile tested this commit. Haven't tried reproducing it.

 drivers/scsi/megaraid.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/megaraid.c +1 -0
index e92f1a73cc9b..4dfe8865a18a 100644
@@ -1442,6 +1442,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 		if (cmdid == CMDID_INT_CMDS) {
 			scb = &adapter->int_scb;
 			cmd = scb->cmd;
+			mbox = (mbox_t *)scb->raw_mbox;
 
 			list_del_init(&scb->list);
 			scb->state = SCB_FREE;
Signature · 12 lines
2.39.2




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
#1 lore raw

Hi Maximilian!

Quoted 2 lines

This is similar to commit 7a2ae008a53c ("scsi: megaraid: Fix mega_cmd_done() CMDID_INT_CMDS").

That's supposed to be commit 75cb113cd43f, right?

Quoted 2 lines

When cmdid == CMDID_INT_CMDS and status != 0 then mbox is still NULL but is dereferenced below.

Is this actually a valid scenario, though? The mbox is only dereferenced if there is status returned from an attached device. And I am guessing that a controller-internal command does not talk to any attached device. Thus status should always be 0 for CMDID_INT_CMDS. I don't have the megaraid firmware manual so this is pure guesswork on my part. But you would think we would have come across an invalid deref since the original 2014 commit made the offending change.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw
Quoted 1 line · Martin K. Petersen

Hi Maximilian!

Hi Martin,

thanks for your response.

Quoted 5 lines
Quoted 3 lines

This is similar to commit 7a2ae008a53c ("scsi: megaraid: Fix mega_cmd_done() CMDID_INT_CMDS").

That's supposed to be commit 75cb113cd43f, right?

Sorry, yes I meant this commit. I accidentally got the commit id form the 5.4 backport.

Quoted 4 lines
Quoted 3 lines

When cmdid == CMDID_INT_CMDS and status != 0 then mbox is still NULL but is dereferenced below.

Quoted 8 lines

Is this actually a valid scenario, though? The mbox is only dereferenced if there is status returned from an attached device. And I am guessing that a controller-internal command does not talk to any attached device. Thus status should always be 0 for CMDID_INT_CMDS. I don't have the megaraid firmware manual so this is pure guesswork on my part. But you would think we would have come across an invalid deref since the original 2014 commit made the offending change.

This could indeed be the case. I only found this because it was reported by static code analysis. However, by reading the code it's not obvious that this is how it works. Should we therefore skip the whole status checking switch for internal commands to make it more clear? For example, by a goto to the end of the loop when the scb gets freed or just adding the scb free, list removal and a continue?

Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879