From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00E3D42BEA6 for ; Fri, 17 Jul 2026 14:53:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784300006; cv=none; b=q6iw8EN1S3TPUgaILVp9v6CB9mNlZdjBTX5eff2SjUOPj0XiImpAog6qpO8IgOUEqQao2mLVVhDp/vLVwqVcBUaquzm05bb/Cj42h6Lldb3yLNBH2nF5PxiWIyi6qaRSIY0BklLx/NXHFHh78YEgb5cZ9D2yhDKthu1epfyt8js= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784300006; c=relaxed/simple; bh=V7UJIhHONa6PwjxaQPM/lB8FRDMH/CPmUpkAoTsUR5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=px3l0VW82gdhYzFSp3TIREUNRlaPwE5HVq9eQsFqN4V4nh06ms6DVZDLm7C2gxluex6Q3DX72wYqZIN9f4jRlrzsJCKifk3PX05tT5yM98FTBqXeZkQz1VmJchLVRdk6uAanitKYaUQlXflfaR1Vvudgt+sy+kiOg8RMl43NwP8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=gv+t3KpE; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="gv+t3KpE" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id C4FF74E40E1E; Fri, 17 Jul 2026 14:53:13 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 96C7160361; Fri, 17 Jul 2026 14:53:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 473B111BD02F3; Fri, 17 Jul 2026 16:53:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1784299991; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=+9CnYiJau8FhyP1JC2OGvkUSIj/sOWL5/3RPGsZv/CE=; b=gv+t3KpEI3R2Gs7Gk0luJ0opt4BhYBTkL7kim/VBsj7uOll+ubo8E0dPcSpJtpB2IQjfdx hZgDnu+SWi9bSSs7iIvpEb8oQ8DEagzQr8eunj2e8YkjSf1RFswKUW4/Px2drur/G2Bh9W p4ouBo8tHFH/QsMpNqGPkGz4kjQHIziiTSHxaUpxjUzQMWZnVFFIITEhLvVvJuOb2tpTEO bSBBcJFzouSbB7M8SxOvO/PDpzrk3JT7lhHHi+jV5TZmGlsmUNqJ2Rz8dMTLyG1kK1YyLv IsnIoDIWD9Oq3P9OCz40KC2avX+Sk/7FiACrFZjMxrQ2JrL976sK5SqZ9Mn/AQ== From: Herve Codina To: Richard Cheng , Andrew Lunn , Rob Herring , Saravana Kannan , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Bjorn Helgaas , David Rhodes , Richard Fitzgerald , Charles Keepax , Linus Walleij , Len Brown , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Davidlohr Bueso , Jonathan Cameron , Dave Jiang , Alison Schofield , Vishal Verma , Dan Williams , Ira Weiny , Li Ming , Lizhi Hou , Herve Codina Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, patches@opensource.cirrus.com, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Daniel Machon , Steen Hegelund , Luca Ceresoli , Thomas Petazzoni , stable+noautosel@kernel.org Subject: [PATCH v10 10/10] PCI: of: Guard against node removal with incorrect np->data Date: Fri, 17 Jul 2026 16:51:45 +0200 Message-ID: <20260717145147.823749-11-herve.codina@bootlin.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260717145147.823749-1-herve.codina@bootlin.com> References: <20260717145147.823749-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: driver-core@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 of_pci_remove_node() and of_pci_remove_host_bridge_node() check whether the node is dynamic but not whether it has valid private data. During the node creation, an OF changeset is used and this changeset is stored in np->data to be available for removal functions. If, for instance, a PCI host bridge is created using a device-tree overlay, the related node will have the dynamic flag set but np->data will be NULL. This leads to NULL pointer dereferences. Further more, having a NULL np->data pointer means that the node has been created out of our PCI node creation process and so shouldn't be handled by our PCI node removal process. Add a np->data check for NULL to bail out early of PCI node removal functions. Fixes: 407d1a51921e ("PCI: Create device tree node for bridge") Fixes: 1f340724419e ("PCI: of: Create device tree PCI host bridge node") Cc: # Not triggered but 'This could be a problem...' Signed-off-by: Herve Codina --- drivers/pci/of.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 28896f748e8d..9f35e1e07cdc 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -654,7 +654,7 @@ void of_pci_remove_node(struct pci_dev *pdev) struct device_node *np; np = pci_device_to_OF_node(pdev); - if (!np || !of_node_check_flag(np, OF_DYNAMIC)) + if (!np || !of_node_check_flag(np, OF_DYNAMIC) || !np->data) return; fw_devlink_set_device(&np->fwnode, NULL); @@ -750,7 +750,7 @@ void of_pci_remove_host_bridge_node(struct pci_host_bridge *bridge) struct device_node *np; np = pci_bus_to_OF_node(bridge->bus); - if (!np || !of_node_check_flag(np, OF_DYNAMIC)) + if (!np || !of_node_check_flag(np, OF_DYNAMIC) || !np->data) return; fw_devlink_set_device(&np->fwnode, NULL); -- 2.55.0