Skip to content

Commit de31c3c

Browse files
Steven Rostedtrostedt
authored andcommitted
jump label: Fix error with preempt disable holding mutex
Kprobes and jump label were having a race between mutexes that was fixed by reordering the jump label. But this reordering moved the jump label mutex into a preempt disable location. This patch does a little fiddling to move the grabbing of the jump label mutex from inside the preempt disable section and still keep the order correct between the mutex and the kprobes lock. Reported-by: Ingo Molnar <mingo@elte.hu> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Jason Baron <jbaron@redhat.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 91bad2f commit de31c3c

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎kernel/kprobes.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,17 +1145,13 @@ int __kprobes register_kprobe(struct kprobe *p)
11451145
if (ret)
11461146
return ret;
11471147

1148-
preempt_disable();
11491148
jump_label_lock();
1149+
preempt_disable();
11501150
if (!kernel_text_address((unsigned long) p->addr) ||
11511151
in_kprobes_functions((unsigned long) p->addr) ||
11521152
ftrace_text_reserved(p->addr, p->addr) ||
1153-
jump_label_text_reserved(p->addr, p->addr)) {
1154-
preempt_enable();
1155-
jump_label_unlock();
1156-
return -EINVAL;
1157-
}
1158-
jump_label_unlock();
1153+
jump_label_text_reserved(p->addr, p->addr))
1154+
goto fail_with_jump_label;
11591155

11601156
/* User can pass only KPROBE_FLAG_DISABLED to register_kprobe */
11611157
p->flags &= KPROBE_FLAG_DISABLED;
@@ -1169,22 +1165,21 @@ int __kprobes register_kprobe(struct kprobe *p)
11691165
* We must hold a refcount of the probed module while updating
11701166
* its code to prohibit unexpected unloading.
11711167
*/
1172-
if (unlikely(!try_module_get(probed_mod))) {
1173-
preempt_enable();
1174-
return -EINVAL;
1175-
}
1168+
if (unlikely(!try_module_get(probed_mod)))
1169+
goto fail_with_jump_label;
1170+
11761171
/*
11771172
* If the module freed .init.text, we couldn't insert
11781173
* kprobes in there.
11791174
*/
11801175
if (within_module_init((unsigned long)p->addr, probed_mod) &&
11811176
probed_mod->state != MODULE_STATE_COMING) {
11821177
module_put(probed_mod);
1183-
preempt_enable();
1184-
return -EINVAL;
1178+
goto fail_with_jump_label;
11851179
}
11861180
}
11871181
preempt_enable();
1182+
jump_label_unlock();
11881183

11891184
p->nmissed = 0;
11901185
INIT_LIST_HEAD(&p->list);
@@ -1226,6 +1221,11 @@ int __kprobes register_kprobe(struct kprobe *p)
12261221
module_put(probed_mod);
12271222

12281223
return ret;
1224+
1225+
fail_with_jump_label:
1226+
preempt_enable();
1227+
jump_label_unlock();
1228+
return -EINVAL;
12291229
}
12301230
EXPORT_SYMBOL_GPL(register_kprobe);
12311231

0 commit comments

Comments
 (0)