All of lore.kernel.org
 help / color / mirror / Atom feed
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: Re: seq_buf_str() silent truncation (data corruption)
Date: Thu, 29 Oct 2026 12:48:38 +0100	[thread overview]
Message-ID: <auMyY4Xfuo9lZA24@devuan> (raw)
In-Reply-To: <20261028210444.295bbf96@fedora>

[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]

Hi Kees,

> Date: 2026-10-28 21:04:44-0400
> From: Steven Rostedt <rostedt@goodmis.org>
>
> On Wed, 28 Oct 2026 22:30:38 +0100
> Alejandro Colomar <alx+linux-hardening@kernel.org> wrote:
> 
> > Let's see the implementation of seq_buf_str():
> > 
> > 	$ git show v7.3:include/linux/seq_buf.h | grepc seq_buf_str
> > 	(standard input):static inline const char *seq_buf_str(struct seq_buf *s)
> > 	{
> > 		if (WARN_ON(s->size == 0))
> > 			return "";
> > 
> > 		if (seq_buf_buffer_left(s))
> > 			s->buffer[s->len] = 0;
> > 		else
> > 			s->buffer[s->size - 1] = 0;
> > 
> > 		return s->buffer;
> > 	}
> > 
> > The first check is fine (we don't trigger the WARN_ON()).
> > seq_buf_buffer_left(s) will return 0 (it returns 's->size - s->len').
> > This means we'll execute the second branch.  That branch will result in
> > overwriting the third byte with a '\0', without reporting the overflow.
> 
> Yes, Kees and I already discussed this:
> 
>   https://lore.kernel.org/all/20261016145928.16eddc9a@gandalf.local.home/

Oh, indeed!  I didn't understand it enough back then so didn't relate it
to this.  :-)


Have a lovely day!
Alex

> 
> -- Steve

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2026-10-29 11:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 17:13 seq_buf_putc() and strings Alejandro Colomar
2026-10-28 17:30 ` 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 [this message]

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=auMyY4Xfuo9lZA24@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 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.