From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, P J P <ppandit@redhat.com>
Cc: Qemu Developers <qemu-devel@nongnu.org>,
Thomas Huth <thuth@redhat.com>, Fam Zheng <famz@redhat.com>,
Prasad J Pandit <pjp@fedoraproject.org>,
Ameya More <ameya.more@oracle.com>
Subject: Re: [Qemu-devel] [PATCH v1] lsi53c895a: check message length value is valid
Date: Mon, 29 Oct 2018 18:56:35 +0100 [thread overview]
Message-ID: <1b9136bd-47b8-4a39-59c1-5831498a2578@redhat.com> (raw)
In-Reply-To: <CAFEAcA8auV_NMER=nfrMnHOQ8oSSAupCt8ap2W+XJ4ypsR5uDA@mail.gmail.com>
On 26/10/2018 22:55, Peter Maydell wrote:
>> + assert(len <= LSI_MAX_MSGIN_LEN);
>> pci_dma_write(PCI_DEVICE(s), s->dnad, s->msg, len);
>> /* Linux drivers rely on the last byte being in the SIDL. */
>> s->sidl = s->msg[len - 1];
> Is it possible to get here with len == 0 ?
No, all calls to
lsi_set_phase(s, PHASE_MI);
are followed or preceded by lsi_add_msg_byte. But an assertion is good
to add. What do you think of squashing this on top:
diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index 3a40e62853..72d85c42dd 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -865,9 +865,9 @@ static void lsi_do_msgin(LSIState *s)
trace_lsi_do_msgin(s->dbc, s->msg_len);
s->sfbr = s->msg[0];
len = s->msg_len;
+ assert(len >= 0 && len <= LSI_MAX_MSGIN_LEN);
if (len > s->dbc)
len = s->dbc;
- assert(len <= LSI_MAX_MSGIN_LEN);
pci_dma_write(PCI_DEVICE(s), s->dnad, s->msg, len);
/* Linux drivers rely on the last byte being in the SIDL. */
s->sidl = s->msg[len - 1];
@@ -1706,8 +1706,10 @@
break;
case 0x58: /* SBDL */
/* Some drivers peek at the data bus during the MSG IN phase. */
- if ((s->sstat1 & PHASE_MASK) == PHASE_MI)
+ if ((s->sstat1 & PHASE_MASK) == PHASE_MI) {
+ assert(s->msg_len >= 0);
return s->msg[0];
+ }
ret = 0;
break;
case 0x59: /* SBDL high */
Paolo
next prev parent reply other threads:[~2018-10-29 17:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-26 19:43 [Qemu-devel] [PATCH v1] lsi53c895a: check message length value is valid P J P
2018-10-26 20:55 ` Peter Maydell
2018-10-29 17:56 ` Paolo Bonzini [this message]
2018-10-29 17:58 ` Paolo Bonzini
2018-10-30 6:36 ` P J P
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=1b9136bd-47b8-4a39-59c1-5831498a2578@redhat.com \
--to=pbonzini@redhat.com \
--cc=ameya.more@oracle.com \
--cc=famz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=pjp@fedoraproject.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.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).