qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH] pci: fix pci_default_read_config().
Date: Thu, 27 May 2010 17:13:16 +0300	[thread overview]
Message-ID: <20100527141316.GB8287@redhat.com> (raw)
In-Reply-To: <20100527054442.GI31807@valinux.co.jp>

On Thu, May 27, 2010 at 02:44:42PM +0900, Isaku Yamahata wrote:
> address and config_size are both unsigned.
> So check which is bigger before minus operation.
> Otherwise the result of minus can be unexpected
> big value.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

An this happen in practice? If yes, how?

> ---
>  hw/pci.c |    9 +++++++--
>  1 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index 3362842..39a6206 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -988,9 +988,14 @@ uint32_t pci_default_read_config(PCIDevice *d,
>                                   uint32_t address, int len)
>  {
>      uint32_t val = 0;
> +    uint32_t config_size = pci_config_size(d);
>      assert(len == 1 || len == 2 || len == 4);
> -    len = MIN(len, pci_config_size(d) - address);
> -    memcpy(&val, d->config + address, len);
> +    if (address < config_size) {
> +        len = MIN(len, config_size - address);
> +        memcpy(&val, d->config + address, len);
> +    } else {
> +        val = ~0;
> +    }
>      return le32_to_cpu(val);
>  }
>  
> -- 
> 1.6.6.1
> 

  reply	other threads:[~2010-05-27 14:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-27  5:44 [Qemu-devel] [PATCH] pci: fix pci_default_read_config() Isaku Yamahata
2010-05-27 14:13 ` Michael S. Tsirkin [this message]
2010-05-28  9:41   ` [Qemu-devel] " Isaku Yamahata

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=20100527141316.GB8287@redhat.com \
    --to=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yamahata@valinux.co.jp \
    /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).