From: Alejandro Colomar <alx+linux-hardening@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Kosina <jkosina@suse.cz>, Petr Mladek <pmladek@suse.cz>,
Kees Cook <kees@kernel.org>,
linux-hardening@vger.kernel.org
Subject: seq_buf_putc() and strings
Date: Wed, 28 Oct 2026 18:13:40 +0100 [thread overview]
Message-ID: <auIrUV7A8eF8DCGG@devuan> (raw)
[-- Attachment #1: Type: text/plain, Size: 901 bytes --]
Hi Steven,
I've been looking at rewriting seq_buf with pointers instead of sizes.
While doing that, I've found one place which writes to seq_buf without
forming a proper string (that is, a null-terminated string).
$ git show v7.3:lib/seq_buf.c | grepc seq_buf_putc
(standard input):int seq_buf_putc(struct seq_buf *s, unsigned char c)
{
WARN_ON(s->size == 0);
if (seq_buf_can_fit(s, 1)) {
s->buffer[s->len++] = c;
return 0;
}
seq_buf_set_overflow(s);
return -1;
}
I think a safe API for handling strings would have to make sure that it
*always* holds a string. I think this function should write a NUL byte
after the byte written, and so, I suggest doing this:
s->buffer[s->len++] = c;
+ s->buffer[s->len] = '\0';
Are there any reasons to not write that NUL byte?
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2026-10-28 17:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 17:13 Alejandro Colomar [this message]
2026-10-28 17:30 ` seq_buf_putc() and strings Alejandro Colomar
2026-10-28 17:47 ` Steven Rostedt
2026-10-28 18:00 ` Alejandro Colomar
2026-10-28 20:59 ` seq_buf_used() return value on overflow Alejandro Colomar
2026-10-28 21:03 ` Alejandro Colomar
2026-10-28 21:30 ` seq_buf_str() silent truncation (data corruption) Alejandro Colomar
2026-10-29 1:04 ` Steven Rostedt
2026-10-29 11:48 ` Alejandro Colomar
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=auIrUV7A8eF8DCGG@devuan \
--to=alx+linux-hardening@kernel.org \
--cc=jkosina@suse.cz \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=pmladek@suse.cz \
--cc=rostedt@goodmis.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