scsi: libiscsi: fix possible NULL pointer dereference in case of TMF
authorVarun Prakash <varun@chelsio.com>
Wed, 11 Jul 2018 16:39:52 +0000 (22:09 +0530)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 13 Jul 2018 03:08:09 +0000 (23:08 -0400)
In iscsi_check_tmf_restrictions() task->hdr is dereferenced to print the
opcode, it is possible that task->hdr is NULL.

There are two cases based on opcode argument:

1. ISCSI_OP_SCSI_CMD - In this case alloc_pdu() is called
after iscsi_check_tmf_restrictions()

iscsi_prep_scsi_cmd_pdu() -> iscsi_check_tmf_restrictions() -> alloc_pdu().

Transport drivers allocate memory for iSCSI hdr in alloc_pdu() and assign
it to task->hdr. In case of TMF task->hdr will be NULL resulting in NULL
pointer dereference.

2. ISCSI_OP_SCSI_DATA_OUT - In this case transport driver can free the
memory for iSCSI hdr after transmitting the pdu so task->hdr can be NULL or
invalid.

This patch fixes this issue by removing task->hdr->opcode from the printk
statement.

Signed-off-by: Varun Prakash <varun@chelsio.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/libiscsi.c

index d6093838f5f203dfc0968f2c2ee34f402af96093..c972cc2b3d5b7962e36bb6a428bd2f2795f34358 100644 (file)
@@ -284,11 +284,11 @@ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode)
                 */
                if (opcode != ISCSI_OP_SCSI_DATA_OUT) {
                        iscsi_conn_printk(KERN_INFO, conn,
-                                         "task [op %x/%x itt "
+                                         "task [op %x itt "
                                          "0x%x/0x%x] "
                                          "rejected.\n",
-                                         task->hdr->opcode, opcode,
-                                         task->itt, task->hdr_itt);
+                                         opcode, task->itt,
+                                         task->hdr_itt);
                        return -EACCES;
                }
                /*
@@ -297,10 +297,10 @@ static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode)
                 */
                if (conn->session->fast_abort) {
                        iscsi_conn_printk(KERN_INFO, conn,
-                                         "task [op %x/%x itt "
+                                         "task [op %x itt "
                                          "0x%x/0x%x] fast abort.\n",
-                                         task->hdr->opcode, opcode,
-                                         task->itt, task->hdr_itt);
+                                         opcode, task->itt,
+                                         task->hdr_itt);
                        return -EACCES;
                }
                break;