Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp568750ybz; Fri, 24 Apr 2020 05:36:14 -0700 (PDT) X-Google-Smtp-Source: APiQypKfsoxJH4VfpVb47XppCxrLJJ5Zi4k8SSkEPTycoi2Dzbedtk34PPS5gRukyp/73dsGXlIt X-Received: by 2002:a17:906:4ecb:: with SMTP id i11mr6627718ejv.79.1587731774546; Fri, 24 Apr 2020 05:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587731774; cv=none; d=google.com; s=arc-20160816; b=TbNtygd/Zab6IXX3fGpV8l7plsDC5oPVPcnrb529qArh97ZdnvOmJbniK+0ER6VYtE IzyQNhCzWx3gjWejvxl9uwbpz4pYYre67sBWxab9qJsS8IJrHa2VL712T2/mFs0NbqVY b2fHWJicGY5UPxZYV4jvqM+BzBLcVAl4lgZBmqTwdLDr1aFDRg5ICb99tqfJj53Vx4PW 4uvzo/864k97zjadck9t81k7xX4KjPwvD9Xc7Jk+YHeSBahnCWFEuZljCOSSW/v4xrdV 9JQ+8KaRT2GWRXFNQQyM/UJym2fQ2g9UBy0nuzGWXMirvRKBrWjxEi7Aze3zFdmwVxzo vUMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uT9WJ0UUmTrbkAWEkSkps5i4Xj9JH747zQ3gVCXknAk=; b=CTEwMIknyCwt4wdTcbDT0KtzXvFIRwyiBY2gRpl+FJedWOSyGEPwKcxgTVLNfxN6bD CSjWPLwgR0YxsGmb/38nbimIgntE1Pwu68yzVPZAFiD/GnlETtFyPN02s1ATJNeFgADM TF0zjCgu8fexlFIcLWf4z2/JPUEHTkdyAFrx5twBqiKUzBCHYyu2OmGk1UbYfZZ5lAn8 qra5lAnj+EE5Os4rKoPpWE52u4p0x767+NBApK8M8BRMV+z7ZMb1s8aWXUxbV0AjBj4O oTU9uQEAR2oWC4pGQ2mFh998Mtkkl1xwvuZZpbv0KjwjoRxzNH+uZdAG5pDDrRR0J0iW 8f/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MLe3RMcV; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n20si3052484ejr.443.2020.04.24.05.35.50; Fri, 24 Apr 2020 05:36:14 -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=@kernel.org header.s=default header.b=MLe3RMcV; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728431AbgDXMcT (ORCPT + 99 others); Fri, 24 Apr 2020 08:32:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:52390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727781AbgDXMXA (ORCPT ); Fri, 24 Apr 2020 08:23:00 -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 B61A6215A4; Fri, 24 Apr 2020 12:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587730979; bh=f5gA1/aIFeOtSaG/MyaRYS8peF9JIhvDtG2xbcm4O/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MLe3RMcVtsKRqeIjgM9+AemRRvSxmiIH2QVLhIFA/8e3QJ44mE6VHz0MDyc6Bf+o3 oxey8TVOsHa0OElroGC+Q/+EF4K1oK0Kfji+tz1cmaZIYMKfjG1ysAR+ERWrugoKsI 4oTlKz+e/JNlMpfst3do8XafGyqvXGoc5QQ1fz9c= 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 5.6 19/38] objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings Date: Fri, 24 Apr 2020 08:22:17 -0400 Message-Id: <20200424122237.9831-19-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424122237.9831-1-sashal@kernel.org> References: <20200424122237.9831-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 2b765bbbef922..95c485d3d4d83 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2307,14 +2307,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