From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Kees Cook <keescook@chromium.org>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org, Marco Elver <elver@google.com>,
Eric Biggers <ebiggers@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results
Date: Tue, 6 Feb 2024 10:36:15 -0600 [thread overview]
Message-ID: <89a743fb-37fa-40b9-8ce5-d118ae95af38@embeddedor.com> (raw)
In-Reply-To: <20240206103201.2013060-1-keescook@chromium.org>
On 2/6/24 04:31, 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.
>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Better to be concise and direct. 🙂
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks!
--
Gustavo
> ---
> 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.
> *
> - * *@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.
> */
> #define check_add_overflow(a, b, d) \
> __must_check_overflow(__builtin_add_overflow(a, b, d))
> @@ -72,11 +70,9 @@ static inline bool __must_check __must_check_overflow(bool overflow)
> * @b: subtrahend; value to subtract from @a
> * @d: pointer to store difference
> *
> - * Returns 0 on success.
> + * Returns 0 on success, 1 on wrap-around.
> *
> - * *@d holds the results of the attempted subtraction, but is not considered
> - * "safe for use" on a non-zero return value, which indicates that the
> - * difference has underflowed or been truncated.
> + * *@d holds the results of the attempted subtraction, which may wrap-around.
> */
> #define check_sub_overflow(a, b, d) \
> __must_check_overflow(__builtin_sub_overflow(a, b, d))
> @@ -87,11 +83,9 @@ static inline bool __must_check __must_check_overflow(bool overflow)
> * @b: second factor
> * @d: pointer to store product
> *
> - * Returns 0 on success.
> + * Returns 0 on success, 1 on wrap-around.
> *
> - * *@d holds the results of the attempted multiplication, but is not
> - * considered "safe for use" on a non-zero return value, which indicates
> - * that the product has overflowed or been truncated.
> + * *@d holds the results of the attempted multiplication, which may wrap-around.
> */
> #define check_mul_overflow(a, b, d) \
> __must_check_overflow(__builtin_mul_overflow(a, b, d))
next prev parent reply other threads:[~2024-02-06 16:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-06 10:31 [PATCH v4 0/3] overflow: Introduce wrapping helpers Kees Cook
2024-02-06 10:31 ` [PATCH v4 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results Kees Cook
2024-02-06 16:36 ` Gustavo A. R. Silva [this message]
2024-02-06 10:31 ` [PATCH v4 2/3] overflow: Introduce wrapping_add(), wrapping_sub(), and wrapping_mul() Kees Cook
2024-02-06 16:54 ` Gustavo A. R. Silva
2024-02-07 9:35 ` Kees Cook
2024-02-06 10:31 ` [PATCH v4 3/3] overflow: Introduce wrapping_inc() and wrapping_dec() 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=89a743fb-37fa-40b9-8ce5-d118ae95af38@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=akpm@linux-foundation.org \
--cc=ebiggers@kernel.org \
--cc=elver@google.com \
--cc=gustavoars@kernel.org \
--cc=keescook@chromium.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
all inboxes | Powered by JetHome®