Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: make the mlock() stack guard page checks stricter

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 <ijc@hellion.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+16 -5
+16 -5
mm/mlock.c
··· 135 135 } 136 136 } 137 137 138 + /* Is the vma a continuation of the stack vma above it? */ 139 + static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr) 140 + { 141 + return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN); 142 + } 143 + 144 + static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr) 145 + { 146 + return (vma->vm_flags & VM_GROWSDOWN) && 147 + (vma->vm_start == addr) && 148 + !vma_stack_continue(vma->vm_prev, addr); 149 + } 150 + 138 151 /** 139 152 * __mlock_vma_pages_range() - mlock a range of pages in the vma. 140 153 * @vma: target vma ··· 181 168 gup_flags |= FOLL_WRITE; 182 169 183 170 /* We don't try to access the guard page of a stack vma */ 184 - if (vma->vm_flags & VM_GROWSDOWN) { 185 - if (start == vma->vm_start) { 186 - start += PAGE_SIZE; 187 - nr_pages--; 188 - } 171 + if (stack_guard_page(vma, start)) { 172 + addr += PAGE_SIZE; 173 + nr_pages--; 189 174 } 190 175 191 176 while (nr_pages > 0) {