Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gary Guo" <gary@garyguo.net>
Cc: linux-pci@vger.kernel.org, cassel@kernel.org,
	dri-devel@lists.freedesktop.org, linux-ide@vger.kernel.org,
	dlemoal@kernel.org, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 3/9] ipack: tpci200: don't store pci_device_id
Date: Tue, 07 Jul 2026 14:12:14 +0000	[thread overview]
Message-ID: <20260707141214.CE9E61F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260706-pci_id_fix-v3-3-2d48fc025acc@garyguo.net>

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

Pre-existing issues:
- [High] Unconditional return of 1 in `ipack_unregister_bus_member` halts bus device iteration prematurely, leaving most devices orphaned but still registered.
--

commit 6023ba18e50f5578e133a944842fdee804f479b0
Author: Gary Guo <gary@garyguo.net>

    ipack: tpci200: don't store pci_device_id
    
    pci_device_id is not guaranteed to live longer than probe due to presence
    of dynamic ID. This stored ID is unused so remove it.

> diff --git a/drivers/ipack/carriers/tpci200.c b/drivers/ipack/carriers/tpci200.c
> index 05dcb6675cd66..1cf51f7632932 100644
> --- a/drivers/ipack/carriers/tpci200.c
> +++ b/drivers/ipack/carriers/tpci200.c
> @@ -562,7 +562,6 @@ static int tpci200_pci_probe(struct pci_dev *pdev,
>  
>  	/* Save struct pci_dev pointer */
>  	tpci200->info->pdev = pdev;
> -	tpci200->info->id_table = (struct pci_device_id *)id;
>  
>  	/* register the device and initialize it */
>  	ret = tpci200_install(tpci200);

[Severity: High]
This is a pre-existing issue, but I noticed a potential use-after-free during
bus unregistration that I wanted to ask about.

When a carrier driver is unbound and calls ipack_bus_unregister(), it uses
bus_for_each_dev() to iterate and unregister child devices:

drivers/ipack/ipack.c:ipack_bus_unregister() {
    ...
	bus_for_each_dev(&ipack_bus_type, NULL, bus,
		ipack_unregister_bus_member);
	ida_free(&ipack_ida, bus->bus_nr);
	kfree(bus);
    ...
}

However, the callback unconditionally returns 1:

drivers/ipack/ipack.c:ipack_unregister_bus_member() {
    ...
	if (idev->bus == bus)
		ipack_device_del(idev);

	return 1;
}

Since bus_for_each_dev() halts iteration on any non-zero return value, does
this stop after evaluating only the first device in the bus list?

If the iteration stops prematurely, the remaining devices would be orphaned but
stay registered. Because ipack_bus_unregister() immediately frees the bus
structure after the iteration, could this result in a use-after-free if an
ipack client driver later binds to one of these orphaned devices or their sysfs
attributes are accessed?

> diff --git a/drivers/ipack/carriers/tpci200.h b/drivers/ipack/carriers/tpci200.h
> index e79ac64abcffa..a2bf3125794b7 100644
> --- a/drivers/ipack/carriers/tpci200.h
> +++ b/drivers/ipack/carriers/tpci200.h
> @@ -145,7 +145,6 @@ struct tpci200_slot {
>   */
>  struct tpci200_infos {
>  	struct pci_dev			*pdev;
> -	struct pci_device_id		*id_table;
>  	struct tpci200_regs __iomem	*interface_regs;
>  	void __iomem			*cfg_regs;
>  	struct ipack_bus_device		*ipack_bus;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260706-pci_id_fix-v3-0-2d48fc025acc@garyguo.net?part=3

  reply	other threads:[~2026-07-07 14:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 14:11 [PATCH v3 0/9] pci: fix UAF and TOCTOU related to dynamic ID Gary Guo
2026-07-06 14:11 ` [PATCH v3 1/9] ata: don't store pci_device_id Gary Guo
2026-07-07  1:12   ` Damien Le Moal
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 2/9] nsp32: " Gary Guo
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 3/9] ipack: tpci200: " Gary Guo
2026-07-07 14:12   ` sashiko-bot [this message]
2026-07-06 14:11 ` [PATCH v3 4/9] mlxsw: " Gary Guo
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 5/9] agp/via: don't rely on address of pci_device_id Gary Guo
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 6/9] agp/amd-k7: " Gary Guo
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 7/9] pci: make pci_match_one_device match on ID instead of device Gary Guo
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 8/9] pci: fix dyn_id add TOCTOU Gary Guo
2026-07-07 14:12   ` sashiko-bot
2026-07-06 14:11 ` [PATCH v3 9/9] pci: fix UAF when probe runs concurrent to dyn ID removal Gary Guo
2026-07-07 14:12   ` sashiko-bot

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=20260707141214.CE9E61F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox