Skip to content

Commit 9dd721c

Browse files
keesH. Peter Anvin
authored andcommitted
x86, kaslr: fix module lock ordering problem
There was a potential lock ordering problem with the module kASLR patch ("x86, kaslr: randomize module base load address"). This patch removes the usage of the module_mutex and creates a new mutex to protect the module base address offset value. Chain exists of: text_mutex --> kprobe_insn_slots.mutex --> module_mutex [ 0.515561] Possible unsafe locking scenario: [ 0.515561] [ 0.515561] CPU0 CPU1 [ 0.515561] ---- ---- [ 0.515561] lock(module_mutex); [ 0.515561] lock(kprobe_insn_slots.mutex); [ 0.515561] lock(module_mutex); [ 0.515561] lock(text_mutex); [ 0.515561] [ 0.515561] *** DEADLOCK *** Reported-by: Fengguang Wu <[email protected]> Signed-off-by: Andy Honig <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Masami Hiramatsu <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent e2b32e6 commit 9dd721c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/x86/kernel/module.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ do { \
4848
static unsigned long module_load_offset;
4949
static int randomize_modules = 1;
5050

51+
/* Mutex protects the module_load_offset. */
52+
static DEFINE_MUTEX(module_kaslr_mutex);
53+
5154
static int __init parse_nokaslr(char *p)
5255
{
5356
randomize_modules = 0;
@@ -58,7 +61,7 @@ early_param("nokaslr", parse_nokaslr);
5861
static unsigned long int get_module_load_offset(void)
5962
{
6063
if (randomize_modules) {
61-
mutex_lock(&module_mutex);
64+
mutex_lock(&module_kaslr_mutex);
6265
/*
6366
* Calculate the module_load_offset the first time this
6467
* code is called. Once calculated it stays the same until
@@ -67,7 +70,7 @@ static unsigned long int get_module_load_offset(void)
6770
if (module_load_offset == 0)
6871
module_load_offset =
6972
(get_random_int() % 1024 + 1) * PAGE_SIZE;
70-
mutex_unlock(&module_mutex);
73+
mutex_unlock(&module_kaslr_mutex);
7174
}
7275
return module_load_offset;
7376
}

0 commit comments

Comments
 (0)