From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40F50C55194 for ; Fri, 24 Apr 2020 12:26:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19A8021473 for ; Fri, 24 Apr 2020 12:26:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587731181; bh=0GvmNt9mwFiaQ3xCIhI/I6TQsp0Zq2J3mkzA5GIG2Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ggMeCj/qvUL4bhC/yROe0NlV83TI5cd9hz/nEzYliT4sVrDBKi6TjK+zPS/HrKfEA tSXY0rpM1b1RIcFU07GY2Bp3iEE7Y0E0Kue9eun5LTd06wb3bfav1SMIjkp/AySyI8 48OsPNPfw9eUcwE4IvWvlFw7C89uqRdGBAYzZzhI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728577AbgDXMY4 (ORCPT ); Fri, 24 Apr 2020 08:24:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:55874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbgDXMYz (ORCPT ); Fri, 24 Apr 2020 08:24:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A150E21569; Fri, 24 Apr 2020 12:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587731094; bh=0GvmNt9mwFiaQ3xCIhI/I6TQsp0Zq2J3mkzA5GIG2Bs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iBu/ECY+qo5S54RnLgHN02mcuh1Uu0ZH3aRg3U44yptnBCHRCUhZ01q1quyys2wmv GxZCKuF94I/z9wFVNN0LyWd6RhRvLq6TyWAs7IfIbx6rJFNGSINOIWPv+3MGU9/yPu 5EsX9mGBpJVr3rolBms51HD38OMbyaRFtum/f3Ak= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Josh Poimboeuf , Randy Dunlap , Borislav Petkov , Kees Cook , Miroslav Benes , Peter Zijlstra , Sasha Levin Subject: [PATCH AUTOSEL 4.9 06/13] objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings Date: Fri, 24 Apr 2020 08:24:39 -0400 Message-Id: <20200424122447.10882-6-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424122447.10882-1-sashal@kernel.org> References: <20200424122447.10882-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Josh Poimboeuf [ Upstream commit bd841d6154f5f41f8a32d3c1b0bc229e326e640a ] 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 Signed-off-by: Josh Poimboeuf Signed-off-by: Borislav Petkov Reviewed-by: Kees Cook Reviewed-by: Miroslav Benes Acked-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/6653ad73c6b59c049211bd7c11ed3809c20ee9f5.1585761021.git.jpoimboe@redhat.com Signed-off-by: Sasha Levin --- tools/objtool/check.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 09782ff427d0d..a4b157dc1c45e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2038,14 +2038,27 @@ static bool ignore_unreachable_insn(struct instruction *insn) !strcmp(insn->sec->name, ".altinstr_aux")) 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 * CONFIG_UBSAN or CONFIG_KASAN. * * End the search at 5 instructions to avoid going into the weeds. */ - if (!insn->func) - return false; for (i = 0; i < 5; i++) { if (is_kasan_insn(insn) || is_ubsan_insn(insn)) -- 2.20.1