All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal/debugfs: Fix truncated cooling state transitions
@ 2026-11-20 18:16 Sumeet Pawnikar
  0 siblings, 0 replies; only message in thread
From: Sumeet Pawnikar @ 2026-11-20 18:16 UTC (permalink / raw)
  To: rafael, daniel.lezcano, rui.zhang
  Cc: lukasz.luba, linux-pm, linux-kernel, sumeet4linux

cdev_tt_seq_show() can truncate cooling device transition labels
in the trans_table debugfs output. The largest packed label,
"65535->65535" needs 13 bytes including the terminator. A W=1
build exposes this problem as a format-truncation error.

The buffer was sized for an assumed maximum cooling state of 1024,
but the transition identifier reserves 16 bits for each state and
does not enforce that assumption. The signed identifier was also
shifted directly, which can sign-extend the upper state when bit
number 31 is set.

Decode the packed identifier through a u32 and size the buffer
from the largest representable transition string. This prevents
truncation and prints both state fields as unsigned values.

Issue reproduced and verified with a W=1 build.

Fixes: 755113d76786 ("thermal/debugfs: Add thermal cooling device debugfs information")

Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com>
---
 drivers/thermal/thermal_debugfs.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/thermal_debugfs.c b/drivers/thermal/thermal_debugfs.c
index da02d8f179b0..107569d12965 100644
--- a/drivers/thermal/thermal_debugfs.c
+++ b/drivers/thermal/thermal_debugfs.c
@@ -322,14 +322,11 @@ static int cdev_tt_seq_show(struct seq_file *s, void *v)
 		seq_puts(s, "Transition\tOccurrences\n");
 
 	list_for_each_entry(entry, &transitions[i], node) {
-		/*
-		 * Assuming maximum cdev states is 1024, the longer
-		 * string for a transition would be "1024->1024\0"
-		 */
-		char buffer[11];
+		u32 transition = entry->id;
+		char buffer[sizeof("65535->65535")];
 
-		snprintf(buffer, ARRAY_SIZE(buffer), "%d->%d",
-			 entry->id >> 16, entry->id & 0xFFFF);
+		snprintf(buffer, sizeof(buffer), "%u->%u",
+			 transition >> 16, transition & 0xffff);
 
 		seq_printf(s, "%-10s\t%-10llu\n", buffer, entry->count);
 	}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 18:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 18:16 [PATCH] thermal/debugfs: Fix truncated cooling state transitions Sumeet Pawnikar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.