Skip to content

Commit 55ca614

Browse files
jiangliutorvalds
authored andcommitted
kprobes: fix a memory leak in function pre_handler_kretprobe()
In function pre_handler_kretprobe(), the allocated kretprobe_instance object will get leaked if the entry_handler callback returns non-zero. This may cause all the preallocated kretprobe_instance objects exhausted. This issue can be reproduced by changing samples/kprobes/kretprobe_example.c to probe "mutex_unlock". And the fix is straightforward: just put the allocated kretprobe_instance object back onto the free_instances list. [[email protected]: use raw_spin_lock/unlock] Signed-off-by: Jiang Liu <[email protected]> Acked-by: Jim Keniston <[email protected]> Acked-by: Ananth N Mavinakayanahalli <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Anil S Keshavamurthy <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent cbcb834 commit 55ca614

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/kprobes.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,8 +1673,12 @@ static int __kprobes pre_handler_kretprobe(struct kprobe *p,
16731673
ri->rp = rp;
16741674
ri->task = current;
16751675

1676-
if (rp->entry_handler && rp->entry_handler(ri, regs))
1676+
if (rp->entry_handler && rp->entry_handler(ri, regs)) {
1677+
raw_spin_lock_irqsave(&rp->lock, flags);
1678+
hlist_add_head(&ri->hlist, &rp->free_instances);
1679+
raw_spin_unlock_irqrestore(&rp->lock, flags);
16771680
return 0;
1681+
}
16781682

16791683
arch_prepare_kretprobe(ri, regs);
16801684

0 commit comments

Comments
 (0)