From: Ewan Milne <emilne@redhat.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Andrea Gelmini <andrea.gelmini@gelma.net>,
linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
dgilbert@interlog.com
Subject: Re: BUG: KASAN: slab-out-of-bounds in ses_enclosure_data_process+0x900/0xe50
Date: Fri, 04 Dec 2015 15:40:45 -0500 [thread overview]
Message-ID: <1449261645.4067.150.camel@localhost.localdomain> (raw)
In-Reply-To: <1449256614.27077.11.camel@HansenPartnership.com>
On Fri, 2015-12-04 at 11:16 -0800, James Bottomley wrote:
> On Fri, 2015-12-04 at 11:58 -0500, Ewan Milne wrote:
> > On Thu, 2015-12-03 at 23:20 +0100, Andrea Gelmini wrote:
> > > On Thu, Dec 03, 2015 at 12:59:06PM -0800, James Bottomley wrote:
> > > > sg_map -i
> > > >
> > > > in your system, you should see something with an inquiry string like
> > > > enclosure. It's the /dev/sg<n> of that you need to run sg_ses on.
> > >
> > > root@glen:/home/gelma# sg_map -i
> > > /dev/sg0 /dev/sda ATA Samsung SSD 850 1B6Q
> > > /dev/sg1 /dev/sr0 HL-DT-ST DVDRAM GU40N QX23
> > > /dev/sg2 /dev/sdb WD My Passport 0820 1007
> > > /dev/sg3 WD SES Device 1007
> > >
> > > And following Douglas' instructions:
> > >
> > > root@glen:/home/gelma# lsscsi -gs
> > > [0:0:0:0] disk ATA Samsung SSD 850 1B6Q /dev/sda /dev/sg0 1.02TB
> > > [1:0:0:0] cd/dvd HL-DT-ST DVDRAM GU40N QX23 /dev/sr0 /dev/sg1 -
> > > [8:0:0:0] disk WD My Passport 0820 1007 /dev/sdb /dev/sg2 2.00TB
> > > [8:0:0:1] enclosu WD SES Device 1007 - /dev/sg3
> > >
> > > root@glen:/home/gelma# sg_ses /dev/sg3
> > > WD SES Device 1007
> > > Supported diagnostic pages:
> > > Supported Diagnostic Pages [sdp] [0x0]
> > > Short Enclosure Status (SES) [ses] [0x8]
> > > <unknown> [0x80]
> > > <unknown> [0x83]
> > > <unknown> [0x84]
> > > <unknown> [0x85]
> > >
> > >
> > > Well, if it's better for you, I can give you root access to a machine with this device
> > > connected to.
> > >
> > > Thanks a lot for your time,
> > > Andrea
> >
> > There seems to be a problem with the ses code if the device only reports
> > Short Enclosure Status. We probably need to do something like:
> >
> > diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
> > index eba183c..065a528 100644
> > --- a/drivers/scsi/ses.c
> > +++ b/drivers/scsi/ses.c
> > @@ -537,6 +537,15 @@ static int ses_intf_add(struct device *cdev,
> > if (result)
> > goto recv_failed;
> >
> > + /* If enclosure only supports Short Enclosure Status page (08),
> > + * it returns that page regardless of what we requested, and
> > + * only returns vendor-specific status. There is nothing wrong
> > + * with such enclosures, we just can't make use of them. */
> > + if (hdr_buf[0] == 8) {
> > + err = -ENODEV;
> > + goto err_init_free_nomsg;
> > + }
> > +
> > len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
> > buf = kzalloc(len, GFP_KERNEL);
> > if (!buf)
> > @@ -646,9 +655,10 @@ static int ses_intf_add(struct device *cdev,
> > kfree(ses_dev->page2);
> > kfree(ses_dev->page1);
> > err_init_free:
> > + sdev_printk(KERN_ERR, sdev, "Failed to bind enclosure %d\n",
> > err);
> > + err_init_free_nomsg:
> > kfree(ses_dev);
> > kfree(hdr_buf);
> > - sdev_printk(KERN_ERR, sdev, "Failed to bind enclosure %d\n",
> > err);
> > return err;
> > }
> >
> > Otherwise we go off issuing commands for pages the device says it won't
> > return. I don't see offhand how this would cause KASAN errors though.
>
> I think we have two separate bugs. One is the usual USB devices getting
> into a new SCSI standard and getting it wrong. The other looks to be an
> enumeration problem ... possibly because ses2 added an indexed
> descriptor which current SES doesn't cope with.
>
> Anyway, in concentrating on the USB problem first, I think we need to
> code a little more defensively, like this.
This could certainly be the case for a USB device, however I have also
had a report of this for regular SCSI attached devices with EncServ=1
that only supported Short Enclosure Status. The SES-3 spec 4.3.3 says
that in this case, it "...shall always return the Short Enclosure
Status diagnostic page, regardless of which SES diagnostic page is
requested..." The person who reported the problem wanted to have the
error messages removed about all his spec-compliant devices.
Short Enclosure Status appears to be vendor-specific, it doesn't look
like we can do anything with it.
But anyway, there's still the other problem...
-Ewan
>
> James
>
> ---
>
> diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
> index dcb0d76..7d9cec5 100644
> --- a/drivers/scsi/ses.c
> +++ b/drivers/scsi/ses.c
> @@ -84,6 +84,7 @@ static void init_device_slot_control(unsigned char *dest_desc,
> static int ses_recv_diag(struct scsi_device *sdev, int page_code,
> void *buf, int bufflen)
> {
> + int ret;
> unsigned char cmd[] = {
> RECEIVE_DIAGNOSTIC,
> 1, /* Set PCV bit */
> @@ -92,9 +93,26 @@ static int ses_recv_diag(struct scsi_device *sdev, int page_code,
> bufflen & 0xff,
> 0
> };
> + unsigned char recv_page_code;
>
> - return scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen,
> + ret = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen,
> NULL, SES_TIMEOUT, SES_RETRIES, NULL);
> + if (unlikely(!ret))
> + return ret;
> +
> + recv_page_code = ((unsigned char *)buf)[0];
> +
> + if (likely(recv_page_code == page_code))
> + return ret;
> +
> + /* successful diagnostic but wrong page code. This happens to some
> + * USB devices, just print a message and pretend there was an error */
> +
> + sdev_printk(KERN_ERR, sdev,
> + "Wrong diagnostic page; asked for %d got %u\n",
> + page_code, recv_page_code);
> +
> + return -EINVAL;
> }
>
> static int ses_send_diag(struct scsi_device *sdev, int page_code,
>
>
next prev parent reply other threads:[~2015-12-04 20:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-01 20:20 BUG: KASAN: slab-out-of-bounds in ses_enclosure_data_process+0x900/0xe50 Andrea Gelmini
2015-12-02 22:58 ` James Bottomley
2015-12-03 20:36 ` Andrea Gelmini
2015-12-03 20:59 ` James Bottomley
2015-12-03 21:11 ` Douglas Gilbert
2015-12-03 21:20 ` James Bottomley
2015-12-03 22:20 ` Andrea Gelmini
2015-12-04 16:58 ` Ewan Milne
2015-12-04 19:16 ` James Bottomley
2015-12-04 20:40 ` Ewan Milne [this message]
2015-12-04 17:09 ` James Bottomley
2015-12-04 17:46 ` Andrea Gelmini
2015-12-04 19:04 ` James Bottomley
-- strict thread matches above, loose matches on Subject: below --
2015-12-03 14:20 Pavel Tikhomirov
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=1449261645.4067.150.camel@localhost.localdomain \
--to=emilne@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=andrea.gelmini@gelma.net \
--cc=dgilbert@interlog.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/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