test_klp_livepatch.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
  3. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  4. #include <linux/module.h>
  5. #include <linux/kernel.h>
  6. #include <linux/livepatch.h>
  7. #include <linux/seq_file.h>
  8. static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
  9. {
  10. seq_printf(m, "%s: %s\n", THIS_MODULE->name,
  11. "this has been live patched");
  12. return 0;
  13. }
  14. static struct klp_func funcs[] = {
  15. {
  16. .old_name = "cmdline_proc_show",
  17. .new_func = livepatch_cmdline_proc_show,
  18. }, { }
  19. };
  20. static struct klp_object objs[] = {
  21. {
  22. /* name being NULL means vmlinux */
  23. .funcs = funcs,
  24. }, { }
  25. };
  26. static struct klp_patch patch = {
  27. .mod = THIS_MODULE,
  28. .objs = objs,
  29. };
  30. static int test_klp_livepatch_init(void)
  31. {
  32. return klp_enable_patch(&patch);
  33. }
  34. static void test_klp_livepatch_exit(void)
  35. {
  36. }
  37. module_init(test_klp_livepatch_init);
  38. module_exit(test_klp_livepatch_exit);
  39. MODULE_LICENSE("GPL");
  40. MODULE_INFO(livepatch, "Y");
  41. MODULE_AUTHOR("Seth Jennings <sjenning@redhat.com>");
  42. MODULE_DESCRIPTION("Livepatch test: livepatch module");