Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3292659pxk; Mon, 21 Sep 2020 09:52:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1YbHZRDf5mawvlGSoaf/0ON6ZgBuEGoz5clrJ6jfhrZjGxZltFBUv3XjTmMs6dt2dpfIv X-Received: by 2002:aa7:dc16:: with SMTP id b22mr590134edu.252.1600707153727; Mon, 21 Sep 2020 09:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707153; cv=none; d=google.com; s=arc-20160816; b=uiuOGOpbtniVOWg9zA72G6p1oB0bNF8t9A+TvnOazj/oPxihAEM08qToospXHKYnED O/mXDTFYhl4NGbAynPNX2MioY+OyvZkQK9yW+cRpvLpi0Z0e5CuMjiyQAL8ZJ3ccJcSa J8/hONrin6PjstXJ99t74jhv/NJZ13NRVqjFzHjROnvlIBADiJDfOfX2pTwHuYSYVAJA tofATxGGzwsdRrtTVUC3sTzW6g4RMBUozrU49DWBBKaCDbSIWQejXxN55OXKOPPEL6+6 WKj4VXQonLjUjpGHzYWvEL4zqTeYD08Oz978bkrZc0R9ZUyN5nIfmuuwxFuQqjYJC9oi XcLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=gVfzDlgm3AjlhLPfD/PKu06jc0A49KijvnhM+NCvAtE=; b=jyU0hxrMy6p4a5bFdvLYxUGvrlGhSEhJHtUmLNbAqiqR3rSG5R0DcSbjZ6tX5aszm4 EMQ+C2Mn2+zN2fMcmZG0vplfFyoIfrOycfjEMqmstOOQR8fQfdkRmuhi+jxrtUCR0L6z R/IPE8IDJJtmtpWBlbNzNMeD9Av8rTJNG68SMjSc6+lhXO52juwLbjJNiCRa22Td2N+b L3a45Qw8lP9vgUCuwsK/sLA5Pww7N7HUsjObd/W4d7+zQlD2f6sfgqR20+5PCSXfivFg CvhLrs3ivI/ndR39ph/NxJmSMygETfvf56SvN1UC4zfdVGqsiR8ZCzZ7THpb/m9+BiQI Cb5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lA42DkUt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rPGj3exW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si8735447ejd.363.2020.09.21.09.52.09; Mon, 21 Sep 2020 09:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=lA42DkUt; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=rPGj3exW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730094AbgIUQvR (ORCPT + 99 others); Mon, 21 Sep 2020 12:51:17 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:52704 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730074AbgIUQvP (ORCPT ); Mon, 21 Sep 2020 12:51:15 -0400 Date: Mon, 21 Sep 2020 16:51:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600707072; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gVfzDlgm3AjlhLPfD/PKu06jc0A49KijvnhM+NCvAtE=; b=lA42DkUts5sGVQjJ9hli9afXyjP6AyShGvDFmxY40yI4uiUF3LiwsJcyWADUvyglJxqYBX O1T/ZPkNVUWWT+sSW7rg99p96PXYVBCVzAHAp4BDQWkXiIJ8t4259X3KDTi9uhzd/9/Hyz aGw/OuKO+tMHNDylVyjKLmJnlP53pu2ZXT1oOZ8yfzLKtq4EvZOAsfRHfRTIc7NStD3kLn luEVfHherWJz9nL5855uRU1xG8/dNTvopVkynFgDtgEdEbcTIDP+eoP07ASK5/FrbAEOm0 j+VfVI30IKO2zCGzswLXCZUSW7OCBcQkdhOL/Kc4TQJpwG1wAbdmSRQytJrVjw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600707072; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gVfzDlgm3AjlhLPfD/PKu06jc0A49KijvnhM+NCvAtE=; b=rPGj3exW2Dhoz0IZpgLvk7sfYpVIILlwL7wmucTl7btJpa8QgCxx0KH1xHV8x1xQu3N3D7 vlOPZwa/+j/uIPDg== From: "tip-bot2 for Ilie Halip" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Ignore unreachable trap after call to noreturn functions Cc: Nick Desaulniers , Rong Chen , Marco Elver , Philip Li , Borislav Petkov , kasan-dev@googlegroups.com, x86@kernel.org, clang-built-linux@googlegroups.com, kbuild test robot , Ilie Halip , Sedat Dilek , Josh Poimboeuf , LKML In-Reply-To: References: MIME-Version: 1.0 Message-ID: <160070707105.15536.14094674309505985856.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the objtool/core branch of tip: Commit-ID: 14db1f0a93331d0958e90da522c429ff0890d2d6 Gitweb: https://git.kernel.org/tip/14db1f0a93331d0958e90da522c429ff0890d2d6 Author: Ilie Halip AuthorDate: Sat, 19 Sep 2020 09:41:18 +03:00 Committer: Josh Poimboeuf CommitterDate: Mon, 21 Sep 2020 10:20:10 -05:00 objtool: Ignore unreachable trap after call to noreturn functions With CONFIG_UBSAN_TRAP enabled, the compiler may insert a trap instruction after a call to a noreturn function. In this case, objtool warns that the UD2 instruction is unreachable. This is a behavior seen with Clang, from the oldest version capable of building the mainline x64_64 kernel (9.0), to the latest experimental version (12.0). Objtool silences similar warnings (trap after dead end instructions), so so expand that check to include dead end functions. Cc: Nick Desaulniers Cc: Rong Chen Cc: Marco Elver Cc: Philip Li Cc: Borislav Petkov Cc: kasan-dev@googlegroups.com Cc: x86@kernel.org Cc: clang-built-linux@googlegroups.com BugLink: https://github.com/ClangBuiltLinux/linux/issues/1148 Link: https://lore.kernel.org/lkml/CAKwvOdmptEpi8fiOyWUo=AiZJiX+Z+VHJOM2buLPrWsMTwLnyw@mail.gmail.com Suggested-by: Nick Desaulniers Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers Reported-by: kbuild test robot Signed-off-by: Ilie Halip Tested-by: Sedat Dilek Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index a4796e3..2df9f76 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2638,9 +2638,10 @@ static bool is_ubsan_insn(struct instruction *insn) "__ubsan_handle_builtin_unreachable")); } -static bool ignore_unreachable_insn(struct instruction *insn) +static bool ignore_unreachable_insn(struct objtool_file *file, struct instruction *insn) { int i; + struct instruction *prev_insn; if (insn->ignore || insn->type == INSN_NOP) return true; @@ -2668,8 +2669,11 @@ static bool ignore_unreachable_insn(struct instruction *insn) * __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). + * + * It may also insert a UD2 after calling a __noreturn function. */ - if (list_prev_entry(insn, list)->dead_end && + prev_insn = list_prev_entry(insn, list); + if ((prev_insn->dead_end || dead_end_function(file, prev_insn->call_dest)) && (insn->type == INSN_BUG || (insn->type == INSN_JUMP_UNCONDITIONAL && insn->jump_dest && insn->jump_dest->type == INSN_BUG))) @@ -2796,7 +2800,7 @@ static int validate_reachable_instructions(struct objtool_file *file) return 0; for_each_insn(file, insn) { - if (insn->visited || ignore_unreachable_insn(insn)) + if (insn->visited || ignore_unreachable_insn(file, insn)) continue; WARN_FUNC("unreachable instruction", insn->sec, insn->offset);