mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Minfei Huang <mhuang@redhat.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	Kees Cook <keescook@chromium.org>, Borislav Petkov <bp@suse.de>,
	Baoquan He <bhe@redhat.com>, Thomas Gleixner <tglx@linutronix.de>,
	Jiri Kosina <jkosina@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Matt Fleming <matt.fleming@intel.com>
Subject: Re: [PATCH v4] x86, kaslr: Access the correct kaslr_enabled variable
Date: Sun, 15 Mar 2015 20:18:45 +0800	[thread overview]
Message-ID: <20150315121845.GA22920@dhcp-128-1.nay.redhat.com> (raw)
In-Reply-To: <1426405767-21100-1-git-send-email-yinghai@kernel.org>

On 03/15/15 at 12:49am, Yinghai Lu wrote:
> While trying to optimize setup_data handling code, found commit f47233c2d34f
> ("x86/mm/ASLR: Propagate base load address calculation"), uses a physical
> address as the value.
> 
> It leads to wrong kaslr status. That kaslr status is passed for controlling
> module load offset. So when kernel has kasl support compiled in, and user
> use nokaslr to disable kaslr, wrong value cause unwanted offset for module
> loading.
> 

Hi, Yinghai!

It confuses me with the virtual address in function parse_kaslr_setup.
When we are in here(parse_kaslr_setup), we already use the virtual
address, instead of physical address. Is it all right?

In the other words, using physical address in parse_kaslr_setup is
always a mistake, whatever the kaslr is on or off.

Thanks
Minfei

> We should keep kaslr status consistent between aslr randrom kernel base,
> and late module random offset. That is old behavior before that commit.
> 
> The setup_data linked list and thus the element which contains
> kaslr_enabled is chained together using physical addresses. At the time
> when we access it in the kernel, we're already running with paging enabled
> and therefore must access it through its virtual address.
> 
> This patch changes the code to use early_memmap() and access the value,
> as it is still in kernel early stage, we don't have kernel mapping setup
> yet.
> 
> Fixes: f47233c2d34f ("x86/mm/ASLR: Propagate base load address calculation")
> Cc: Matt Fleming <matt.fleming@intel.com>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Jiri Kosina <jkosina@suse.cz>
> Acked-by: Jiri Kosina <jkosina@suse.cz>
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> 
> ---
> -v3: add checking return from early_memmap according to Boris.
> -v4: add description about setup_data accessing from Boris to change log.
> 
> ---
>  arch/x86/kernel/setup.c |   13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/arch/x86/kernel/setup.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/kernel/setup.c
> +++ linux-2.6/arch/x86/kernel/setup.c
> @@ -429,7 +429,18 @@ static void __init reserve_initrd(void)
>  
>  static void __init parse_kaslr_setup(u64 pa_data, u32 data_len)
>  {
> -	kaslr_enabled = (bool)(pa_data + sizeof(struct setup_data));
> +	/* kaslr_setup_data is defined in aslr.c */
> +	unsigned char *data;
> +	unsigned long offset = sizeof(struct setup_data);
> +
> +	data = early_memremap(pa_data, offset + 1);
> +	if (!data) {
> +		kaslr_enabled = true;
> +		return;
> +	}
> +
> +	kaslr_enabled = *(data + offset);
> +	early_memunmap(data, offset + 1);
>  }
>  
>  static void __init parse_setup_data(void)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  reply	other threads:[~2015-03-15 12:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-15  7:49 Yinghai Lu
2015-03-15 12:18 ` Minfei Huang [this message]
2015-03-15 17:02   ` Yinghai Lu
2015-03-16  3:08     ` Minfei Huang
2015-03-16  3:28 ` Baoquan He
2015-03-16  4:36   ` Yinghai Lu
2015-03-16  5:11     ` Baoquan He
2015-03-16  5:04   ` Yinghai Lu
2015-03-16  5:19     ` Baoquan He

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=20150315121845.GA22920@dhcp-128-1.nay.redhat.com \
    --to=mhuang@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=bp@suse.de \
    --cc=hpa@zytor.com \
    --cc=jkosina@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.fleming@intel.com \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yinghai@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®