All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sg: fix dxferp in from_to case
@ 2016-03-03  5:31 Douglas Gilbert
  2016-03-08  2:18 ` Martin K. Petersen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Douglas Gilbert @ 2016-03-03  5:31 UTC (permalink / raw)
  To: SCSI development list, dvyukov

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

This patch is in response to this report:
    http://www.spinics.net/lists/linux-scsi/msg93456.html

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 a change in
2008 and syzkaller found that out recently.

    ChangeLog:
       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.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>

[-- Attachment #2: sg_null_deref.patch --]
[-- Type: text/x-patch, Size: 563 bytes --]

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 5e82067..ae7d9bd 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -652,7 +652,8 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
 	else
 		hp->dxfer_direction = (mxsize > 0) ? SG_DXFER_FROM_DEV : SG_DXFER_NONE;
 	hp->dxfer_len = mxsize;
-	if (hp->dxfer_direction == SG_DXFER_TO_DEV)
+	if ((hp->dxfer_direction == SG_DXFER_TO_DEV) ||
+	    (hp->dxfer_direction == SG_DXFER_TO_FROM_DEV))
 		hp->dxferp = (char __user *)buf + cmd_size;
 	else
 		hp->dxferp = NULL;

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

* Re: [PATCH] sg: fix dxferp in from_to case
  2016-03-03  5:31 [PATCH] sg: fix dxferp in from_to case Douglas Gilbert
@ 2016-03-08  2:18 ` Martin K. Petersen
  2016-03-09 16:09 ` Ewan Milne
  2016-03-10  1:42 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2016-03-08  2:18 UTC (permalink / raw)
  To: Douglas Gilbert; +Cc: SCSI development list, dvyukov

>>>>> "Doug" == Douglas Gilbert <dgilbert@interlog.com> writes:

Doug> This patch is in response to this report:
Doug> http://www.spinics.net/lists/linux-scsi/msg93456.html

Doug> One of the strange things that the original sg driver did was let
Doug> the user provide both a data-out buffer (it followed the
Doug> sg_header+cdb) _and_ specify a reply length greater than
Doug> zero. What happened was that the user data-out buffer was copied
Doug> into some kernel buffers and then the mid level was told a read
Doug> type operation would take place with the data from the device
Doug> overwriting the same kernel buffers. The user would then read
Doug> those kernel buffers back into the user space.

Doug> From what I can tell, the above action was broken by a change in
Doug> 2008 and syzkaller found that out recently.

Doug>    ChangeLog: make sure that a user space pointer is passed
Doug> through when data follows the sg_header structure and command.
Doug> Fix the abnormal case when a non-zero reply_len is also given.

Somebody please review.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH] sg: fix dxferp in from_to case
  2016-03-03  5:31 [PATCH] sg: fix dxferp in from_to case Douglas Gilbert
  2016-03-08  2:18 ` Martin K. Petersen
@ 2016-03-09 16:09 ` Ewan Milne
  2016-03-10  1:42 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Ewan Milne @ 2016-03-09 16:09 UTC (permalink / raw)
  To: dgilbert; +Cc: SCSI development list, dvyukov

On Thu, 2016-03-03 at 00:31 -0500, Douglas Gilbert wrote:
> This patch is in response to this report:
>     http://www.spinics.net/lists/linux-scsi/msg93456.html
> 
> 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 a change in
> 2008 and syzkaller found that out recently.
> 
>     ChangeLog:
>        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.
> 
> Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>

This looks correct to me.  hp->dxferp used to be set unconditionally,
but commit fad7f01e changed it to only be set in the SG_DXFER_TO_DEV
case.

Reviewed-by: Ewan D. Milne <emilne@redhat.com>



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

* Re: [PATCH] sg: fix dxferp in from_to case
  2016-03-03  5:31 [PATCH] sg: fix dxferp in from_to case Douglas Gilbert
  2016-03-08  2:18 ` Martin K. Petersen
  2016-03-09 16:09 ` Ewan Milne
@ 2016-03-10  1:42 ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2016-03-10  1:42 UTC (permalink / raw)
  To: Douglas Gilbert; +Cc: SCSI development list, dvyukov

>>>>> "Doug" == Douglas Gilbert <dgilbert@interlog.com> writes:

Doug> Make sure that a user space pointer is passed through when data
Doug> follows the sg_header structure and command.  Fix the abnormal
Doug> case when a non-zero reply_len is also given.

Applied to 4.5/scsi-fixes.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2016-03-10  1:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-03  5:31 [PATCH] sg: fix dxferp in from_to case Douglas Gilbert
2016-03-08  2:18 ` Martin K. Petersen
2016-03-09 16:09 ` Ewan Milne
2016-03-10  1:42 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.