Skip to content

Commit ccace93

Browse files
samitolvanenkees
authored andcommitted
x86: Add types to indirectly called assembly functions
With CONFIG_CFI_CLANG, assembly functions indirectly called from C code must be annotated with type identifiers to pass CFI checking. Define the __CFI_TYPE helper macro to match the compiler generated function preamble, and ensure SYM_TYPED_FUNC_START also emits ENDBR with IBT. Signed-off-by: Sami Tolvanen <[email protected]> Reviewed-by: Kees Cook <[email protected]> Tested-by: Kees Cook <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ca7e10b commit ccace93

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

arch/x86/crypto/blowfish-x86_64-asm_64.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <linux/linkage.h>
9+
#include <linux/cfi_types.h>
910

1011
.file "blowfish-x86_64-asm.S"
1112
.text
@@ -141,7 +142,7 @@ SYM_FUNC_START(__blowfish_enc_blk)
141142
RET;
142143
SYM_FUNC_END(__blowfish_enc_blk)
143144

144-
SYM_FUNC_START(blowfish_dec_blk)
145+
SYM_TYPED_FUNC_START(blowfish_dec_blk)
145146
/* input:
146147
* %rdi: ctx
147148
* %rsi: dst
@@ -332,7 +333,7 @@ SYM_FUNC_START(__blowfish_enc_blk_4way)
332333
RET;
333334
SYM_FUNC_END(__blowfish_enc_blk_4way)
334335

335-
SYM_FUNC_START(blowfish_dec_blk_4way)
336+
SYM_TYPED_FUNC_START(blowfish_dec_blk_4way)
336337
/* input:
337338
* %rdi: ctx
338339
* %rsi: dst

arch/x86/include/asm/linkage.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343

4444
#endif /* __ASSEMBLY__ */
4545

46+
#define __CFI_TYPE(name) \
47+
SYM_START(__cfi_##name, SYM_L_LOCAL, SYM_A_NONE) \
48+
.fill 11, 1, 0x90 ASM_NL \
49+
.byte 0xb8 ASM_NL \
50+
.long __kcfi_typeid_##name ASM_NL \
51+
SYM_FUNC_END(__cfi_##name)
52+
53+
/* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
54+
#define SYM_TYPED_FUNC_START(name) \
55+
SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \
56+
ENDBR
57+
4658
/* SYM_FUNC_START -- use for global functions */
4759
#define SYM_FUNC_START(name) \
4860
SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \

arch/x86/lib/memcpy_64.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright 2002 Andi Kleen */
33

44
#include <linux/linkage.h>
5+
#include <linux/cfi_types.h>
56
#include <asm/errno.h>
67
#include <asm/cpufeatures.h>
78
#include <asm/alternative.h>
@@ -27,7 +28,7 @@
2728
* Output:
2829
* rax original destination
2930
*/
30-
SYM_FUNC_START(__memcpy)
31+
SYM_TYPED_FUNC_START(__memcpy)
3132
ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
3233
"jmp memcpy_erms", X86_FEATURE_ERMS
3334

0 commit comments

Comments
 (0)