xref: /linux/tools/testing/selftests/livepatch/test_modules/test_klp_kprobe.c (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2024 Marcos Paulo de Souza <mpdesouza@suse.com>
3 // Copyright (C) 2024 Michael Vetter <mvetter@suse.com>
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 
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 
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 
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 <mvetter@suse.com>");
38 MODULE_DESCRIPTION("Livepatch test: kprobe function");
39