Skip to contentSkip to conversation

kprobes: fix race in unregister_kprobe()

PATCH New Ananth N Mavinakayanahalli 1 participant 1 message Dec 1, 2005 kprobes

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes: fix race in unregister_kprobe()

From: Ananth N Mavinakayanahalli <[email protected]>

On architectures which have no-execute support, we use a module_alloc()ed scratch area to store the kprobed instruction for out-of-line single-stepping. This instruction slot is released during unregister_kprobe().

We are currently releasing the slot before synchronize_sched() would return, leading to a potential reuse of the slot by another kprobe before the current references are released. Small patch to fix that condition.

---

 kernel/kprobes.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)
kernel/kprobes.c +2 -1
Index: linux-2.6.15-rc3/kernel/kprobes.c
===================================================================
@@ -436,7 +436,6 @@ static inline void cleanup_kprobe(struct
 	arch_disarm_kprobe(p);
 	hlist_del_rcu(&p->hlist);
 	spin_unlock_irqrestore(&kprobe_lock, flags);
-	arch_remove_kprobe(p);
 }
 
 static inline void cleanup_aggr_kprobe(struct kprobe *old_p,
@@ -506,6 +505,8 @@ void __kprobes unregister_kprobe(struct 
 			cleanup_kprobe(p, flags);
 
 		synchronize_sched();
+		arch_remove_kprobe(p);
+
 		if (old_p->pre_handler == aggr_pre_handler &&
 				list_empty(&old_p->list))
 			kfree(old_p);