Skip to contentSkip to conversation

scsi: qla2xxx: Fix use after free in debug code

PATCH Applied Dan Carpenter 4 participants 5 messages Aug 3, 2021 – Aug 10, 2021

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

PATCH 1/1 scsi: qla2xxx: Fix use after free in debug code

The sp->free(sp); call frees "sp" and then the debug code dereferences it on the next line. Swap the order.

Fixes 84318a9f01ce ("scsi: qla2xxx: edif: Add send, receive, and accept for auth_els")
---
 drivers/scsi/qla2xxx/qla_bsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_bsg.c +2 -2
index 0739f8ad525a..4b5d28d89d69 100644
@@ -25,12 +25,12 @@ void qla2x00_bsg_job_done(srb_t *sp, int res)
 	struct bsg_job *bsg_job = sp->u.bsg_job;
 	struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 
-	sp->free(sp);
-
 	ql_dbg(ql_dbg_user, sp->vha, 0x7009,
 	    "%s: sp hdl %x, result=%x bsg ptr %p\n",
 	    __func__, sp->handle, res, bsg_job);
 
+	sp->free(sp);
+
 	bsg_reply->result = res;
 	bsg_job_done(bsg_job, bsg_reply->result,
 		       bsg_reply->reply_payload_rcv_len);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Dan Carpenter

The sp->free(sp); call frees "sp" and then the debug code dereferences it on the next line. Swap the order.

Fixes 84318a9f01ce ("scsi: qla2xxx: edif: Add send, receive, and accept for auth_els")
---
 drivers/scsi/qla2xxx/qla_bsg.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_bsg.c +2 -3
index 0739f8ad525a..4b5d28d89d69 100644
@@ -25,12 +25,12 @@ void qla2x00_bsg_job_done(srb_t *sp, int res)
        struct bsg_job *bsg_job = sp->u.bsg_job;
        struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 
-       sp->free(sp);
-
        ql_dbg(ql_dbg_user, sp->vha, 0x7009,
            "%s: sp hdl %x, result=%x bsg ptr %p\n",
            __func__, sp->handle, res, bsg_job);
 
+       sp->free(sp);
+
        bsg_reply->result = res;
        bsg_job_done(bsg_job, bsg_reply->result,
                       bsg_reply->reply_payload_rcv_len);
--

2.20.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 35 lines · Dan Carpenter

The sp->free(sp); call frees "sp" and then the debug code dereferences it on the next line. Swap the order.

Fixes 84318a9f01ce ("scsi: qla2xxx: edif: Add send, receive, and accept for auth_els")

---
drivers/scsi/qla2xxx/qla_bsg.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_bsg.c +2 -2
index 0739f8ad525a..4b5d28d89d69 100644
@@ -25,12 +25,12 @@ void qla2x00_bsg_job_done(srb_t *sp, int res)
 	struct bsg_job *bsg_job = sp->u.bsg_job;
 	struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 
-	sp->free(sp);
-
 	ql_dbg(ql_dbg_user, sp->vha, 0x7009,
 	    "%s: sp hdl %x, result=%x bsg ptr %p\n",
 	    __func__, sp->handle, res, bsg_job);
 
+	sp->free(sp);
+
 	bsg_reply->result = res;
 	bsg_job_done(bsg_job, bsg_reply->result,
 		       bsg_reply->reply_payload_rcv_len);
Signature · 1 line
2.20.1

--
Himanshu Madhani Oracle Linux Engineering

#3 lore raw
In reply to Dan Carpenter

Dan,

Quoted 2 lines

The sp->free(sp); call frees "sp" and then the debug code dereferences it on the next line. Swap the order.

Applied to 5.15/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering