Skip to content

Commit 285a54e

Browse files
mhiramatIngo Molnar
authored andcommitted
x86/alternatives: Sync bp_patching update for avoiding NULL pointer exception
ftracetest multiple_kprobes.tc testcase hits the following NULL pointer exception: BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 800000007bf60067 P4D 800000007bf60067 PUD 7bf5f06 PMD 0 Oops: 0000 [#1] PREEMPT SMP PTI RIP: 0010:poke_int3_handler+0x39/0x100 Call Trace: <IRQ> do_int3+0xd/0xf0 int3+0x42/0x50 RIP: 0010:sched_clock+0x6/0x10 poke_int3_handler+0x39 was alternatives:958: static inline void *text_poke_addr(struct text_poke_loc *tp) { return _stext + tp->rel_addr; <------ Here is line #958 } This seems to be caused by tp (bp_patching.vec) being NULL but bp_patching.nr_entries != 0. There is a small chance for this to happen, because we have no synchronization between the zeroing of bp_patching.nr_entries and before clearing bp_patching.vec. Steve suggested we could fix this by adding sync_core(), because int3 is done with interrupts disabled, and the on_each_cpu() requires all CPUs to have had their interrupts enabled. [ mingo: Edited the comments and the changelog. ] Suggested-by: Steven Rostedt (VMware) <[email protected]> Tested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Fixes: c0213b0 ("x86/alternative: Batch of patch operations") Link: https://lkml.kernel.org/r/157483421229.25881.15314414408559963162.stgit@devnote2 Signed-off-by: Ingo Molnar <[email protected]>
1 parent 76ffa72 commit 285a54e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arch/x86/kernel/alternative.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,14 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
11341134
* sync_core() implies an smp_mb() and orders this store against
11351135
* the writing of the new instruction.
11361136
*/
1137-
bp_patching.vec = NULL;
11381137
bp_patching.nr_entries = 0;
1138+
/*
1139+
* This sync_core () call ensures that all INT3 handlers in progress
1140+
* have finished. This allows poke_int3_handler() after this to
1141+
* avoid touching bp_paching.vec by checking nr_entries == 0.
1142+
*/
1143+
text_poke_sync();
1144+
bp_patching.vec = NULL;
11391145
}
11401146

11411147
void text_poke_loc_init(struct text_poke_loc *tp, void *addr,

0 commit comments

Comments
 (0)