From: Boudewijn van der Heide <boudewijn@delta-utec.com>
To: peterz@infradead.org
Cc: mingo@redhat.com, will@kernel.org, boqun.feng@gmail.com,
longman@redhat.com, linux-kernel@vger.kernel.org
Subject: [PATCH] locking/lockdep: Fix string truncation and length accounting in seq_stats()
Date: Fri, 19 Dec 2025 16:11:39 +0100 [thread overview]
Message-ID: <aUVrKwedNdTYpi4d@bou-desktop> (raw)
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
reply other threads:[~2025-12-19 15:11 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=aUVrKwedNdTYpi4d@bou-desktop \
--to=boudewijn@delta-utec.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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