Skip to content

Commit a88d9db

Browse files
vauradkarmartinkpetersen
authored andcommitted
scsi: pm80xx: Fix dereferencing dangling pointer
sas_task structure should not be used after task_done is called. If the device is gone or not attached, we call task_done on t and continue to use in the sas_task in rest of the function. task_done is pointing to sas_ata_task_done, may free the memory associated with the task before returning. Link: https://lore.kernel.org/r/[email protected] Acked-by: Jack Wang <[email protected]> Signed-off-by: Vikram Auradkar <[email protected]> Signed-off-by: Deepak Ukey <[email protected]> Signed-off-by: Viswas G <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent e90e236 commit a88d9db

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/scsi/pm8001/pm8001_sas.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ static int pm8001_task_exec(struct sas_task *task,
388388
struct pm8001_ccb_info *ccb;
389389
u32 tag = 0xdeadbeef, rc = 0, n_elem = 0;
390390
unsigned long flags = 0;
391+
enum sas_protocol task_proto = t->task_proto;
391392

392393
if (!dev->port) {
393394
struct task_status_struct *tsm = &t->task_status;
@@ -412,7 +413,7 @@ static int pm8001_task_exec(struct sas_task *task,
412413
pm8001_dev = dev->lldd_dev;
413414
port = &pm8001_ha->port[sas_find_local_port_id(dev)];
414415
if (DEV_IS_GONE(pm8001_dev) || !port->port_attached) {
415-
if (sas_protocol_ata(t->task_proto)) {
416+
if (sas_protocol_ata(task_proto)) {
416417
struct task_status_struct *ts = &t->task_status;
417418
ts->resp = SAS_TASK_UNDELIVERED;
418419
ts->stat = SAS_PHY_DOWN;
@@ -434,7 +435,7 @@ static int pm8001_task_exec(struct sas_task *task,
434435
goto err_out;
435436
ccb = &pm8001_ha->ccb_info[tag];
436437

437-
if (!sas_protocol_ata(t->task_proto)) {
438+
if (!sas_protocol_ata(task_proto)) {
438439
if (t->num_scatter) {
439440
n_elem = dma_map_sg(pm8001_ha->dev,
440441
t->scatter,
@@ -454,7 +455,7 @@ static int pm8001_task_exec(struct sas_task *task,
454455
ccb->ccb_tag = tag;
455456
ccb->task = t;
456457
ccb->device = pm8001_dev;
457-
switch (t->task_proto) {
458+
switch (task_proto) {
458459
case SAS_PROTOCOL_SMP:
459460
rc = pm8001_task_prep_smp(pm8001_ha, ccb);
460461
break;
@@ -471,8 +472,7 @@ static int pm8001_task_exec(struct sas_task *task,
471472
break;
472473
default:
473474
dev_printk(KERN_ERR, pm8001_ha->dev,
474-
"unknown sas_task proto: 0x%x\n",
475-
t->task_proto);
475+
"unknown sas_task proto: 0x%x\n", task_proto);
476476
rc = -EINVAL;
477477
break;
478478
}
@@ -495,7 +495,7 @@ static int pm8001_task_exec(struct sas_task *task,
495495
pm8001_tag_free(pm8001_ha, tag);
496496
err_out:
497497
dev_printk(KERN_ERR, pm8001_ha->dev, "pm8001 exec failed[%d]!\n", rc);
498-
if (!sas_protocol_ata(t->task_proto))
498+
if (!sas_protocol_ata(task_proto))
499499
if (n_elem)
500500
dma_unmap_sg(pm8001_ha->dev, t->scatter, t->num_scatter,
501501
t->data_dir);

0 commit comments

Comments
 (0)