Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
mm: make the mlock() stack guard page checks stricter
Browse files Browse the repository at this point in the history
If we've split the stack vma, only the lowest one has the guard page.
Now that we have a doubly linked list of vma's, checking this is trivial.

Tested-by: Ian Campbell <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed Aug 21, 2010
1 parent 297c5ee commit 7798330
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mm/mlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ void munlock_vma_page(struct page *page)
}
}

/* Is the vma a continuation of the stack vma above it? */
static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
{
return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
}

static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
{
return (vma->vm_flags & VM_GROWSDOWN) &&
(vma->vm_start == addr) &&
!vma_stack_continue(vma->vm_prev, addr);
}

/**
* __mlock_vma_pages_range() - mlock a range of pages in the vma.
* @vma: target vma
Expand Down Expand Up @@ -168,11 +181,9 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
gup_flags |= FOLL_WRITE;

/* We don't try to access the guard page of a stack vma */
if (vma->vm_flags & VM_GROWSDOWN) {
if (start == vma->vm_start) {
start += PAGE_SIZE;
nr_pages--;
}
if (stack_guard_page(vma, start)) {
addr += PAGE_SIZE;
nr_pages--;
}

while (nr_pages > 0) {
Expand Down

0 comments on commit 7798330

Please sign in to comment.