kretprobe: check re-registration of the same kretprobe earlier
PATCH v2 1/1 kretprobe: check re-registration of the same kretprobe earlier
Our system encountered a use-after-free when re-register the same kretprobe, it access the kretprobe_instance in rp->free_instances which has been released already.
Prevent re-registration has been implemented for kprobe before, but it's too late for kretprobe. We must check the re-registration before re-initializing the kretprobe, otherwise it will destroy the data and struct of the kretprobe registered, it can lead to use-after-free, memory leak, system crash, and even other unexpected behaviors.
Use check_kprobe_rereg() to check re-registration, also give a warning message.
Signed-off-by Cheng Jian <[email protected]>
Acked-by Masami Hiramatsu <[email protected]>
--- kernel/kprobes.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/kprobes.c +8 -0
@@ -1946,6 +1946,14 @@ int register_kretprobe(struct kretprobe *rp) } } +/* +* Return error if it's being re-registered, +* also give a warning message to the developer. +*/ + ret =check_kprobe_rereg (&rp->kp); +if (WARN_ON (ret)) +return ret; + rp->kp.pre_handler = pre_handler_kretprobe; rp->kp.post_handler =NULL ; rp->kp.fault_handler =NULL ;
Signature · 1 line
2.7.4