stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuernberger, Stefan" <snu@amazon.de>
To: "boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>,
	"Nuernberger, Stefan" <snu@amazon.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"Seidel, Conny" <consei@amazon.de>,
	"jgross@suse.com" <jgross@suse.com>,
	"ross.lagerwall@citrix.com" <ross.lagerwall@citrix.com>,
	"Dannowski, Uwe" <uwed@amazon.de>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH] xen/pciback: Prevent NULL pointer dereference in quirks_show
Date: Fri, 6 Dec 2019 18:09:48 +0000	[thread overview]
Message-ID: <1575655787.7257.42.camel@amazon.de> (raw)
In-Reply-To: <9917a357-12f6-107f-e08d-33e464036317@oracle.com>

On Fri, 2019-12-06 at 10:11 -0500, Boris Ostrovsky wrote:
> On 12/6/19 8:48 AM, Stefan Nuernberger wrote:
> > 
> > From: Uwe Dannowski <uwed@amazon.de>
> > 
> > Reading /sys/bus/pci/drivers/pciback/quirks while unbinding can
> > result
> > in dereferencing a NULL pointer. Instead, skip printing information
> > about the dangling quirk.
> > 
> > Reported-by: Conny Seidel <consei@amazon.de>
> > Signed-off-by: Uwe Dannowski <uwed@amazon.de>
> > Signed-off-by: Stefan Nuernberger <snu@amazon.com>
> > 
> > Cc: xen-devel@lists.xenproject.org
> > Cc: stable@vger.kernel.org
> > ---
> >  drivers/xen/xen-pciback/pci_stub.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-
> > pciback/pci_stub.c
> > index 097410a7cdb7..da725e474294 100644
> > --- a/drivers/xen/xen-pciback/pci_stub.c
> > +++ b/drivers/xen/xen-pciback/pci_stub.c
> > @@ -1346,6 +1346,8 @@ static ssize_t quirks_show(struct
> > device_driver *drv, char *buf)
> >  				   quirk->devid.subdevice);
> >  
> >  		dev_data = pci_get_drvdata(quirk->pdev);
> > +		if (!dev_data)
> > +			continue;
> >  
> >  		list_for_each_entry(cfg_entry, &dev_data-
> > >config_fields, list) {
> Couldn't you have the same race here?

Not quite the same, but it might not be entirely safe yet. The
'quirks_show' takes the 'device_ids_lock' and races with unbind /
'pcistub_device_release' "which takes device_lock mutex". So this might
now be a UAF read access instead of a NULL pointer dereference. We have
not observed adversarial effects in our testing (compared to the
obvious issues with NULL pointer) but that's not a guarantee of course.

So should quirks_show actually be protected by pcistub_devices_lock
instead as are other functions that access dev_data? Does it need both
locks in that case?

-Stefan

> 
> -boris
> 
> > 
> >  			field = cfg_entry->field;



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879



  reply	other threads:[~2019-12-06 18:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-06 13:48 [PATCH] xen/pciback: Prevent NULL pointer dereference in quirks_show Stefan Nuernberger
2019-12-06 15:11 ` Boris Ostrovsky
2019-12-06 18:09   ` Nuernberger, Stefan [this message]
2019-12-06 20:15     ` Boris Ostrovsky
2019-12-09 18:16       ` Nuernberger, Stefan
2019-12-09 21:21         ` Boris Ostrovsky

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=1575655787.7257.42.camel@amazon.de \
    --to=snu@amazon.de \
    --cc=boris.ostrovsky@oracle.com \
    --cc=consei@amazon.de \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ross.lagerwall@citrix.com \
    --cc=stable@vger.kernel.org \
    --cc=uwed@amazon.de \
    --cc=xen-devel@lists.xenproject.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 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).