Skip to content

Commit a425ac5

Browse files
committed
gup: add warning if some caller would seem to want stack expansion
It feels very unlikely that anybody would want to do a GUP in an unmapped area under the stack pointer, but real users sometimes do some really strange things. So add a (temporary) warning for the case where a GUP fails and expanding the stack might have made it work. It's trivial to do the expansion in the caller as part of getting the mm lock in the first place - see __access_remote_vm() for ptrace, for example - it's just that it's unnecessarily painful to do it deep in the guts of the GUP lookup when we might have to drop and re-take the lock. I doubt anybody actually does anything quite this strange, but let's be proactive: adding these warnings is simple, and will make debugging it much easier if they trigger. Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8d7071a commit a425ac5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mm/gup.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,11 @@ static long __get_user_pages(struct mm_struct *mm,
10961096

10971097
/* first iteration or cross vma bound */
10981098
if (!vma || start >= vma->vm_end) {
1099-
vma = vma_lookup(mm, start);
1099+
vma = find_vma(mm, start);
1100+
if (vma && (start < vma->vm_start)) {
1101+
WARN_ON_ONCE(vma->vm_flags & VM_GROWSDOWN);
1102+
vma = NULL;
1103+
}
11001104
if (!vma && in_gate_area(mm, start)) {
11011105
ret = get_gate_page(mm, start & PAGE_MASK,
11021106
gup_flags, &vma,
@@ -1265,9 +1269,13 @@ int fixup_user_fault(struct mm_struct *mm,
12651269
fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
12661270

12671271
retry:
1268-
vma = vma_lookup(mm, address);
1272+
vma = find_vma(mm, address);
12691273
if (!vma)
12701274
return -EFAULT;
1275+
if (address < vma->vm_start ) {
1276+
WARN_ON_ONCE(vma->vm_flags & VM_GROWSDOWN);
1277+
return -EFAULT;
1278+
}
12711279

12721280
if (!vma_permits_fault(vma, fault_flags))
12731281
return -EFAULT;

0 commit comments

Comments
 (0)