mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Bill Wendling <morbo@google.com>
Cc: Kees Cook <kees@kernel.org>, Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] seq_buf: add seq_buf_strlen(), seq_buf_init_append(), seq_buf_puts_trunc()
Date: Wed, 16 Sep 2026 16:47:11 -0700	[thread overview]
Message-ID: <20260916164711.1cf51b0c3f085639dac5d690@linux-foundation.org> (raw)
In-Reply-To: <20260916222125.1259631-1-morbo@google.com>

On Wed, 16 Sep 2026 22:21:25 +0000 Bill Wendling <morbo@google.com> wrote:

> Converting some strlcat() call sites seq_buf need behavior seq_buf doesn't
> currently provide, either directly or without introducing subtle bugs:
> 
>  - seq_buf_strlen(): seq_buf_used() reports the full buffer size when the
>    buffer is completely filled, even though seq_buf_str() then overwrites the
>    final byte with a NUL terminator, leaving only size - 1 bytes of
>    actual content. Callers that need the true length of the
>    NUL-terminated string have to fall back to strlen(seq_buf_str(s)).
>    seq_buf_strlen() mirrors seq_buf_str()'s NUL-termination logic but returns
>    the resulting string's length directly.
> 
>  - seq_buf_init_append(): seq_buf_init() always clears the buffer it's given
>    via seq_buf_clear(). Code migrating from strlcat(buf, ...), which
>    appends to whatever @buf already contains, can't use seq_buf_init()
>    without silently discarding that existing content. seq_buf_init_append()
>    preserves it and positions the seq_buf to append after it.
> 
>  - seq_buf_puts_trunc(): seq_buf_puts() (like seq_buf_printf() and friends)
>    writes nothing at all if the string doesn't fully fit, whereas strlcat()
>    always copies as much of the source as there is room for. Converting a
>    strlcat() call site that relied on that partial-copy behavior to
>    plain seq_buf_puts() can silently drop content that used to survive
>    truncated. seq_buf_puts_trunc() keeps the leading bytes of the string
>    that fit.
> 
> ...
>
>  include/linux/seq_buf.h | 60 +++++++++++++++++++++++++++++++++++++++++
>  lib/seq_buf.c           | 35 ++++++++++++++++++++++++
>  2 files changed, 95 insertions(+)

This seems a lot of code for enabling some strlcat removals.  How many
is "some"?  If "3" then perhaps do something different at those
callsites?

Sashiko had a couple of comments:
	https://sashiko.dev/#/patchset/20260916222125.1259631-1-morbo@google.com

Should these new functions be added to lib/tests/seq_buf_kunit.c?

  reply	other threads:[~2026-09-16 23:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 22:15 [PATCH] " Bill Wendling
2026-09-16 22:21 ` [PATCH v2] " Bill Wendling
2026-09-16 23:47   ` Andrew Morton [this message]
2026-09-16 23:55     ` Bill Wendling
2026-09-17  1:13   ` [PATCH v3] " Bill Wendling
2026-09-17 14:24     ` Kees Cook

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=20260916164711.1cf51b0c3f085639dac5d690@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=morbo@google.com \
    --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

all inboxes | Powered by JetHome®