FAILED: patch "[PATCH] scsi: qla2xxx: Fix mem access after free" failed to apply to 5.4-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y
git checkout FETCH_HEAD
git cherry-pick -x b843adde8d490934d042fbe9e3e46697cb3a64d2
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023072125-educator-unroll-251d@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..
Possible dependencies:
b843adde8d49 ("scsi: qla2xxx: Fix mem access after free")d3affdeb400f ("scsi: qla2xxx: Synchronize the IOCB count to be in order") c39587bc0aba ("scsi: qla2xxx: Fix crash due to stale SRB access around I/O timeouts") 5597616333ea ("scsi: qla2xxx: Stop using the SCSI pointer")79e30b884a01 ("scsi: qla2xxx: Call scsi_done() directly")e56b2234ab64 ("scsi: qla2xxx: Open-code qla2xxx_eh_target_reset()") 622299f16f33 ("scsi: qla2xxx: Simplify return value logic in qla2x00_get_sp_from_handle()") f45bca8c5052 ("scsi: qla2xxx: Fix double scsi_done for abort path")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b843adde8d490934d042fbe9e3e46697cb3a64d2 Mon Sep 17 00:00:00 2001
From: Quinn Tran <[email protected]>
Date: Fri, 28 Apr 2023 00:53:37 -0700
Subject: [PATCH] scsi: qla2xxx: Fix mem access after free
System crash, where driver is accessing scsi layer's memory (scsi_cmnd->device->host) to search for a well known internal pointer (vha). The scsi_cmnd was released back to upper layer which could be freed, but the driver is still accessing it.
7 [ffffa8e8d2c3f8d0] page_fault at ffffffff86c010fe
[exception RIP: __qla2x00_eh_wait_for_pending_commands+240]
RIP: ffffffffc0642350 RSP: ffffa8e8d2c3f988 RFLAGS: 00010286 RAX: 0000000000000165 RBX: 0000000000000002 RCX: 00000000000036d8 RDX: 0000000000000000 RSI: ffff9c5c56535188 RDI: 0000000000000286 RBP: ffff9c5bf7aa4a58 R8: ffff9c589aecdb70 R9: 00000000000003d1 R10: 0000000000000001 R11: 0000000000380000 R12: ffff9c5c5392bc78 R13: ffff9c57044ff5c0 R14: ffff9c56b5a3aa00 R15: 00000000000006db ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0018
8 [ffffa8e8d2c3f9c8] qla2x00_eh_wait_for_pending_commands at ffffffffc0646dd5 [qla2xxx] 9 [ffffa8e8d2c3fa00] __qla2x00_async_tm_cmd at ffffffffc0658094 [qla2xxx]
Remove access of freed memory. Currently the driver was checking to see if scsi_done was called by seeing if the sp->type has changed. Instead, check to see if the command has left the oustanding_cmds[] array as sign of scsi_done was called.
drivers/scsi/qla2xxx/qla_isr.c +31 -7
@@ -1862,9 +1862,9 @@ qla2x00_process_completed_request(struct scsi_qla_host *vha, } } -srb_t * -qla2x00_get_sp_from_handle (scsi_qla_host_t *vha,const char *func, -struct req_que *req,void *iocb) +static srb_t * +qla_get_sp_from_handle (scsi_qla_host_t *vha,const char *func, +struct req_que *req,void *iocb,u16 *ret_index) {struct qla_hw_data *ha = vha->hw;sts_entry_t *pkt = iocb;
@@ -1899,12 +1899,25 @@ qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,return NULL ; } - req->outstanding_cmds[index] =NULL ; - + *ret_index = index;qla_put_fw_resources (sp->qpair, &sp->iores);return sp; } +srb_t * +qla2x00_get_sp_from_handle (scsi_qla_host_t *vha,const char *func, +struct req_que *req,void *iocb) +{ +uint16_t index; +srb_t *sp; + + sp =qla_get_sp_from_handle (vha, func, req, iocb, &index); +if (sp) + req->outstanding_cmds[index] =NULL ; + +return sp; +} +static void qla2x00_mbx_iocb_entry (scsi_qla_host_t *vha,struct req_que *req,struct mbx_entry *mbx)
@@ -3237,13 +3250,13 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)return ; } - req->outstanding_cmds[handle] =NULL ; cp =GET_CMD_SP (sp);if (cp ==NULL ) {ql_dbg (ql_dbg_io, vha,0x3018 ,"Command already returned (0x%x/%p).\n" , sts->handle, sp); + req->outstanding_cmds[handle] =NULL ;return ; }
@@ -3514,6 +3527,9 @@ qla2x00_status_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, void *pkt)if (rsp->status_srb ==NULL ) sp->done (sp, res); + +/* for io's, clearing of outstanding_cmds[handle] means scsi_done was called */ + req->outstanding_cmds[handle] =NULL ; }/**
@@ -3590,6 +3606,7 @@ qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)uint16_t que =MSW (pkt->handle);struct req_que *req =NULL ;int res =DID_ERROR <<16 ; +u16 index; ql_dbg(ql_dbg_async, vha, 0x502a, "iocb type %xh with error status %xh, handle %xh, rspq id %d\n",
@@ -3608,7 +3625,6 @@ qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)switch (pkt->entry_type) {case NOTIFY_ACK_TYPE : -case STATUS_TYPE :case STATUS_CONT_TYPE :case LOGINOUT_PORT_IOCB_TYPE :case CT_IOCB_TYPE :
@@ -3628,6 +3644,14 @@ qla2x00_error_entry(scsi_qla_host_t *vha, struct rsp_que *rsp, sts_entry_t *pkt)case CTIO_TYPE7 :case CTIO_CRC2 :return 1 ; +case STATUS_TYPE : + sp =qla_get_sp_from_handle (vha, func, req, pkt, &index); +if (sp) { + sp->done (sp, res); + req->outstanding_cmds[index] =NULL ; +return 0 ; + } +break ; } fatal: ql_log(ql_log_warn, vha, 0x5030,
drivers/scsi/qla2xxx/qla_os.c +64 -66
154 lines not on this page · raw message