mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-03 18:20:25 +02:00 
			
		
		
		
	objtool: Add straight-line-speculation validation
Teach objtool to validate the straight-line-speculation constraints: - speculation trap after indirect calls - speculation trap after RET Notable: when an instruction is annotated RETPOLINE_SAFE, indicating speculation isn't a problem, also don't care about sls for that instruction. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20211204134908.023037659@infradead.org
This commit is contained in:
		
							parent
							
								
									b17c2baa30
								
							
						
					
					
						commit
						1cc1e4c8aa
					
				
					 5 changed files with 27 additions and 6 deletions
				
			
		| 
						 | 
					@ -531,6 +531,11 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case 0xcc:
 | 
				
			||||||
 | 
							/* int3 */
 | 
				
			||||||
 | 
							*type = INSN_TRAP;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	case 0xe3:
 | 
						case 0xe3:
 | 
				
			||||||
		/* jecxz/jrcxz */
 | 
							/* jecxz/jrcxz */
 | 
				
			||||||
		*type = INSN_JUMP_CONDITIONAL;
 | 
							*type = INSN_JUMP_CONDITIONAL;
 | 
				
			||||||
| 
						 | 
					@ -697,10 +702,10 @@ const char *arch_ret_insn(int len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	static const char ret[5][5] = {
 | 
						static const char ret[5][5] = {
 | 
				
			||||||
		{ BYTE_RET },
 | 
							{ BYTE_RET },
 | 
				
			||||||
		{ BYTE_RET, BYTES_NOP1 },
 | 
							{ BYTE_RET, 0xcc },
 | 
				
			||||||
		{ BYTE_RET, BYTES_NOP2 },
 | 
							{ BYTE_RET, 0xcc, BYTES_NOP1 },
 | 
				
			||||||
		{ BYTE_RET, BYTES_NOP3 },
 | 
							{ BYTE_RET, 0xcc, BYTES_NOP2 },
 | 
				
			||||||
		{ BYTE_RET, BYTES_NOP4 },
 | 
							{ BYTE_RET, 0xcc, BYTES_NOP3 },
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (len < 1 || len > 5) {
 | 
						if (len < 1 || len > 5) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@
 | 
				
			||||||
#include <objtool/objtool.h>
 | 
					#include <objtool/objtool.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
 | 
					bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
 | 
				
			||||||
     validate_dup, vmlinux, mcount, noinstr, backup;
 | 
					     validate_dup, vmlinux, mcount, noinstr, backup, sls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char * const check_usage[] = {
 | 
					static const char * const check_usage[] = {
 | 
				
			||||||
	"objtool check [<options>] file.o",
 | 
						"objtool check [<options>] file.o",
 | 
				
			||||||
| 
						 | 
					@ -45,6 +45,7 @@ const struct option check_options[] = {
 | 
				
			||||||
	OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
 | 
						OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
 | 
				
			||||||
	OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"),
 | 
						OPT_BOOLEAN('M', "mcount", &mcount, "generate __mcount_loc"),
 | 
				
			||||||
	OPT_BOOLEAN('B', "backup", &backup, "create .orig files before modification"),
 | 
						OPT_BOOLEAN('B', "backup", &backup, "create .orig files before modification"),
 | 
				
			||||||
 | 
						OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"),
 | 
				
			||||||
	OPT_END(),
 | 
						OPT_END(),
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3084,6 +3084,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 | 
				
			||||||
		switch (insn->type) {
 | 
							switch (insn->type) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case INSN_RETURN:
 | 
							case INSN_RETURN:
 | 
				
			||||||
 | 
								if (next_insn && next_insn->type == INSN_TRAP) {
 | 
				
			||||||
 | 
									next_insn->ignore = true;
 | 
				
			||||||
 | 
								} else if (sls && !insn->retpoline_safe) {
 | 
				
			||||||
 | 
									WARN_FUNC("missing int3 after ret",
 | 
				
			||||||
 | 
										  insn->sec, insn->offset);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			return validate_return(func, insn, &state);
 | 
								return validate_return(func, insn, &state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case INSN_CALL:
 | 
							case INSN_CALL:
 | 
				
			||||||
| 
						 | 
					@ -3127,6 +3133,14 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case INSN_JUMP_DYNAMIC:
 | 
							case INSN_JUMP_DYNAMIC:
 | 
				
			||||||
 | 
								if (next_insn && next_insn->type == INSN_TRAP) {
 | 
				
			||||||
 | 
									next_insn->ignore = true;
 | 
				
			||||||
 | 
								} else if (sls && !insn->retpoline_safe) {
 | 
				
			||||||
 | 
									WARN_FUNC("missing int3 after indirect jump",
 | 
				
			||||||
 | 
										  insn->sec, insn->offset);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								/* fallthrough */
 | 
				
			||||||
		case INSN_JUMP_DYNAMIC_CONDITIONAL:
 | 
							case INSN_JUMP_DYNAMIC_CONDITIONAL:
 | 
				
			||||||
			if (is_sibling_call(insn)) {
 | 
								if (is_sibling_call(insn)) {
 | 
				
			||||||
				ret = validate_sibling_call(file, insn, &state);
 | 
									ret = validate_sibling_call(file, insn, &state);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@ enum insn_type {
 | 
				
			||||||
	INSN_CLAC,
 | 
						INSN_CLAC,
 | 
				
			||||||
	INSN_STD,
 | 
						INSN_STD,
 | 
				
			||||||
	INSN_CLD,
 | 
						INSN_CLD,
 | 
				
			||||||
 | 
						INSN_TRAP,
 | 
				
			||||||
	INSN_OTHER,
 | 
						INSN_OTHER,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern const struct option check_options[];
 | 
					extern const struct option check_options[];
 | 
				
			||||||
extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
 | 
					extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
 | 
				
			||||||
            validate_dup, vmlinux, mcount, noinstr, backup;
 | 
					            validate_dup, vmlinux, mcount, noinstr, backup, sls;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
 | 
					extern int cmd_parse_options(int argc, const char **argv, const char * const usage[]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue