All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Jiri Kosina <jkosina@suse.cz>, Kees Cook <keescook@chromium.org>
Cc: "H. Peter Anvin" <hpa@linux.intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	live-patching@vger.kernel.org, Linux-MM <linux-mm@kvack.org>,
	"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH v2] x86, kaslr: propagate base load address calculation
Date: Tue, 17 Feb 2015 11:44:43 +0100	[thread overview]
Message-ID: <20150217104443.GC9784@pd.tnic> (raw)
In-Reply-To: <alpine.LNX.2.00.1502131602360.2423@pobox.suse.cz>

On Fri, Feb 13, 2015 at 04:04:55PM +0100, Jiri Kosina wrote:
> Commit e2b32e678 ("x86, kaslr: randomize module base load address") makes 
> the base address for module to be unconditionally randomized in case when 
> CONFIG_RANDOMIZE_BASE is defined and "nokaslr" option isn't present on the 
> commandline.
> 
> This is not consistent with how choose_kernel_location() decides whether 
> it will randomize kernel load base.
> 
> Namely, CONFIG_HIBERNATION disables kASLR (unless "kaslr" option is 
> explicitly specified on kernel commandline), which makes the state space 
> larger than what module loader is looking at. IOW CONFIG_HIBERNATION && 
> CONFIG_RANDOMIZE_BASE is a valid config option, kASLR wouldn't be applied 
> by default in that case, but module loader is not aware of that.
> 
> Instead of fixing the logic in module.c, this patch takes more generic 
> aproach. It introduces a new bootparam setup data_type SETUP_KASLR and 
> uses that to pass the information whether kaslr has been applied during 
> kernel decompression, and sets a global 'kaslr_enabled' variable 
> accordingly, so that any kernel code (module loading, livepatching, ...) 
> can make decisions based on its value.
> 
> x86 module loader is converted to make use of this flag.
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> ---
> 
> v1 -> v2:
> 
> Originally I just calculated the fact on the fly from difference between 
> __START_KERNEL and &text, but Kees correctly pointed out that this doesn't 
> properly catch the case when the offset is randomized to zero. I don't see 

Yeah, about that. I think we want to do the thing in addition so that
we don't have the misleading "Kernel Offset:..." line in splats in case
kaslr is off.

Right?

