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>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>, stable@vger.kernel.org
Subject: [PATCH 05/15] resource: Check that the resource is in the tree when releasing it
Date: Tue,  1 Dec 2026 17:58:29 +0200	[thread overview]
Message-ID: <20261201155844.2278-6-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com>

__release_resource() dereferences the parent of the resource without
checking whether the resource is in a resource tree at all. Releasing
a resource that is not in the tree or has already been removed from it
results in a NULL pointer dereference. Callers cannot check the parent
beforehand without racing as release_resource() takes the resource lock
only internally.

Looping a BAR resize through sysfs against a rescan of the parent bus
on a QEMU guest released a PCI bridge window that had already been
released:

  BUG: kernel NULL pointer dereference, address: 0000000000000038
  Oops: Oops: 0000 [#1] SMP
  CPU: 0 UID: 0 PID: 49 Comm: init Not tainted 7.4.0-rc1-00001-g4aa3acaaeb08 #1 PREEMPTLAZY
  RIP: 0010:__release_resource+0x8/0x70
  Call Trace:
   release_resource+0x22/0x40
   pci_release_resource+0x54/0x90
   pci_do_resource_release_and_resize+0x1f3/0x3d0
   __resource_resize_store+0xf0/0x180
   kernfs_fop_write_iter+0xfe/0x150
   vfs_write+0xf7/0x160
   ksys_write+0x6c/0xa0
   do_syscall_64+0x3b/0x1b0
   entry_SYSCALL_64_after_hwframe+0x4b/0x53

The double release was due to a race in the PCI bridge window sizing
and resource assignment, which is fixed separately, but the resource
tree code should have prevented the NULL pointer dereference too.

Return -EINVAL if the resource has no parent.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---

The PCI race fixes series mentioned in the changelog is here:

  https://lore.kernel.org/linux-pci/20261125230925.2441-1-ilpo.jarvinen@linux.intel.com/

 kernel/resource.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/resource.c b/kernel/resource.c
index 0c315c917fbb..68843852f342 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -218,6 +218,9 @@ static int __release_resource(struct resource *old, bool release_child)
 {
 	struct resource *tmp, **p, *chd;
 
+	if (!old->parent)
+		return -EINVAL;
+
 	p = &old->parent->child;
 	for (;;) {
 		tmp = *p;
-- 
2.47.3


  parent reply	other threads:[~2026-12-01 16:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 15:58 [PATCH 00/15] PCI: Resource release fixes and improvements Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 01/15] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 02/15] PCI: Set new BAR Size only after releasing the BARs for BAR resize Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 03/15] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 04/15] PCI: Consistently use Header Type to detect bridge headers Ilpo Järvinen
2026-12-01 15:58 ` Ilpo Järvinen [this message]
2026-12-01 15:58 ` [PATCH 06/15] resource: Add KUnit test for releasing a resource not in the tree Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 07/15] resource: Add release_leaf_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 08/15] resource: Add KUnit test for release_leaf_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 09/15] PCI: Do not release resources with children in pci_release_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 10/15] resource: Rename next_resource() and for_each_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 11/15] resource: Make resource_lock and resource tree traversal available Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 12/15] resource: Add release_resource_locked() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 13/15] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 14/15] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 15/15] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-02  0:22   ` 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=20261201155844.2278-6-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=matthew.brost@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=robh@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tursulin@ursulin.net \
    --cc=ville.syrjala@linux.intel.com \
    /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®