Skip to content

Commit 65ee03c

Browse files
gjulianmtorvalds
authored andcommitted
mm: fix overflow in vm_map_ram()
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]>
1 parent 4340fa5 commit 65ee03c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

mm/vmalloc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ EXPORT_SYMBOL_GPL(vm_unmap_aliases);
11051105
*/
11061106
void vm_unmap_ram(const void *mem, unsigned int count)
11071107
{
1108-
unsigned long size = count << PAGE_SHIFT;
1108+
unsigned long size = (unsigned long)count << PAGE_SHIFT;
11091109
unsigned long addr = (unsigned long)mem;
11101110

11111111
BUG_ON(!addr);
@@ -1140,7 +1140,7 @@ EXPORT_SYMBOL(vm_unmap_ram);
11401140
*/
11411141
void *vm_map_ram(struct page **pages, unsigned int count, int node, pgprot_t prot)
11421142
{
1143-
unsigned long size = count << PAGE_SHIFT;
1143+
unsigned long size = (unsigned long)count << PAGE_SHIFT;
11441144
unsigned long addr;
11451145
void *mem;
11461146

@@ -1574,14 +1574,15 @@ void *vmap(struct page **pages, unsigned int count,
15741574
unsigned long flags, pgprot_t prot)
15751575
{
15761576
struct vm_struct *area;
1577+
unsigned long size; /* In bytes */
15771578

15781579
might_sleep();
15791580

15801581
if (count > totalram_pages)
15811582
return NULL;
15821583

1583-
area = get_vm_area_caller((count << PAGE_SHIFT), flags,
1584-
__builtin_return_address(0));
1584+
size = (unsigned long)count << PAGE_SHIFT;
1585+
area = get_vm_area_caller(size, flags, __builtin_return_address(0));
15851586
if (!area)
15861587
return NULL;
15871588

0 commit comments

Comments
 (0)