All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking/lockdep: Fix string truncation and length accounting in seq_stats()
@ 2025-12-19 15:11 Boudewijn van der Heide
  0 siblings, 0 replies; only message in thread
From: Boudewijn van der Heide @ 2025-12-19 15:11 UTC (permalink / raw)
  To: peterz; +Cc: mingo, will, boqun.feng, longman, linux-kernel

GCC 14 reports a -Wformat-truncation warning when appending "#%d" and
"/%d" to the lock class name in seq_stats(), as the buffer size was
insufficient and the resulting length was tracked incorrectly.

Use scnprintf() with remaining-buffer accounting to safely append the
suffixes and update namelen based on the actual number of characters
written.

Signed-off-by: Boudewijn van der Heide <boudewijn@delta-utec.com>
---
 kernel/locking/lockdep_proc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 1916db9aa46b..8fe977c32a3d 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -496,12 +496,14 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
 
 	namelen = strlen(name);
 	if (class->name_version > 1) {
-		snprintf(name+namelen, 3, "#%d", class->name_version);
-		namelen += 2;
+		namelen += scnprintf(name + namelen,
+				sizeof(name) - namelen, "#%d",
+				class->name_version);
 	}
 	if (class->subclass) {
-		snprintf(name+namelen, 3, "/%d", class->subclass);
-		namelen += 2;
+		namelen += scnprintf(name + namelen,
+				sizeof(name) - namelen, "/%d",
+				class->subclass);
 	}
 
 	if (stats->write_holdtime.nr) {
-- 
2.47.3


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

only message in thread, other threads:[~2025-12-19 15:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19 15:11 [PATCH] locking/lockdep: Fix string truncation and length accounting in seq_stats() Boudewijn van der Heide

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.