Skip to content

Commit

Permalink
mm: fix overflow in vm_map_ram()
Browse files Browse the repository at this point in the history
When remapping pages accounting for 4G or more memory space, the
operation 'count << PAGE_SHIFT' overflows as it is performed on an
integer.  Solution: cast before doing the bitshift.

[[email protected]: fix vm_unmap_ram() also]
[[email protected]: fix vmap() as well, per Guillermo]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Guillermo Julián Moreno <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
gjulianm authored and torvalds committed Jun 3, 2016
1 parent 4340fa5 commit 65ee03c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ EXPORT_SYMBOL_GPL(vm_unmap_aliases);
*/
void vm_unmap_ram(const void *mem, unsigned int count)
{
unsigned long size = count << PAGE_SHIFT;
unsigned long size = (unsigned long)count << PAGE_SHIFT;
unsigned long addr = (unsigned long)mem;

BUG_ON(!addr);
Expand Down Expand Up @@ -1140,7 +1140,7 @@ EXPORT_SYMBOL(vm_unmap_ram);
*/
void *vm_map_ram(struct page **pages, unsigned int count, int node, pgprot_t prot)
{
unsigned long size = count << PAGE_SHIFT;
unsigned long size = (unsigned long)count << PAGE_SHIFT;
unsigned long addr;
void *mem;

Expand Down Expand Up @@ -1574,14 +1574,15 @@ void *vmap(struct page **pages, unsigned int count,
unsigned long flags, pgprot_t prot)
{
struct vm_struct *area;
unsigned long size; /* In bytes */

might_sleep();

if (count > totalram_pages)
return NULL;

area = get_vm_area_caller((count << PAGE_SHIFT), flags,
__builtin_return_address(0));
size = (unsigned long)count << PAGE_SHIFT;
area = get_vm_area_caller(size, flags, __builtin_return_address(0));
if (!area)
return NULL;

Expand Down

0 comments on commit 65ee03c

Please sign in to comment.