Re: [PATCH] slab: Saturate to SIZE_MAX for allocation size overflows
From: Kees Cook
Date: Wed Feb 25 2026 - 02:16:06 EST
On Wed, Feb 25, 2026 at 03:59:08AM +0000, Matthew Wilcox wrote:
> On Tue, Feb 24, 2026 at 05:40:02PM -0800, Kees Cook wrote:
> > +++ b/include/linux/slab.h
> > @@ -1105,7 +1105,7 @@ static inline __alloc_size(1, 2) void *kmalloc_array_noprof(size_t n, size_t siz
> > size_t bytes;
> >
> > if (unlikely(check_mul_overflow(n, size, &bytes)))
> > - return NULL;
> > + bytes = SIZE_MAX;
> > return kmalloc_noprof(bytes, flags);
>
> Wouldn't this be better written as:
>
> return kmalloc_noprof(size_mul(n, size), flags);
>
> (etc)
Sure, I can convert them all that way if that's preferred?
--
Kees Cook