diff --git a/1_Livepatch/1.0_livepatch_sample/livepatch-sample.c b/1_Livepatch/1.0_livepatch_sample/livepatch-sample.c index cd76d7e..160dfea 100644 --- a/1_Livepatch/1.0_livepatch_sample/livepatch-sample.c +++ b/1_Livepatch/1.0_livepatch_sample/livepatch-sample.c @@ -30,12 +30,16 @@ */ #include + +/* This is the replacement function that we are going to override with */ static int livepatch_cmdline_proc_show(struct seq_file *m, void *v) { seq_printf(m, "%s\n", "this has been live patched"); return 0; } +/* We have to provide the livepatch API with the following struct + * that indicates which kernel function we are overwriting and with what */ static struct klp_func funcs[] = { { .old_name = "cmdline_proc_show", @@ -43,6 +47,8 @@ }, { } }; +/* The struct above gets passed as a field in the following klp_object + * (kernel live patch)_object. */ static struct klp_object objs[] = { { /* name being NULL means vmlinux */ @@ -50,11 +56,15 @@ }, { } }; +/* Again, the struct above gets passed a field to the following klp_patch + * object. The address of this object in memory will be passed to the + * klp_enable_patch() function */ static struct klp_patch patch = { .mod = THIS_MODULE, .objs = objs, }; +/* Initialize our patch */ static int livepatch_init(void) { return klp_enable_patch(&patch); @@ -67,4 +77,5 @@ module_init(livepatch_init); module_exit(livepatch_exit); MODULE_LICENSE("GPL"); +/* We have to tell the kernel that this LKM is a livepatch module */ MODULE_INFO(livepatch, "Y");