From: "syzbot" <syzbot@kernel.org>
To: syzkaller-bugs@googlegroups.com, Marco Elver <elver@google.com>,
"Yehezkel Bernat" <YehezkelShB@gmail.com>,
"Andreas Noever" <andreas.noever@gmail.com>,
<linux-usb@vger.kernel.org>,
"Mika Westerberg" <westeri@kernel.org>
Cc: linux-kernel@vger.kernel.org, syzbot@lists.linux.dev
Subject: [PATCH] thunderbolt: Validate BAR 0 resource type and size
Date: Tue, 25 Aug 2026 16:09:37 +0000 (UTC) [thread overview]
Message-ID: <9e0d4fdc-4e1d-4195-80c0-7a70d34d1fc2@mail.kernel.org> (raw)
From: Marco Elver <elver@google.com>
The thunderbolt driver can crash with a page fault if it binds to an
arbitrary PCI device (e.g., via sysfs driver_override) that has an I/O port
BAR at index 0 instead of an MMIO BAR.
The driver maps this BAR without validating its type or size. When it
attempts to read a Thunderbolt register at a large offset, the resulting
I/O port cookie overflows the reserved PIO space on x86. This causes the
generic ioread32() function to misinterpret the out-of-bounds I/O port
cookie as a valid MMIO virtual address, leading to a direct dereference of
an unmapped physical-like address and a page fault:
BUG: unable to handle page fault for address: 00000000000556c0
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
...
Call Trace:
<TASK>
nhi_probe+0xcc/0x870 drivers/thunderbolt/nhi.c:1198
nhi_pci_probe+0x46b/0x580 drivers/thunderbolt/pci.c:479
local_pci_probe drivers/pci/pci-driver.c:332 [inline]
pci_call_probe drivers/pci/pci-driver.c:394 [inline]
__pci_device_probe drivers/pci/pci-driver.c:455 [inline]
pci_device_probe+0x431/0xc90 drivers/pci/pci-driver.c:489
To fix this, add explicit validation in nhi_pci_probe() to ensure that BAR
0 is an MMIO resource and is large enough to contain all the NHI registers
before attempting to map it. The NHI register space extends up to offset
0x39944 (REG_FW_STS), so checking for a minimum size of 0x40000 (256 KB) is
appropriate.
Fixes: 16603153666d ("thunderbolt: Add initial cactus ridge NHI support")
Assisted-by: Gemini:gemini-3.7-flash Gemini:gemini-3.1-pro-preview syzbot
Reported-by: syzbot+97999b836ee62ddb0181@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=97999b836ee62ddb0181
Link: https://syzkaller.appspot.com/ai_job?id=2570f821-2184-40c8-8bd7-344a30c18a13
Signed-off-by: Marco Elver <elver@google.com>
---
diff --git a/drivers/thunderbolt/nhi_regs.h b/drivers/thunderbolt/nhi_regs.h
index d6a197fab..1feb0bfb0 100644
--- a/drivers/thunderbolt/nhi_regs.h
+++ b/drivers/thunderbolt/nhi_regs.h
@@ -140,6 +140,9 @@ struct ring_desc {
#define REG_FW_STS_ICM_EN_INVERT BIT(1)
#define REG_FW_STS_ICM_EN BIT(0)
+/* Minimum BAR size to contain NHI registers */
+#define NHI_MIN_BAR_SIZE 0x40000
+
/* ICL NHI VSEC registers */
/* FW ready */
diff --git a/drivers/thunderbolt/pci.c b/drivers/thunderbolt/pci.c
index bbd186c29..fa69e4609 100644
--- a/drivers/thunderbolt/pci.c
+++ b/drivers/thunderbolt/pci.c
@@ -466,6 +466,14 @@ static int nhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
nhi->dev = dev;
nhi->ops = (const struct tb_nhi_ops *)id->driver_data ?: &pci_nhi_default_ops;
+ /* Ensure BAR 0 is an MMIO resource */
+ if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM))
+ return dev_err_probe(dev, -EINVAL, "BAR 0 is not an MMIO resource\n");
+
+ /* Ensure BAR 0 is large enough to contain the NHI registers */
+ if (pci_resource_len(pdev, 0) < NHI_MIN_BAR_SIZE)
+ return dev_err_probe(dev, -EINVAL, "BAR 0 is too small\n");
+
nhi->iobase = pcim_iomap_region(pdev, 0, "thunderbolt");
res = PTR_ERR_OR_ZERO(nhi->iobase);
if (res)
base-commit: 8d3ae59288f1e7d58d76558a6ee96d533bc5019f
--
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
The person who has signed off on the patch is responsible for
addressing comments.
syzbot engineers can be reached at syzkaller@googlegroups.com.
next reply other threads:[~2026-08-25 16:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 16:09 syzbot [this message]
2026-08-26 4:39 ` [PATCH] thunderbolt: Validate BAR 0 resource type and size Mika Westerberg
2026-08-26 6:08 ` Greg KH
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=9e0d4fdc-4e1d-4195-80c0-7a70d34d1fc2@mail.kernel.org \
--to=syzbot@kernel.org \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=elver@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=syzbot@lists.linux.dev \
--cc=syzkaller-bugs@googlegroups.com \
--cc=westeri@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 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.