From: Paolo Bonzini <pbonzini@redhat.com>
To: "Théo Maillart" <tmaillart@freebox.fr>,
"Fam Zheng" <fam@euphon.net>,
qemu-devel@nongnu.org
Subject: Re: [PATCH] scsi: check inquiry buffer length to prevent crash
Date: Wed, 10 May 2023 18:11:40 +0200 [thread overview]
Message-ID: <62e34905-91fc-6498-d228-faa37b26fd60@redhat.com> (raw)
In-Reply-To: <20230426133747.403945-1-tmaillart@freebox.fr>
On 4/26/23 15:37, Théo Maillart wrote:
> --- a/hw/scsi/scsi-generic.c
> +++ b/hw/scsi/scsi-generic.c
> @@ -191,7 +191,7 @@ static int scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s, int len)
> if ((s->type == TYPE_DISK || s->type == TYPE_ZBC) &&
> (r->req.cmd.buf[1] & 0x01)) {
> page = r->req.cmd.buf[2];
> - if (page == 0xb0) {
> + if (page == 0xb0 && r->buflen >= 12) {
> uint64_t max_transfer = calculate_max_transfer(s);
> stl_be_p(&r->buf[8], max_transfer);
> /* Also take care of the opt xfer len. */
> --
This is not enough because right below there is a store of bytes 12..15.
The best thing to do is to:
1) do the stores in an "uint8_t buf[8]" on the stack, followed by a
memcpy to r->buf + 8.
2) add "&& r->buflen > 8" to the condition similar to what you've done
above.
Paolo
next prev parent reply other threads:[~2023-05-10 16:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 13:37 [PATCH] scsi: check inquiry buffer length to prevent crash Théo Maillart
2023-04-26 17:13 ` Théo Maillart
2023-05-10 7:28 ` Théo Maillart
2023-05-10 16:11 ` Paolo Bonzini [this message]
2023-05-11 10:37 ` Théo Maillart
2023-05-11 11:00 ` Paolo Bonzini
2023-05-11 19:58 ` Théo Maillart
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=62e34905-91fc-6498-d228-faa37b26fd60@redhat.com \
--to=pbonzini@redhat.com \
--cc=fam@euphon.net \
--cc=qemu-devel@nongnu.org \
--cc=tmaillart@freebox.fr \
/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).