Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp250017pxk; Thu, 17 Sep 2020 01:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+tKRGfbkgE6GEsDGoH5g0FAt/K2tAZ9V5QF13NJ8fNKsmIfetC3m8N5ksA2nsowXnZS+P X-Received: by 2002:a50:8881:: with SMTP id d1mr32114749edd.306.1600332683094; Thu, 17 Sep 2020 01:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600332683; cv=none; d=google.com; s=arc-20160816; b=B63ZfLKA4DvK/BhBnNTpmt8E02tta2vQ4vee2jWs7KP04MxB/cz8qNyJ9GxpOzkmlh nipKPEPN/xZUDeYYdcoBaYXNVGV4zCzAdHdB/bIgfIr91ZsHReZidVKoFGBbSoi6i9c0 3jzY5NnMu0QG+PcNzC5TfdnKg2jrAZASwkfb0hiQkK1rOYoVw4p+Q0T+lSTqVuqFQDUi iutTlzeLprxEZtLwrh62MA1U7tqTmczzh/AKKF9vhQ6NGfvdYTkh24NxXGv4kxnhPyEi Dbruvk1gY0CiF6/DO+jWql7l7Ud9kgKE+dNnO/Y6UOgbAMEtK7nVdNA1ZVPkjNRkucZ0 aCHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oRBptC4sIuVYjiXcshYa7R4ABF1BI07mPrwI7LaWCH4=; b=MMG2lC9rhY1bC86+Ns222/P8JATeFBihaMueYdgFffGe5OzLFo9eJUuyvSlndngqu4 EjEzFITgFgTHrmlGd6ZVfZUrfJj/RldNL6NSzuzCK/ttoSJ3tH5yXje0N3+lALuXpSCh oeAU5Yl+L7Mr6cq6sKIdTLAUQvChIYWXl3gbZhN6P6fBcKhf907QgpqyLAQ5OUJuwvaA 0pIz7ZOFzYW35KAV9H3zU2XongjT7aqTUPuWpwG/iDXnE7P9/1/5R3BzPKM2FeY3w6nH PjLjwKfmesdAVmIYlbqBSyX3DJpBDK6D7NK+rLpMIFFAQNb3gs605A/mVkgX3NNPBNWP hDxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GfuKs9Cu; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb19si13372504ejb.589.2020.09.17.01.50.59; Thu, 17 Sep 2020 01:51:23 -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=@gmail.com header.s=20161025 header.b=GfuKs9Cu; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgIQItT (ORCPT + 99 others); Thu, 17 Sep 2020 04:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726368AbgIQItN (ORCPT ); Thu, 17 Sep 2020 04:49:13 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 218B7C06174A for ; Thu, 17 Sep 2020 01:49:12 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id a17so1135992wrn.6 for ; Thu, 17 Sep 2020 01:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oRBptC4sIuVYjiXcshYa7R4ABF1BI07mPrwI7LaWCH4=; b=GfuKs9CupTvPHUeC0pLyByeMS9VlPteXtpVvw3eVnMktD3hVWlOva70eptZTmo2p4F syBEHJPfteXVSsVWEqvacoBo9SExvMS+GMyjhDJ4wmfFvZ8pXzclt43WjULaVPUC0QgI 1wLw5SvIvDg+o5mTxDuNVaWtM8eqdxF9XJ8jCGrX7O9VFmVoi3WOOdbagw+2mfNnF4kp L+X2xOwfiIFPtAjKtau93s5E2/PGD+cn5geBJ0bF1rq1m7yM461/PAXteqxV/5Cdo1UE +cfkyhTugAKAKgqlbiNbz03TyPVT/B7OZjclKKoSf9tlUJYAn4rGdc5IWKri9P0rYKcY 4KhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oRBptC4sIuVYjiXcshYa7R4ABF1BI07mPrwI7LaWCH4=; b=Ojny8L0MKoBafsGik4zj7xnG+5EJEGkDbLlYieqJ+iw0L+ThR/iqTQ8vsWG9H9RuzE F5KQ47RddZ5IgWpvOUZA3ajnz9dspX3jPjs1N+pt6LKI89scPXnOmEBviEdKobOpVUXf S2ecbh9WrK4BxfEKaVqRpDEC8q+8YZJ/WL7uXlLVh66goKh/VYvQ2QxJ3vDRCxA8ePD0 35S8EhfjsCefMEZxsYn/zlYM3XYi3Q/2PQGU+Cy3mhjATnXeXD9nD/ZR5wI+GRJEm5JK +3zAKXcVVnYACJduR0p8UhhxwqTutm/m45RD3BNHOx6g1uwDs+z2gn5AulD4WAORDz+w A7Jg== X-Gm-Message-State: AOAM5303gngtAF/UEn/rCvMsY8IzRWUV2wb4C7zghQMo1HmbVYy00I+e /ZdSAkme3HICkMjM79kVETa87E4nCKb2iM6NZ5M= X-Received: by 2002:adf:efc9:: with SMTP id i9mr32318001wrp.187.1600332550694; Thu, 17 Sep 2020 01:49:10 -0700 (PDT) Received: from localhost.localdomain ([2a02:a58:8532:8700:329c:23ff:fea8:6c81]) by smtp.gmail.com with ESMTPSA id t22sm11973299wmt.1.2020.09.17.01.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 01:49:10 -0700 (PDT) From: Ilie Halip To: linux-kernel@vger.kernel.org Cc: Ilie Halip , Nick Desaulniers , Rong Chen , Marco Elver , Philip Li , Borislav Petkov , kasan-dev@googlegroups.com, x86@kernel.org, clang-built-linux@googlegroups.com, Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor Subject: [PATCH] objtool: ignore unreachable trap after call to noreturn functions Date: Thu, 17 Sep 2020 11:49:04 +0300 Message-Id: <20200917084905.1647262-1-ilie.halip@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. objtool silences similar warnings (trap after dead end instructions), 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 Signed-off-by: Ilie Halip --- 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 e034a8f24f46..eddf8bf16b05 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2612,9 +2612,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; @@ -2639,8 +2640,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). + * CONFIG_UBSAN_TRAP 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))) @@ -2767,7 +2771,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); -- 2.25.1