Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp884650ybb; Wed, 1 Apr 2020 11:25:11 -0700 (PDT) X-Google-Smtp-Source: APiQypLalvA4roQEEuMGnfd3zh79FotF8oke9XSct2Q9PifcpjWJ9vRb6kxlHY/3w420dKGwmQs0 X-Received: by 2002:a9d:58c2:: with SMTP id s2mr3951060oth.100.1585765510830; Wed, 01 Apr 2020 11:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585765510; cv=none; d=google.com; s=arc-20160816; b=zME31gqMTaxL+ZTs+bEeSo5wpRzAQSnpjjy8YuLLRRuyEhOIAqmzDakE8iMA6bNrMY +NXIAu8AOhEI0ySJeOOe1q+JiktjSkjG4u/1hiEYVt0KZPeCg52nGE1OzRzKomnOCd5Y UC5rgr2Nmo7lrVRsEc/vJeclxB1ZjtwzpTVARkCESNv8b6pvpJtMHy/ZGYwuEsIM3Rwi yL3rZV/t68IZvGSdddSalsbCyzwBgSuroBz0PTURMQ2O5JYvdvW/YG+yDUjNUJwvrZSC Blgii0YTzpM3tddCWuqG9jr8ckh6XdyADfbvtZY/mYSFqFoFJObpDeHV1kJE9nps3zYJ ozUA== 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=qLxBO84kF8H5EGei+//43ik3y+DXrskN0pkB/NdJH9g=; b=b6gwbJN9xivdzM8YsVXf77x1eLdwxrwA5B4gu6o1m2Px7Jfarjur8eGwNq8FcEB8Pz GfoL1oTqP/Ll070TKtn+86h96pbOAkcD8z8QgyhD5EvGOySZWT4oL4so5LVXf3WgIq5Z iAHyARcTLF7BUUUmfquJbM02o2uAG8A/wkG3zWrtS0jW3zHwrAaOumoy+qUdoi5phD2m ieBwx2QYzLziBN8iCqW28rP8BO0GCcjtuFeXgNvJLNrF+cxKCWzw4Y7+eBE7ANdCXWkC P9hxeJhDDI31Ks4btjjNhhy3CvMKurUddXn+PDcMCePVoKFpmdWP86HytjQ7E7M/zdyz dl0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eaFAU3Xz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c19si1178490otr.276.2020.04.01.11.24.58; Wed, 01 Apr 2020 11:25:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eaFAU3Xz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732806AbgDASXm (ORCPT + 99 others); Wed, 1 Apr 2020 14:23:42 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:52354 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732285AbgDASXm (ORCPT ); Wed, 1 Apr 2020 14:23:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585765420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qLxBO84kF8H5EGei+//43ik3y+DXrskN0pkB/NdJH9g=; b=eaFAU3XzOF3AQWPeRhwlhwQZrTZeoBzlZFKM1EyYbkjQFYr0MTdIKPx1CtI0mQT+tF+2X2 T0c3PSZQZJj7X1Q+heiwGKFo9c9/D0blw/k7zD1UW1BP8u1ZX49eQCup06ujByhtZVtsxj H5qQ87YrC5CZ98WfyXrBy99EEcfye8I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-62-u02ICRzSMVaOtQ3WiV-PWA-1; Wed, 01 Apr 2020 14:23:39 -0400 X-MC-Unique: u02ICRzSMVaOtQ3WiV-PWA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF333800D5B; Wed, 1 Apr 2020 18:23:37 +0000 (UTC) Received: from treble.redhat.com (ovpn-118-135.phx2.redhat.com [10.3.118.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 439B660BEC; Wed, 1 Apr 2020 18:23:37 +0000 (UTC) From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Julien Thierry , Kees Cook , Randy Dunlap Subject: [PATCH 1/5] objtool: Fix CONFIG_UBSAN_TRAP unreachable warnings Date: Wed, 1 Apr 2020 13:23:25 -0500 Message-Id: <6653ad73c6b59c049211bd7c11ed3809c20ee9f5.1585761021.git.jpoimboe@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 i= nstruction We weren't able to figure out a way to get rid of the double UD2s, so just silence the warning. Cc: Kees Cook Reported-by: Randy Dunlap Signed-off-by: Josh Poimboeuf --- 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 e3bb76358148..aaec5e1277ea 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2382,14 +2382,27 @@ static bool ignore_unreachable_insn(struct instru= ction *insn) !strcmp(insn->sec->name, ".altinstr_aux")) return true; =20 + 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 =3D=3D INSN_BUG || + (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL && + insn->jump_dest && insn->jump_dest->type =3D=3D 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 =3D 0; i < 5; i++) { =20 if (is_kasan_insn(insn) || is_ubsan_insn(insn)) --=20 2.21.1