* [PATCH] scsi: ibmvfc: Unmap scatterlists before completing BSG jobs
@ 2026-11-18 13:57 Suyuan Wang via B4 Relay
0 siblings, 0 replies; only message in thread
From: Suyuan Wang via B4 Relay @ 2026-11-18 13:57 UTC (permalink / raw)
To: tyreld; +Cc: linux-kernel, linux-scsi, linuxppc-dev
From: Suyuan Wang <stevewong@hust.edu.cn>
ibmvfc_bsg_request() calls bsg_job_done() before unmapping the request
and reply scatterlists.
bsg_job_done() starts block request completion, which can run
bsg_teardown_job() and free both scatterlists before the following
dma_unmap_sg() calls. The unmaps can then read freed memory.
Complete the job after the common DMA cleanup instead. The completion
path has already saved the operation result in bsg_reply and set rc to
zero; paths that return an error keep their existing cleanup and leave
completion to the FC transport. passthru_mutex stays held until after
the completion call.
Found with a static analysis tool and checked by hand.
Fixes: d31429e1517c ("[SCSI] ibmvfc: Add FC Passthru support")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on powerpc with clang (W=1, no new warnings). I don't
have IBM Power virtual FC hardware.
---
drivers/scsi/ibmvscsi/ibmvfc-core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
index aa7ae81df41b..6dce72cb80b5 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
@@ -2392,14 +2392,15 @@ static int ibmvfc_bsg_request(struct bsg_job *job)
ibmvfc_free_event(evt);
spin_unlock_irqrestore(&vhost->host->host_lock, flags);
bsg_reply->result = rc;
- bsg_job_done(job, bsg_reply->result,
- bsg_reply->reply_payload_rcv_len);
rc = 0;
out:
dma_unmap_sg(vhost->dev, job->request_payload.sg_list,
job->request_payload.sg_cnt, DMA_TO_DEVICE);
dma_unmap_sg(vhost->dev, job->reply_payload.sg_list,
job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
+ if (!rc)
+ bsg_job_done(job, bsg_reply->result,
+ bsg_reply->reply_payload_rcv_len);
mutex_unlock(&vhost->passthru_mutex);
LEAVE;
return rc;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 13:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 13:57 [PATCH] scsi: ibmvfc: Unmap scatterlists before completing BSG jobs Suyuan Wang via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®