Stack expansion on ia64

From: Arun Sharma <arun.sharma_at_intel.com>
Date: 2003-06-25 08:36:50
We ran into this while testing IA-32 compatibility, but I think this applies to native ia64 programs as well.

Currently, IA-32 kernels limit stack expansion to 32 bytes below the stack pointer. However, ia64 kernels allow the stack to be expanded as long as it's within the region and allowed by RLIMIT_STACK and RLIMIT_AS.

The attached patch limits the memory stack expansion on both IA-32 and ia64. On IA-32 it mimics the native i386 behavior. On IA-64, it prohibits stack expansion below r12 (the stack pointer according to the software convention).

Please let me know if you have any comments.

	-Arun

PS: The patch is against 2.4, minor changes to ptrace.h may be needed for 2.5.

--- linux/include/asm-ia64/ptrace.h-	Thu Jun 12 15:19:26 2003
+++ linux/include/asm-ia64/ptrace.h	Thu Jun 12 15:20:12 2003
@@ -216,6 +216,7 @@
 # define ia64_task_regs(t)		(((struct pt_regs *) ((char *) (t) + IA64_STK_OFFSET)) - 1)
 # define ia64_psr(regs)			((struct ia64_psr *) &(regs)->cr_ipsr)
 # define user_mode(regs)		(((struct ia64_psr *) &(regs)->cr_ipsr)->cpl != 0)
+# define user_mode_ia32(regs)		(((struct ia64_psr *) &(regs)->cr_ipsr)->is != 0)
 
   struct task_struct;			/* forward decl */
 
--- linux/arch/ia64/mm/fault.c-	Wed Jun  4 16:51:27 2003
+++ linux/arch/ia64/mm/fault.c	Thu Jun 12 15:22:14 2003
@@ -50,7 +50,7 @@
 	struct vm_area_struct *vma, *prev_vma;
 	struct mm_struct *mm = current->mm;
 	struct siginfo si;
-	unsigned long mask;
+	unsigned long mask, stack_lim;
 
 	/*
 	 * If we're in an interrupt or have no user context, we must not take the fault..
@@ -132,6 +132,19 @@
 		if (rgn_index(address) != rgn_index(vma->vm_start)
 		    || rgn_offset(address) >= RGN_MAP_LIMIT)
 			goto bad_area;
+		if (user_mode(regs)) {
+			stack_lim = regs->r12;
+#ifdef CONFIG_IA32_SUPPORT
+			/* Accesses to upto 32 bytes below sp are legal for 
+                         * IA-32 programs. See the comment in 
+                         * arch/i386/mm/fault.c */
+			if (user_mode_ia32(regs)) {
+				stack_lim = (stack_lim & 0xffffffffUL) - 32;
+			}
+#endif
+			if (address < stack_lim)
+				goto bad_area;
+		}
 		if (expand_stack(vma, address))
 			goto bad_area;
 	} else {



-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Tue Jun 24 18:37:22 2003

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:15 EST