Re: [PATCH 1/2] overflow: Implement size_t saturating arithmetic helpers

From: Nick Desaulniers
Date: Mon Jan 24 2022 - 18:48:03 EST


On Mon, Jan 24, 2022 at 1:13 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> What I'd really like is a "store this in a size_t" check to catch dumb
> storage size problems (or related overflows). In other words:
>
> size_t big1 = 2147483647;
> size_t big2 = 2147483647;
>
> /* Doesn't overflow, but 4611686014132420609 becomes a 1 for int */
> int size = size_mul(big1, big2);
> ...
> ptr = kmalloc(size, GFP_KERNEL); /* Allocates a 1 instead... */

-Wshorten-64-to-32
?

--
Thanks,
~Nick Desaulniers