mm: don't allow oversized kvmalloc() calls
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 14 Jul 2021 16:45:49 +0000 (09:45 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Oct 2021 13:56:03 +0000 (15:56 +0200)
commit57a269a1b12a3a6fe51f62e1be5e74494bad1d92
tree99ca19fb4845ef8978ea9c1f6c12ea74e883d75b
parentda5b8b9319f044c2ca24f6602c54033931e0c1cc
mm: don't allow oversized kvmalloc() calls

commit 7661809d493b426e979f39ab512e3adf41fbcc69 upstream.

'kvmalloc()' is a convenience function for people who want to do a
kmalloc() but fall back on vmalloc() if there aren't enough physically
contiguous pages, or if the allocation is larger than what kmalloc()
supports.

However, let's make sure it doesn't get _too_ easy to do crazy things
with it.  In particular, don't allow big allocations that could be due
to integer overflow or underflow.  So make sure the allocation size fits
in an 'int', to protect against trivial integer conversion issues.

Acked-by: Willy Tarreau <w@1wt.eu>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/util.c