mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings
CONFIG_UBSAN_TRAP causes GCC to emit a UD2 whenever it encounters an unreachable code path. This includes __builtin_unreachable(). Because the BUG() macro uses __builtin_unreachable() after it emits its own UD2, this results in a double UD2. In this case objtool rightfully detects that the second UD2 is unreachable: init/main.o: warning: objtool: repair_env_string()+0x1c8: unreachable instruction We weren't able to figure out a way to get rid of the double UD2s, so just silence the warning. Reported-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Miroslav Benes <mbenes@suse.cz> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/6653ad73c6b59c049211bd7c11ed3809c20ee9f5.1585761021.git.jpoimboe@redhat.com
This commit is contained in:
		
							parent
							
								
									8f3d9f3542
								
							
						
					
					
						commit
						bd841d6154
					
				
					 1 changed files with 15 additions and 2 deletions
				
			
		| 
						 | 
					@ -2364,14 +2364,27 @@ static bool ignore_unreachable_insn(struct instruction *insn)
 | 
				
			||||||
	    !strcmp(insn->sec->name, ".altinstr_aux"))
 | 
						    !strcmp(insn->sec->name, ".altinstr_aux"))
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!insn->func)
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * CONFIG_UBSAN_TRAP inserts a UD2 when it sees
 | 
				
			||||||
 | 
						 * __builtin_unreachable().  The BUG() macro has an unreachable() after
 | 
				
			||||||
 | 
						 * the UD2, which causes GCC's undefined trap logic to emit another UD2
 | 
				
			||||||
 | 
						 * (or occasionally a JMP to UD2).
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (list_prev_entry(insn, list)->dead_end &&
 | 
				
			||||||
 | 
						    (insn->type == INSN_BUG ||
 | 
				
			||||||
 | 
						     (insn->type == INSN_JUMP_UNCONDITIONAL &&
 | 
				
			||||||
 | 
						      insn->jump_dest && insn->jump_dest->type == INSN_BUG)))
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Check if this (or a subsequent) instruction is related to
 | 
						 * Check if this (or a subsequent) instruction is related to
 | 
				
			||||||
	 * CONFIG_UBSAN or CONFIG_KASAN.
 | 
						 * CONFIG_UBSAN or CONFIG_KASAN.
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * End the search at 5 instructions to avoid going into the weeds.
 | 
						 * End the search at 5 instructions to avoid going into the weeds.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (!insn->func)
 | 
					 | 
				
			||||||
		return false;
 | 
					 | 
				
			||||||
	for (i = 0; i < 5; i++) {
 | 
						for (i = 0; i < 5; i++) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (is_kasan_insn(insn) || is_ubsan_insn(insn))
 | 
							if (is_kasan_insn(insn) || is_ubsan_insn(insn))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue