All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 2/2] thunderbolt: Add device links for Apple T2 NHI
Date: Fri, 24 Jul 2026 17:05:51 +0000	[thread overview]
Message-ID: <20260724170552.397EA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724164641.2239-3-atharvatiwarilinuxdev@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Lockless traversal of the PCI bus devices list exposes the driver to a use-after-free race during concurrent hotplug or sysfs device removal.
--

--- Patch [2]: [PATCH v4 2/2] thunderbolt: Add device links for Apple T2 NHI ---
commit ee5a1e7f9e85d72f9c6e9327c898de2f33a51e3d
Author: Andre Eikmeyer <andre@negmaster.com>

thunderbolt: Add device links for Apple T2 NHI

This commit adds device links for the Icelake Thunderbolt NHI on Apple T2
Macs. It finds the root ports (TRP0, TRP1, etc.) in ACPI and creates device
links to ensure PCIe tunnels can be re-established after sleep.

> diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
> index c69c323e6952a..625451ff3ea08 100644
> --- a/drivers/thunderbolt/tb.c
> +++ b/drivers/thunderbolt/tb.c

[ ... ]

> @@ -3305,21 +3307,73 @@ static const struct tb_cm_ops tb_cm_ops = {
>  static bool tb_apple_add_links(struct tb_nhi *nhi)
>  {
>  	struct pci_dev *upstream, *pdev;
> -	bool ret;
> +	bool ret = false;
>  
>  	if (!x86_apple_machine)
>  		return false;

[ ... ]

>  	upstream = pci_upstream_bridge(nhi->pdev);
>  	while (upstream) {
>  		if (!pci_is_pcie(upstream))

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this function
I noticed a pre-existing issue further down in tb_apple_add_links():

	for_each_pci_bridge(pdev, upstream->subordinate) {
		const struct device_link *link;

		if (!pci_is_pcie(pdev))
			continue;

Could traversing upstream->subordinate without holding the pci_bus_sem read
lock lead to list corruption or a use-after-free?

If a user concurrently writes to /sys/bus/pci/devices/.../remove for one of
the downstream ports while the Thunderbolt host controller is probing,
pci_remove_bus_device() could delete the device from the list via
list_del(&dev->bus_list) while this lockless traversal is happening.

The newly added T2 Mac path safely avoids this by using pci_get_slot(),
which handles the locking internally. Would it make sense to acquire
pci_bus_sem for the older architecture paths as well?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724164641.2239-1-atharvatiwarilinuxdev@gmail.com?part=2

      reply	other threads:[~2026-07-24 17:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 16:46 [PATCH v4 0/2] Add Apple T2 NHI device links Atharva Tiwari
2026-07-24 16:46 ` [PATCH v4 1/2] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-07-24 16:53   ` sashiko-bot
2026-07-24 16:46 ` [PATCH v4 2/2] thunderbolt: Add device links for Apple T2 NHI Atharva Tiwari
2026-07-24 17:05   ` sashiko-bot [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=20260724170552.397EA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=atharvatiwarilinuxdev@gmail.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.