From: Douglas Gilbert <dgilbert@interlog.com>
To: Kangjie Lu <kjlu@umn.edu>
Cc: pakki001@umn.edu,
"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: fix a double-fetch bug in sg_write
Date: Tue, 25 Dec 2018 22:42:52 -0500 [thread overview]
Message-ID: <7e727b1a-88e5-7062-159e-bf4be110d168@interlog.com> (raw)
In-Reply-To: <20181225202427.69476-1-kjlu@umn.edu>
On 2018-12-25 3:24 p.m., Kangjie Lu wrote:
> "opcode" has been copied in from user space and checked. We should not
> copy it in again, which may have been modified by malicous
> multi-threading user programs through race conditions. The fix uses the
> opcode fetched in the first copy.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Also applied to my sg v4 driver code. The v1 and v2 interfaces (based on
struct sg_header) did not provide a command length field. The sg driver
needed to read the first byte of the command (the "opcode") to determine
the full command's length prior to actually reading it in full.
Hard to think of an example of an exploit based on this double read.
> ---
> drivers/scsi/sg.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 4dacbfffd113..41774e4f9508 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -686,7 +686,8 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
> hp->flags = input_size; /* structure abuse ... */
> hp->pack_id = old_hdr.pack_id;
> hp->usr_ptr = NULL;
> - if (__copy_from_user(cmnd, buf, cmd_size))
> + cmnd[0] = opcode;
> + if (__copy_from_user(cmnd + 1, buf + 1, cmd_size - 1))
> return -EFAULT;
> /*
> * SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV,
>
prev parent reply other threads:[~2018-12-26 3:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-25 20:24 Kangjie Lu
2018-12-26 3:42 ` Douglas Gilbert [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7e727b1a-88e5-7062-159e-bf4be110d168@interlog.com \
--to=dgilbert@interlog.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=kjlu@umn.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=pakki001@umn.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®