1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2024 Marcos Paulo de Souza <[email protected]>
3 // Copyright (C) 2024 Michael Vetter <[email protected]>
4 
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/kprobes.h>
8 
9 static bool has_post_handler = true;
10 module_param(has_post_handler, bool, 0444);
11 
post_handler(struct kprobe * p,struct pt_regs * regs,unsigned long flags)12 static void __kprobes post_handler(struct kprobe *p, struct pt_regs *regs,
13 				unsigned long flags)
14 {
15 }
16 
17 static struct kprobe kp = {
18 	.symbol_name = "cmdline_proc_show",
19 };
20 
kprobe_init(void)21 static int __init kprobe_init(void)
22 {
23 	if (has_post_handler)
24 		kp.post_handler = post_handler;
25 
26 	return register_kprobe(&kp);
27 }
28 
kprobe_exit(void)29 static void __exit kprobe_exit(void)
30 {
31 	unregister_kprobe(&kp);
32 }
33 
34 module_init(kprobe_init)
35 module_exit(kprobe_exit)
36 MODULE_LICENSE("GPL");
37 MODULE_AUTHOR("Michael Vetter <[email protected]>");
38 MODULE_DESCRIPTION("Livepatch test: kprobe function");
39