test_klp_atomic_replace.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Joe Lawrence <[email protected]>
  3. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/livepatch.h>
  7. static int replace;
  8. module_param(replace, int, 0644);
  9. MODULE_PARM_DESC(replace, "replace (default=0)");
  10. #include <linux/seq_file.h>
  11. static int livepatch_meminfo_proc_show(struct seq_file *m, void *v)
  12. {
  13. seq_printf(m, "%s: %s\n", THIS_MODULE->name,
  14. "this has been live patched");
  15. return 0;
  16. }
  17. static struct klp_func funcs[] = {
  18. {
  19. .old_name = "meminfo_proc_show",
  20. .new_func = livepatch_meminfo_proc_show,
  21. }, {}
  22. };
  23. static struct klp_object objs[] = {
  24. {
  25. /* name being NULL means vmlinux */
  26. .funcs = funcs,
  27. }, {}
  28. };
  29. static struct klp_patch patch = {
  30. .mod = THIS_MODULE,
  31. .objs = objs,
  32. /* set .replace in the init function below for demo purposes */
  33. };
  34. static int test_klp_atomic_replace_init(void)
  35. {
  36. patch.replace = replace;
  37. return klp_enable_patch(&patch);
  38. }
  39. static void test_klp_atomic_replace_exit(void)
  40. {
  41. }
  42. module_init(test_klp_atomic_replace_init);
  43. module_exit(test_klp_atomic_replace_exit);
  44. MODULE_LICENSE("GPL");
  45. MODULE_INFO(livepatch, "Y");
  46. MODULE_AUTHOR("Joe Lawrence <[email protected]>");
  47. MODULE_DESCRIPTION("Livepatch test: atomic replace");