From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752337AbeBHXK1 (ORCPT ); Thu, 8 Feb 2018 18:10:27 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51992 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752018AbeBHXJ7 (ORCPT ); Thu, 8 Feb 2018 18:09:59 -0500 From: Josh Poimboeuf To: x86@kernel.org Cc: Borislav Petkov , Peter Zijlstra , Linus Torvalds , kbuild test robot , Ingo Molnar , Thomas Gleixner , linux-kernel@vger.kernel.org, Arjan van de Ven Subject: [PATCH 1/2] objtool: Fix seg fault in ignore_unreachable_insn() Date: Thu, 8 Feb 2018 17:09:25 -0600 Message-Id: In-Reply-To: References: <20180208203146.GF577@pd.tnic> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Peter Zijlstra's patch for converting WARN() to use UD2 triggered a bunch of false "unreachable instruction" warnings, which then triggered a seg fault in ignore_unreachable_insn(). The seg fault happened when it tried to dereference a NULL 'insn->func' pointer. Thanks to static_cpu_has(), some functions can jump to a non-function area in the .altinstr_aux section. That breaks ignore_unreachable_insn()'s assumption that it's always inside the original function. Make sure ignore_unreachable_insn() only follows jumps within the current function. Reported-by: Borislav Petkov Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b00b1896547e..4ec1a3bf7bf2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1899,13 +1899,19 @@ static bool ignore_unreachable_insn(struct instruction *insn) if (is_kasan_insn(insn) || is_ubsan_insn(insn)) return true; - if (insn->type == INSN_JUMP_UNCONDITIONAL && insn->jump_dest) { - insn = insn->jump_dest; - continue; + if (insn->type == INSN_JUMP_UNCONDITIONAL) { + if (insn->jump_dest && + insn->jump_dest->func == insn->func) { + insn = insn->jump_dest; + continue; + } + + break; } if (insn->offset + insn->len >= insn->func->offset + insn->func->len) break; + insn = list_next_entry(insn, list); } -- 2.14.3