From 63813f5bb33f99710d6adf89fc89bd8dd3ede28b Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Mon, 26 Nov 2007 18:47:40 -0500 Subject: [PATCH] --- yaml --- r: 74643 b: refs/heads/master c: 7cd94146cd504016315608e297219f9fb7b1413b h: refs/heads/master i: 74641: 80b50c470d439a9471fd49dffadc80d1469331ab 74639: 57cf4a2d2943f4b0183240582466eebbedf45629 v: v3 --- [refs] | 2 +- trunk/include/linux/mm.h | 16 ++++++++++++++++ trunk/mm/mmap.c | 3 +++ trunk/mm/nommu.c | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 392f406eb92b..48db6a4d9bda 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 8869477a49c3e99def1fcdadd6bbc407fea14b45 +refs/heads/master: 7cd94146cd504016315608e297219f9fb7b1413b diff --git a/trunk/include/linux/mm.h b/trunk/include/linux/mm.h index 520238cbae5d..1b7b95c67aca 100644 --- a/trunk/include/linux/mm.h +++ b/trunk/include/linux/mm.h @@ -12,6 +12,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -512,6 +513,21 @@ static inline void set_page_links(struct page *page, enum zone_type zone, set_page_section(page, pfn_to_section_nr(pfn)); } +/* + * If a hint addr is less than mmap_min_addr change hint to be as + * low as possible but still greater than mmap_min_addr + */ +static inline unsigned long round_hint_to_min(unsigned long hint) +{ +#ifdef CONFIG_SECURITY + hint &= PAGE_MASK; + if (((void *)hint != NULL) && + (hint < mmap_min_addr)) + return PAGE_ALIGN(mmap_min_addr); +#endif + return hint; +} + /* * Some inline functions in vmstat.h depend on page_zone() */ diff --git a/trunk/mm/mmap.c b/trunk/mm/mmap.c index 938313c76d02..f4cfc6ac08db 100644 --- a/trunk/mm/mmap.c +++ b/trunk/mm/mmap.c @@ -912,6 +912,9 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, if (!len) return -EINVAL; + if (!(flags & MAP_FIXED)) + addr = round_hint_to_min(addr); + error = arch_mmap_check(addr, len, flags); if (error) return error; diff --git a/trunk/mm/nommu.c b/trunk/mm/nommu.c index 35622c590925..b989cb928a7c 100644 --- a/trunk/mm/nommu.c +++ b/trunk/mm/nommu.c @@ -829,6 +829,9 @@ unsigned long do_mmap_pgoff(struct file *file, void *result; int ret; + if (!(flags & MAP_FIXED)) + addr = round_hint_to_min(addr); + /* decide whether we should attempt the mapping, and if so what sort of * mapping */ ret = validate_mmap_request(file, addr, len, prot, flags, pgoff,