---
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index ab4734e5411d..a203da9cc445 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1275,6 +1275,9 @@ static struct notifier_block kernel_offset_notifier = {
 
 static int __init register_kernel_offset_dumper(void)
 {
+	if (!kaslr_enabled)
+		return 0;
+
 	atomic_notifier_chain_register(&panic_notifier_list,
 					&kernel_offset_notifier);
 	return 0;

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

WARNING: multiple messages have this Message-ID (diff)
From: Borislav Petkov <bp@alien8.de>
To: Jiri Kosina <jkosina@suse.cz>, Kees Cook <keescook@chromium.org>
Cc: "H. Peter Anvin" <hpa@linux.intel.com>,
	LKML <linux-kernel@vger.kernel.org>,
	live-patching@vger.kernel.org, Linux-MM <linux-mm@kvack.org>,
	"x86@kernel.org" <x86@kernel.org>
Subject: Re: [PATCH v2] x86, kaslr: propagate base load address calculation
Date: Tue, 17 Feb 2015 11:44:43 +0100	[thread overview]
Message-ID: <20150217104443.GC9784@pd.tnic> (raw)
In-Reply-To: <alpine.LNX.2.00.1502131602360.2423@pobox.suse.cz>

On Fri, Feb 13, 2015 at 04:04:55PM +0100, Jiri Kosina wrote:
> Commit e2b32e678 ("x86, kaslr: randomize module base load address") makes 
> the base address for module to be unconditionally randomized in case when 
> CONFIG_RANDOMIZE_BASE is defined and "nokaslr" option isn't present on the 
> commandline.
> 
> This is not consistent with how choose_kernel_location() decides whether 
> it will randomize kernel load base.
> 
> Namely, CONFIG_HIBERNATION disables kASLR (unless "kaslr" option is 
> explicitly specified on kernel commandline), which makes the state space 
> larger than what module loader is looking at. IOW CONFIG_HIBERNATION && 
> CONFIG_RANDOMIZE_BASE is a valid config option, kASLR wouldn't be applied 
> by default in that case, but module loader is not aware of that.
> 
> Instead of fixing the logic in module.c, this patch takes more generic 
> aproach. It introduces a new bootparam setup data_type SETUP_KASLR and 
> uses that to pass the information whether kaslr has been applied during 
> kernel decompression, and sets a global 'kaslr_enabled' variable 
> accordingly, so that any kernel code (module loading, livepatching, ...) 
> can make decisions based on its value.
> 
> x86 module loader is converted to make use of this flag.
> 
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> ---
> 
> v1 -> v2:
> 
> Originally I just calculated the fact on the fly from difference between 
> __START_KERNEL and &text, but Kees correctly pointed out that this doesn't 
> properly catch the case when the offset is randomized to zero. I don't see 

Yeah, about that. I think we want to do the thing in addition so that
we don't have the misleading "Kernel Offset:..." line in splats in case
kaslr is off.

Right?

---
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index ab4734e5411d..a203da9cc445 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1275,6 +1275,9 @@ static struct notifier_block kernel_offset_notifier = {
 
 static int __init register_kernel_offset_dumper(void)
 {
+	if (!kaslr_enabled)
+		return 0;
+
 	atomic_notifier_chain_register(&panic_notifier_list,
 					&kernel_offset_notifier);
 	return 0;

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2015-02-17 10:45 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-10 13:17 [PATCH] x86, kaslr: propagate base load address calculation Jiri Kosina
2015-02-10 13:17 ` Jiri Kosina
2015-02-10 17:25 ` Kees Cook
2015-02-10 17:25   ` Kees Cook
2015-02-10 23:07   ` Jiri Kosina
2015-02-10 23:07     ` Jiri Kosina
2015-02-10 23:13     ` Jiri Kosina
2015-02-10 23:13       ` Jiri Kosina
2015-02-13 15:04       ` [PATCH v2] " Jiri Kosina
2015-02-13 15:04         ` Jiri Kosina
2015-02-13 17:49         ` Kees Cook
2015-02-13 17:49           ` Kees Cook
2015-02-13 22:20           ` Jiri Kosina
2015-02-13 22:20             ` Jiri Kosina
2015-02-13 23:25             ` Kees Cook
2015-02-13 23:25               ` Kees Cook
2015-02-16 11:55               ` Borislav Petkov
2015-02-16 11:55                 ` Borislav Petkov
2015-02-16 19:27                 ` Kees Cook
2015-02-16 19:27                   ` Kees Cook
2015-02-16 19:42                   ` Borislav Petkov
2015-02-16 19:42                     ` Borislav Petkov
2015-02-17 10:44         ` Borislav Petkov [this message]
2015-02-17 10:44           ` Borislav Petkov
2015-02-17 12:21           ` Jiri Kosina
2015-02-17 12:21             ` Jiri Kosina
2015-02-17 12:39             ` Borislav Petkov
2015-02-17 12:39               ` Borislav Petkov
2015-02-17 16:45               ` Kees Cook
2015-02-17 16:45                 ` Kees Cook
2015-02-17 22:31                 ` Borislav Petkov
2015-02-17 22:31                   ` Borislav Petkov
2015-02-18  3:33                   ` Kees Cook
2015-02-18  3:33                     ` Kees Cook
2015-02-18  8:32                     ` Borislav Petkov
2015-02-18  8:32                       ` Borislav Petkov
2015-02-18 10:46                       ` Jiri Kosina
2015-02-18 10:46                         ` 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=20150217104443.GC9784@pd.tnic \
    --to=bp@alien8.de \
    --cc=hpa@linux.intel.com \
    --cc=jkosina@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=live-patching@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.