-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch-hook: fix possible cast errors
Livepatch callbacks are packed into specific sections by gcc by the macros defined in kpatch-macros.h. Callbacks take the form of: struct example { type *(fn)(struct klp_object *obj); char* objname; } However, create-diff-objects.c can't include the kernel livepatch header because it is compiled separately from the kernel module. So the solution before was to define the structs in the header file as: struct example { type *(fn)(void *obj); char* objname; } and then cast fn to (type *(fn)(struct klp_object *obj)) if necessary. This way, the same header file and definitions can be used in both places. But! If compiled with the right GCC flags, such as -Wbad-function-cast, this casting may throw an error during livepatch building, which is what I am seeing (not sure why, since it was always fine before...). Solution: Define the callback function parameter as the correct type, which allows us to get rid of the troublesome casting. Since we need to know if callbacks are present in kpatch-patch.h, we can move the definition of HAVE_CALLBACKS to from livepatch-patch-hook.c to kpatch-patch.h. IMPORTANT: For correctness, this change requires proper ordering of include statements! kpatch-patch.h must always be included AFTER linux/livepatch.h (if using linux/livepatch.h). Signed-off-by: Brennan Lamoreaux <[email protected]>
- Loading branch information
1 parent
846db25
commit 5f12b31
Showing
3 changed files
with
39 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2013-2014 Josh Poimboeuf <[email protected]> | ||
* Copyright (C) 2014 Seth Jennings <[email protected]> | ||
* Copyright (C) 2014 Seth Jennings <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -56,14 +56,6 @@ | |
# 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 | ||
|
||
#ifdef RHEL_RELEASE_CODE | ||
# if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 8) && \ | ||
RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(8, 0)) || \ | ||
|
@@ -356,8 +348,7 @@ static int add_callbacks_to_patch_objects(void) | |
object->name ? object->name : "vmlinux"); | ||
return -EINVAL; | ||
} | ||
object->callbacks.pre_patch = (int (*)(struct klp_object *)) | ||
p_pre_patch_callback->callback; | ||
object->callbacks.pre_patch = p_pre_patch_callback->callback; | ||
} | ||
|
||
for (p_post_patch_callback = __kpatch_callbacks_post_patch; | ||
|
@@ -371,8 +362,7 @@ static int add_callbacks_to_patch_objects(void) | |
object->name ? object->name : "vmlinux"); | ||
return -EINVAL; | ||
} | ||
object->callbacks.post_patch = (void (*)(struct klp_object *)) | ||
p_post_patch_callback->callback; | ||
object->callbacks.post_patch = p_post_patch_callback->callback; | ||
} | ||
|
||
for (p_pre_unpatch_callback = __kpatch_callbacks_pre_unpatch; | ||
|
@@ -386,8 +376,7 @@ static int add_callbacks_to_patch_objects(void) | |
object->name ? object->name : "vmlinux"); | ||
return -EINVAL; | ||
} | ||
object->callbacks.pre_unpatch = (void (*)(struct klp_object *)) | ||
p_pre_unpatch_callback->callback; | ||
object->callbacks.pre_unpatch = p_pre_unpatch_callback->callback; | ||
} | ||
|
||
for (p_post_unpatch_callback = __kpatch_callbacks_post_unpatch; | ||
|
@@ -401,8 +390,7 @@ static int add_callbacks_to_patch_objects(void) | |
object->name ? object->name : "vmlinux"); | ||
return -EINVAL; | ||
} | ||
object->callbacks.post_unpatch = (void (*)(struct klp_object *)) | ||
p_post_unpatch_callback->callback; | ||
object->callbacks.post_unpatch = p_post_unpatch_callback->callback; | ||
} | ||
|
||
return 0; | ||
|