public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] st: fix race in st_scsi_execute_end
@ 2011-10-21 11:31 Petr Uzel
  2011-10-21 17:00 ` Kai Makisara
  2012-03-21 10:09 ` James Bottomley
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Uzel @ 2011-10-21 11:31 UTC (permalink / raw)
  To: linux-kernel, Willem Riede; +Cc: jack, linux-scsi, juergen.gross

[-- Attachment #1: Type: text/plain, Size: 1331 bytes --]

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.

CC: stable@kernel.org
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
Reported-by: Juergen Groß <juergen.gross@ts.fujitsu.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
 drivers/scsi/st.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 1871b8a..9b28f39 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -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);
 }
 
-- 
1.7.3.4


Petr

--
Petr Uzel
IRC: ptr_uzl @ freenode

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] st: fix race in st_scsi_execute_end
  2011-10-21 11:31 [PATCH] st: fix race in st_scsi_execute_end Petr Uzel
@ 2011-10-21 17:00 ` Kai Makisara
  2012-03-21 10:09 ` James Bottomley
  1 sibling, 0 replies; 3+ messages in thread
From: Kai Makisara @ 2011-10-21 17:00 UTC (permalink / raw)
  To: Petr Uzel; +Cc: linux-kernel, Willem Riede, jack, linux-scsi, juergen.gross

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1473 bytes --]

On Fri, 21 Oct 2011, Petr Uzel wrote:

> 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.
> 
> CC: stable@kernel.org
> Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
> Reported-by: Juergen Groß <juergen.gross@ts.fujitsu.com>
> Reviewed-by: Jan Kara <jack@suse.cz>

Acked-by: Kai Mäkisara <kai.makisara@kolumbus.fi>

> ---
>  drivers/scsi/st.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index 1871b8a..9b28f39 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -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);
>  }
>  
> 

Thanks for the fix.

Kai

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] st: fix race in st_scsi_execute_end
  2011-10-21 11:31 [PATCH] st: fix race in st_scsi_execute_end Petr Uzel
  2011-10-21 17:00 ` Kai Makisara
@ 2012-03-21 10:09 ` James Bottomley
  1 sibling, 0 replies; 3+ messages in thread
From: James Bottomley @ 2012-03-21 10:09 UTC (permalink / raw)
  To: Petr Uzel; +Cc: linux-kernel, Willem Riede, jack, linux-scsi, juergen.gross

On Fri, 2011-10-21 at 13:31 +0200, Petr Uzel wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-21 10:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-21 11:31 [PATCH] st: fix race in st_scsi_execute_end Petr Uzel
2011-10-21 17:00 ` Kai Makisara
2012-03-21 10:09 ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox