mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	linux-pci@vger.kernel.org,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: Sashiko <sashiko-bot@kernel.org>, stable@vger.kernel.org
Subject: [PATCH 1/3] PCI: Fix NULL dereference when shrinking window without optional size
Date: Mon,  9 Nov 2026 16:45:51 +0200	[thread overview]
Message-ID: <20261109144553.2516-2-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261109144553.2516-1-ilpo.jarvinen@linux.intel.com>

adjust_bridge_window() assumes a bridge window it needs to shrink is on
add_list. A window is only added to add_list when it has optional size
or alignment. When resource distribution gives a window that is not on
add_list less space than its required size, res_to_dev_res() returns NULL
that is unconditionally dereferenced.

Consider a hotplug Root Port with no spare pref space and a switch below
it with two non-hotplug Downstream Ports. 02:00.0 has a 2M pref BAR below
it and 02:01.0 a 1M one. Alignment leaves only 1M of pref space for
02:00.0, and hot-add (emulated using a remove+rescan cycle) crashes in
the inlined adjust_bridge_window():

  BUG: kernel NULL pointer dereference, address: 0000000000000030
  RIP: 0010:pci_bus_distribute_available_resources+0x19b/0x4b0
  Call Trace:
   <TASK>
   pci_bus_distribute_available_resources+0x468/0x4b0
   pci_bus_distribute_available_resources+0x468/0x4b0
   pci_bridge_distribute_available_resources+0x7a/0x90
   pci_assign_unassigned_bridge_resources+0x43/0xe0
   pci_rescan_bus_bridge_resize+0x23/0x40
   bus_rescan_store+0x63/0x80

The required size must not be shrunk, so return early when the window
has no optional size.

Fixes: dc4b4d04e1ca ("PCI: Prevent shrinking bridge window from its required size")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---

As it was a non-public run of sashiko, no link is available to sashiko's
report.

 drivers/pci/setup-bus.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ed16ef7c26fa..bd0974def921 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1896,7 +1896,11 @@ static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res,
 				break;
 		}
 
+		/* Without optional size, there is nothing to shrink. */
 		dev_res = res_to_dev_res(add_list, res);
+		if (!dev_res)
+			return;
+
 		add_size = size - new_size;
 		if (add_size < dev_res->add_size) {
 			dev_res->add_size -= add_size;
-- 
2.47.3


  reply	other threads:[~2026-11-09 14:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 14:45 [PATCH 0/3] PCI: Fix hotplug memory distribute Ilpo Järvinen
2026-11-09 14:45 ` Ilpo Järvinen [this message]
2026-11-09 14:45 ` [PATCH 2/3] PCI: Fix start of available space for the next bridge during distribution Ilpo Järvinen
2026-11-09 14:45 ` [PATCH 3/3] PCI: Honor window granularity during resource distribution Ilpo Järvinen

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=20261109144553.2516-2-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®