Skip to content

Commit

Permalink
mm: mremap: validate input before taking lock
Browse files Browse the repository at this point in the history
This patch is very similar to commit 84d96d8 ("mm: madvise:
complete input validation before taking lock"): perform some basic
validation of the input to mremap() before taking the
&current->mm->mmap_sem lock.

This also makes the MREMAP_FIXED => MREMAP_MAYMOVE dependency slightly
more explicit.

Signed-off-by: Rasmus Villemoes <[email protected]>
Cc: KOSAKI Motohiro <[email protected]>
Cc: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed Jul 9, 2013
1 parent 34e3a58 commit 9a2458a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mm/mremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,14 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
unsigned long charged = 0;
bool locked = false;

down_write(&current->mm->mmap_sem);

if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
goto out;
return ret;

if (flags & MREMAP_FIXED && !(flags & MREMAP_MAYMOVE))
return ret;

if (addr & ~PAGE_MASK)
goto out;
return ret;

old_len = PAGE_ALIGN(old_len);
new_len = PAGE_ALIGN(new_len);
Expand All @@ -473,12 +474,13 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
* a zero new-len is nonsensical.
*/
if (!new_len)
goto out;
return ret;

down_write(&current->mm->mmap_sem);

if (flags & MREMAP_FIXED) {
if (flags & MREMAP_MAYMOVE)
ret = mremap_to(addr, old_len, new_addr, new_len,
&locked);
ret = mremap_to(addr, old_len, new_addr, new_len,
&locked);
goto out;
}

Expand Down

0 comments on commit 9a2458a

Please sign in to comment.