diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c index f9e9f06..fd12dbc 100644 --- a/kmod/patch/livepatch-patch-hook.c +++ b/kmod/patch/livepatch-patch-hook.c @@ -53,6 +53,14 @@ #define HAVE_IMMEDIATE #endif +#ifdef RHEL_RELEASE_CODE +# if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5) +# define HAVE_CALLBACKS +# endif +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0) +# define HAVE_CALLBACKS +#endif + /* * There are quite a few similar structures at play in this file: * - livepatch.h structs prefixed with klp_* @@ -79,7 +87,9 @@ struct patch_object { struct list_head list; struct list_head funcs; struct list_head relocs; +#ifdef HAVE_CALLBACKS struct klp_callbacks callbacks; +#endif const char *name; int funcs_nr, relocs_nr; }; @@ -216,6 +226,7 @@ extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpat extern struct kpatch_pre_unpatch_callback __kpatch_callbacks_pre_unpatch[], __kpatch_callbacks_pre_unpatch_end[]; extern struct kpatch_post_unpatch_callback __kpatch_callbacks_post_unpatch[], __kpatch_callbacks_post_unpatch_end[]; +#ifdef HAVE_CALLBACKS static int add_callbacks_to_patch_objects(void) { struct kpatch_pre_patch_callback *p_pre_patch_callback; @@ -286,6 +297,24 @@ static int add_callbacks_to_patch_objects(void) return 0; } +#else /* HAVE_CALLBACKS */ +static inline int add_callbacks_to_patch_objects(void) +{ + if (__kpatch_callbacks_pre_patch != + __kpatch_callbacks_pre_patch_end || + __kpatch_callbacks_post_patch != + __kpatch_callbacks_post_patch_end || + __kpatch_callbacks_pre_unpatch != + __kpatch_callbacks_pre_unpatch_end || + __kpatch_callbacks_post_unpatch != + __kpatch_callbacks_post_unpatch_end) { + pr_err("patch callbacks are not supported\n"); + return -EINVAL; + } + + return 0; +} +#endif /* HAVE_CALLBACKS */ extern struct kpatch_patch_func __kpatch_funcs[], __kpatch_funcs_end[]; #ifndef HAVE_ELF_RELOCS @@ -392,7 +421,9 @@ static int __init patch_init(void) } #endif /* HAVE_ELF_RELOCS */ +#ifdef HAVE_CALLBACKS lobject->callbacks = object->callbacks; +#endif i++; }