Skip to content

Commit 8ca3eb0

Browse files
aegltorvalds
authored andcommitted
guard page for stacks that grow upwards
pa-risc and ia64 have stacks that grow upwards. Check that they do not run into other mappings. By making VM_GROWSUP 0x0 on architectures that do not ever use it, we can avoid some unpleasant #ifdefs in check_stack_guard_page(). Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9559fcd commit 8ca3eb0

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

include/linux/mm.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ extern unsigned int kobjsize(const void *objp);
7878
#define VM_MAYSHARE 0x00000080
7979

8080
#define VM_GROWSDOWN 0x00000100 /* general info on the segment */
81+
#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
8182
#define VM_GROWSUP 0x00000200
83+
#else
84+
#define VM_GROWSUP 0x00000000
85+
#endif
8286
#define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page", just pure PFN */
8387
#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
8488

@@ -1330,8 +1334,10 @@ unsigned long ra_submit(struct file_ra_state *ra,
13301334

13311335
/* Do stack extension */
13321336
extern int expand_stack(struct vm_area_struct *vma, unsigned long address);
1333-
#ifdef CONFIG_IA64
1337+
#if VM_GROWSUP
13341338
extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
1339+
#else
1340+
#define expand_upwards(vma, address) do { } while (0)
13351341
#endif
13361342
extern int expand_stack_downwards(struct vm_area_struct *vma,
13371343
unsigned long address);

mm/memory.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,11 +2760,9 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
27602760
}
27612761

27622762
/*
2763-
* This is like a special single-page "expand_downwards()",
2764-
* except we must first make sure that 'address-PAGE_SIZE'
2763+
* This is like a special single-page "expand_{down|up}wards()",
2764+
* except we must first make sure that 'address{-|+}PAGE_SIZE'
27652765
* doesn't hit another vma.
2766-
*
2767-
* The "find_vma()" will do the right thing even if we wrap
27682766
*/
27692767
static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
27702768
{
@@ -2783,6 +2781,15 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
27832781

27842782
expand_stack(vma, address - PAGE_SIZE);
27852783
}
2784+
if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
2785+
struct vm_area_struct *next = vma->vm_next;
2786+
2787+
/* As VM_GROWSDOWN but s/below/above/ */
2788+
if (next && next->vm_start == address + PAGE_SIZE)
2789+
return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
2790+
2791+
expand_upwards(vma, address + PAGE_SIZE);
2792+
}
27862793
return 0;
27872794
}
27882795

mm/mmap.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,9 +1716,6 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
17161716
* PA-RISC uses this for its stack; IA64 for its Register Backing Store.
17171717
* vma is the last one with address > vma->vm_end. Have to extend vma.
17181718
*/
1719-
#ifndef CONFIG_IA64
1720-
static
1721-
#endif
17221719
int expand_upwards(struct vm_area_struct *vma, unsigned long address)
17231720
{
17241721
int error;

0 commit comments

Comments
 (0)