mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Jiri Kosina <jkosina@suse.cz>
Cc: x86@kernel.org, Borislav Petkov <bp@alien8.de>,
	Kees Cook <keescook@chromium.org>,
	Seth Jennings <sjenning@redhat.com>,
	Vojtech Pavlik <vojtech@suse.cz>,
	linux-kernel@vger.kernel.org, live-patching@vger.kernel.org
Subject: Re: [PATCH 1/2] x86: introduce kaslr_offset()
Date: Tue, 28 Apr 2015 07:08:38 -0500	[thread overview]
Message-ID: <20150428120838.GA16487@treble.redhat.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1504271334300.16113@pobox.suse.cz>

On Mon, Apr 27, 2015 at 04:28:07PM +0200, Jiri Kosina wrote:
> Offset that has been chosen for kaslr during kernel decompression can be 
> easily computed as a difference between _text and __START_KERNEL. We are 
> already making use of this in dump_kernel_offset() notifier.
> 
> Introduce kaslr_offset() that makes this computation instead of 
> hard-coding it, so that other kernel code (such as live patching) can make 
> use of it.
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> ---
>  arch/x86/include/asm/setup.h | 6 ++++++
>  arch/x86/kernel/setup.c      | 2 +-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h
> index f69e06b..785ac2f 100644
> --- a/arch/x86/include/asm/setup.h
> +++ b/arch/x86/include/asm/setup.h
> @@ -65,12 +65,18 @@ static inline void x86_ce4100_early_setup(void) { }
>   * This is set up by the setup-routine at boot-time
>   */
>  extern struct boot_params boot_params;
> +extern char _text[];
>  
>  static inline bool kaslr_enabled(void)
>  {
>  	return !!(boot_params.hdr.loadflags & KASLR_FLAG);
>  }
>  
> +static inline unsigned long kaslr_offset(void)
> +{
> +	return (unsigned long)&_text - __START_KERNEL;
> +}
> +
>  /*
>   * Do NOT EVER look at the BIOS memory size location.
>   * It does not work on many machines.
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index d74ac33..5056d3c 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -834,7 +834,7 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
>  {
>  	if (kaslr_enabled()) {
>  		pr_emerg("Kernel Offset: 0x%lx from 0x%lx (relocation range: 0x%lx-0x%lx)\n",
> -			 (unsigned long)&_text - __START_KERNEL,
> +			 kaslr_offset(),
>  			 __START_KERNEL,
>  			 __START_KERNEL_map,
>  			 MODULES_VADDR-1);

It looks like kaslr_offset() can also be used by
arch_crash_save_vmcoreinfo() in machine_kexec_64.c.

-- 
Josh

  reply	other threads:[~2015-04-28 12:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 14:27 [PATCH 0/2] introduce kaslr_offset() and its users Jiri Kosina
2015-04-27 14:28 ` [PATCH 1/2] x86: introduce kaslr_offset() Jiri Kosina
2015-04-28 12:08   ` Josh Poimboeuf [this message]
2015-04-28 15:15     ` [PATCH v2 " Jiri Kosina
2015-04-28 15:57       ` Jiri Kosina
2015-04-28 15:59         ` Borislav Petkov
2015-04-29 14:56           ` Jiri Kosina
2015-04-29 16:16             ` Jiri Kosina
2015-04-27 14:28 ` [PATCH 2/2] livepatch: x86: make kASLR logic more accurate Jiri Kosina
2015-04-27 14:41   ` Minfei Huang
2015-04-27 23:29     ` Jiri Kosina
2015-04-28  0:08       ` Minfei Huang
2015-04-28 12:09   ` Josh Poimboeuf
2015-04-29 14:56     ` Jiri Kosina

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=20150428120838.GA16487@treble.redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=bp@alien8.de \
    --cc=jkosina@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=sjenning@redhat.com \
    --cc=vojtech@suse.cz \
    --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

Powered by JetHome