On Wed, Sep 30, 2026 at 04:52:29PM -0700, Kees Cook wrote:
> seq_buf_do_printk() prints a buffer line by line, then prints whatever
> follows the last newline. When a string has overflowed at exactly a
> newline, an empty line is printed since the pointer hasn't reached the
> overflow mark of the seq_buf. Switch to just check if the string is
> already empty and only print if not.
> 
> The only caller is the memory cgroup OOM report, so this could only ever
> add a blank line to a report whose statistics already did not fit.
> 
> Add a test that registers a console to count the records that
> seq_buf_do_printk() emits. It counts the records carrying the test's
> marker, and the records holding nothing but a line feed that arrive
> after one, so that unrelated kernel messages do not disturb it. Both
> states that reach the flaw are covered: exactly full, and overflowed.
> 
> Tests passed under qemu on ARCH=x86_64 with GCC 16.2.0 and CONFIG_KASAN=y,
> and on big-endian ARCH=s390 with GCC s390x-linux-gnu 16.1.0.

...

>       KUNIT_EXPECT_STREQ(test, seq_buf_str(&s), expected);
>  }
>  
> +

I believe a single blank line is enough.

> +/*
> + * Counters for the console that seq_buf_do_printk_test() registers while it
> + * runs. Only records carrying the marker are counted, so unrelated kernel
> + * messages do not disturb them.
> + *
> + * An empty record carries nothing to recognize it by, so count one only
> + * where the flaw puts it: directly after a record of ours, with nothing in
> + * between. That still misreads a bare line feed printed by another CPU in
> + * exactly that gap, but no longer counts one printed at any point while the
> + * console happens to be registered.
> + */

...

> +static void seq_buf_printk_capture(struct console *con, const char *s,
> +                                unsigned int count)

I would re-split to have it wrapped on logical boundary:

static void seq_buf_printk_capture(struct console *con,
                                   const char *s, unsigned int count)

Or having the whole on a single line.

-- 
With Best Regards,
Andy Shevchenko



Reply via email to