From: Sumeet Pawnikar <sumeet4linux@gmail.com>
To: rafael@kernel.org, daniel.lezcano@kernel.org, rui.zhang@intel.com
Cc: lukasz.luba@arm.com, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org, sumeet4linux@gmail.com
Subject: [PATCH] thermal/debugfs: Fix truncated cooling state transitions
Date: Fri, 20 Nov 2026 23:46:20 +0530 [thread overview]
Message-ID: <20261120181620.12648-1-sumeet4linux@gmail.com> (raw)
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
reply other threads:[~2026-11-20 18:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120181620.12648-1-sumeet4linux@gmail.com \
--to=sumeet4linux@gmail.com \
--cc=daniel.lezcano@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox