mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-21 14:44:06 +00:00
lkdtm: Emit an indirect call for CFI tests
Clang can convert the indirect calls in lkdtm_CFI_FORWARD_PROTO into direct calls. Move the call into a noinline function that accepts the target address as an argument to ensure the compiler actually emits an indirect call instead. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Kees Cook <keescook@chromium.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Acked-by: Kees Cook <keescook@chromium.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220908215504.3686827-8-samitolvanen@google.com
This commit is contained in:
parent
e84e008e7b
commit
cf90d03835
1 changed files with 9 additions and 6 deletions
|
@ -20,6 +20,13 @@ static noinline int lkdtm_increment_int(int *counter)
|
||||||
|
|
||||||
return *counter;
|
return *counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Don't allow the compiler to inline the calls. */
|
||||||
|
static noinline void lkdtm_indirect_call(void (*func)(int *))
|
||||||
|
{
|
||||||
|
func(&called_count);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This tries to call an indirect function with a mismatched prototype.
|
* This tries to call an indirect function with a mismatched prototype.
|
||||||
*/
|
*/
|
||||||
|
@ -29,15 +36,11 @@ static void lkdtm_CFI_FORWARD_PROTO(void)
|
||||||
* Matches lkdtm_increment_void()'s prototype, but not
|
* Matches lkdtm_increment_void()'s prototype, but not
|
||||||
* lkdtm_increment_int()'s prototype.
|
* lkdtm_increment_int()'s prototype.
|
||||||
*/
|
*/
|
||||||
void (*func)(int *);
|
|
||||||
|
|
||||||
pr_info("Calling matched prototype ...\n");
|
pr_info("Calling matched prototype ...\n");
|
||||||
func = lkdtm_increment_void;
|
lkdtm_indirect_call(lkdtm_increment_void);
|
||||||
func(&called_count);
|
|
||||||
|
|
||||||
pr_info("Calling mismatched prototype ...\n");
|
pr_info("Calling mismatched prototype ...\n");
|
||||||
func = (void *)lkdtm_increment_int;
|
lkdtm_indirect_call((void *)lkdtm_increment_int);
|
||||||
func(&called_count);
|
|
||||||
|
|
||||||
pr_err("FAIL: survived mismatched prototype function call!\n");
|
pr_err("FAIL: survived mismatched prototype function call!\n");
|
||||||
pr_expected_config(CONFIG_CFI_CLANG);
|
pr_expected_config(CONFIG_CFI_CLANG);
|
||||||
|
|
Loading…
Add table
Reference in a new issue