Skip to content

Commit ca043a6

Browse files
committed
Merge branch 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, pat: don't use rb-tree based lookup in reserve_memtype() x86: Increase MIN_GAP to include randomized stack
2 parents 1218259 + 3bb045f commit ca043a6

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

arch/x86/include/asm/elf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ do { \
299299

300300
#ifdef CONFIG_X86_32
301301

302+
#define STACK_RND_MASK (0x7ff)
303+
302304
#define VDSO_HIGH_BASE (__fix_to_virt(FIX_VDSO))
303305

304306
#define ARCH_DLINFO ARCH_DLINFO_IA32(vdso_enabled)

arch/x86/mm/mmap.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,26 @@
2929
#include <linux/random.h>
3030
#include <linux/limits.h>
3131
#include <linux/sched.h>
32+
#include <asm/elf.h>
33+
34+
static unsigned int stack_maxrandom_size(void)
35+
{
36+
unsigned int max = 0;
37+
if ((current->flags & PF_RANDOMIZE) &&
38+
!(current->personality & ADDR_NO_RANDOMIZE)) {
39+
max = ((-1U) & STACK_RND_MASK) << PAGE_SHIFT;
40+
}
41+
42+
return max;
43+
}
44+
3245

3346
/*
3447
* Top of mmap area (just below the process stack).
3548
*
36-
* Leave an at least ~128 MB hole.
49+
* Leave an at least ~128 MB hole with possible stack randomization.
3750
*/
38-
#define MIN_GAP (128*1024*1024)
51+
#define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
3952
#define MAX_GAP (TASK_SIZE/6*5)
4053

4154
/*

arch/x86/mm/pat.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,9 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
424424

425425
spin_lock(&memtype_lock);
426426

427-
entry = memtype_rb_search(&memtype_rbroot, new->start);
428-
if (likely(entry != NULL)) {
429-
/* To work correctly with list_for_each_entry_continue */
430-
entry = list_entry(entry->nd.prev, struct memtype, nd);
431-
} else {
432-
entry = list_entry(&memtype_list, struct memtype, nd);
433-
}
434-
435427
/* Search for existing mapping that overlaps the current range */
436428
where = NULL;
437-
list_for_each_entry_continue(entry, &memtype_list, nd) {
429+
list_for_each_entry(entry, &memtype_list, nd) {
438430
if (end <= entry->start) {
439431
where = entry->nd.prev;
440432
break;
@@ -532,7 +524,7 @@ int free_memtype(u64 start, u64 end)
532524
* in sorted start address
533525
*/
534526
saved_entry = entry;
535-
list_for_each_entry(entry, &memtype_list, nd) {
527+
list_for_each_entry_from(entry, &memtype_list, nd) {
536528
if (entry->start == start && entry->end == end) {
537529
rb_erase(&entry->rb, &memtype_rbroot);
538530
list_del(&entry->nd);

0 commit comments

Comments
 (0)