From: David Laight <david.laight.linux@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] lib/vsprintf: Fix to check field_width and precision
Date: Tue, 24 Mar 2026 17:24:33 +0000 [thread overview]
Message-ID: <20260324172433.05292942@pumpkin> (raw)
In-Reply-To: <acK_vXwxn8pWdWvy@pathway.suse.cz>
On Tue, 24 Mar 2026 17:45:49 +0100
Petr Mladek <pmladek@suse.com> wrote:
> On Mon 2026-03-23 13:59:05, David Laight wrote:
...
> > I've also just fixed nolibc's handling of %*.*s (which is in 'next' since
> > I only wrote it recently), the above is actually broken.
> > Negative 'precision' (all values) are fine, they just request the default.
>
> Great catch! We should clamp the precision to (0, PRECISION_MAX). But we
> should warn only when it is outside of (-PRECISION_MAX, PRECISION_MAX).
No, you are going to clamp it needs to be to (-1, PRECISION_MAX);
but max(precision, PRECISION_MAX) if fine now the value is being saved
in an int.
And there is no need to warn about changing negative values - they
all mean exactly the same thing.
There isn't actually any need to worry about large precision values
for %s - they request truncation, precision only increases the output
for numbers.
>
> > So the patch needs a big fat NACK...
>
> What is an acceptable solution then, please?
You could do:
spec->precision = clamp(prec, -1, PRECISION_MAX);
if (spec->precision < prec)
WARN(...);
David
>
> Frankly, I would like to stay on earth. This started as a simple fix
> of a regression added a year ago. For me, any solution which
> restores the year old behavior is good enough.
>
> We might need to find another volunteer to implement a better
> solution, e.g. the new non-panicing MSG_AND_BT() macro.
>
> Alternatively, we could remove the WARN_ONCE() completely.
> It looks acceptable for me. But Rasmus would need to agree as well.
>
> Best Regards,
> Petr
next prev parent reply other threads:[~2026-03-24 17:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 14:41 [PATCH v3 0/2] lib/vsprintf: Fixes size check Masami Hiramatsu (Google)
2026-03-21 14:41 ` [PATCH v3 1/2] lib/vsprintf: Fix to check field_width and precision Masami Hiramatsu (Google)
2026-03-23 13:27 ` Andy Shevchenko
2026-03-23 13:59 ` David Laight
2026-03-24 16:45 ` Petr Mladek
2026-03-24 17:24 ` David Laight [this message]
2026-03-25 0:33 ` Masami Hiramatsu
2026-03-25 1:17 ` Masami Hiramatsu
2026-03-25 9:14 ` David Laight
2026-03-25 0:26 ` Masami Hiramatsu
2026-03-21 14:41 ` [PATCH v3 2/2] lib/vsprintf: Limit the returning size to INT_MAX Masami Hiramatsu (Google)
2026-03-24 16:50 ` Petr Mladek
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=20260324172433.05292942@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mhiramat@kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.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