Fix data buffer handling in sg driver
Subsystems (2)
cover Fix data buffer handling in sg driver
This fixes a problem in the sg driver that occurs with CONFIG_DEBUG_PAGEALLOC enabled. It is the same patch as in
http://marc.info/?l=linux-scsi&m=125303366703782&w=2
I only added the acked-by from Fujita and the CC to [email protected]
--
Christof
PATCH 1/1 sg: Free data buffers after calling blk_rq_unmap_user
From: Christof Schmitt <[email protected]>
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_ioctlsg_new_readsg_finish_rem_reqblk_rq_unmap_user__blk_rq_unmap_userbio_uncopy_user__bio_copy_iovcopy_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.
--- drivers/scsi/sg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/scsi/sg.c +5 -5
@@ -1708,11 +1708,6 @@ static int sg_finish_rem_req(Sg_requestSg_scatter_hold *req_schp = &srp->data;SCSI_LOG_TIMEOUT (4 ,printk ("sg_finish_rem_req: res_used=%d\n" , (int ) srp->res_used)); -if (srp->res_used) -sg_unlink_reserve (sfp, srp); -else -sg_remove_scat (req_schp); -if (srp->rq) {if (srp->bio) ret =blk_rq_unmap_user (srp->bio);
@@ -1720,6 +1715,11 @@ static int sg_finish_rem_req(Sg_requestblk_put_request (srp->rq); } +if (srp->res_used) +sg_unlink_reserve (sfp, srp); +else +sg_remove_scat (req_schp); +sg_remove_request (sfp, srp);return ret;
Douglas Gilbert
maintainerRe: [patch 1/1] sg: Free data buffers after calling blk_rq_unmap_user
Quoted 15 lines · Christof Schmitt
From: Christof Schmitt <[email protected]>
Running
sg_lunson s390x withCONFIG_DEBUG_PAGEALLOCenabled fails with EFAULT from theSG_IOioctl. The EFAULT is the result fromcopy_to_userfailing in this call chain:
sg_ioctlsg_new_readsg_finish_rem_reqblk_rq_unmap_user__blk_rq_unmap_userbio_uncopy_user__bio_copy_iovcopy_to_user
Quoted 8 lines
The sg driver calls
sg_remove_scatto free the memory pages before callingblk_rq_unmap_userthat tries to copy the data back to userspace. Change the order to first callblk_rq_unmap_userbefore freeing the pages insg_remove_scat.Acked-by FUJITA Tomonori <[email protected]>Signed-off-by Christof Schmitt <[email protected]>