Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact()
       [not found] <20261203195529.3063246-1-lee@kernel.org>
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation Lee Jones
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Jez Ng, Aubrey Li, Ricardo Neri, Len Brown, linux-pm
  Cc: linux-kernel, stable

intel_hfi_online() passes hfi_features.nr_table_pages (a page count) to
alloc_pages_exact() and free_pages_exact() instead of the table size in
bytes.  When CPUID leaf 6 enumerates more than one HFI table page, only
a single page is allocated, allowing hardware writes via
MSR_IA32_HW_FEEDBACK_PTR to corrupt adjacent physical memory and
intel_hfi_process_event() to read out of bounds.

Convert the page count to bytes using hfi_features.nr_table_pages <<
PAGE_SHIFT, matching the local_table allocation.

Fixes: 2d74e6319abe ("thermal: intel: hfi: Handle CPU hotplug events")
Closes: https://sashiko.dev/#/bug/linux-213cb649-d604-43fc-b43b-8cb453a252d6
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/intel/intel_hfi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c
index 8ff094eccbaf..19355679c1df 100644
--- a/drivers/thermal/intel/intel_hfi.c
+++ b/drivers/thermal/intel/intel_hfi.c
@@ -470,7 +470,7 @@ void intel_hfi_online(unsigned int cpu)
 	 * even after having been reprogrammed. Keep using the same pages. Do
 	 * not free them.
 	 */
-	hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages,
+	hfi_instance->hw_table = alloc_pages_exact(hfi_features.nr_table_pages << PAGE_SHIFT,
 						   GFP_KERNEL | __GFP_ZERO);
 	if (!hfi_instance->hw_table)
 		goto unlock;
@@ -508,7 +508,8 @@ void intel_hfi_online(unsigned int cpu)
 	return;
 
 free_hw_table:
