Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1972228pxb; Wed, 9 Feb 2022 08:18:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRzlmFX5L1Y687WC5xndaRvRy9jl9udNPuxK6wUdOtbfifd29u3XxGFLgc3ZmWFRmyg2bl X-Received: by 2002:a17:90a:311:: with SMTP id 17mr3368891pje.200.1644423522535; Wed, 09 Feb 2022 08:18:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644423522; cv=none; d=google.com; s=arc-20160816; b=xzyPSVIso+xPUjBAymBW0cRILK7a3BIWpYd/khLzJjytklfdNcjmf8IcMUsz0bOTfp /GDzazTo8pZF1Fb8LcDtDanbAttWJnPuAtyrTy6QQKzWJ9H+R9gd0i8qa1mMVI4EFqxd Z1yotkmD35KhvNQtMvSiFKqjDyicvp9fIKx/PyIfBKTijabItdgTOp6zf6hOHrTPDQTR QOm7RywGT9oJlEh3/cDv0YsK91vV/4A/POmTHQQmoHDi8y1Ly/51TXRutzPCBPlKGKxg WbKZLtivKiRK+Vht0LR/+e/I1Co/sazgiL4fdELPba38lj6bzaAVrJlQgNACjtGxZsP1 /dww== 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=Cg3BreKapOWrcjA/myDb7wb6nkioNEwwwkcLOSzaG3k=; b=zE5GlV7nsYmq25gS7+T9W92mskki/bEuRpNzYlKYLu8LdzhjNjraLUJTcUf6nYrmvR 2htzGuMoRNdzwoudQXJ3t14j9LWlIPJBXhxZvjLvGWV1EL6bK2nnpEXeZXGzMwIcYtMz lkqEPJs+57lYeOc/0rFw7aJOf5hBWkrE+hgBRq1bjaH4Oc6dz4VtKlx62NktAUx2E5Se kvP2IIdRTGCLuD7TuxTwg/reeWqAET9YFRk4A2NRY6mQi2ScBoobAO8dpTdgxA29u4Z+ eHK6TDnFdMsoddrN4RIx1baWKT2SgBad345yJCIdb9SEJDxyaiLbqlESVfEgPlOLoDY7 rbcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="CYwBPHV/"; 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 16si14164754pfo.294.2022.02.09.08.18.27; Wed, 09 Feb 2022 08:18:42 -0800 (PST) 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=@infradead.org header.s=desiato.20200630 header.b="CYwBPHV/"; 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 S231757AbiBIMDs (ORCPT + 99 others); Wed, 9 Feb 2022 07:03:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232036AbiBIMDP (ORCPT ); Wed, 9 Feb 2022 07:03:15 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 886AAC03E965 for ; Wed, 9 Feb 2022 03:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Cg3BreKapOWrcjA/myDb7wb6nkioNEwwwkcLOSzaG3k=; b=CYwBPHV/nGZpvtuFaGg+bEeYQG hjGXpURWA6SOjdPDsNmd3ETz4Q9TgGovkE3yWIinrS2M/PEhx26FrnFQTJOQPXUK1+MP5VFXe+znC jgPhycUFHU1/W1tRYvtz/Ee/kRs1h5lfzEqcOC1KCO+NbbF4DspBCO79AI1qw+8tf5unUqJOxAm3q oRWQGCm7TjvZbDa/udWLZMCVCMnDo6tGGUbbMgr13bH5/THtCYk6ZO6YaR956cLlKjoVjGsE/7Ys3 GwVCnItq1oAaciY6vIRr2J0damNtPvNrW74CdGY9yiSO6dmGilidP8KgRDLvCCTs2uYLud7sGw9kK eTMyKSlQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHlLy-008Pay-Ka; Wed, 09 Feb 2022 11:41:42 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 3DB0A9853C7; Wed, 9 Feb 2022 12:41:41 +0100 (CET) Date: Wed, 9 Feb 2022 12:41:41 +0100 From: Peter Zijlstra To: Kees Cook Cc: Josh Poimboeuf , 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: <20220209114141.GN23216@worktop.programming.kicks-ass.net> References: <20211122170301.764232470@infradead.org> <20211122170805.338489412@infradead.org> <20211124193037.nu7q4pa3sianzqtc@treble> <202202081542.F685EC23@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202202081542.F685EC23@keescook> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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? I have patches that write a 4 byte #UD there instead of a nop. That would make !IBT hardware splat as well when it hits a sealed function (and in that case actually having those extra ENDBR generated is a bonus). Anyway, I have some newer patches and some hardware, except it's a NUC and working with those things is a royal pain in the arse since they don't have serial. I finally did get XHCI debug port working, but there's no XDBC grub support, so now I managed to boot a dead kernel and the thing is a brick until I can be arsed to connect a keybaord and screen to it again :-( KVM/qemu has no IBT support merged yet, so I can't use that either.