From: Lukas Wunner <lukas@wunner.de>
To: Nam Cao <namcao@linutronix.de>
Cc: "Bjorn Helgaas" <bhelgaas@google.com>,
"Yinghai Lu" <yinghai@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Mika Westerberg" <mika.westerberg@linux.intel.com>
Subject: Re: [PATCH v2 2/2] PCI: pciehp: Abort hot-plug if pci_hp_add_bridge() fails
Date: Mon, 27 May 2024 14:33:22 +0200 [thread overview]
Message-ID: <ZlR9kg-SEshXvBEP@wunner.de> (raw)
In-Reply-To: <20240527092322.N8nbxYAL@linutronix.de>
On Mon, May 27, 2024 at 11:23:22AM +0200, Nam Cao wrote:
> On Mon, May 27, 2024 at 11:15:55AM +0200, Lukas Wunner wrote:
> > We already check for a NULL subordinate pointer in various places.
> > See e.g. commit 62e4492c3063 ("PCI: Prevent NULL dereference during
> > pciehp probe").
>
> Ah, so bridge without subordinate bus is allowed in the kernel.
>
> > If we're missing such checks, I'd suggest to add those.
> >
> > If you believe having a NULL subordinate pointer is wrong and the
> > bridge should be de-enumerated altogether, I think you would have
> > to remove these NULL pointer checks as they'd otherwise become
> > pointless with your change.
> >
> > Just adding missing NULL pointer checks seems to be the most
> > straightforward solution to me.
>
> If the kernel do permits bridges without subordinate bus number, I am
> happy to go this direction. I expect going this way will require many more
> patches, I will dig into it and come back later.
It seems a lot of functions use a "if (dev->subordinate)" check
to distinguish between bridges and endpoints.
A bridge with a NULL subordinate pointer is then basically treated
like an endpoint.
There are places which use other ways to recognize bridges, e.g.
by looking at dev->hdr_type. Only these code paths will have to
check for a NULL subordinate pointer. In the case of pciehp,
portdrv binds to anything with class PCI_CLASS_BRIDGE_PCI_NORMAL,
without consideration for the subordinate pointer, hence a check
was needed in pciehp.
pciehp is used a lot by Thunderbolt/USB4, SD 7.0 and for NVMe drives.
I think shpchp isn't used as much, so its code paths aren't exercised
as heavily and bugs aren't found and fixed as quickly. So chances are
that more checks are missing in shpchp than in pciehp.
Thanks,
Lukas
prev parent reply other threads:[~2024-05-27 12:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-04 16:15 [PATCH v2 0/2] abort hot-plug if pci_hp_add_bridge() fails Nam Cao
2024-05-04 16:15 ` [PATCH v2 1/2] PCI: shpchp: Abort " Nam Cao
2024-05-04 16:15 ` [PATCH v2 2/2] PCI: pciehp: " Nam Cao
2024-05-05 5:45 ` Lukas Wunner
2024-05-05 7:14 ` Nam Cao
2024-05-06 8:37 ` Nam Cao
2024-05-06 19:36 ` Lukas Wunner
2024-05-07 14:27 ` Nam Cao
2024-05-27 9:15 ` Lukas Wunner
2024-05-27 9:23 ` Nam Cao
2024-05-27 12:33 ` Lukas Wunner [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=ZlR9kg-SEshXvBEP@wunner.de \
--to=lukas@wunner.de \
--cc=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=namcao@linutronix.de \
--cc=yinghai@kernel.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