Linux Hardening
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Andy Shevchenko <andy@kernel.org>,
	"Gustavo A . R . Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Marco Elver <elver@google.com>,
	Eric Biggers <ebiggers@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results
Date: Wed, 14 Feb 2024 11:38:57 -0800	[thread overview]
Message-ID: <202402141136.6B12D6E6@keescook> (raw)
In-Reply-To: <ZcyqqN3wVrKwkzrs@FVFF77S0Q05N>

On Wed, Feb 14, 2024 at 11:57:28AM +0000, Mark Rutland wrote:
> On Tue, Feb 13, 2024 at 02:10:57PM -0800, Kees Cook wrote:
> > The check_*_overflow() helpers will return results with potentially
> > wrapped-around values. These values have always been checked by the
> > selftests, so avoid the confusing language in the kern-doc. The idea of
> > "safe for use" was relative to the expectation of whether or not the
> > caller wants a wrapped value -- the calculation itself will always follow
> > arithmetic wrapping rules.
> > 
> > Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> > Cc: linux-hardening@vger.kernel.org
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> >  include/linux/overflow.h | 18 ++++++------------
> >  1 file changed, 6 insertions(+), 12 deletions(-)
> > 
> > diff --git a/include/linux/overflow.h b/include/linux/overflow.h
> > index 7b5cf4a5cd19..4e741ebb8005 100644
> > --- a/include/linux/overflow.h
> > +++ b/include/linux/overflow.h
> > @@ -57,11 +57,9 @@ static inline bool __must_check __must_check_overflow(bool overflow)
> >   * @b: second addend
> >   * @d: pointer to store sum
> >   *
> > - * Returns 0 on success.
> > + * Returns 0 on success, 1 on wrap-around.
> 
> Sorry for the last minute bikeshedding, but could we clarify 'success' here?
> e.g. I think it'd be clearer to say:
> 
>   Returns true on wrap-around, false otherwise.
> 
> Note that also uses true/false since these all return bool (as do the
> underlying __builtin_*_overflow() functions).

Yeah, that's a good point. I'll update this.

> >   *
> > - * *@d holds the results of the attempted addition, but is not considered
> > - * "safe for use" on a non-zero return value, which indicates that the
> > - * sum has overflowed or been truncated.
> > + * *@d holds the results of the attempted addition, which may wrap-around.
> 
> How about:
> 
>   @d holds the results of the attempted addition, regardless of whether
>   wrap-around occurred.
> 
> ... and likewise for the others below?

Yeah, that's more clear. Thanks!

-Kees

-- 
Kees Cook

  reply	other threads:[~2024-02-14 19:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 22:10 [PATCH v6 0/3] overflow: Introduce wrapping helpers Kees Cook
2024-02-13 22:10 ` [PATCH v6 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results Kees Cook
2024-02-14 11:57   ` Mark Rutland
2024-02-14 19:38     ` Kees Cook [this message]
2024-02-13 22:10 ` [PATCH v6 2/3] overflow: Introduce wrapping_add(), wrapping_sub(), and wrapping_mul() Kees Cook
2024-02-14 11:58   ` Mark Rutland
2024-02-13 22:10 ` [PATCH v6 3/3] overflow: Introduce wrapping_assign_add() and wrapping_assign_sub() Kees Cook

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=202402141136.6B12D6E6@keescook \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=elver@google.com \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rasmus.villemoes@prevas.dk \
    /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