public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Gerd Bayer <gbayer@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Pierre Morel <pmorel@linux.ibm.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>
Subject: Re: [PATCH] PCI: s390: Fix use-after-free of PCI bus resources with s390 per-function hotplug
Date: Tue, 14 Feb 2023 11:00:53 +0100	[thread overview]
Message-ID: <198c6f7f19d77b8471bd609767b3d359a989b9ca.camel@linux.ibm.com> (raw)
In-Reply-To: <bce832f7305a132fc2e2b47fc668292234820465.camel@linux.ibm.com>

On Tue, 2023-02-14 at 10:46 +0100, Gerd Bayer wrote:
> Hi Niklas,
> 
> when comparing pci_bus_remove_resource with pci_bus_remove_resources,
> I find that the "single-resource" variant might be ending too early.
> 
> On Fri, 2023-02-03 at 12:48 +0100, Niklas Schnelle wrote:
> > +void pci_bus_remove_resource(struct pci_bus *bus, struct resource
> > *res)
> > +{
> > +       struct pci_bus_resource *bus_res, *tmp;
> > +       int i;
> > +
> > +       for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) {
> > +               if (bus->resource[i] == res) {
> > +                       bus->resource[i] = NULL;
> > +                       return;
>                           ^^^^^^^
> Did you mean to "break" here, rather than end the routine?

No the return is intended. We're looking to remove a single resource
and if I understand things correctly then that resource can either be
in bus->resource[] (x)or in bus->resources depending on whether it is a
PCI bridge resource. Either way once found and removed from the
respective array/list we're done and can thus return immediately.

> > +               }
> > +       }
> > +
> > +       list_for_each_entry_safe(bus_res, tmp, &bus->resources, list)
> > {
> > +               if (bus_res->res == res) {
> > +                       list_del(&bus_res->list);
> > +                       kfree(bus_res);
> > +                       return;
>                           ^^^^^^^
> Here "break" and "return" have the same effect, but "break" would be
> "symmetric".
> > +               }
> > +       }
> > +       return;
> > +
> > +}
> 
> While this might be a nit, I'd like to better separate the "single-
> resource" variant's name. How about pci_bus_remove_one_resource - I
> know it's getting long...
> 
> Thanks,
> Gerd

I have no strong feelings on the name.


      reply	other threads:[~2023-02-14 10:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 11:48 [PATCH] PCI: s390: Fix use-after-free of PCI bus resources with s390 per-function hotplug Niklas Schnelle
2023-02-14  9:46 ` Gerd Bayer
2023-02-14 10:00   ` Niklas Schnelle [this message]

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=198c6f7f19d77b8471bd609767b3d359a989b9ca.camel@linux.ibm.com \
    --to=schnelle@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=bhelgaas@google.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gbayer@linux.ibm.com \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=pmorel@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    /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