aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/mm/mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/mm/mmap.c')
-rw-r--r--arch/powerpc/mm/mmap.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
index cb8bdbe4972f..0f0502e12f6c 100644
--- a/arch/powerpc/mm/mmap.c
+++ b/arch/powerpc/mm/mmap.c
@@ -53,21 +53,20 @@ static inline int mmap_is_legacy(void)
53 return sysctl_legacy_va_layout; 53 return sysctl_legacy_va_layout;
54} 54}
55 55
56static unsigned long mmap_rnd(void) 56unsigned long arch_mmap_rnd(void)
57{ 57{
58 unsigned long rnd = 0; 58 unsigned long rnd;
59
60 /* 8MB for 32bit, 1GB for 64bit */
61 if (is_32bit_task())
62 rnd = (unsigned long)get_random_int() % (1<<(23-PAGE_SHIFT));
63 else
64 rnd = (unsigned long)get_random_int() % (1<<(30-PAGE_SHIFT));
59 65
60 if (current->flags & PF_RANDOMIZE) {
61 /* 8MB for 32bit, 1GB for 64bit */
62 if (is_32bit_task())
63 rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
64 else
65 rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
66 }
67 return rnd << PAGE_SHIFT; 66 return rnd << PAGE_SHIFT;
68} 67}
69 68
70static inline unsigned long mmap_base(void) 69static inline unsigned long mmap_base(unsigned long rnd)
71{ 70{
72 unsigned long gap = rlimit(RLIMIT_STACK); 71 unsigned long gap = rlimit(RLIMIT_STACK);
73 72
@@ -76,7 +75,7 @@ static inline unsigned long mmap_base(void)
76 else if (gap > MAX_GAP) 75 else if (gap > MAX_GAP)
77 gap = MAX_GAP; 76 gap = MAX_GAP;
78 77
79 return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd()); 78 return PAGE_ALIGN(TASK_SIZE - gap - rnd);
80} 79}
81 80
82/* 81/*
@@ -85,6 +84,11 @@ static inline unsigned long mmap_base(void)
85 */ 84 */
86void arch_pick_mmap_layout(struct mm_struct *mm) 85void arch_pick_mmap_layout(struct mm_struct *mm)
87{ 86{
87 unsigned long random_factor = 0UL;
88
89 if (current->flags & PF_RANDOMIZE)
90 random_factor = arch_mmap_rnd();
91
88 /* 92 /*
89 * Fall back to the standard layout if the personality 93 * Fall back to the standard layout if the personality
90 * bit is set, or if the expected stack growth is unlimited: 94 * bit is set, or if the expected stack growth is unlimited:
@@ -93,7 +97,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
93 mm->mmap_base = TASK_UNMAPPED_BASE; 97 mm->mmap_base = TASK_UNMAPPED_BASE;
94 mm->get_unmapped_area = arch_get_unmapped_area; 98 mm->get_unmapped_area = arch_get_unmapped_area;
95 } else { 99 } else {
96 mm->mmap_base = mmap_base(); 100 mm->mmap_base = mmap_base(random_factor);
97 mm->get_unmapped_area = arch_get_unmapped_area_topdown; 101 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
98 } 102 }
99} 103}