Skip to contentSkip to conversation

st: fix race in st_scsi_execute_end

PATCH In review Petr Uzel 3 participants 3 messages Oct 21, 2011 – Mar 21, 2012

Subsystems (2)
lore
Share & tools
lore

Petr Uzel

author
#0 lore raw

PATCH 1/1 st: fix race in st_scsi_execute_end

The call to complete() in st_scsi_execute_end() wakes up sleeping thread in write_behind_check(), which frees the st_request, thus invalidating the pointer to the associated bio structure, which is then passed to the blk_rq_unmap_user(). Fix by storing pointer to bio structure into temporary local variable.

This bug is present since at least linux-2.6.32.

---
 drivers/scsi/st.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/scsi/st.c +3 -1
index 1871b8a..9b28f39 100644
@@ -462,14 +462,16 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
 {
 	struct st_request *SRpnt = req->end_io_data;
 	struct scsi_tape *STp = SRpnt->stp;
+	struct bio *tmp;
 
 	STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
 	STp->buffer->cmdstat.residual = req->resid_len;
 
+	tmp = SRpnt->bio;
 	if (SRpnt->waiting)
 		complete(SRpnt->waiting);
 
-	blk_rq_unmap_user(SRpnt->bio);
+	blk_rq_unmap_user(tmp);
 	__blk_put_request(req->q, req);
 }
 
Signature · 8 lines
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Petr Uzel

The call to complete() in st_scsi_execute_end() wakes up sleeping thread in write_behind_check(), which frees the st_request, thus invalidating the pointer to the associated bio structure, which is then passed to the blk_rq_unmap_user(). Fix by storing pointer to bio structure into temporary local variable.

Quoted 6 lines

This bug is present since at least linux-2.6.32.

Quoted 17 lines
---
 drivers/scsi/st.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/scsi/st.c +1 -0
index 1871b8a..9b28f39 100644
@@ -462,14 +462,16 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
 {
 	struct st_request *SRpnt = req->end_io_data;
 	struct scsi_tape *STp = SRpnt->stp;
+	struct bio *tmp;
 
 	STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
 	STp->buffer->cmdstat.residual = req->resid_len;

drivers/scsi/st.c static void st_scsi_execute_end(struct request *req, int uptodate) · line 477

Quoted 10 lines
drivers/scsi/st.c +2 -1
 
+	tmp = SRpnt->bio;
 	if (SRpnt->waiting)
 		complete(SRpnt->waiting);
 
-	blk_rq_unmap_user(SRpnt->bio);
+	blk_rq_unmap_user(tmp);
 	__blk_put_request(req->q, req);
 }
 

Thanks for the fix.

Kai

maintainer
#2 lore raw
In reply to Petr Uzel
Quoted 7 lines · Petr Uzel

The call to complete() in st_scsi_execute_end() wakes up sleeping thread in write_behind_check(), which frees the st_request, thus invalidating the pointer to the associated bio structure, which is then passed to the blk_rq_unmap_user(). Fix by storing pointer to bio structure into temporary local variable.

This bug is present since at least linux-2.6.32.

This patch isn't applyable. That's because gpg has mangled it. You either need to turn it off or do detached signatures.

Thanks,

James