mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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 <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-21-samitolvanen@google.com
This commit is contained in:
		
							parent
							
								
									ca7e10bff1
								
							
						
					
					
						commit
						ccace936ee
					
				
					 3 changed files with 17 additions and 3 deletions
				
			
		| 
						 | 
					@ -6,6 +6,7 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <linux/linkage.h>
 | 
					#include <linux/linkage.h>
 | 
				
			||||||
 | 
					#include <linux/cfi_types.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.file "blowfish-x86_64-asm.S"
 | 
					.file "blowfish-x86_64-asm.S"
 | 
				
			||||||
.text
 | 
					.text
 | 
				
			||||||
| 
						 | 
					@ -141,7 +142,7 @@ SYM_FUNC_START(__blowfish_enc_blk)
 | 
				
			||||||
	RET;
 | 
						RET;
 | 
				
			||||||
SYM_FUNC_END(__blowfish_enc_blk)
 | 
					SYM_FUNC_END(__blowfish_enc_blk)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SYM_FUNC_START(blowfish_dec_blk)
 | 
					SYM_TYPED_FUNC_START(blowfish_dec_blk)
 | 
				
			||||||
	/* input:
 | 
						/* input:
 | 
				
			||||||
	 *	%rdi: ctx
 | 
						 *	%rdi: ctx
 | 
				
			||||||
	 *	%rsi: dst
 | 
						 *	%rsi: dst
 | 
				
			||||||
| 
						 | 
					@ -332,7 +333,7 @@ SYM_FUNC_START(__blowfish_enc_blk_4way)
 | 
				
			||||||
	RET;
 | 
						RET;
 | 
				
			||||||
SYM_FUNC_END(__blowfish_enc_blk_4way)
 | 
					SYM_FUNC_END(__blowfish_enc_blk_4way)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SYM_FUNC_START(blowfish_dec_blk_4way)
 | 
					SYM_TYPED_FUNC_START(blowfish_dec_blk_4way)
 | 
				
			||||||
	/* input:
 | 
						/* input:
 | 
				
			||||||
	 *	%rdi: ctx
 | 
						 *	%rdi: ctx
 | 
				
			||||||
	 *	%rsi: dst
 | 
						 *	%rsi: dst
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,18 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* __ASSEMBLY__ */
 | 
					#endif /* __ASSEMBLY__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define __CFI_TYPE(name)					\
 | 
				
			||||||
 | 
						SYM_START(__cfi_##name, SYM_L_LOCAL, SYM_A_NONE)	\
 | 
				
			||||||
 | 
						.fill 11, 1, 0x90 ASM_NL				\
 | 
				
			||||||
 | 
						.byte 0xb8 ASM_NL					\
 | 
				
			||||||
 | 
						.long __kcfi_typeid_##name ASM_NL			\
 | 
				
			||||||
 | 
						SYM_FUNC_END(__cfi_##name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
 | 
				
			||||||
 | 
					#define SYM_TYPED_FUNC_START(name)				\
 | 
				
			||||||
 | 
						SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)	\
 | 
				
			||||||
 | 
						ENDBR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* SYM_FUNC_START -- use for global functions */
 | 
					/* SYM_FUNC_START -- use for global functions */
 | 
				
			||||||
#define SYM_FUNC_START(name)				\
 | 
					#define SYM_FUNC_START(name)				\
 | 
				
			||||||
	SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)	\
 | 
						SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)	\
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@
 | 
				
			||||||
/* Copyright 2002 Andi Kleen */
 | 
					/* Copyright 2002 Andi Kleen */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <linux/linkage.h>
 | 
					#include <linux/linkage.h>
 | 
				
			||||||
 | 
					#include <linux/cfi_types.h>
 | 
				
			||||||
#include <asm/errno.h>
 | 
					#include <asm/errno.h>
 | 
				
			||||||
#include <asm/cpufeatures.h>
 | 
					#include <asm/cpufeatures.h>
 | 
				
			||||||
#include <asm/alternative.h>
 | 
					#include <asm/alternative.h>
 | 
				
			||||||
| 
						 | 
					@ -27,7 +28,7 @@
 | 
				
			||||||
 * Output:
 | 
					 * Output:
 | 
				
			||||||
 * rax original destination
 | 
					 * rax original destination
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
SYM_FUNC_START(__memcpy)
 | 
					SYM_TYPED_FUNC_START(__memcpy)
 | 
				
			||||||
	ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
 | 
						ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \
 | 
				
			||||||
		      "jmp memcpy_erms", X86_FEATURE_ERMS
 | 
							      "jmp memcpy_erms", X86_FEATURE_ERMS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue