Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1839303pxb; Wed, 9 Feb 2022 05:42:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHBaU4rHMXBG+oAmsEzp0qZs9L4BfTOk5sPIl76LzCBNVNsL2w8TQz2gTnm/lKaO+5w+GD X-Received: by 2002:a17:902:aa90:: with SMTP id d16mr2158349plr.89.1644414125609; Wed, 09 Feb 2022 05:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644414125; cv=none; d=google.com; s=arc-20160816; b=Sdq1hN40WHqH4D6yFrnwfUIkWL4/dYLU+dxUOqQPSkVn4Z7dAZiEGr++L5U/sE99/I MFQGFm+w2n6Rf06gY+nD4AQtQ5JRnob6CivmUGtwrQsfjbwd0VVaWwKQErb6uiaS6B+O Qq+tES64xOmjgV8L5UvSNtW48AOLsCh2yj85JLjpWzZpwwOhB3tCVOVKEelCd3kat5Nd NhdG3POPTRsGIgEAfVVa3SJYG2ajPV0yfKW9SthbrmuOHzHQUkGBJnsJb+94mM5302PC RDZ5Zc4HgkgT3yTr45+WeJzNA+ZUOEu5tXqp2QsOy9pviTkzT/Aqahb9Frq9TS6t7NAG l5Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TGF4Zn/lmJlaMT7UwgKtEW9zKBC5kk/h265Rl1WE1zM=; b=dfZiX3CgkVQ4JC6XwCc4DR/+AjH+7UPYuDM1Z17qpqrZt4p7kEG2zVnZ5zn1I1ca+8 6MTW/3bRnteyxX4PRPpL97ojru+EScGxwSYDx5UMU9ddcikIswbLvXqUa04iFHhn5drt mwKsUHlfPW2sOzUBGsHkkzCdNNu6c6acKUgOAbA3CFgoAkyz/5PuL4qQEN0Mf9OAsCbi Kzd4gpEZqx2HtVyUen6TfCe5hRRjdTSPSVFF7TbmpK7wJgmzi0M3dSBUDaOni8CHkDZc 8kPYx62pI/FNlCDrndAA7S4BFblXGflDFryUktwHR4hOSVWaX6oNjGLU6JYeyumNE2De hUvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bnQgNuMG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i10si17403258plr.231.2022.02.09.05.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 05:42:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bnQgNuMG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8B154E0998D5; Wed, 9 Feb 2022 02:24:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232119AbiBIFYY (ORCPT + 99 others); Wed, 9 Feb 2022 00:24:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243220AbiBIFJC (ORCPT ); Wed, 9 Feb 2022 00:09:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BC660C03F91E for ; Tue, 8 Feb 2022 21:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644383345; 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=TGF4Zn/lmJlaMT7UwgKtEW9zKBC5kk/h265Rl1WE1zM=; b=bnQgNuMGZiPdg53YCOVNg/QoJhyRCoDLJKQ+kLzXLl+GhX6bEnyFd8s9TrXYkxI/3/n8vP 4oy5k6/BbKmWXDo/sUSXkgjj78b2/ZzR9qAIaobknlU9hwH03uB80ZhB0670cSfrsqWQ3J rrTmMUzdsll102NBriSvhgyFGeg2WsE= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-383-zzTazHpoPsmwvVbkt9-CCw-1; Wed, 09 Feb 2022 00:09:04 -0500 X-MC-Unique: zzTazHpoPsmwvVbkt9-CCw-1 Received: by mail-qk1-f198.google.com with SMTP id z1-20020ae9f441000000b00507a22b2d00so706124qkl.8 for ; Tue, 08 Feb 2022 21:09:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TGF4Zn/lmJlaMT7UwgKtEW9zKBC5kk/h265Rl1WE1zM=; b=l5xWyVHvU+q9g8x6h/tAbxsypV9PWZI6XqeIobjSD4pBS5SbcgJC2zL9VrHtjFT7Db /3sn0uRe6kbqvZSQOxeF+u9Uf41ZaqDAiOTY9avNTH5KUxS2Fq/I53l9Frpto0NhDR52 ZnkWo6RzUrZbfN31yItOd0vPXn8P/LJN248Ksghi6JEDn8xj4JiIQWWm+nNfzOOEe/sc v3Fh62vbJiv0OLoX4vR76xpC/OAA1hsBbl1UbUWp2AwMHTjhc7Vh4i5yAf4sNw+aGH9/ AT6iF5yjPj2O2IhKlkq576kA3wo4N6gMrG3s5KQhtrSJT6ilXgCVm28yM1D4ZQysDquv NYfg== X-Gm-Message-State: AOAM530VxOTrB6sD44+n1ESXGp9QTJvbSb31UqooT3mAxGO1PZS9vmJl cusC8bXa/aOh2/RRf+QQgxlUq77xBnt804uIq62bucr7mMBYs8OGwbL7T/gLHD9NgyK0yL4iLNp YmlAkiA5NFwb5STLtnj/qwaHI X-Received: by 2002:a05:620a:454c:: with SMTP id u12mr233640qkp.515.1644383343673; Tue, 08 Feb 2022 21:09:03 -0800 (PST) X-Received: by 2002:a05:620a:454c:: with SMTP id u12mr233629qkp.515.1644383343413; Tue, 08 Feb 2022 21:09:03 -0800 (PST) Received: from treble ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id i20sm8608161qtx.44.2022.02.08.21.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:09:02 -0800 (PST) Date: Tue, 8 Feb 2022 21:09:00 -0800 From: Josh Poimboeuf To: Kees Cook Cc: Peter Zijlstra , x86@kernel.org, joao@overdrivepizza.com, hjl.tools@gmail.com, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org, ndesaulniers@google.com, samitolvanen@google.com Subject: Re: [RFC][PATCH 6/6] objtool: Add IBT validation / fixups Message-ID: <20220209050900.vb676ocdrt6gsomf@treble> References: <20211122170301.764232470@infradead.org> <20211122170805.338489412@infradead.org> <20211124193037.nu7q4pa3sianzqtc@treble> <202202081542.F685EC23@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202202081542.F685EC23@keescook> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 08, 2022 at 03:43:27PM -0800, Kees Cook wrote: > On Wed, Nov 24, 2021 at 11:30:37AM -0800, Josh Poimboeuf wrote: > > On Mon, Nov 22, 2021 at 06:03:07PM +0100, Peter Zijlstra wrote: > > > +static int validate_ibt_reloc(struct objtool_file *file, struct reloc *reloc, char **name) > > > +{ > > > + struct instruction *dest; > > > + struct section *sec; > > > + unsigned long off; > > > + > > > + sec = reloc->sym->sec; > > > + off = reloc->sym->offset + reloc->addend; > > > + > > > + dest = find_insn(file, sec, off); > > > + if (!dest) > > > + return 0; > > > + > > > + if (name && dest->func) > > > + *name = dest->func->name; > > > > I think these checks can be further narrowed down by only looking for > > X86_64_64 relocs. > > > > > + list_for_each_entry(insn, &file->endbr_list, call_node) { > > > + if (ibt_seal) { > > > + elf_write_insn(file->elf, insn->sec, > > > + insn->offset, insn->len, > > > + arch_nop_insn(insn->len)); > > > + } > > > > Like the retpoline rewriting, I'd much rather have objtool create > > annotations which the kernel can then read and patch itself. > > > > e.g. have '.ibt.direct_call_sites' and '.ibt.unused_endbr_insns' > > sections. > > Why have the kernel do that work at every boot when it can be known at > link time? True, but: - The kernel is already doing several other flavors of boot-time self-patching. IMO it's better to consolidate such craziness in one place (or a limited number of places) if we can. It seems more robust, and limits confusion about who's patching what and when. - Patching text at link time has pitfalls and I'd like to avoid (as much as reasonably possible) objtool having the ability to brick the kernel. -- Josh