diff options
author | Christof Schmitt <christof.schmitt@de.ibm.com> | 2009-09-17 03:10:14 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2009-10-02 10:45:58 -0400 |
commit | e27168f8c337b12b8aa8d59c3123c79d2f83603d (patch) | |
tree | 947d5e483ca1d4ee0bbbbdc7abf317f1f591dbd0 /drivers/scsi | |
parent | 5915136d4d3954867cced8a2297bddd16caf36a1 (diff) |
[SCSI] sg: Free data buffers after calling blk_rq_unmap_user
Running sg_luns on s390x with CONFIG_DEBUG_PAGEALLOC enabled fails
with EFAULT from the SG_IO ioctl. The EFAULT is the result from
copy_to_user failing in this call chain:
sg_ioctl
sg_new_read
sg_finish_rem_req
blk_rq_unmap_user
__blk_rq_unmap_user
bio_uncopy_user
__bio_copy_iov
copy_to_user
The sg driver calls sg_remove_scat to free the memory pages before
calling blk_rq_unmap_user that tries to copy the data back to
userspace. Change the order to first call blk_rq_unmap_user before
freeing the pages in sg_remove_scat.
Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: stable@kernel.org
Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/sg.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 0cb049f5cc56..a328b5f284de 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c | |||
@@ -1708,11 +1708,6 @@ static int sg_finish_rem_req(Sg_request * srp) | |||
1708 | Sg_scatter_hold *req_schp = &srp->data; | 1708 | Sg_scatter_hold *req_schp = &srp->data; |
1709 | 1709 | ||
1710 | SCSI_LOG_TIMEOUT(4, printk("sg_finish_rem_req: res_used=%d\n", (int) srp->res_used)); | 1710 | SCSI_LOG_TIMEOUT(4, printk("sg_finish_rem_req: res_used=%d\n", (int) srp->res_used)); |
1711 | if (srp->res_used) | ||
1712 | sg_unlink_reserve(sfp, srp); | ||
1713 | else | ||
1714 | sg_remove_scat(req_schp); | ||
1715 | |||
1716 | if (srp->rq) { | 1711 | if (srp->rq) { |
1717 | if (srp->bio) | 1712 | if (srp->bio) |
1718 | ret = blk_rq_unmap_user(srp->bio); | 1713 | ret = blk_rq_unmap_user(srp->bio); |
@@ -1720,6 +1715,11 @@ static int sg_finish_rem_req(Sg_request * srp) | |||
1720 | blk_put_request(srp->rq); | 1715 | blk_put_request(srp->rq); |
1721 | } | 1716 | } |
1722 | 1717 | ||
1718 | if (srp->res_used) | ||
1719 | sg_unlink_reserve(sfp, srp); | ||
1720 | else | ||
1721 | sg_remove_scat(req_schp); | ||
1722 | |||
1723 | sg_remove_request(sfp, srp); | 1723 | sg_remove_request(sfp, srp); |
1724 | 1724 | ||
1725 | return ret; | 1725 | return ret; |