Skip to content

Commit 7661809

Browse files
committed
mm: don't allow oversized kvmalloc() calls
'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 <[email protected]> Cc: Kees Cook <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 111c1aa commit 7661809

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/util.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,10 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
593593
if (ret || size <= PAGE_SIZE)
594594
return ret;
595595

596+
/* Don't even allow crazy sizes */
597+
if (WARN_ON_ONCE(size > INT_MAX))
598+
return NULL;
599+
596600
return __vmalloc_node(size, 1, flags, node,
597601
__builtin_return_address(0));
598602
}

0 commit comments

Comments
 (0)