From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793831474; b=QB/+RGZgpYPtJl/L0qD85XAcNaBfSTMC/J+jiBKekuFnlOeHuRd8PBPnQePPrNKvS+AU pF9hYV4sjwKlVhXcT8geUBw9jpY/5MY4Rl/rVQ2UL3HTzVy6/eU/qKVY5mmjW3BZd1Vwq GJ0jOQTeliJ+li29MQMYq9m+d2Qd3TRiIySiHY+xfvfXfEvzs50Fmnsiuqb1ITSMkaC/+ zGEXCKRWzoQOp0xaZCgv+7d1hfQjQDMKxq65HbIxFDsLk+PxLNfjOB/bf0dqv6UNmpm/Y 0tlyQvricQGY9+CfcERTmORd9TGZ4ph/wDu57TqzgAJia/69Jk3kuHFy3z95cDrdl4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793831474; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ZtIExRDApcJwNV2228+mOeE+p4BdVFrYRWdeW52dK34=; b=IQFjy0D5D6L8ej2o5MCi0ZM2z2bUoLuGKSKd3egeT6JNrIlVOhOBvhbWCKVa0PlX4cde TY4Wo5BNGPeAaUrzebpYkfhqs8BHki5pbRV3Ccpbra7sjQlU/XEt07WAltxdaJdEFLAti 0gUYZEQmU/EHP7rw4daEwC31r8PUz4SgdZp7jYVNoWl8OynZxzwmJySvkcSoN6anUohS5 WDf5v71TlV5a9rbefLAVKVysUrkgrt1NYIM4QbarmXFTstmIR6jGlKAfkjUbt3WIm46S0 sneA1YGuvR6Pyaui2FrvWULC53RkMyGb54bk5lnI7RKM0bg3A8t/Op3fFTEGe5LweOg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nDGhNlTK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95168606AC2A; Wed, 4 Nov 2026 22:31:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nDGhNlTK Received: by smtp.kernel.org (Postfix) with ESMTPSA id E153F1F000C1; Wed, 4 Nov 2026 22:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793831474; bh=ZtIExRDApcJwNV2228+mOeE+p4BdVFrYRWdeW52dK34=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nDGhNlTKIlM/yyUN3h0FFN4JgxfkDJQw69MlKADcaRJq0CieZJ10NcpyWy+uaD1ju uFVZsnKy+5HY9uRggfTgU4v3JyIPpaMTPRszamIexSeI7wowrGE4h5egS4XwcRG+QE EnsJKD/0NWbXeRNI7dzYTUZqXY41SrgKXi9cpNTk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Balakrishnan Sambath , Eugen Hristev , Hans Verkuil Subject: [PATCH 6.18 0726/1005] media: microchip-isc: take a reference on the parsed endpoints Date: Wed, 4 Nov 2026 16:07:39 -0500 Message-ID: <20261104211103.838192690@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261104211043.516122098@linuxfoundation.org> References: <20261104211043.516122098@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Balakrishnan Sambath commit f2eb2fd388bf3f1959556a326e797cacca341c86 upstream. for_each_endpoint_of_node() drops the reference on the current node as it advances. xisc_parse_dt() and isc_parse_dt() store the node in subdev_entity->epn and release it later with of_node_put(), but never took their own reference, so the stored pointer refers to an already-released node. This underflows the refcount and can use-after-free, reachable through the camera device tree overlay. Take a reference with of_node_get() when storing the node, and drop it in microchip_isc_subdev_cleanup() so the entities the bind loop never reaches on an early exit do not leak it. Fixes: c9aa973884a1 ("media: atmel: atmel-isc: add microchip-xisc driver") Fixes: d6701f13bd07 ("media: atmel: Use v4l2_async_notifier_add_fwnode_remote_subdev") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath Reviewed-by: Eugen Hristev Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/microchip/microchip-isc-base.c | 6 +++++ drivers/media/platform/microchip/microchip-sama5d2-isc.c | 17 ++++++++++----- drivers/media/platform/microchip/microchip-sama7g5-isc.c | 17 ++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) --- a/drivers/media/platform/microchip/microchip-isc-base.c +++ b/drivers/media/platform/microchip/microchip-isc-base.c @@ -1860,6 +1860,12 @@ void microchip_isc_subdev_cleanup(struct list_for_each_entry(subdev_entity, &isc->subdev_entities, list) { v4l2_async_nf_unregister(&subdev_entity->notifier); v4l2_async_nf_cleanup(&subdev_entity->notifier); + /* + * Release the endpoint reference taken while parsing. It is + * NULL for entities the bind loop already consumed, so this + * only drops the ones left over on an early exit. + */ + of_node_put(subdev_entity->epn); } INIT_LIST_HEAD(&isc->subdev_entities); --- a/drivers/media/platform/microchip/microchip-sama5d2-isc.c +++ b/drivers/media/platform/microchip/microchip-sama5d2-isc.c @@ -356,28 +356,30 @@ static int isc_parse_dt(struct device *d struct device_node *epn; struct isc_subdev_entity *subdev_entity; unsigned int flags; + int ret; INIT_LIST_HEAD(&isc->subdev_entities); for_each_endpoint_of_node(np, epn) { struct v4l2_fwnode_endpoint v4l2_epn = { .bus_type = 0 }; - int ret; ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(epn), &v4l2_epn); if (ret) { - of_node_put(epn); dev_err(dev, "Could not parse the endpoint\n"); - return -EINVAL; + of_node_put(epn); + ret = -EINVAL; + goto err_cleanup; } subdev_entity = devm_kzalloc(dev, sizeof(*subdev_entity), GFP_KERNEL); if (!subdev_entity) { of_node_put(epn); - return -ENOMEM; + ret = -ENOMEM; + goto err_cleanup; } - subdev_entity->epn = epn; + subdev_entity->epn = of_node_get(epn); flags = v4l2_epn.bus.parallel.flags; @@ -398,6 +400,11 @@ static int isc_parse_dt(struct device *d } return 0; + +err_cleanup: + list_for_each_entry(subdev_entity, &isc->subdev_entities, list) + of_node_put(subdev_entity->epn); + return ret; } static int microchip_isc_probe(struct platform_device *pdev) --- a/drivers/media/platform/microchip/microchip-sama7g5-isc.c +++ b/drivers/media/platform/microchip/microchip-sama7g5-isc.c @@ -340,6 +340,7 @@ static int xisc_parse_dt(struct device * struct isc_subdev_entity *subdev_entity; unsigned int flags; bool mipi_mode; + int ret; INIT_LIST_HEAD(&isc->subdev_entities); @@ -347,23 +348,24 @@ static int xisc_parse_dt(struct device * for_each_endpoint_of_node(np, epn) { struct v4l2_fwnode_endpoint v4l2_epn = { .bus_type = 0 }; - int ret; ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(epn), &v4l2_epn); if (ret) { - of_node_put(epn); dev_err(dev, "Could not parse the endpoint\n"); - return -EINVAL; + of_node_put(epn); + ret = -EINVAL; + goto err_cleanup; } subdev_entity = devm_kzalloc(dev, sizeof(*subdev_entity), GFP_KERNEL); if (!subdev_entity) { of_node_put(epn); - return -ENOMEM; + ret = -ENOMEM; + goto err_cleanup; } - subdev_entity->epn = epn; + subdev_entity->epn = of_node_get(epn); flags = v4l2_epn.bus.parallel.flags; @@ -387,6 +389,11 @@ static int xisc_parse_dt(struct device * } return 0; + +err_cleanup: + list_for_each_entry(subdev_entity, &isc->subdev_entities, list) + of_node_put(subdev_entity->epn); + return ret; } static int microchip_xisc_probe(struct platform_device *pdev)