From: Kees Cook <keescook@chromium.org>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: Kees Cook <kees@kernel.org>, Eric Biggers <ebiggers@kernel.org>,
linux-hardening@vger.kernel.org,
Mark Rutland <mark.rutland@arm.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Marco Elver <elver@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()
Date: Tue, 6 Feb 2024 02:01:53 -0800 [thread overview]
Message-ID: <202402060200.EDE488F8@keescook> (raw)
In-Reply-To: <1ee4bd0f-2a70-4696-bad3-782b5c0887f7@prevas.dk>
On Tue, Feb 06, 2024 at 09:42:26AM +0100, Rasmus Villemoes wrote:
> On 06/02/2024 00.21, Kees Cook wrote:
> >
> >
> > On February 5, 2024 11:17:12 PM GMT, Eric Biggers <ebiggers@kernel.org> wrote:
> >> On Mon, Feb 05, 2024 at 02:44:14PM -0800, Kees Cook wrote:
> >>> On Mon, Feb 05, 2024 at 12:21:45PM -0800, Eric Biggers wrote:
> >>>> On Mon, Feb 05, 2024 at 01:12:30AM -0800, Kees Cook wrote:
> >>>>> Subject: Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()
> >>>>
> >>>> Maybe these should be called wrapping_add, wrapping_sub, and wrapping_mul?
> >>>> Those names are more grammatically correct, and Rust chose those names too.
> >>>
> >>> Sure, that works for me. What bout the inc_wrap() and dec_wrap() names?
> >>> I assume wrapping_inc() and wrapping_dec() ?
> >>>
> >>
> >> Yes, though I'm not sure those should exist at all. Maybe a += b should just
> >> become a = wrapping_add(a, b), instead of wrapping_inc(a, b)?
> >> wrapping_inc(a, b) isn't as self-explanatory. Likewise for wrapping_dec.
> >
> > It was to avoid repeating type information, as it would go from:
> >
> > var_a += var_b;
> >
> > to:
> >
> > var_a = wrapping_add(typeof(var_a), var_a, var_b);
> >
> > Which repeats "var_a" 3 times. :|
>
> Yeah, I think that's a reasonable rationale. I'm fine with the
> wrapping_* naming, and then the _inc and _dec helpers should follow.
Sounds good.
> However, I now wonder if those should really also return the new value.
> Yes, that corresponds to the value of the expression (a += b), but
> nobody would ever write c = (a += b) or otherwise make use of that
> value, and the naming doesn't immediately imply whether one should think
> of ++a or a++.
They were designed to return the new value, and the selftests validate
that. I've updated the kern-doc to reflect this.
--
Kees Cook
next prev parent reply other threads:[~2024-02-06 10:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 9:12 [PATCH v3 0/3] overflow: Introduce wrapping helpers Kees Cook
2024-02-05 9:12 ` [PATCH v3 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results Kees Cook
2024-02-05 20:00 ` Gustavo A. R. Silva
2024-02-05 9:12 ` [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap() Kees Cook
2024-02-05 13:31 ` Marco Elver
2024-02-05 19:53 ` Gustavo A. R. Silva
2024-02-06 10:05 ` Kees Cook
2024-02-05 20:21 ` Eric Biggers
2024-02-05 22:44 ` Kees Cook
2024-02-05 23:17 ` Eric Biggers
2024-02-05 23:21 ` Kees Cook
2024-02-06 8:42 ` Rasmus Villemoes
2024-02-06 10:01 ` Kees Cook [this message]
2024-02-05 9:12 ` [PATCH v3 3/3] overflow: Introduce inc_wrap() and dec_wrap() 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=202402060200.EDE488F8@keescook \
--to=keescook@chromium.org \
--cc=ebiggers@kernel.org \
--cc=elver@google.com \
--cc=gustavoars@kernel.org \
--cc=kees@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