Skip to content

Commit

Permalink
ipc/shm: kill the historical/wrong mm->start_stack check
Browse files Browse the repository at this point in the history
do_shmat() is the only user of ->start_stack (proc just reports its
value), and this check looks ugly and wrong.

The reason for this check is not clear at all, and it wrongly assumes that
the stack can only grow down.

But the main problem is that in general mm->start_stack has nothing to do
with stack_vma->vm_start.  Not only the application can switch to another
stack and even unmap this area, setup_arg_pages() expands the stack
without updating mm->start_stack during exec().  This means that in the
likely case "addr > start_stack - size - PAGE_SIZE * 5" is simply
impossible after find_vma_intersection() == F, or the stack can't grow
anyway because of RLIMIT_STACK.

Many thanks to Hugh for his explanations.

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Hugh Dickins <[email protected]>
Cc: Cyrill Gorcunov <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Oct 14, 2014
1 parent 1195d94 commit bf77b94
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,13 +1172,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,

if (find_vma_intersection(current->mm, addr, addr + size))
goto invalid;
/*
* If shm segment goes below stack, make sure there is some
* space left for the stack to grow (at least 4 pages).
*/
if (addr < current->mm->start_stack &&
addr > current->mm->start_stack - size - PAGE_SIZE * 5)
goto invalid;
}

addr = do_mmap_pgoff(file, addr, size, prot, flags, 0, &populate);
Expand Down

0 comments on commit bf77b94

Please sign in to comment.