-	free_pages_exact(hfi_instance->hw_table, hfi_features.nr_table_pages);
+	free_pages_exact(hfi_instance->hw_table,
+			 hfi_features.nr_table_pages << PAGE_SHIFT);
 	goto unlock;
 }
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation
       [not found] <20261203195529.3063246-1-lee@kernel.org>
  2026-12-03 19:54 ` [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact() Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone Lee Jones
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Jez Ng, Aubrey Li, Ricardo Neri, Len Brown, linux-pm
  Cc: linux-kernel, stable

intel_hfi_online() stores hfi_instance in per-CPU hfi_cpu_info before
allocating hw_table and local_table, and fails to clear
hfi_instance->hw_table after free_pages_exact() when local_table
allocation fails.  Because the thermal LVT is still unmasked,
intel_hfi_process_event() and hfi_syscore_resume() can then dereference
NULL or freed pointers.

Defer publishing info->hfi_instance until the instance has been fully
initialised, clear hfi_instance->hw_table after freeing it on error,
and check hfi_instance for NULL in hfi_syscore_resume().

Fixes: 2d74e6319abe ("thermal: intel: hfi: Handle CPU hotplug events")
Closes: https://sashiko.dev/#/bug/linux-02550489-11c2-419c-9a5f-9dfad590b556
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/intel/intel_hfi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c
index 19355679c1df..79d06b510fdc 100644
--- a/drivers/thermal/intel/intel_hfi.c
+++ b/drivers/thermal/intel/intel_hfi.c
@@ -435,10 +435,7 @@ void intel_hfi_online(unsigned int cpu)
 	if (!hfi_instances)
 		return;
 
-	/*
-	 * Link @cpu to the HFI instance of its package. It does not
-	 * matter whether the instance has been initialized.
-	 */
+	/* Find the HFI instance of @cpu's package. */
 	info = &per_cpu(hfi_cpu_info, cpu);
 	pkg_id = topology_logical_package_id(cpu);
 	hfi_instance = info->hfi_instance;
@@ -447,7 +444,6 @@ void intel_hfi_online(unsigned int cpu)
 			return;
 
 		hfi_instance = &hfi_instances[pkg_id];
-		info->hfi_instance = hfi_instance;
 	}
 
 	init_hfi_cpu_index(info);
@@ -491,6 +487,7 @@ void intel_hfi_online(unsigned int cpu)
 	raw_spin_lock_init(&hfi_instance->event_lock);
 
 enable:
+	info->hfi_instance = hfi_instance;
 	cpumask_set_cpu(cpu, hfi_instance->cpus);
 
 	/*
@@ -510,6 +507,7 @@ void intel_hfi_online(unsigned int cpu)
 free_hw_table:
 	free_pages_exact(hfi_instance->hw_table,
 			 hfi_features.nr_table_pages << PAGE_SHIFT);
+	hfi_instance->hw_table = NULL;
 	goto unlock;
 }
 
@@ -621,7 +619,7 @@ static void hfi_syscore_resume(void *data)
 	struct hfi_instance *hfi_instance = info->hfi_instance;
 
 	/* No locking needed. There is no concurrency with CPU online. */
-	if (hfi_clients_nr > 0)
+	if (hfi_instance && hfi_clients_nr > 0)
 		hfi_enable_instance(hfi_instance);
 }
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone
       [not found] <20261203195529.3063246-1-lee@kernel.org>
  2026-12-03 19:54 ` [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact() Lee Jones
  2026-12-03 19:54 ` [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration Lee Jones
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Matthew Garrett, linux-pm
  Cc: linux-kernel, stable

int3400_thermal_remove() calls cleanup_odvp() before
thermal_zone_device_unregister().  A concurrent sysfs mode write can
still invoke int3400_thermal_change_mode() -> evaluate_odvp(),
recreating the odvpN sysfs attributes before priv is freed and leaving
dangling attributes that trigger a use-after-free in odvp_show().

Move cleanup_odvp() after thermal_zone_device_unregister(), matching
the probe error path.

Fixes: 006f006f1e5c ("thermal/int340x_thermal: Export OEM vendor variables")
Closes: https://sashiko.dev/#/bug/linux-fb387528-ad8f-418c-b2af-878f7ad81af1
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index 5d70301d4a3d..7cd533414973 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -668,8 +668,6 @@ static void int3400_thermal_remove(struct platform_device *pdev)
 			priv->adev->handle, ACPI_DEVICE_NOTIFY,
 			int3400_notify);
 
-	cleanup_odvp(priv);
-
 	if (!priv->rel_misc_dev_res)
 		acpi_thermal_rel_misc_device_remove(priv->adev->handle);
 
@@ -678,6 +676,7 @@ static void int3400_thermal_remove(struct platform_device *pdev)
 	sysfs_remove_group(&pdev->dev.kobj, &uuid_attribute_group);
 	sysfs_remove_group(&pdev->dev.kobj, &imok_attribute_group);
 	thermal_zone_device_unregister(priv->thermal);
+	cleanup_odvp(priv);
 	kfree(priv->data_vault);
 	kfree(priv->trts);
 	kfree(priv->arts);
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (2 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 05/10] thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors Lee Jones
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
	Daniel Lezcano, Zhang Rui, Lukasz Luba, Eduardo Valentin,
	linux-arm-msm, linux-pm
  Cc: linux-kernel, stable

data_tsens_v1 allows up to 11 sensors via tsens_v1_feat.max_sensors,
whereas calibrate_v1() passes 10-element stack arrays p1[10] and p2[10]
and the 10-entry tsens_qcs404_nvmem table to
tsens_read_calibration_legacy() and compute_intercept_slope().  With 11
sensors configured, both read past tsens_qcs404_nvmem.sp and overflow
p1 and p2 on the stack.

Reject legacy calibration in calibrate_v1() when priv->num_sensors
exceeds ARRAY_SIZE(p1).

Fixes: e8c24c6f5d1c ("drivers: thermal: tsens: Add generic support for TSENS v1 IP")
Closes: https://sashiko.dev/#/bug/linux-cb651f32-9e59-4f52-9175-a61de369ed59
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/qcom/tsens-v1.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 7bda8e6087c4..12fe0fbefad4 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -49,8 +49,11 @@ static int calibrate_v1(struct tsens_priv *priv)
 	int mode, ret;
 
 	ret = tsens_calibrate_common(priv);
-	if (!ret)
-		return 0;
+	if (!ret || ret == -EPROBE_DEFER)
+		return ret;
+
+	if (priv->num_sensors > ARRAY_SIZE(p1))
+		return -EINVAL;
 
 	qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
 	if (IS_ERR(qfprom_cdata))
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 05/10] thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (3 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove Lee Jones
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
	Daniel Lezcano, Zhang Rui, Lukasz Luba, Rob Herring,
	Eduardo Valentin, Bjorn Andersson, linux-arm-msm, linux-pm
  Cc: linux-kernel, stable

tsens_probe() allocates priv->sensor[] with priv->num_sensors entries,
which may be smaller than the SoC default when #qcom,sensors is set in
Device Tree.  The per-SoC init helpers for 8226, 8909, 8939, 9607,
8952, and 8956 index priv->sensor[] with hardcoded constants up to the
SoC maximum, writing past the end of the heap allocation when fewer
sensors are configured.

Replace the hardcoded assignments with static lookup tables and bound
each loop by priv->num_sensors.

Fixes: 6d7c70d1cd65 ("thermal: qcom: tsens: Allow number of sensors to come from DT")
Closes: https://sashiko.dev/#/bug/linux-f4750172-f8d0-40d4-94de-1c800cb4cc51
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/qcom/tsens-v0_1.c | 67 ++++++++++++-------------------
 drivers/thermal/qcom/tsens-v1.c   | 49 +++++++---------------
 2 files changed, 41 insertions(+), 75 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 32d2d3e33287..468da9e513e2 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -209,69 +209,54 @@ static int calibrate_8974(struct tsens_priv *priv)
 
 static int __init init_8226(struct tsens_priv *priv)
 {
-	priv->sensor[0].slope = 2901;
-	priv->sensor[1].slope = 2846;
-	priv->sensor[2].slope = 3038;
-	priv->sensor[3].slope = 2955;
-	priv->sensor[4].slope = 2901;
-	priv->sensor[5].slope = 2846;
+	static const u32 slopes[] = { 2901, 2846, 3038, 2955, 2901, 2846 };
+
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+		priv->sensor[i].slope = slopes[i];
 
 	return init_common(priv);
 }
 
 static int __init init_8909(struct tsens_priv *priv)
 {
-	int i;
+	static const int p1_offsets[] = { 0, -10, 0, -9, -8 };
+	static const int p2_offsets[] = { 0, -6, 0, -9, -10 };
 
-	for (i = 0; i < priv->num_sensors; ++i)
+	for (unsigned int i = 0; i < priv->num_sensors; ++i)
 		priv->sensor[i].slope = 3000;
 
-	priv->sensor[0].p1_calib_offset = 0;
-	priv->sensor[0].p2_calib_offset = 0;
-	priv->sensor[1].p1_calib_offset = -10;
-	priv->sensor[1].p2_calib_offset = -6;
-	priv->sensor[2].p1_calib_offset = 0;
-	priv->sensor[2].p2_calib_offset = 0;
-	priv->sensor[3].p1_calib_offset = -9;
-	priv->sensor[3].p2_calib_offset = -9;
-	priv->sensor[4].p1_calib_offset = -8;
-	priv->sensor[4].p2_calib_offset = -10;
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+		priv->sensor[i].p1_calib_offset = p1_offsets[i];
+		priv->sensor[i].p2_calib_offset = p2_offsets[i];
+	}
 
 	return init_common(priv);
 }
 
-static int __init init_8939(struct tsens_priv *priv) {
-	priv->sensor[0].slope = 2911;
-	priv->sensor[1].slope = 2789;
-	priv->sensor[2].slope = 2906;
-	priv->sensor[3].slope = 2763;
-	priv->sensor[4].slope = 2922;
-	priv->sensor[5].slope = 2867;
-	priv->sensor[6].slope = 2833;
-	priv->sensor[7].slope = 2838;
-	priv->sensor[8].slope = 2840;
-	/* priv->sensor[9].slope = 2852; */
+static int __init init_8939(struct tsens_priv *priv)
+{
+	static const u32 slopes[] = {
+		2911, 2789, 2906, 2763, 2922, 2867, 2833, 2838, 2840,
+	};
+
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+		priv->sensor[i].slope = slopes[i];
 
 	return init_common(priv);
 }
 
 static int __init init_9607(struct tsens_priv *priv)
 {
-	int i;
+	static const int p1_offsets[] = { 1, -4, 4, -3, -4 };
+	static const int p2_offsets[] = { 1, -2, 8, -5, -4 };
 
-	for (i = 0; i < priv->num_sensors; ++i)
+	for (unsigned int i = 0; i < priv->num_sensors; ++i)
 		priv->sensor[i].slope = 3000;
 
-	priv->sensor[0].p1_calib_offset = 1;
-	priv->sensor[0].p2_calib_offset = 1;
-	priv->sensor[1].p1_calib_offset = -4;
-	priv->sensor[1].p2_calib_offset = -2;
-	priv->sensor[2].p1_calib_offset = 4;
-	priv->sensor[2].p2_calib_offset = 8;
-	priv->sensor[3].p1_calib_offset = -3;
-	priv->sensor[3].p2_calib_offset = -5;
-	priv->sensor[4].p1_calib_offset = -4;
-	priv->sensor[4].p2_calib_offset = -4;
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+		priv->sensor[i].p1_calib_offset = p1_offsets[i];
+		priv->sensor[i].p2_calib_offset = p2_offsets[i];
+	}
 
 	return init_common(priv);
 }
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 12fe0fbefad4..a43ccc4bda86 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -150,44 +150,25 @@ static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
 
 static int __init init_8952(struct tsens_priv *priv)
 {
-	priv->sensor[0].p1_calib_offset = 2;
-	priv->sensor[0].p2_calib_offset = -1;
-	priv->sensor[1].p1_calib_offset = -4;
-	priv->sensor[1].p2_calib_offset = -4;
-	priv->sensor[2].p1_calib_offset = 4;
-	priv->sensor[2].p2_calib_offset = 5;
-	priv->sensor[3].p1_calib_offset = 1;
-	priv->sensor[3].p2_calib_offset = 1;
-	priv->sensor[4].p1_calib_offset = 2;
-	priv->sensor[4].p2_calib_offset = 3;
-	priv->sensor[5].p1_calib_offset = -1;
-	priv->sensor[5].p2_calib_offset = -1;
-	priv->sensor[6].p1_calib_offset = 0;
-	priv->sensor[6].p2_calib_offset = -1;
-	priv->sensor[7].p1_calib_offset = 3;
-	priv->sensor[7].p2_calib_offset = 4;
-	priv->sensor[8].p1_calib_offset = 2;
-	priv->sensor[8].p2_calib_offset = 4;
-	priv->sensor[9].p1_calib_offset = 0;
-	priv->sensor[9].p2_calib_offset = 0;
-	priv->sensor[10].p1_calib_offset = -3;
-	priv->sensor[10].p2_calib_offset = -2;
+	static const int p1_offsets[] = { 2, -4, 4, 1, 2, -1, 0, 3, 2, 0, -3 };
+	static const int p2_offsets[] = { -1, -4, 5, 1, 3, -1, -1, 4, 4, 0, -2 };
+
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(p1_offsets); i++) {
+		priv->sensor[i].p1_calib_offset = p1_offsets[i];
+		priv->sensor[i].p2_calib_offset = p2_offsets[i];
+	}
 
 	return init_common(priv);
 }
 
-static int __init init_8956(struct tsens_priv *priv) {
-	priv->sensor[0].slope = 3313;
-	priv->sensor[1].slope = 3275;
-	priv->sensor[2].slope = 3320;
-	priv->sensor[3].slope = 3246;
-	priv->sensor[4].slope = 3279;
-	priv->sensor[5].slope = 3257;
-	priv->sensor[6].slope = 3234;
-	priv->sensor[7].slope = 3269;
-	priv->sensor[8].slope = 3255;
-	priv->sensor[9].slope = 3239;
-	priv->sensor[10].slope = 3286;
+static int __init init_8956(struct tsens_priv *priv)
+{
+	static const u32 slopes[] = {
+		3313, 3275, 3320, 3246, 3279, 3257, 3234, 3269, 3255, 3239, 3286,
+	};
+
+	for (unsigned int i = 0; i < priv->num_sensors && i < ARRAY_SIZE(slopes); i++)
+		priv->sensor[i].slope = slopes[i];
 
 	return init_common(priv);
 }
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (4 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 05/10] thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp() Lee Jones
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Niklas Söderlund, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba, Geert Uytterhoeven, Magnus Damm,
	Kuninori Morimoto, linux-renesas-soc, linux-pm
  Cc: linux-kernel, stable

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 <lee@kernel.org>
---
 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp()
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (5 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating Lee Jones
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Peng Fan, Pengfei Li, linux-pm, imx, linux-arm-kernel
  Cc: linux-kernel, stable

The thermal core allows get_temp() to be called via sysfs even when the
thermal zone has been disabled and imx91_tmu_change_mode() has dropped
the runtime PM reference, gating the TMU clock.  Reading IMX91_TMU_DATA0
in imx91_tmu_get_temp() while the clock is disabled causes an unclocked
register access.

Wrap the register read in imx91_tmu_get_temp() with
pm_runtime_resume_and_get() and pm_runtime_put().

Fixes: c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")
Closes: https://sashiko.dev/#/bug/linux-366503cb-0dfd-43b0-9c97-f75af5382e66
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/imx91_thermal.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/thermal/imx91_thermal.c b/drivers/thermal/imx91_thermal.c
index 6d0aba992244..c3a72df665a8 100644
--- a/drivers/thermal/imx91_thermal.c
+++ b/drivers/thermal/imx91_thermal.c
@@ -110,11 +110,18 @@ static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
 	s16 data;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(tmu->dev);
+	if (ret < 0)
+		return ret;
 
 	/* DATA0 is 16bit signed number */
 	data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
 	*temp = imx91_tmu_to_mcelsius(data);
 
+	pm_runtime_put(tmu->dev);
+
 	return 0;
 }
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (6 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp() Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 09/10] thermal/drivers/qcom/tsens: Drop __init from ops init callbacks Lee Jones
  2026-12-03 19:54 ` [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode() Lee Jones
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Jacob Pan, Neil Horman, linux-pm
  Cc: linux-kernel, stable

prepare_logging() opens /var/tmp/tmon.log with fopen(..., "w+") before
checking lstat() for symlinks or ownership.  Because tmon runs as root
and fopen("w+") follows symlinks and immediately truncates the target,
a local attacker can clobber arbitrary files via a symlink in /var/tmp.

Open the log file with open(..., O_RDWR | O_CREAT | O_NOFOLLOW |
O_CLOEXEC, 0600) without O_TRUNC, validate that the opened descriptor
refers to a regular file owned by the current user via fstat(), and
only then call ftruncate() and fdopen().

Fixes: 951fda3d8c64 ("tmon: Check log file for common secuirty issues")
Closes: https://sashiko.dev/#/bug/linux-d4578ca3-42ad-4e17-b59d-fc6d213bd412
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 tools/thermal/tmon/tmon.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/tools/thermal/tmon/tmon.c b/tools/thermal/tmon/tmon.c
index 70a2ec50a461..701163b4a08a 100644
--- a/tools/thermal/tmon/tmon.c
+++ b/tools/thermal/tmon/tmon.c
@@ -8,6 +8,7 @@
  */
 
 #include <getopt.h>
+#include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -130,37 +131,48 @@ static void start_syslog(void)
 
 static void prepare_logging(void)
 {
-	int i;
+	int i, fd;
 	struct stat logstat;
 
 	if (!logging)
 		return;
 	/* open local data log file */
-	tmon_log = fopen(TMON_LOG_FILE, "w+");
-	if (!tmon_log) {
+	fd = open(TMON_LOG_FILE, O_RDWR | O_CREAT | O_NOFOLLOW | O_CLOEXEC,
+		  0600);
+	if (fd < 0) {
 		syslog(LOG_ERR, "failed to open log file %s\n", TMON_LOG_FILE);
 		return;
 	}
 
-	if (lstat(TMON_LOG_FILE, &logstat) < 0) {
+	if (fstat(fd, &logstat) < 0) {
 		syslog(LOG_ERR, "Unable to stat log file %s\n", TMON_LOG_FILE);
-		fclose(tmon_log);
-		tmon_log = NULL;
+		close(fd);
 		return;
 	}
 
 	/* The log file must be a regular file owned by us */
-	if (S_ISLNK(logstat.st_mode)) {
-		syslog(LOG_ERR, "Log file is a symlink.  Will not log\n");
-		fclose(tmon_log);
-		tmon_log = NULL;
+	if (!S_ISREG(logstat.st_mode)) {
+		syslog(LOG_ERR, "Log file is not a regular file.  Will not log\n");
+		close(fd);
 		return;
 	}
 
 	if (logstat.st_uid != getuid()) {
 		syslog(LOG_ERR, "We don't own the log file.  Not logging\n");
-		fclose(tmon_log);
-		tmon_log = NULL;
+		close(fd);
+		return;
+	}
+
+	if (ftruncate(fd, 0) < 0) {
+		syslog(LOG_ERR, "Unable to truncate log file %s\n", TMON_LOG_FILE);
+		close(fd);
+		return;
+	}
+
+	tmon_log = fdopen(fd, "w+");
+	if (!tmon_log) {
+		syslog(LOG_ERR, "failed to open log file %s\n", TMON_LOG_FILE);
+		close(fd);
 		return;
 	}
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 09/10] thermal/drivers/qcom/tsens: Drop __init from ops init callbacks
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (7 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  2026-12-03 19:54 ` [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode() Lee Jones
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Amit Kucheria, Thara Gopinath, Rafael J. Wysocki,
	Daniel Lezcano, Zhang Rui, Lukasz Luba, Priyansh Jain, Lina Iyer,
	Eduardo Valentin, Rajendra Nayak, linux-arm-msm, linux-pm
  Cc: linux-kernel, stable

The TSENS ops init callbacks (init_common and the per-SoC init helpers)
are annotated with __init even though they are stored in const struct
tsens_ops tables and invoked from non-__init tsens_probe().  When built
into the kernel, deferred probe or driver rebind after free_initmem()
jumps into freed init text.

Remove __init from all nine init callbacks.

Fixes: 9066073c6c27 ("thermal: qcom: tsens: Add a skeletal TSENS drivers")
Closes: https://sashiko.dev/#/bug/linux-efcbd818-b857-4c2b-831f-3fe62a3050ee
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/qcom/tsens-v0_1.c | 8 ++++----
 drivers/thermal/qcom/tsens-v1.c   | 6 +++---
 drivers/thermal/qcom/tsens-v2.c   | 2 +-
 drivers/thermal/qcom/tsens.c      | 2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 468da9e513e2..bcd3c0bf49dd 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -207,7 +207,7 @@ static int calibrate_8974(struct tsens_priv *priv)
 	return 0;
 }
 
-static int __init init_8226(struct tsens_priv *priv)
+static int init_8226(struct tsens_priv *priv)
 {
 	static const u32 slopes[] = { 2901, 2846, 3038, 2955, 2901, 2846 };
 
@@ -217,7 +217,7 @@ static int __init init_8226(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_8909(struct tsens_priv *priv)
+static int init_8909(struct tsens_priv *priv)
 {
 	static const int p1_offsets[] = { 0, -10, 0, -9, -8 };
 	static const int p2_offsets[] = { 0, -6, 0, -9, -10 };
@@ -233,7 +233,7 @@ static int __init init_8909(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_8939(struct tsens_priv *priv)
+static int init_8939(struct tsens_priv *priv)
 {
 	static const u32 slopes[] = {
 		2911, 2789, 2906, 2763, 2922, 2867, 2833, 2838, 2840,
@@ -245,7 +245,7 @@ static int __init init_8939(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_9607(struct tsens_priv *priv)
+static int init_9607(struct tsens_priv *priv)
 {
 	static const int p1_offsets[] = { 1, -4, 4, -3, -4 };
 	static const int p2_offsets[] = { 1, -2, 8, -5, -4 };
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index a43ccc4bda86..14c6c6c2c0d6 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -148,7 +148,7 @@ static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
 	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
 };
 
-static int __init init_8952(struct tsens_priv *priv)
+static int init_8952(struct tsens_priv *priv)
 {
 	static const int p1_offsets[] = { 2, -4, 4, 1, 2, -1, 0, 3, 2, 0, -3 };
 	static const int p2_offsets[] = { -1, -4, 5, 1, 3, -1, -1, 4, 4, 0, -2 };
@@ -161,7 +161,7 @@ static int __init init_8952(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_8956(struct tsens_priv *priv)
+static int init_8956(struct tsens_priv *priv)
 {
 	static const u32 slopes[] = {
 		3313, 3275, 3320, 3246, 3279, 3257, 3234, 3269, 3255, 3239, 3286,
@@ -173,7 +173,7 @@ static int __init init_8956(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-static int __init init_tsens_v1_no_rpm(struct tsens_priv *priv)
+static int init_tsens_v1_no_rpm(struct tsens_priv *priv)
 {
 	int i, ret;
 	u32 mask = 0;
diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c
index 843dd29fad2e..22284973bb61 100644
--- a/drivers/thermal/qcom/tsens-v2.c
+++ b/drivers/thermal/qcom/tsens-v2.c
@@ -220,7 +220,7 @@ static int tsens_v2_calibration(struct tsens_priv *priv)
 	return 0;
 }
 
-static int __init init_tsens_v2_no_rpm(struct tsens_priv *priv)
+static int init_tsens_v2_no_rpm(struct tsens_priv *priv)
 {
 	struct device *dev = priv->dev;
 	int i, ret;
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index ff7c573c6a21..6ea0581e9161 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -929,7 +929,7 @@ static const struct regmap_config tsens_srot_config = {
 	.reg_stride	= 4,
 };
 
-int __init init_common(struct tsens_priv *priv)
+int init_common(struct tsens_priv *priv)
 {
 	void __iomem *tm_base, *srot_base;
 	struct device *dev = priv->dev;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode()
       [not found] <20261203195529.3063246-1-lee@kernel.org>
                   ` (8 preceding siblings ...)
  2026-12-03 19:54 ` [PATCH 09/10] thermal/drivers/qcom/tsens: Drop __init from ops init callbacks Lee Jones
@ 2026-12-03 19:54 ` Lee Jones
  9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 19:54 UTC (permalink / raw)
  To: lee, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Peng Fan, Pengfei Li, linux-pm, imx, linux-arm-kernel
  Cc: linux-kernel, stable

When enabling the thermal zone, imx91_tmu_change_mode() calls
asynchronous pm_runtime_get() and immediately writes TMU control
registers before the device has resumed and enabled its clock.  On
error, it also returns without dropping the incremented runtime PM
usage count.

Use synchronous pm_runtime_resume_and_get() instead.

Fixes: c411d8bf0699 ("thermal/drivers/imx91: Add support for i.MX91 thermal monitoring unit")
Closes: https://sashiko.dev/#/bug/linux-c0418783-a24c-4ee1-a794-72b47eb4dfce
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/thermal/imx91_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/thermal/imx91_thermal.c b/drivers/thermal/imx91_thermal.c
index c3a72df665a8..dbd45a1910f5 100644
--- a/drivers/thermal/imx91_thermal.c
+++ b/drivers/thermal/imx91_thermal.c
@@ -213,7 +213,7 @@ static int imx91_tmu_change_mode(struct thermal_zone_device *tz, enum thermal_de
 	int ret;
 
 	if (mode == THERMAL_DEVICE_ENABLED) {
-		ret = pm_runtime_get(tmu->dev);
+		ret = pm_runtime_resume_and_get(tmu->dev);
 		if (ret < 0)
 			return ret;
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-12-03 19:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261203195529.3063246-1-lee@kernel.org>
2026-12-03 19:54 ` [PATCH 01/10] thermal: intel: hfi: Pass byte size to alloc_pages_exact() and free_pages_exact() Lee Jones
2026-12-03 19:54 ` [PATCH 02/10] thermal: intel: hfi: Publish hfi_instance only after successful initialisation Lee Jones
2026-12-03 19:54 ` [PATCH 03/10] thermal: int3400: Clean up ODVP attributes after unregistering thermal zone Lee Jones
2026-12-03 19:54 ` [PATCH 04/10] thermal/drivers/qcom/tsens-v1: Validate sensor count before legacy calibration Lee Jones
2026-12-03 19:54 ` [PATCH 05/10] thermal/drivers/qcom/tsens: Bound sensor initialisation by num_sensors Lee Jones
2026-12-03 19:54 ` [PATCH 06/10] thermal/drivers/rcar: Free IRQs before cancelling delayed work on remove Lee Jones
2026-12-03 19:54 ` [PATCH 07/10] thermal/drivers/imx91: Acquire runtime PM reference in imx91_tmu_get_temp() Lee Jones
2026-12-03 19:54 ` [PATCH 08/10] tools/thermal/tmon: Open log file with O_NOFOLLOW before validating and truncating Lee Jones
2026-12-03 19:54 ` [PATCH 09/10] thermal/drivers/qcom/tsens: Drop __init from ops init callbacks Lee Jones
2026-12-03 19:54 ` [PATCH 10/10] thermal/drivers/imx91: Use pm_runtime_resume_and_get() in imx91_tmu_change_mode() Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox