Skip to content

Commit 5ecee0a

Browse files
doug-gilbertmartinkpetersen
authored andcommitted
sg: fix dxferp in from_to case
One of the strange things that the original sg driver did was let the user provide both a data-out buffer (it followed the sg_header+cdb) _and_ specify a reply length greater than zero. What happened was that the user data-out buffer was copied into some kernel buffers and then the mid level was told a read type operation would take place with the data from the device overwriting the same kernel buffers. The user would then read those kernel buffers back into the user space. From what I can tell, the above action was broken by commit fad7f01 ("sg: set dxferp to NULL for READ with the older SG interface") in 2008 and syzkaller found that out recently. Make sure that a user space pointer is passed through when data follows the sg_header structure and command. Fix the abnormal case when a non-zero reply_len is also given. Fixes: fad7f01 Cc: <stable@vger.kernel.org> #v2.6.28+ Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Ewan Milne <emilne@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent ff06c5f commit 5ecee0a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/sg.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
652652
else
653653
hp->dxfer_direction = (mxsize > 0) ? SG_DXFER_FROM_DEV : SG_DXFER_NONE;
654654
hp->dxfer_len = mxsize;
655-
if (hp->dxfer_direction == SG_DXFER_TO_DEV)
655+
if ((hp->dxfer_direction == SG_DXFER_TO_DEV) ||
656+
(hp->dxfer_direction == SG_DXFER_TO_FROM_DEV))
656657
hp->dxferp = (char __user *)buf + cmd_size;
657658
else
658659
hp->dxferp = NULL;

0 commit comments

Comments
 (0)