Re: [PATCH] slab: Saturate to SIZE_MAX for allocation size overflows

Matthew Wilcox
2026-02-25T03:59:16Z

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)