public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Josh Law <objecting@objecting.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] lib/vsprintf: use int for field_width in vsscanf()
Date: Tue, 31 Mar 2026 18:12:18 +0200	[thread overview]
Message-ID: <acvyYoA2SRc8fATn@pathway.suse.cz> (raw)
In-Reply-To: <20260331163522.74467342@pumpkin>

On Tue 2026-03-31 16:35:22, David Laight wrote:
> On Tue, 31 Mar 2026 16:31:50 +0200
> Petr Mladek <pmladek@suse.com> wrote:
> 
> > On Wed 2026-03-25 14:00:17, Andy Shevchenko wrote:
> > > On Tue, Mar 24, 2026 at 10:49:39PM +0000, Josh Law wrote:  
> > > > vsscanf() declares field_width as s16 but assigns it from skip_atoi()
> > > > which returns int. Values above 32767 silently truncate to negative,
> > > > causing vsscanf() to abort all remaining parsing. This is inconsistent
> > > > with struct printf_spec which uses int for field_width. 
> > > 
> > > Is the field_width an acceptable integer range by the specifications?  
> > 
> > I am not sure what is allowed by specification. Anyway, the code is
> > not ready for a bigger values, for example:
> > 
> > 		case 's':
> > 		{
> > 			char *s = (char *)va_arg(args, char *);
> > 			if (field_width == -1)
> > 				field_width = SHRT_MAX;
> > 
> > clearly expects signed short int range.
> > 
> > I wonder if it might even open some backdoor. The code matching
> > as sequence of characters expects a defined field width, see
> > 
> > 
> > 		case '[':
> > 		{
> > [...]
> > 			/* field width is required */
> > 			if (field_width == -1)
> > 				return num;
> > 
> > The current code limits valid field width values to positive ones,

I meant this code:

		/* get field width */
		field_width = -1;
		if (isdigit(*fmt)) {
			field_width = skip_atoi(&fmt);
			if (field_width <= 0)
				break;
		}

If we change the type of the local variable then the above check will
suddenly accept fied_width <= INT_MAX instead of SHRT_MAX.

As a result, The above mentioned "case '[':" handling will suddely
allow to iternate over INT_MAX long string instead of SHRT_MAX.

I doubt that there is any kernel code which would be affected
by this. But I do not want to risk it.

> > aka SHRT_MAX which is clearly much lover than INT_MAX. And it might
> > prevent some out of bound access.
 
> > Best Regards,
> > Petr
> > 
> > 
> 
> Notwithstanding what the code actually does there is no point defining a
> local variable as a 'short' unless you really want arithmetic to wrap
> at 16 bits.
> All it does is force the compiler to keep adding code to fix the sign
> extension to 32 bits.
> Look at the object for anything other than x86 (or m68k).

If you think that it is important enough, feel free to send
a patch.

I not taking this patch from Josh Law, definitely!

Best Regards,
Petr

PS: Note that Josh Law seems to be an AI virtual person, see
    https://lore.kernel.org/all/cbd0aafa-bd45-4f4d-a2dd-440473657dba@lucifer.local/

    I am even not sure what to do with the other 3 patches. They look
    correct. But I should not take patches with an unclear origin, see
    https://lore.kernel.org/all/2f824be3-7b30-41c6-b517-de1086624171@kernel.org/

  reply	other threads:[~2026-03-31 16:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 22:49 [PATCH 0/4] lib/vsprintf: assorted bug fixes Josh Law
2026-03-24 22:49 ` [PATCH 1/4] lib/vsprintf: always advance args in bstr_printf() pointer path Josh Law
2026-03-30 16:06   ` Petr Mladek
2026-03-24 22:49 ` [PATCH 2/4] lib/vsprintf: fix OOB write in vbin_printf() when size is zero Josh Law
2026-03-30 16:17   ` Petr Mladek
2026-03-30 16:31   ` Steven Rostedt
2026-03-30 16:32     ` Josh Law
2026-03-30 16:32     ` Josh Law
2026-03-30 16:32     ` Josh Law
2026-03-30 16:34     ` Josh Law
2026-03-24 22:49 ` [PATCH 3/4] lib/vsprintf: use int for field_width in vsscanf() Josh Law
2026-03-25 12:00   ` Andy Shevchenko
2026-03-31 14:31     ` Petr Mladek
2026-03-31 15:35       ` David Laight
2026-03-31 16:12         ` Petr Mladek [this message]
2026-03-31 16:13           ` Josh Law
2026-03-31 16:13           ` Josh Law
2026-03-31 16:13           ` Josh Law
2026-04-01 14:22           ` David Laight
2026-04-01 18:29             ` David Laight
2026-03-24 22:49 ` [PATCH 4/4] lib/vsprintf: add missing (u8) cast in format_decode() lookup Josh Law
2026-03-25 12:02   ` Andy Shevchenko
2026-03-31 14:33   ` Petr Mladek
2026-03-31 14:44     ` Josh Law
2026-03-31 14:44     ` Josh Law
2026-03-25 12:05 ` [PATCH 0/4] lib/vsprintf: assorted bug fixes Andy Shevchenko
2026-03-25 17:20   ` Josh Law

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=acvyYoA2SRc8fATn@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=objecting@objecting.org \
    --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