arm64: Add types to indirect called assembly functions
authorSami Tolvanen <samitolvanen@google.com>
Thu, 8 Sep 2022 21:54:51 +0000 (14:54 -0700)
committerKees Cook <keescook@chromium.org>
Mon, 26 Sep 2022 17:13:13 +0000 (10:13 -0700)
With CONFIG_CFI_CLANG, assembly functions indirectly called from C
code must be annotated with type identifiers to pass CFI checking. Use
SYM_TYPED_FUNC_START for the indirectly called functions, and ensure
we emit `bti c` also with SYM_TYPED_FUNC_START.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>
Tested-by: Nathan Chancellor <nathan@kernel.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-10-samitolvanen@google.com
arch/arm64/crypto/ghash-ce-core.S
arch/arm64/crypto/sm3-ce-core.S
arch/arm64/include/asm/linkage.h
arch/arm64/kernel/cpu-reset.S
arch/arm64/mm/proc.S

index 7868330dd54ec2f22faf815b1568abfd339787ce..ebe5558929b7bba68fa2802906fbf88a759de077 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/cfi_types.h>
 #include <asm/assembler.h>
 
        SHASH           .req    v0
@@ -350,11 +351,11 @@ CPU_LE(   rev64           T1.16b, T1.16b  )
         * void pmull_ghash_update(int blocks, u64 dg[], const char *src,
         *                         struct ghash_key const *k, const char *head)
         */
-SYM_FUNC_START(pmull_ghash_update_p64)
+SYM_TYPED_FUNC_START(pmull_ghash_update_p64)
        __pmull_ghash   p64
 SYM_FUNC_END(pmull_ghash_update_p64)
 
-SYM_FUNC_START(pmull_ghash_update_p8)
+SYM_TYPED_FUNC_START(pmull_ghash_update_p8)
        __pmull_ghash   p8
 SYM_FUNC_END(pmull_ghash_update_p8)
 
index ef97d3187cb7fce869b4165b0e8f3dc64b8e7325..ca70cfacd0d0aa094a9a2d4e7088c559cdde9276 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/cfi_types.h>
 #include <asm/assembler.h>
 
        .irp            b, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
@@ -73,7 +74,7 @@
         *                       int blocks)
         */
        .text
-SYM_FUNC_START(sm3_ce_transform)
+SYM_TYPED_FUNC_START(sm3_ce_transform)
        /* load state */
        ld1             {v8.4s-v9.4s}, [x0]
        rev64           v8.4s, v8.4s
index 43f8c25b3fda655577859cf7a8ce59c1a049ed6b..1436fa1cde24d7edb0bc1b389ea8d631a4108e0f 100644 (file)
@@ -39,4 +39,8 @@
        SYM_START(name, SYM_L_WEAK, SYM_A_NONE)         \
        bti c ;
 
+#define SYM_TYPED_FUNC_START(name)                             \
+       SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)        \
+       bti c ;
+
 #endif
index 48a8af97faa9ab32eb9d29374bb7ca88288fe75f..6b752fe89745196b9d844c27810ccbdffeb3b7cf 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/cfi_types.h>
 #include <asm/assembler.h>
 #include <asm/sysreg.h>
 #include <asm/virt.h>
@@ -28,7 +29,7 @@
  * branch to what would be the reset vector. It must be executed with the
  * flat identity mapping.
  */
-SYM_CODE_START(cpu_soft_restart)
+SYM_TYPED_FUNC_START(cpu_soft_restart)
        mov_q   x12, INIT_SCTLR_EL1_MMU_OFF
        pre_disable_mmu_workaround
        /*
@@ -47,6 +48,6 @@ SYM_CODE_START(cpu_soft_restart)
        mov     x1, x3                          // arg1
        mov     x2, x4                          // arg2
        br      x8
-SYM_CODE_END(cpu_soft_restart)
+SYM_FUNC_END(cpu_soft_restart)
 
 .popsection
index 7837a69524c530deead50aab490ccadd686d19f9..8b9f419fcad99b5b0d7dd99f2f3ebf87f0ec2070 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/init.h>
 #include <linux/linkage.h>
 #include <linux/pgtable.h>
+#include <linux/cfi_types.h>
 #include <asm/assembler.h>
 #include <asm/asm-offsets.h>
 #include <asm/asm_pointer_auth.h>
@@ -185,7 +186,7 @@ SYM_FUNC_END(cpu_do_resume)
  * This is the low-level counterpart to cpu_replace_ttbr1, and should not be
  * called by anything else. It can only be executed from a TTBR0 mapping.
  */
-SYM_FUNC_START(idmap_cpu_replace_ttbr1)
+SYM_TYPED_FUNC_START(idmap_cpu_replace_ttbr1)
        save_and_disable_daif flags=x2
 
        __idmap_cpu_set_reserved_ttbr1 x1, x3
@@ -253,7 +254,7 @@ SYM_FUNC_END(idmap_cpu_replace_ttbr1)
 SYM_DATA(__idmap_kpti_flag, .long 1)
        .popsection
 
-SYM_FUNC_START(idmap_kpti_install_ng_mappings)
+SYM_TYPED_FUNC_START(idmap_kpti_install_ng_mappings)
        cpu             .req    w0
        temp_pte        .req    x0
        num_cpus        .req    w1