From: sashiko-bot@kernel.org
To: "Gary Guo" <gary@garyguo.net>
Cc: linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org,
cassel@kernel.org, linux-ide@vger.kernel.org, dlemoal@kernel.org
Subject: Re: [PATCH v2 2/7] nsp32: don't keep pci_device_id
Date: Wed, 01 Jul 2026 11:10:42 +0000 [thread overview]
Message-ID: <20260701111043.5E5531F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260630-pci_id_fix-v2-2-b834a98c0af2@garyguo.net>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Probe failure incorrectly treated as success leading to NULL pointer dereferences.
- [High] Unvalidated `driver_data` from dynamic PCI IDs causes out-of-bounds reads on the `nsp32_model` array.
- [High] Race condition in `nsp32_probe` due to use of a shared global variable for instance data.
- [High] Double endianness swap in MMIO read/write functions.
--
commit 68e40f6c7308e7ebef3fc97b6095ad0f3e42988d
Author: Gary Guo <gary@garyguo.net>
nsp32: don't keep pci_device_id
pci_device_id is not guaranteed to live longer than probe due to presence
of dynamic ID. All information apart from driver_data can be easily
retrieved from pci_dev, so just store driver_data.
> diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
> index e893d56772417..9c9281222a0ac 100644
> --- a/drivers/scsi/nsp32.c
> +++ b/drivers/scsi/nsp32.c
[ ... ]
> @@ -3340,7 +3340,7 @@ static int nsp32_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> }
>
> data->Pci = pdev;
> - data->pci_devid = id;
> + data->model = id->driver_data;
[Severity: High]
This is a pre-existing issue, but I have a question about how driver_data
is used.
If a user with root privileges writes a dynamic PCI ID to
/sys/bus/pci/drivers/nsp32/new_id with an arbitrary, large driver_data
value, the driver unconditionally uses this value as an index into the
7-element nsp32_model string array here in nsp32_probe() via
id->driver_data, and later in nsp32_show_info().
Could this unvalidated driver_data from dynamic PCI IDs cause an
out-of-bounds read?
[Severity: High]
This isn't a bug introduced by this patch, but I have a concern about
the global nsp32_data_base variable.
If two nsp32 PCI devices are probed concurrently, for example via concurrent
sysfs bind operations, both threads will concurrently modify the single
global static variable nsp32_data_base at the start of nsp32_probe() before
it is copied into the per-device host structure in nsp32_detect().
Does using this shared global variable for instance data create a race
condition in nsp32_probe()?
[Severity: Critical]
This is a pre-existing issue, but there might be an issue with the error
handling path.
If nsp32_detect() fails, it returns 1, and nsp32_probe() blindly propagates
this positive value to the PCI core. The PCI core treats positive return
values from probe() as a success, meaning the device successfully binds to
the driver even though initialization completely failed.
Because pci_set_drvdata() is not called on the error path, subsequent driver
callbacks like nsp32_remove() will receive a NULL pointer from
pci_get_drvdata(), causing a NULL pointer dereference.
Does nsp32_probe() incorrectly treat probe failures as success?
> data->IrqNumber = pdev->irq;
> data->BaseAddress = pci_resource_start(pdev, 0);
> data->NumAddress = pci_resource_len (pdev, 0);
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but I noticed something in the
MMIO accessors.
In drivers/scsi/nsp32_io.h, nsp32_mmio_write4() explicitly uses cpu_to_le32()
in combination with writel(), and nsp32_mmio_read4() uses le32_to_cpu() with
readl(). Because writel() and readl() intrinsically perform the correct
host-to-PCI byte swapping, manually adding the byte-swap macros results in a
double byte-swap.
Do the MMIO read and write functions perform a double endianness swap on
big-endian architectures?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260630-pci_id_fix-v2-0-b834a98c0af2@garyguo.net?part=2
next prev parent reply other threads:[~2026-07-01 11:10 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 11:09 [PATCH v2 0/7] pci: fix UAF and TOCTOU related to dynamic ID Gary Guo
2026-06-30 11:09 ` [PATCH v2 1/7] ata: don't keep pci_device_id Gary Guo
2026-06-30 11:59 ` Niklas Cassel
2026-06-30 12:41 ` Gary Guo
2026-06-30 19:46 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot
2026-06-30 11:09 ` [PATCH v2 2/7] nsp32: " Gary Guo
2026-06-30 19:46 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot [this message]
2026-06-30 11:09 ` [PATCH v2 3/7] ipack: tpci200: " Gary Guo
2026-06-30 19:47 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot
2026-06-30 11:09 ` [PATCH v2 4/7] mlxsw: " Gary Guo
2026-06-30 19:48 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot
2026-07-01 13:57 ` Petr Machata
2026-06-30 11:09 ` [PATCH v2 5/7] pci: make pci_match_one_device match on ID instead of device Gary Guo
2026-06-30 20:04 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot
2026-06-30 11:09 ` [PATCH v2 6/7] pci: fix dyn_id add TOCTOU Gary Guo
2026-06-30 20:16 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot
2026-06-30 11:09 ` [PATCH v2 7/7] pci: fix UAF when probe runs concurrent to dyn ID removal Gary Guo
2026-06-30 20:25 ` Danilo Krummrich
2026-07-01 11:10 ` sashiko-bot
2026-07-01 11:44 ` Gary Guo
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=20260701111043.5E5531F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.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