Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp673582ybz; Fri, 1 May 2020 06:35:30 -0700 (PDT) X-Google-Smtp-Source: APiQypKK7eu6KMtN0ZoK0kIxnxs9ANSchqWCbUGBYMucqlxv5H56oQaTKKsVfMl/+827PXbNxaCG X-Received: by 2002:a05:6402:333:: with SMTP id q19mr3721065edw.186.1588340129817; Fri, 01 May 2020 06:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588340129; cv=none; d=google.com; s=arc-20160816; b=PH0CyUXXManL5zPphRi854HuFzHDpvKahiPfK6IhQ9ZuGApcty57BEWJgTFq2m2ZmZ sc9ZAaedb3+l3h2bGVWKOsMlZuJeCu+OYEtXXBZkxkv58ziTeEyv4wx0jsTHr6O6EBVP AmKjB35XqD/IozpOokyBw32PxlO3cM9TcIVQJTUFymWKaeFvmEYGU3HoPl5p9T4YZfvi m2cPWGyYGADrqPW03c6PFs/xUR43Abt4RfB8uRP7vbcaJUfdu1xN2rU2JAG1nbGuyfRF GoqurLQabSN2OpmNpljUJqFvy08L0g+PbSIe/WhKZiLEaEQhu/GrYxWG/ZbIHtADZheC hCsg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4u8Dzwo5guEu6qappsAvycDHeaj32mdiDxTe0y8ZG0A=; b=qogCbe5325zwD3UY3sfe605Gd0sN5kTSzG6fJKT0EghhUjics6RBgH4A/sefYvVJ2o 3+nZGzkOrxvgKnBKYtw8VHfAk5yq1j8oVo9zKZMp7YUidcvjPNN7i0vK8oWZhksr0WC+ KkO0HUhM8mMfPujHSiWxCME3rM0EDn+k/RD9wn6eoaULMAqSZfDLU+XcG5urFA2BeWRu QHcLBRcEZJPf797qPcv+C6u8xORiSKvYe3YXdvjS0CWAHg/wZWBPlN1b0A/Y6MIevN6Z JVs+pmEEenkqHOOhuXSkS6zQl2SPFuq2dRL/I/vaV3PWLIKSSuZpgUXlePPxqpvCnyaL yx2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xuW27QwM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p1si1653195ejw.313.2020.05.01.06.35.06; Fri, 01 May 2020 06:35:29 -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=xuW27QwM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730005AbgEANao (ORCPT + 99 others); Fri, 1 May 2020 09:30:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:54840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730000AbgEANam (ORCPT ); Fri, 1 May 2020 09:30:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB80520757; Fri, 1 May 2020 13:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588339842; bh=ECf6nK1O1fTbfWY+mavzkiqe7aClD9oO4zkdv6nSnJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xuW27QwMjeKQpcfm0HB04+cIHNE+e4lNrLAp5B6o5EilrtHYj6Kn1I0grdUS4IxlL vVZeEijuQv+O9gXX6+QppupzuUH3XZyMR4X0cIAhFyTWZ4wfuRt6j8pNvIBdmneg5J 4knpjT9KKIoigtFxwn0mKmgGcslOYP9SeaAG6p8o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Randy Dunlap , Josh Poimboeuf , Borislav Petkov , Kees Cook , Miroslav Benes , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 4.9 69/80] objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings Date: Fri, 1 May 2020 15:22:03 +0200 Message-Id: <20200501131535.615149228@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501131513.810761598@linuxfoundation.org> References: <20200501131513.810761598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 db105207757bc..360845926f665 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2035,14 +2035,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