All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx+linux-hardening@kernel.org>
To: Kees Cook <kees@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	 Alejandro Colomar <alx@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 Bill Wendling <morbo@google.com>, Petr Mladek <pmladek@suse.com>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Shuvam Pandey <shuvampandey1@gmail.com>,
	 linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] seq_buf: Mark a seq_buf overflowed when terminating it loses a byte
Date: Fri, 30 Oct 2026 21:19:07 +0100	[thread overview]
Message-ID: <auT50pyaME8jbTco@devuan> (raw)
In-Reply-To: <20261030192049.stay.397-kees@kernel.org>

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

Hi Kees,

> Date: 2026-10-30 12:20:54-0700
> From: Kees Cook <kees@kernel.org>
>
[...]
> 
> Reported-by: Steven Rostedt <rostedt@goodmis.org>
> Closes: https://lore.kernel.org/all/20261016145928.16eddc9a@gandalf.local.home/
> Fixes: 8d1478bfd63be ("seq_buf: Add seq_buf_strlen()")

That Fixes tag seems wrong.  That commit was only moving code around,
AFAICS.  I see the bug already present in v5.13, when
seq_buf_terminate() was added.

	$ git show v5.13:include/linux/seq_buf.h | grepc seq_buf_terminate;
	(standard input):static inline void seq_buf_terminate(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;
	}

Back then, we already had a _putmem() function that could fill the
entire buffer:

	$ git show v5.13:lib/seq_buf.c | grepc seq_buf_putmem;
	(standard input):int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len)
	{
		WARN_ON(s->size == 0);

		if (seq_buf_can_fit(s, len)) {
			memcpy(s->buffer + s->len, mem, len);
			s->len += len;
			return 0;
		}
		seq_buf_set_overflow(s);
		return -1;
	}

	$ git show v5.13:lib/seq_buf.c | grepc seq_buf_can_fit;
	(standard input):static bool seq_buf_can_fit(struct seq_buf *s, size_t len)
	{
		return s->len + len <= s->size;
	}

Unless I'm missing something, the bug was introduced in f2616c772c76
(2021-03-18; "seq_buf: Add seq_buf_terminate() API").  Thus:

	Fixes: f2616c772c768 ("seq_buf: Add seq_buf_terminate() API")


Have a lovely night!
Alex

> Signed-off-by: Kees Cook <kees@kernel.org>

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

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

      parent reply	other threads:[~2026-10-30 20:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 19:20 [PATCH v2] seq_buf: Mark a seq_buf overflowed when terminating it loses a byte Kees Cook
2026-10-30 19:53 ` Steven Rostedt
2026-10-30 20:19 ` 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=auT50pyaME8jbTco@devuan \
    --to=alx+linux-hardening@kernel.org \
    --cc=alx@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=morbo@google.com \
    --cc=pmladek@suse.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shuvampandey1@gmail.com \
    /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.