From: Stefan Hajnoczi <stefanha@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: "qemu-trivial@nongnu.org" <qemu-trivial@nongnu.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
Thomas Higdon <thigdon@akamai.com>,
"paul@codesourcery.com" <paul@codesourcery.com>
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] scsi: Guard against buflen exceeding req->cmd.xfer in scsi_disk_emulate_command
Date: Fri, 27 Jan 2012 05:59:52 +0000 [thread overview]
Message-ID: <20120127055952.GF17836@stefanha-thinkpad.localdomain> (raw)
In-Reply-To: <20120124171944.GD14494@akamai.com>
On Tue, Jan 24, 2012 at 12:19:44PM -0500, Thomas Higdon wrote:
> On Tue, Jan 24, 2012 at 08:53:03AM -0500, Kevin Wolf wrote:
> > Am 23.01.2012 18:15, schrieb Thomas Higdon:
> > > This prevents the emulated SCSI device from trying to DMA more bytes to the
> > > initiator than are expected. Without this, the SCRIPTS code in the emulated LSI
> > > device eventually raises a DMA interrupt for a data overrun when an INQUIRY
> > > command whose buflen exceeds req->cmd.xfer is processed. It's the
> > > responsibility of the client to provide a request buffer and allocation
> > > length that are large enough for the result of the command.
> > >
> > > Signed-off-by: Thomas Higdon <thigdon@akamai.com>
> > > ---
> > > hw/scsi-disk.c | 3 +++
> > > 1 files changed, 3 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> > > index 5d8bf53..71fe2a3 100644
> > > --- a/hw/scsi-disk.c
> > > +++ b/hw/scsi-disk.c
> > > @@ -477,6 +477,9 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)
> > > "buffer size %zd\n", page_code, req->cmd.xfer);
> > > return -1;
> > > }
> > > + if (buflen > req->cmd.xfer) {
> > > + buflen = req->cmd.xfer;
> > > + }
> > > /* done with EVPD */
> > > return buflen;
> > > }
> >
> > I wonder if it would make sense to make this check in a more central
> > place like scsi_send_command(). This way we would avoid similar bugs in
> > other commands.
>
> Limit the return value (corresponding to the length of the buffer to be
> DMAed back to the intiator) to the value in req->cmd.xfer, which is the
> amount of data that the initiator expects. Eliminate now-duplicate code
> that does this guarding in the functions for individual commands.
>
> Without this, the SCRIPTS code in the emulated LSI device eventually
> raises a DMA interrupt for a data overrun when an INQUIRY command whose
> buflen exceeds req->cmd.xfer is processed. It's the responsibility of
> the client to provide a request buffer and allocation length that are
> large enough for the result of the command.
>
> Signed-off-by: Thomas Higdon <thigdon@akamai.com>
> ---
Kevin: Will you take this through your block/scsi tree?
Stefan
next prev parent reply other threads:[~2012-01-27 6:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-23 17:15 [Qemu-devel] [PATCH] scsi: restrict buffer length to req->cmd.xfer for responses to INQUIRY commands Thomas Higdon
2012-01-23 17:47 ` Paolo Bonzini
2012-01-23 18:14 ` Thomas Higdon
2012-01-24 8:21 ` Paolo Bonzini
2012-01-24 13:53 ` Kevin Wolf
2012-01-24 17:19 ` [Qemu-devel] [PATCH] scsi: Guard against buflen exceeding req->cmd.xfer in scsi_disk_emulate_command Thomas Higdon
2012-01-26 7:50 ` Paolo Bonzini
2012-01-26 10:41 ` Kevin Wolf
2012-01-26 10:53 ` Paolo Bonzini
2012-01-27 5:59 ` Stefan Hajnoczi [this message]
2012-01-27 8:44 ` [Qemu-devel] [Qemu-trivial] " Paolo Bonzini
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=20120127055952.GF17836@stefanha-thinkpad.localdomain \
--to=stefanha@gmail.com \
--cc=kwolf@redhat.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=thigdon@akamai.com \
/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;
as well as URLs for NNTP newsgroup(s).