Skip to content

Commit

Permalink
livepatch: x86: make kASLR logic more accurate
Browse files Browse the repository at this point in the history
We give up old_addr hint from the coming patch module in cases when kernel load
base has been randomized (as in such case, the coming module has no idea about
the exact randomization offset).

We are currently too pessimistic, and give up immediately as soon as
CONFIG_RANDOMIZE_BASE is set; this doesn't however directly imply that the
load base has actually been randomized. There are config options that
disable kASLR (such as hibernation), user could have disabled kaslr on
kernel command-line, etc.

The loader propagates the information whether kernel has been randomized
through bootparams. This allows us to have the condition more accurate.

On top of that, it seems unnecessary to give up old_addr hints even if
randomization is active. The relocation offset can be computed using
kaslr_ofsset(), and therefore old_addr can be adjusted accordingly.

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Jiri Kosina committed Apr 29, 2015
1 parent 4545c89 commit 5d4351b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions arch/x86/include/asm/livepatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef _ASM_X86_LIVEPATCH_H
#define _ASM_X86_LIVEPATCH_H

#include <asm/setup.h>
#include <linux/module.h>
#include <linux/ftrace.h>

Expand Down
5 changes: 3 additions & 2 deletions kernel/livepatch/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ static int klp_find_verify_func_addr(struct klp_object *obj,
int ret;

#if defined(CONFIG_RANDOMIZE_BASE)
/* KASLR is enabled, disregard old_addr from user */
func->old_addr = 0;
/* If KASLR has been enabled, adjust old_addr accordingly */
if (kaslr_enabled() && func->old_addr)
func->old_addr += kaslr_offset();
#endif

if (!func->old_addr || klp_is_module(obj))
Expand Down

0 comments on commit 5d4351b

Please sign in to comment.