Messages in this thread Patch in this message | | | From | Ard Biesheuvel <> | Subject | [RFC PATCH 5/7] static_call: use non-function types to refer to the trampolines | Date | Tue, 9 Nov 2021 17:45:47 +0100 |
| |
In order to prevent CFI enabled code from grabbing a jump table entry that jumps to the trampoline, rather than the trampoline itself, use an incomplete non-function type for the trampoline, and cast it to the right type only when invoking it.
Acked-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> --- include/linux/static_call.h | 2 +- include/linux/static_call_types.h | 6 +++--- tools/include/linux/static_call_types.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/linux/static_call.h b/include/linux/static_call.h index 391f737496eb..6b261fe96ba3 100644 --- a/include/linux/static_call.h +++ b/include/linux/static_call.h @@ -144,7 +144,7 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool #define static_call_update(name, func) \ ({ \ - typeof(&STATIC_CALL_TRAMP(name)) __F = (func); \ + typeof(STATIC_CALL_QUERY(name)()) __F = (func); \ __static_call_update(&STATIC_CALL_KEY(name), \ STATIC_CALL_TRAMP_ADDR(name), __F); \ }) diff --git a/include/linux/static_call_types.h b/include/linux/static_call_types.h index 2fce9aa8a995..eae11c5b015d 100644 --- a/include/linux/static_call_types.h +++ b/include/linux/static_call_types.h @@ -47,7 +47,7 @@ struct static_call_site { extern __weak struct static_call_key STATIC_CALL_KEY(name); \ extern __weak struct static_call_key *STATIC_CALL_GETKEY(name)(void);\ extern __weak typeof(func) *STATIC_CALL_QUERY(name)(void); \ - extern typeof(func) STATIC_CALL_TRAMP(name) + extern struct static_call_tramp STATIC_CALL_TRAMP(name) #define __static_call_query(name) \ ((typeof(STATIC_CALL_QUERY(name)()))READ_ONCE(STATIC_CALL_KEY(name).func)) @@ -66,7 +66,7 @@ struct static_call_site { #define static_call(name) \ ({ \ __STATIC_CALL_ADDRESSABLE(name); \ - (&STATIC_CALL_TRAMP(name)); \ + ((typeof(STATIC_CALL_QUERY(name)()))&STATIC_CALL_TRAMP(name)); \ }) #ifdef CONFIG_HAVE_STATIC_CALL_INLINE @@ -107,7 +107,7 @@ struct static_call_key { }; #define static_call(name) \ - ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) + ((typeof(STATIC_CALL_QUERY(name)()))(STATIC_CALL_KEY(name).func)) #endif /* CONFIG_HAVE_STATIC_CALL */ diff --git a/tools/include/linux/static_call_types.h b/tools/include/linux/static_call_types.h index 2fce9aa8a995..eae11c5b015d 100644 --- a/tools/include/linux/static_call_types.h +++ b/tools/include/linux/static_call_types.h @@ -47,7 +47,7 @@ struct static_call_site { extern __weak struct static_call_key STATIC_CALL_KEY(name); \ extern __weak struct static_call_key *STATIC_CALL_GETKEY(name)(void);\ extern __weak typeof(func) *STATIC_CALL_QUERY(name)(void); \ - extern typeof(func) STATIC_CALL_TRAMP(name) + extern struct static_call_tramp STATIC_CALL_TRAMP(name) #define __static_call_query(name) \ ((typeof(STATIC_CALL_QUERY(name)()))READ_ONCE(STATIC_CALL_KEY(name).func)) @@ -66,7 +66,7 @@ struct static_call_site { #define static_call(name) \ ({ \ __STATIC_CALL_ADDRESSABLE(name); \ - (&STATIC_CALL_TRAMP(name)); \ + ((typeof(STATIC_CALL_QUERY(name)()))&STATIC_CALL_TRAMP(name)); \ }) #ifdef CONFIG_HAVE_STATIC_CALL_INLINE @@ -107,7 +107,7 @@ struct static_call_key { }; #define static_call(name) \ - ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func)) + ((typeof(STATIC_CALL_QUERY(name)()))(STATIC_CALL_KEY(name).func)) #endif /* CONFIG_HAVE_STATIC_CALL */ -- 2.30.2
| |