Linux Hardening
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <kees@kernel.org>,
	"Darrick J . Wong" <djwong@kernel.org>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2 1/3] lib: fix _parse_integer_limit() to handle overflow
Date: Fri, 23 Jan 2026 18:06:37 +0200	[thread overview]
Message-ID: <aXOcjQqvE3TNUlel@smile.fi.intel.com> (raw)
In-Reply-To: <20260123114647.1606335-2-dmantipov@yandex.ru>

On Fri, Jan 23, 2026 at 02:46:45PM +0300, Dmitry Antipov wrote:
> In '_parse_integer_limit()', replace native integer arithmetic with
> 'check_mul_overflow()' and 'check_add_overflow()' to check whether
> an intermediate result goes out of range, and denote such a case
> with ULLONG_MAX. Adjust comment to kernel-doc style as well.

Probably you also wanted to say that this is to be aligned with libc behaviour
of strto*()?

...

>  		/*
> +		 * Accumulate result if no overflow detected.
> +		 * Otherwise just consume valid characters.
>  		 */
> +		if (res != ULLONG_MAX) {

Here I would put another comment explaining that the order operations matters
(has a side effect), id est the result of the first one is used in the second
one.

			/*
			 * Keep an eye on the order.
			 *
			 * @tmp is being used in the second operation,
			 * if the first one succeeds.
			 */

> +			if (check_mul_overflow(res, base, &tmp) ||
> +			    check_add_overflow(tmp, val, &res)) {
> +				res = ULLONG_MAX;
>  				rv |= KSTRTOX_OVERFLOW;
> +			}
>  		}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-01-23 16:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-23 11:46 [PATCH v2 0/3] lib and lib/cmdline enhancements Dmitry Antipov
2026-01-23 11:46 ` [PATCH v2 1/3] lib: fix _parse_integer_limit() to handle overflow Dmitry Antipov
2026-01-23 16:06   ` Andy Shevchenko [this message]
2026-01-23 11:46 ` [PATCH v2 2/3] lib/cmdline_kunit: add test case for memparse() Dmitry Antipov
2026-01-23 16:10   ` Andy Shevchenko
2026-01-23 11:46 ` [PATCH v2 3/3] lib/cmdline: adjust a few comments to fix kernel-doc -Wreturn warnings Dmitry Antipov

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=aXOcjQqvE3TNUlel@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=djwong@kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=kees@kernel.org \
    --cc=linux-hardening@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