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=1796431281; b=bmhEPxUDVyaMIYQWqiklHAkGUQWVpqDzeYFh7iTPAggTRfpLRsRogzIEstpPuZHuSGZC zpAmXNVEPpFauiYYcPqo0BuaJjBuF4NHJ9wspwjls7XoaGK2wSwskw1oq3qycSvMgbK+E sU0mvSCxZ6ri1FQePAs51Zgre7Dp8e+QJ16PF5/naU/JYYZMxdUR5VZxZqYIRE0XXTWpi ce6bX4YYGFmcAZ2FsA3QHIFWl4AqcqYCs/y/JVTTNM793lkLsApSgNZnte147FLT8c5LD CZzY19UhSTYpwvz1x+MwGqk+wTk0bghiBu+uflJT29vcTY+FpKDIMzjSH3iWDzSrnng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796431281; 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=M7cPAjliNVbAZAODL63jcTw0QFoXT/HDvCpOEkhh8S8WFEvYg3pclNklErXviHp+jxqc xX9WYLiarFD4JW/VMJn6uWmilMOO5mUAqv/UI93yS7j0Mw5XDty626IN3KIoIPDJVNLqF 2625KqOQZY424361VuFFJBx+VayCpEq8jXBD4/ONC01ryZgP2tri0f5YBG/rs5TySGnrh Moj4TAQ0nMe1Gpt3ljC4S1nOfpvJYcL4x7uNyEji8tNAWQEdB0hg6HeFkeaVxFGs3bVpP miY1JmvSDCauDaL5C3j8dnOQ5uEGccJcfvsLQqowA64n7B74sTWF5mCCCvZezy5fs6w== 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=kw8wgllE; 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 BCE0C606A330; Sat, 5 Dec 2026 00:41:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCE0C606A330 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=kw8wgllE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796431281; x=1827967281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EE9vnXVBhF5PJCgiRX/PCBzyTiRunhbTwlOGmjIosUg=; b=kw8wgllEI6Vd1bUmYKYx/oyW0OkGQTLw4QVM+J+faK43GVR+AOLsThvE mcD/GQZhUnnjfp7hk1cq3KmIgFEirhTwtaqUX36XGNOVcstRD8SU1TPyY FmF+QsM6sbPylEUE3HqlyrUHTzs+ZAHmVqRaOGZv9ZGO2se3TKSgKqojc 5Szw9q3A0lLVVdGvw3hMPgDira5ypni+rpJCFtDdjtcE50AVEC3slrb9y bRy+7cnet/j0eBNhAM04ptvDAgFHibbNHp2PM8HwtEevLXL/nL+jx/Ax2 ouD55Idpm2aKi2T9dCdjH7/9taVpiKqgjvjQNLrPQXtFK3YVa18wDfjGy A==; X-CSE-ConnectionGUID: tyf/Y9HHRniQI7Otd5I2ig== X-CSE-MsgGUID: AiAFgE/5R/SWQwl5ziWZQg== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5325091" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5325091" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:41:20 -0800 X-CSE-ConnectionGUID: V2rp1gTuTdGK65D016xGrQ== X-CSE-MsgGUID: i3xflbtdQIGzvPGB2U+9WQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="13992039" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:41:12 -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, Anthony Pighin , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , stable@vger.kernel.org Subject: [PATCH v2 05/16] resource: Check that the resource is in the tree when releasing it Date: Sat, 5 Dec 2026 02:39:40 +0200 Message-ID: <20261205003957.3304-6-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-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