Skip to contentSkip to conversation

scsi: megasas: check request object in MegasasCmd

PATCH In review P J P 2 participants 3 messages May 10, 2017

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 scsi: megasas: check request object in MegasasCmd

From: Prasad J Pandit <[email protected]>

When processing completed commands, if SCSIRequest object 'cmd->req' was null, it could lead to null pointer dereference in megasas_complete_command. Add check to avoid it.

---
 hw/scsi/megasas.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/scsi/megasas.c +5 -3
index 84b8caf..25e3541 100644
@@ -580,9 +580,11 @@ static void megasas_complete_command(MegasasCmd *cmd)
     cmd->iov_size = 0;
     cmd->iov_offset = 0;
 
-    cmd->req->hba_private = NULL;
-    scsi_req_unref(cmd->req);
-    cmd->req = NULL;
+    if (cmd->req) {
+        cmd->req->hba_private = NULL;
+        scsi_req_unref(cmd->req);
+        cmd->req = NULL;
+    }
 
     megasas_unmap_frame(cmd->state, cmd);
     megasas_complete_frame(cmd->state, cmd->context);
Signature · 1 line
2.9.3
#1 lore raw
Quoted 8 lines · P J P

From: Prasad J Pandit <[email protected]>

When processing completed commands, if SCSIRequest object 'cmd->req' was null, it could lead to null pointer dereference in megasas_complete_command. Add check to avoid it.

What version was this reported for? It should be fixed in v2.8.0 and newer by commit 9e55d58806 ("megasas: clean up and fix request completion/cancellation", 2016-11-28).

Thanks,

Paolo

author
#2 lore raw

Hello Paolo,

+-- On Wed, 10 May 2017, Paolo Bonzini wrote --+
| What version was this reported for?  It should be fixed in v2.8.0 and
| newer by commit 9e55d58806 ("megasas: clean up and fix request
| completion/cancellation", 2016-11-28).

I checked the reproducer against current upstream git, it does work. IIUC, the above commit appears to have introduced the issue.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F