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=1796327784; b=Cbm/hgUxYBFU8Fdk5xbYiIqLBa0pjYmeBc288gHQbzk3VhERcmbDKpyIZLPrI2fJKLct 5PRyM3cBdzM8F/lGRBVQqauC2ZfDx8QRujLCchF7qA0O/yutzG/5+lPLZR2C1Hn1EPXSu XjXeOC+4sO8+gOX4A6hetvn0q3vbfG8ni9cnl6+rm2GrQJcdjGQQM2cxf66L4mc5DHC/A Xhf0aciqwfVzD55m8f4AV+4n9jz7wK2vax2K9GJbpMGjzkGptxFY9Nasm+Bqk7K0G5NqM gEvsDPe8Ogws3Nhm6DHEy1vKOQVZ/dzX0veqwkDf7Q+v6x/jG09Yz3N3or2RA9E+C1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796327784; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Tljfe19lbhfTtL6RM9awOWkA3vQXfVoXyFZeyvkZiOc=; b=krLkUPA5yxA+uMqya4U5pUhLDBvIBlg6n3kehxLZzr3uRTrgXx3bYV+8NC76Bz/B2XAV L5bIulZwZD85lo3r/sexUp9zSjxO/AUDJXXLA075DBIjJMkM1+li8KHxIfoTlOppNIS5V /TMRzIjGbv55w7QV+KqqISYazkJLsC+5kZjPi9+/Dn5CHabXuBMbPvrAsYt+LyLWj0xDM FBkr0tpGAZXCtk7xvgk9nsewCs2G+l6c/EJjqubQ1DkTq+VtqZ2tbrkrwDFJWKuLVesqm PK3RPpSJHi19UU9EE1AUcUsnByx1yMkFZMDRB4yzXrzvFPDRRtxuqkkm9Ff8t62HqZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SnESmqrr; 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 5D74F606A32C; Thu, 3 Dec 2026 19:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SnESmqrr Received: by smtp.kernel.org (Postfix) with ESMTPSA id D787E1F000C2; Thu, 3 Dec 2026 19:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796327784; bh=Tljfe19lbhfTtL6RM9awOWkA3vQXfVoXyFZeyvkZiOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SnESmqrr6992Jv4f5/mAHhu/UCRu/gcJFXNcsCCYkaO1u24NBosFcbVeAtPmRomBJ daa4GPbphhsvPEH2foXjGXQNtrZpMU4mAOOXqu7Kn2kZePrQFhFw0GzKgfDHzn9e43 qPrVk49tYmxH1xvz+qyDLrErNrinsfhQ0LMJOoS4qhI0j6vgyW1OTbCL/lYTXEwLJY 3GID2WIH15aCB0WufBJjL/rNpJ7YP6VupOQOSBizqlHs2jeOWNtLBfERbSMsHKEzNZ yJXLbusuieOSUflrqlBb3xSUY862zF2MN82yXP9KpTkJYOXnkqbPHuOSVC47ZGnxQQ xM3i0Jy4DxSzg== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Niklas=20S=C3=B6derlund?= , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Geert Uytterhoeven , Magnus Damm , Kuninori Morimoto , linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove Date: Thu, 3 Dec 2026 19:54:17 +0000 Message-ID: <20261203195529.3063246-7-lee@kernel.org> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261203195529.3063246-1-lee@kernel.org> References: <20261203195529.3063246-1-lee@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit rcar_thermal_probe() requests shared IRQs via devm_request_irq(), so rcar_thermal_irq() remains active during rcar_thermal_remove() until devres teardown runs after the remove callback returns. Because rcar_thermal_irq() drops common->lock before queueing priv->work, an in-flight interrupt can re-queue the delayed work after cancel_delayed_work_sync() has returned, triggering a use-after-free after devres frees priv. Record the requested IRQ numbers in struct rcar_thermal_common and explicitly release them with devm_free_irq() in rcar_thermal_remove() before cancelling delayed work, disabling hardware interrupts, and dropping runtime PM. Fixes: e0a5172e9eec ("thermal: rcar: add interrupt support") Closes: https://sashiko.dev/#/bug/linux-45588606-8892-47eb-8398-6b410ae17278 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- drivers/thermal/renesas/rcar_thermal.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/renesas/rcar_thermal.c b/drivers/thermal/renesas/rcar_thermal.c index af6d09a75bb6..3e02b16084b4 100644 --- a/drivers/thermal/renesas/rcar_thermal.c +++ b/drivers/thermal/renesas/rcar_thermal.c @@ -39,11 +39,15 @@ /* THSSR */ #define CTEMP 0x3f +#define RCAR_THERMAL_MAX_IRQS 2 + struct rcar_thermal_common { void __iomem *base; struct device *dev; struct list_head head; spinlock_t lock; + int irqs[RCAR_THERMAL_MAX_IRQS]; + unsigned int nirqs; }; struct rcar_thermal_chip { @@ -377,9 +381,15 @@ static void rcar_thermal_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; struct rcar_thermal_priv *priv; - rcar_thermal_for_each_priv(priv, common) { + rcar_thermal_for_each_priv(priv, common) rcar_thermal_irq_disable(priv); + + for (unsigned int i = 0; i < common->nirqs; i++) + devm_free_irq(dev, common->irqs[i], common); + + rcar_thermal_for_each_priv(priv, common) { cancel_delayed_work_sync(&priv->work); + rcar_thermal_irq_disable(priv); if (priv->chip->use_of_thermal) thermal_remove_hwmon_sysfs(priv->zone); else @@ -444,10 +454,16 @@ static int rcar_thermal_probe(struct platform_device *pdev) idle = 0; /* polling delay is not needed */ } + if (common->nirqs >= RCAR_THERMAL_MAX_IRQS) { + ret = -EINVAL; + goto error_unregister; + } + ret = devm_request_irq(dev, irq, rcar_thermal_irq, IRQF_SHARED, dev_name(dev), common); if (ret) goto error_unregister; + common->irqs[common->nirqs++] = irq; /* update ENR bits */ if (chip->irq_per_ch) -- 2.56.1.911.g883d8bcb20-goog