Skip to contentSkip to conversation

qla2xxx: Fix oops in qla2x00_probe_one error path

PATCH Applied Douglas Miller 3 participants 5 messages Oct 20, 2017 – Oct 31, 2017

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

cover qla2xxx: Fix oops in qla2x00_probe_one error path

See [PATCH 1/1] qla2xxx: Fix oops in qla2x00_probe_one error path

#1 lore raw

PATCH 1/1 qla2xxx: Fix oops in qla2x00_probe_one error path

On error, kthread_create() returns an errno-encoded pointer, not NULL. The routine qla2x00_probe_one() detects the error case and jumps to probe_failed, but has already assigned the return value from kthread_create() to ha->dpc_thread. Then probe_failed checks to see if ha->dpc_thread is not NULL before doing cleanup on it. Since in the error case this is also not NULL, it ends up trying to access an invalid task pointer.

Solution is to assign NULL to ha->dpc_thread in the error path to avoid kthread cleanup in that case.

---
 drivers/scsi/qla2xxx/qla_os.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/scsi/qla2xxx/qla_os.c +1 -0
index 9372098..bd39bf2 100644
@@ -3212,6 +3212,7 @@ static void qla2x00_iocb_work_fn(struct work_struct *work)
 		ql_log(ql_log_fatal, base_vha, 0x00ed,
 		    "Failed to start DPC thread.\n");
 		ret = PTR_ERR(ha->dpc_thread);
+		ha->dpc_thread = NULL;
 		goto probe_failed;
 	}
 	ql_dbg(ql_dbg_init, base_vha, 0x00ee,
Signature · 1 line
1.7.1
#2 lore raw

Douglas,

Quoted 10 lines

On error, kthread_create() returns an errno-encoded pointer, not NULL. The routine qla2x00_probe_one() detects the error case and jumps to probe_failed, but has already assigned the return value from kthread_create() to ha->dpc_thread. Then probe_failed checks to see if ha->dpc_thread is not NULL before doing cleanup on it. Since in the error case this is also not NULL, it ends up trying to access an invalid task pointer.

Solution is to assign NULL to ha->dpc_thread in the error path to avoid kthread cleanup in that case.

QLogic folks: Please review!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
Acked-by on v1 1/1
#3 lore raw
In reply to Douglas Miller
Quoted 34 lines · Douglas Miller

On error, kthread_create() returns an errno-encoded pointer, not NULL. The routine qla2x00_probe_one() detects the error case and jumps to probe_failed, but has already assigned the return value from kthread_create() to ha->dpc_thread. Then probe_failed checks to see if ha->dpc_thread is not NULL before doing cleanup on it. Since in the error case this is also not NULL, it ends up trying to access an invalid task pointer.

Solution is to assign NULL to ha->dpc_thread in the error path to avoid kthread cleanup in that case.

---
drivers/scsi/qla2xxx/qla_os.c | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
drivers/scsi/qla2xxx/qla_os.c +1 -0
index 9372098..bd39bf2 100644
@@ -3212,6 +3212,7 @@ static void qla2x00_iocb_work_fn(struct work_struct *work)
 		ql_log(ql_log_fatal, base_vha, 0x00ed,
 		    "Failed to start DPC thread.\n");
 		ret = PTR_ERR(ha->dpc_thread);
+		ha->dpc_thread = NULL;
 		goto probe_failed;
 	}
 	ql_dbg(ql_dbg_init, base_vha, 0x00ee,
Signature · 1 line
1.7.1

Looks good.

Thanks,
- Himanshu

#4 lore raw
In reply to Douglas Miller

Douglas,

Quoted 10 lines

On error, kthread_create() returns an errno-encoded pointer, not NULL. The routine qla2x00_probe_one() detects the error case and jumps to probe_failed, but has already assigned the return value from kthread_create() to ha->dpc_thread. Then probe_failed checks to see if ha->dpc_thread is not NULL before doing cleanup on it. Since in the error case this is also not NULL, it ends up trying to access an invalid task pointer.

Solution is to assign NULL to ha->dpc_thread in the error path to avoid kthread cleanup in that case.

Applied to 4.14/scsi-fixes. Thank you!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering