From: David Laight <David.Laight@ACULAB.COM>
To: 'Bartosz Golaszewski' <brgl@bgdev.pl>, Jiri Slaby <jirislaby@kernel.org>
Cc: Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Greg KH <gregkh@linuxfoundation.org>,
"linux-hardening@vger.kernel.org"
<linux-hardening@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [PATCH] lib: string_helpers: fix potential snprintf() output truncation
Date: Tue, 22 Oct 2024 11:07:46 +0000 [thread overview]
Message-ID: <bb500daac1dc4cd9abd3f5e39f9329be@AcuMS.aculab.com> (raw)
In-Reply-To: <CAMRc=Mcp4LBj0ZZx=hUg9KBk04XXcAtiNv+QjQesN1iCpDC+KA@mail.gmail.com>
From: Bartosz Golaszewski
> Sent: 22 October 2024 08:30
>
> On Tue, Oct 22, 2024 at 9:15 AM Jiri Slaby <jirislaby@kernel.org> wrote:
> >
> > On 21. 10. 24, 12:04, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > >
> > > The output of ".%03u" with the unsigned int in range [0, 4294966295] may
> > > get truncated if the target buffer is not 12 bytes.
> >
> > Perhaps, if you elaborate on how 'remainder' can become > 999?
> >
>
> Yeah, I guess it can't. Not sure what we do about such false
> positives, do we have some common way to suppress them?
The only way I've found is to 'launder' the buffer size using
OPTIMISER_HIDE_VAR().
Although I can imagine an update to gcc that checks sizeof (buffer)
as well - so that would also need laundering.
You actually want:
#define OPTIMER_HIDE_VAL(x) \
({ __auto_type _x = x; OPTIMER_HIDE_VAR(_x); _x;})
so you can do:
snprintf(OPTIMISER_HIDE_VAL(buffer), OPTOMISER_HIDE_VAL(sizeof buffer), fmt, ...)
Perhaps that could be snprint_truncate() ?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-10-22 11:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 10:04 Bartosz Golaszewski
2024-10-21 10:05 ` Bartosz Golaszewski
2024-10-22 7:15 ` Jiri Slaby
2024-10-22 7:30 ` Bartosz Golaszewski
2024-10-22 9:18 ` Andy Shevchenko
2024-10-22 11:07 ` David Laight [this message]
2024-10-22 9:15 ` Andy Shevchenko
2024-10-22 13:46 ` Rasmus Villemoes
2024-10-22 14:30 ` James Bottomley
-- strict thread matches above, loose matches on Subject: below --
2024-10-21 9:14 Bartosz Golaszewski
2024-10-21 9:25 ` Andy Shevchenko
2024-10-21 9:34 ` Greg KH
2024-10-21 9:36 ` Bartosz Golaszewski
2024-10-21 9:50 ` Greg KH
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=bb500daac1dc4cd9abd3f5e39f9329be@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=andy@kernel.org \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.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®