All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wenxiang Qian <leonwxqian@gmail.com>, P J P <ppandit@redhat.com>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
	"John Snow" <jsnow@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>
Subject: Re: [PATCH] ide:atapi: check io_buffer_index in ide_atapi_cmd_reply_end
Date: Fri, 11 Dec 2020 12:45:22 +0100	[thread overview]
Message-ID: <2c1b5a52-cce0-560e-269b-9d61348cfa92@redhat.com> (raw)
In-Reply-To: <CAKZf9JDg=5y=2v=O6ZQjcLCYXXEn2szM_c3rrQgtTHvLsSicww@mail.gmail.com>

On 11/12/20 09:23, Wenxiang Qian wrote:
> Hello,
> 
> I may not have made the detail clear in my previous email. The details 
> of the AHCI device, after running the reproducer I attached in my report 
> are as follows. If there is any information I can provide, please let me 
> know. Thank you.
> 
> ###root cause###
> (1) The s->packet_transfer_size is bigger than the actual data.
> (2) packet_transfer_size is passed into  ide_atapi_cmd_reply_end, as the 
> total number of iterations. Each iterate round, s->io_buffer_index is 
> increased by 2048, but without boundary check.
> (3) The call to ide_transfer_start_norecurse use s->io_buffer + 
> s->io_buffer_index - size as the index, cause an OOB access.

This is not the root cause.  These are the last steps before bad things 
happen; the root cause is what _led_ to those last steps.  In this case, 
the root cause is that a read request with s->lba == -1 is mistaken for 
a non-read.  Read requests are able to reset s->io_buffer_index and 
start with the index pointing just after the end of the sector buffer; 
non-read requests instead visit the buffer just once and start with 
s->io_buffer_index == 0.

In turn, the fix is to validate:

1) that s->lba is in range when issuing a read request

2) that the size of the device is sane (e.g. the number of blocks is a 
positive 32-bit integer).

Paolo



  parent reply	other threads:[~2020-12-11 11:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 14:27 [PATCH] ide:atapi: check io_buffer_index in ide_atapi_cmd_reply_end P J P
2020-11-27 13:57 ` P J P
2020-12-01 11:51   ` Paolo Bonzini
2020-12-01 15:00     ` P J P
2020-12-01 15:23       ` Philippe Mathieu-Daudé
2020-12-01 15:30         ` Peter Maydell
2020-12-01 15:42           ` Paolo Bonzini
2020-12-01 15:30         ` Paolo Bonzini
2020-12-01 15:30       ` Paolo Bonzini
2020-12-02  7:07         ` Markus Armbruster
2020-12-02 13:17           ` P J P
2020-12-02 13:33             ` Paolo Bonzini
2020-12-02 13:36             ` Philippe Mathieu-Daudé
2020-12-03  9:48               ` P J P
2020-12-11  8:23             ` Wenxiang Qian
2020-12-11  8:32               ` Wenxiang Qian
2020-12-11 11:46                 ` Paolo Bonzini
2020-12-11 11:45               ` Paolo Bonzini [this message]
2020-12-11 14:16                 ` 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=2c1b5a52-cce0-560e-269b-9d61348cfa92@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=leonwxqian@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=ppandit@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.