From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796140808; b=d+PLcY6I7BkPaRVzXBImfqfpAkkvNU5hDmV/hgLBhtYtUuaTfcRhPi0d5RqZIvgZDE0+ doto91gkWPQ5xjMCYveEqwZK6I3NwUlMbVCu6Qp/TjmtLZBG7H37eI5bWn12y/NjPrt5V CRi8N1qAuMUQR6TSe3fsn+riFiW+jrmhhTW2N2wkUn1Q2i1kPIQJvwZ/wGDqsh+h2UFyb wnMbAJpM0Ca/uxhxwE3DXr1lGq8Rzmvg5XMo59i64nHKKKB4cRkPvZVSWIqGpd83HpqX7 WmD1KeZuobFbT+UtH1NB6ZQ+aQjN22HXV/VPSons7JYvqDYKiJ2+VsyZVgf00fXlX2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796140808; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=EE9vnXVBhF5PJCgiRX/PCBzyTiRunhbTwlOGmjIosUg=; b=HFZAXvIvgFY1S2xvqv5gArVUkx0wJ6EWmU+gpFnGf+ae4hRm3O8t4Fg+T8aH+AE3fkUQ CAK0NcMTdvGEdz0S2/Q11b59STftqtOQPHVmiF5KHSeyBaq1TMsdrzbfqGlmTJg3H9NqJ ws3hb5bvWLe72bzcizkn8Wq5IhocJYfReUnsAv/yO/uXgewR10U1EfgOV5birZdfKcS4t hQppV1RPuHdOXTdsz+nqDHb1OdGIiaSqzqM4aDQSAqW43SOEKO37vp6HJ+7bPoYIqzu6P +EOyQGjaNza3ciOa8/rl6JWGKDx0EVjoDAzrZ+Hl5IsmuAIPyH4BP9uvBainENEdl0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=PlQqnc6j; arc=none smtp.remote-ip=192.198.163.12 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B125606A322; Tue, 1 Dec 2026 16:00:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B125606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=PlQqnc6j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796140809; x=1827676809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EE9vnXVBhF5PJCgiRX/PCBzyTiRunhbTwlOGmjIosUg=; b=PlQqnc6j6RLx93I7bFkRbXbFkmXV7xoyHby4+K7crCk8Jx9or6cdRUkv Lpvice1YFj7+OYEvKg9i8nQxHOGvhxH0cZ+UbABztzsOK0NBu8PYM7FF2 pmjGJcYniVrd9YQJYRd9nWumm1SYdvdwmGc/lrJobnZ8o1ebC4OuczHX7 sDE+ZkjzM+W7WNfcGtzvnqXW9vHvxMJYbUjoj11OPHfpdXCZgShKJ4A5i iK9SssgkjhRiMoxncvElQYAP5CqcWu1nQkju7D8AidD7knZeoF4VNe6r5 y7kPRWv7Mp4OU1XDiyarbaNB2K421G/nqMw1yxlMR810zLaJXq6y5Uvxf g==; X-CSE-ConnectionGUID: 8y2M3SHUThCuknDOI9fy2g== X-CSE-MsgGUID: vB04AVTQT1KcpV84PJKACw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4930012" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4930012" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:00:07 -0800 X-CSE-ConnectionGUID: nqQymTOhQheDSLdMAc4s1A== X-CSE-MsgGUID: zknrL7/WQqeQKbw3c6N+hA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13254326" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 07:59:59 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Matthew Brost , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , David Airlie , Simona Vetter , 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: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , 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 Message-ID: <20261201155844.2278-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com> References: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit __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 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