Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp796049ybl; Fri, 31 Jan 2020 08:08:33 -0800 (PST) X-Google-Smtp-Source: APXvYqyxx2sTppaN/EJrXV9N4z3WwM5QsVVMjYXvWK3yLw5sKz73vWCp/CZh0Lq8EA7GV4dV+MEb X-Received: by 2002:aca:f1d4:: with SMTP id p203mr6679753oih.116.1580486913463; Fri, 31 Jan 2020 08:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580486913; cv=none; d=google.com; s=arc-20160816; b=aVJ7t13byR/HKiNF11HPjBEmw6YrDhzz3IdwQwq1B0VIk+90C2ad9lGxnsQUEKwV5W HUgTC5Tk2Z3D3vSs5t5G268bHD/N4lWAdD6GR7ccsRALj64N8IPa8sgUOv+GJRm1J92u mntNbtCD2Go3WRG4mOhYQbkU14H/D749EvG+heRwnRiYirDfdQlLUJFOIxc2jvRAOS5S 4+PgwZadsKhEHKZJ0VDtlkQY1O2DJIC7OKxWBtKRjG5oHazvxOxMCCpZ+TKZxbLjR772 RgU3kZhZhP4Sgl07hrp2S3cATL1VDrdKZ5qqeJQbfNH2dT4pz1erLdMBQHFPN5a4N+yY 7OsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=PEcomJdnQm9uhP4G2ZgarE3vlUkg2zA8b8LUNcIzUTk=; b=ZJDqMTvGOuRDpDLFWVcnLOj7Dw/HvvbLMUNmcLeFSTNX271vM5BtxFoa0pB2B8g/LM gFQhDXe4wbTk8f11kBM7cyKmgoUKghU34zE27dYCKsFkE2rwrhpjCiXLkekb44Qa9e5o /t51sLsBPSAl8mjguOEKH8feuXjRYJtyFrVbhjVk0df3UNOLDxqcOO5+TnaNY02k1NTR lSRRtp1y0bepPMH9Hj3ujbfkMPl7pa/BXoBbrBhlERDbBP1pz9JjqwkcjW5AEMtPaMwu irbHEIglDOE9Vn07ZWX9tfolRvVvnAPlkVgL9yuO9ThubxJm7mLQMawOnPcpoO5DX6OB Iy8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="RXmQhx/+"; 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 q19si4701977otk.136.2020.01.31.08.08.20; Fri, 31 Jan 2020 08:08:33 -0800 (PST) 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="RXmQhx/+"; 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 S1729222AbgAaQF1 (ORCPT + 99 others); Fri, 31 Jan 2020 11:05:27 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30054 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729030AbgAaQF0 (ORCPT ); Fri, 31 Jan 2020 11:05:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580486725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=PEcomJdnQm9uhP4G2ZgarE3vlUkg2zA8b8LUNcIzUTk=; b=RXmQhx/+koGlGYRwbY7Yy1/WPsE1P0TlVawYrPkhbowAF1WpoK8N5PztAUJ0s4wJsKobJG xfddAuSWHgR/nX2p1nWwza3k6/tmirhnygQ4RvkKZUAXlpah1dzkEg2XHZv4iRreQ+6dNJ 9iC76Y+xET7YuT3op8hiUb+9oG8JhGU= 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-1-LDkNTTaAPBWaExkSeGk4lA-1; Fri, 31 Jan 2020 11:05:23 -0500 X-MC-Unique: LDkNTTaAPBWaExkSeGk4lA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 99394107ACCC; Fri, 31 Jan 2020 16:05:21 +0000 (UTC) Received: from treble (ovpn-120-83.rdu2.redhat.com [10.10.120.83]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01D095D9E5; Fri, 31 Jan 2020 16:05:19 +0000 (UTC) Date: Fri, 31 Jan 2020 10:05:18 -0600 From: Josh Poimboeuf To: Borislav Petkov Cc: Linus Torvalds , "Luck, Tony" , Ingo Molnar , Linux Kernel Mailing List , Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Andrew Morton , Julien Thierry Subject: Re: [GIT PULL] x86/asm changes for v5.6 Message-ID: <20200131160518.ou6zadyo5qvkr2xd@treble> References: <20200129132618.GA30979@zn.tnic> <20200129170725.GA21265@agluck-desk2.amr.corp.intel.com> <20200129183404.GB30979@zn.tnic> <20200130085134.GB6684@zn.tnic> <20200130173910.GK6684@zn.tnic> <20200131142727.GB14851@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200131142727.GB14851@zn.tnic> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 31, 2020 at 03:27:27PM +0100, Borislav Petkov wrote: > + Josh. > > On Thu, Jan 30, 2020 at 10:02:54AM -0800, Linus Torvalds wrote: > > Maybe with the exception that a short conditional jump inside the > > alternative code itself is fine. > > > > Because a branch-over inside the alternative sequence (or a loop - > > think inline cmpxchg loop or whatever) would be fine, since it's > > unaffected by code placement. > > Perhaps something like the below as a start. > > The build becomes really noisy if the error case is hit because aborting > in handle_group_alt() really messes up objtool processing but that is > perhaps ok as the idea is to *see* that something's wrong. [ Adding Julien as an FYI -- not sure how it affects arm64 ] Boris, I made the check even broader than we discussed on IRC: it disallows *any* relocations in the alternatives section unless it's the first instruction in the group and it's a call or a jmp. Untested, let me know if it works. diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b6da413bcbd6..382a65363379 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -782,6 +782,20 @@ static int handle_group_alt(struct objtool_file *file, insn->ignore = orig_insn->ignore_alts; insn->func = orig_insn->func; + /* + * The x86 alternatives code adjusts relocation targets only in + * the case where the first instruction is either a call or a + * jump. Otherwise, relocations aren't supported by the + * alternatives code (as there hasn't yet been a need for it). + */ + if (!(insn->offset == special_alt->new_off && + (insn->type == INSN_CALL || insn->type == INSN_JUMP_UNCONDITIONAL)) && + find_rela_by_dest_range(insn->sec, insn->offset, insn->len)) { + WARN_FUNC("relocations not allowed in alternatives section", + insn->sec, insn->offset); + return -1; + } + if (insn->type != INSN_JUMP_CONDITIONAL && insn->type != INSN_JUMP_UNCONDITIONAL) continue; @@ -2509,8 +2523,14 @@ int check(const char *_objname, bool orc) out: cleanup(&file); - /* ignore warnings for now until we get all the code cleaned up */ - if (ret || warnings) - return 0; + if (ret < 0) { + /* + * Fatal error. The binary is corrupt or otherwise broken in + * some way, or objtool is badly broken. Fail the kernel + * build. + */ + return ret; + } + return 0; }