thermal/debugfs: Fix truncated cooling state transitions
PATCH 1/1 thermal/debugfs: Fix truncated cooling state transitions
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.
--- drivers/thermal/thermal_debugfs.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/thermal/thermal_debugfs.c +4 -7
@@ -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); }
Signature · 1 line
2.53.0