Skip to contentSkip to conversation

leave guard page for upwardly growing stacks too

RFC PATCH New Luck, Tony 1 participant 1 message Aug 20, 2010

Subsystems (2)
lore
Share & tools
lore

Luck, Tony

author
#0 lore raw

RFC PATCH 1/1 leave guard page for upwardly growing stacks too

In commit 320b2b8de12698082609ebbc1a17165727f4c893
mm: keep a guard page below a grow-down stack segment

we prevented stacks from growing downwards into other vma areas. But some arhictectures (ia64 and pa-risc) have stacks that grow upwards. Provide the same protection for them.

---

Pointed out to me by Matthew Wilcox.

DANGER, DANGER - NOT TESTED on pa-risc yet DO NOT APPLY WITHOUT AN ACK FROM PA-RISC LAND!

Are there any other architectures with upward growing stacks?

mm/memory.c +22 -8
index b6e5fd2..9dcef72 100644
@@ -2760,21 +2760,35 @@ out_release:
 }
 
 /*
- * This is like a special single-page "expand_downwards()",
- * except we must first make sure that 'address-PAGE_SIZE'
+ * This is like a special single-page "expand_{down|up}wards()",
+ * except we must first make sure that 'address{-|+}PAGE_SIZE'
  * doesn't hit another vma.
  *
  * The "find_vma()" will do the right thing even if we wrap
  */
 static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
 {
-	address &= PAGE_MASK;
-	if ((vma->vm_flags & VM_GROWSDOWN) && address = vma->vm_start) {
-		address -= PAGE_SIZE;
-		if (find_vma(vma->vm_mm, address) != vma)
-			return -ENOMEM;
+	struct vm_area_struct *v;
+
+	if (vma->vm_flags & VM_GROWSDOWN) {
+		address &= PAGE_MASK;
+		if (address = vma->vm_start) {
+			address -= PAGE_SIZE;
+			if (find_vma(vma->vm_mm, address) != vma)
+				return -ENOMEM;
 
-		expand_stack(vma, address);
+			expand_stack(vma, address);
+		}
+	} else if (vma->vm_flags & VM_GROWSUP) {
+		address = PAGE_ALIGN(address + 1);
+		if (address = vma->vm_end) {
+			address += PAGE_SIZE;
+			if ((v = find_vma(vma->vm_mm, address)) &&
+				v->vm_start <= address) {
+				return -ENOMEM;
+			}
+			expand_upwards(vma, address);
+		}
 	}
 	return 0;
 }