Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] utilization of kprobe_mutex is incorrect on x86_64

The up()/down() orders are incorrect in arch/x86_64/kprobes.c file.
kprobe_mutext is used to protect the free kprobe instruction slot list.
arch_prepare_kprobe applies for a slot from the free list, and
arch_remove_kprobe returns a slot to the free list. The incorrect up()/down()
orders to operate on kprobe_mutex fail to protect the free list. If 2 threads
try to get/return kprobe instruction slot at the same time, the free slot list
might be broken, or a free slot might be applied by 2 threads.

Signed-off-by: Zhang Yanmin <Yanmin.zhang@intel.com>
Cc: Andi Kleen <ak@muc.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Zhang, Yanmin and committed by
Linus Torvalds
2dd960d6 32e7a04f

+4 -4
+4 -4
arch/x86_64/kernel/kprobes.c
··· 77 77 int __kprobes arch_prepare_kprobe(struct kprobe *p) 78 78 { 79 79 /* insn: must be on special executable page on x86_64. */ 80 - up(&kprobe_mutex); 81 - p->ainsn.insn = get_insn_slot(); 82 80 down(&kprobe_mutex); 81 + p->ainsn.insn = get_insn_slot(); 82 + up(&kprobe_mutex); 83 83 if (!p->ainsn.insn) { 84 84 return -ENOMEM; 85 85 } ··· 231 231 232 232 void __kprobes arch_remove_kprobe(struct kprobe *p) 233 233 { 234 - up(&kprobe_mutex); 235 - free_insn_slot(p->ainsn.insn); 236 234 down(&kprobe_mutex); 235 + free_insn_slot(p->ainsn.insn); 236 + up(&kprobe_mutex); 237 237 } 238 238 239 239 static inline void save_previous_kprobe(void)