All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: "Daniel P . Berrangé" <berrange@redhat.com>,
	"Prasad J Pandit" <pjp@fedoraproject.org>,
	"Yi Ren" <c4tren@gmail.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"P J P" <ppandit@redhat.com>, "Gerd Hoffmann" <kraxel@redhat.com>,
	"Ren Ding" <rding@gatech.edu>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Hanqing Zhao" <hanqing@gatech.edu>
Subject: Re: [PATCH v2 2/2] pci: ensure configuration access is within bounds
Date: Thu, 4 Jun 2020 07:40:35 -0400	[thread overview]
Message-ID: <20200604073753-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <alpine.BSF.2.22.395.2006041335250.54170@zero.eik.bme.hu>

On Thu, Jun 04, 2020 at 01:37:13PM +0200, BALATON Zoltan wrote:
> On Thu, 4 Jun 2020, Michael S. Tsirkin wrote:
> > On Thu, Jun 04, 2020 at 08:07:52AM +0200, Philippe Mathieu-Daudé wrote:
> > > On 6/4/20 12:13 AM, BALATON Zoltan wrote:
> > > > On Thu, 4 Jun 2020, P J P wrote:
> > > > > From: Prasad J Pandit <pjp@fedoraproject.org>
> > > > > 
> > > > > While reading PCI configuration bytes, a guest may send an
> > > > > address towards the end of the configuration space. It may lead
> > > > > to an OOB access issue. Assert that 'address + len' is within
> > > > > PCI configuration space.
> > > > > 
> > > > > Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > > > Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> > > > > ---
> > > > > hw/pci/pci.c | 2 ++
> > > > > 1 file changed, 2 insertions(+)
> > > > > 
> > > > > Update v2: assert PCI configuration access is within bounds
> > > > >  -> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00711.html
> > > > > 
> > > > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > > > > index 70c66965f5..173bec4fd5 100644
> > > > > --- a/hw/pci/pci.c
> > > > > +++ b/hw/pci/pci.c
> > > > > @@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
> > > > > {
> > > > >     uint32_t val = 0;
> > > > > 
> > > > > +    assert(address + len <= pci_config_size(d));
> > > > 
> > > > Does this allow guest now to crash QEMU? I think it was suggested that
> > > > assert should only be used for cases that can only arise from a
> > > > programming error and not from values set by the guest. If this is
> > > > considered to be an error now to call this function with wrong
> > > > parameters did you check other callers? I've found a few such as:
> > > > 
> > > > hw/scsi/esp-pci.c
> > > > hw/watchdog/wdt_i6300esb.c
> > > > hw/ide/cmd646.c
> > > > hw/vfio/pci.c
> > > > 
> > > > and maybe others. Would it be better to not crash just log invalid
> > > > access and either fix up parameters or return some garbage like 0?
> > > 
> > > Yes, maybe I was not clear while reviewing v1, we need to audit the
> > > callers and fix them first, then we can safely add the assert here.
> > 
> > We can add assert here regardless of auditing callers. Doing that
> > will also make fuzzying easier. But the assert is unrelated to CVE imho.
> 
> I wonder why isn't the check added to pci_default_read_config() right away?
> If we have an assert there the overhead is the same and adding the check
> there would make it unnecessary to patch all callers so it's just one patch
> instead of a whole series.
> 
> Regards,
> BALATON Zoltan

We need to return something, and we can't be sure that callers will
handle returning random stuff correctly. Callers know what
to do on errors, we don't.

-- 
MST



  reply	other threads:[~2020-06-04 11:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 20:22 [PATCH v2 0/2] Ensure PCI configuration access is within bounds P J P
2020-06-03 20:22 ` [PATCH v2 1/2] ait-vga: check address before reading configuration bytes P J P
2020-06-03 21:58   ` BALATON Zoltan
2020-06-04  8:43   ` Daniel P. Berrangé
2020-06-04  9:18     ` P J P
2020-06-04  9:40       ` Michael S. Tsirkin
2020-06-03 20:22 ` [PATCH v2 2/2] pci: ensure configuration access is within bounds P J P
2020-06-03 22:13   ` BALATON Zoltan
2020-06-04  5:14     ` Gerd Hoffmann
2020-06-04  9:44       ` Michael S. Tsirkin
2020-06-04  5:31     ` P J P
2020-06-04  6:07     ` Philippe Mathieu-Daudé
2020-06-04  9:41       ` Michael S. Tsirkin
2020-06-04 11:37         ` BALATON Zoltan
2020-06-04 11:40           ` Michael S. Tsirkin [this message]
2020-06-04 11:49             ` BALATON Zoltan
2020-06-04 11:58               ` Michael S. Tsirkin
2020-06-04 12:14                 ` BALATON Zoltan
2020-06-04 14:11                   ` Michael S. Tsirkin
2020-06-04  9:10   ` Peter Maydell
2020-06-04  9:35     ` Michael S. Tsirkin
2020-06-04  9:38   ` Michael S. Tsirkin

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=20200604073753-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=berrange@redhat.com \
    --cc=c4tren@gmail.com \
    --cc=hanqing@gatech.edu \
    --cc=kraxel@redhat.com \
    --cc=philmd@redhat.com \
    --cc=pjp@fedoraproject.org \
    --cc=ppandit@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rding@gatech.edu \
    /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.