mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Ilya Smith <blackzert@gmail.com>
Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	x86@kernel.org, kirill.shutemov@linux.intel.com,
	dsafonov@virtuozzo.com, hughd@google.com,
	gregkh@linuxfoundation.org, craigb@google.com, oleg@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] Take mmap_min_addr into account while choosing unmapped address for x86-64.
Date: Tue, 27 Feb 2018 09:57:27 +0100	[thread overview]
Message-ID: <20180227085726.GC15357@dhcp22.suse.cz> (raw)
In-Reply-To: <20180226211257.63067-1-blackzert@gmail.com>

On Tue 27-02-18 00:12:57, Ilya Smith wrote:
[...]
> diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
> index 676774b9bb8d..1752fe5cb735 100644
> --- a/arch/x86/kernel/sys_x86_64.c
> +++ b/arch/x86/kernel/sys_x86_64.c
> @@ -17,6 +17,7 @@
>  #include <linux/random.h>
>  #include <linux/uaccess.h>
>  #include <linux/elf.h>
> +#include <linux/security.h>
>  
>  #include <asm/elf.h>
>  #include <asm/compat.h>
> @@ -185,7 +186,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
>  		return addr;
>  
>  	/* requested length too big for entire address space */
> -	if (len > TASK_SIZE)
> +	if (len > TASK_SIZE - mmap_min_addr)
>  		return -ENOMEM;
>  
>  	/* No address checking. See comment at mmap_address_hint_valid() */
> @@ -210,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
>  
>  	info.flags = VM_UNMAPPED_AREA_TOPDOWN;
>  	info.length = len;
> -	info.low_limit = PAGE_SIZE;
> +	info.low_limit = max(PAGE_SIZE, mmap_min_addr);
>  	info.high_limit = get_mmap_base(0);
>  
>  	/*

mmap_min_addr handling is a bit mess... As you say, we would return
EPERM rather than ENOMEM which can be confusing but depleting the
address space like that is quite unlikely on 64b unless I am missing.
It is good to be in sync here with the generic implementation though,
IMO.

> diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
> index 155ecbac9e28..b6d0c317639e 100644
> --- a/arch/x86/mm/mmap.c
> +++ b/arch/x86/mm/mmap.c
> @@ -31,6 +31,7 @@
>  #include <linux/sched/signal.h>
>  #include <linux/sched/mm.h>
>  #include <linux/compat.h>
> +#include <linux/security.h>
>  #include <asm/elf.h>
>  
>  #include "physaddr.h"
> @@ -220,6 +221,9 @@ bool mmap_address_hint_valid(unsigned long addr, unsigned long len)
>  	if (TASK_SIZE - len < addr)
>  		return false;
>  
> +	if (addr < mmap_min_addr)
> +		return false;
> +
>  	return (addr > DEFAULT_MAP_WINDOW) == (addr + len > DEFAULT_MAP_WINDOW);

But is this one necessary? We do sanitze hint address before going to
get_unmapped_address AFAIR.

-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2018-02-27  8:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-26 21:12 Ilya Smith
2018-02-27  8:57 ` Michal Hocko [this message]
2018-02-27 13:27   ` Ilya Smith
2018-02-28  7:17     ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180227085726.GC15357@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=blackzert@gmail.com \
    --cc=craigb@google.com \
    --cc=dsafonov@virtuozzo.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=hughd@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®