From: David Laight <david.laight.linux@gmail.com>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>, <djwong@kernel.org>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 1/5] lib: fix _parse_integer_limit() to handle overflow
Date: Thu, 12 Feb 2026 13:25:17 +0000 [thread overview]
Message-ID: <20260212132517.1ac5de44@pumpkin> (raw)
In-Reply-To: <20260212120030.2f15caaa@pumpkin>
On Thu, 12 Feb 2026 12:00:30 +0000
David Laight <david.laight.linux@gmail.com> wrote:
Re-send with "..." removed from one of the addresses so my MUA (claws) won't
escape the second one and the list-servers fail to accept the mail.
> On Thu, 12 Feb 2026 14:13:16 +0300
> Dmitry Antipov <dmantipov@yandex.ru> wrote:
>
> > On Tue, 2026-02-10 at 09:36 +0200, Andy Shevchenko wrote:
> >
> > > I don't see how max_chars is used. With that said, I would rather see the usual
> > > way of expressing the condition in the for-loop:
> > >
> > > for (rv = 0; rv < max_chars; rv++, s++) {
> >
> > This will break the loop (and so stop consuming characters) if KSTRTOX_OVERFLOW
> > bit is set.
> >
> > > > + if (likely(res != ULLONG_MAX)) {
> > >
> > > Have you seen David's question about these checks?
> > > Maybe I missed your answer...
>
> I've not seen one...
>
> > >
> > > > + if (unlikely(res & (~0ull << 60))) {
> >
> > The first check may be dropped indeed (assuming check_mul_overflow(ULLONG_MAX, a, b)
> > and check_add_overflow(ULLONG_MAX, a, b) always signals an overflow).
>
> That check for the high bits may well be cheaper than the one in
> check_mul_overflow() - which is likely to need to partially generate
> the 128bit result.
> Also if the code is going to call check_mul_overflow() it ought to use the
> result in the 'non-overflow' case.
>
> But there is nothing 'magic' about check_mul_overflow(), given the base
> is known (and the only dificult one is 10) comparing against the known
> limit will be better code.
>
> David
>
>
> >
> > Dmitry
>
next prev parent reply other threads:[~2026-02-12 13:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 16:47 [PATCH v6 0/5] lib and lib/cmdline enhancements Dmitry Antipov
2026-02-09 16:47 ` [PATCH v6 1/5] lib: fix _parse_integer_limit() to handle overflow Dmitry Antipov
2026-02-10 7:36 ` Andy Shevchenko
2026-02-12 11:13 ` Dmitry Antipov
[not found] ` <20260212120030.2f15caaa@pumpkin>
2026-02-12 13:25 ` David Laight [this message]
2026-02-12 13:37 ` Andy Shevchenko
2026-02-09 16:47 ` [PATCH v6 2/5] lib: fix memparse() " Dmitry Antipov
2026-02-10 7:51 ` Andy Shevchenko
2026-02-12 11:21 ` Dmitry Antipov
2026-02-09 16:47 ` [PATCH v6 3/5] lib: add more string to 64-bit integer conversion overflow tests Dmitry Antipov
2026-02-09 16:47 ` [PATCH v6 4/5] lib/cmdline_kunit: add test case for memparse() Dmitry Antipov
2026-02-09 16:47 ` [PATCH v6 5/5] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Dmitry Antipov
2026-02-10 7:53 ` [PATCH v6 0/5] lib and lib/cmdline enhancements Andy Shevchenko
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=20260212132517.1ac5de44@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@intel.com \
--cc=djwong@kernel.org \
--cc=dmantipov@yandex.ru \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@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