Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp375715pxb; Tue, 15 Feb 2022 15:53:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJw041KW/Xbok07i38tDeOjaE/KKx2KWS/PBQd8cLZ7EJL61bEHSKBlrwQmuSRpuZfoT4PhP X-Received: by 2002:a17:906:414e:b0:6b9:7068:1983 with SMTP id l14-20020a170906414e00b006b970681983mr303031ejk.752.1644969200370; Tue, 15 Feb 2022 15:53:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644969200; cv=none; d=google.com; s=arc-20160816; b=CFyZXtRPMoehyD/SO4cWK9p8AoJEt8mF/KlopqkjE4oWTucPpmNQfrCNBuvHEepzSQ bs0yiixFa62TShgJZwHcNuNXojF+uuOqbmbm/AnHi4RszUs19JyviHjVHM1zYBqCGPAQ jT5M9f6747eIZCryXRS/1LtwV614NpohBftMvDmZBm/OM6QyXiyRN8H0Cx/Gqpu/LsSQ 18rEBrgM8d1BxAc1ABe+Ki5tmToeRYvvP0FdJo9wY9EPCWmlZyvHfDUPMT+/T0NQi2Bh wYdhlmnD+0gw/2gQzUpXbAbfiznRypolyF8MDSZR7Kpj8lf+npzTxQbB4iENE163ABHj DZSg== 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=BYpYOt247YYcQkSbIW220dgIYhgVR6WY6sT8wWi/ZtE=; b=EQtPhUs2+z4WXz4XUqF00AswGGxh1i2XTLx6GH+Fyk2PszpnQLGyUVauZMz8FqIB9j KHYvERKJ/9HmpE48YHKv3fxXgGsWHzke7satNM5YloQB1iAec+X5hwo/6HBaVc8qCRJX FfkBjioJewiNZlPovoN+xy/bU6jLbYS3IQnz+CtZNYd5VCuTSnu8wLd0LZD3AIBPAU0T KbuvTZ7raHRKi2zOM5dFswEU6b+exitYRnF9d2BR1EzR+7QOrHVYo0q8pElAeJanrj1s /I2k/dDlizDofyk+LXIz2xKDZJwh5NdVUludSF4DrdtK5+dNvjVC5RYgLTrLJIMn3Uiy vDhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EJvqgsGq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r25si15066327ejc.298.2022.02.15.15.52.57; Tue, 15 Feb 2022 15:53:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EJvqgsGq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244016AbiBOUDr (ORCPT + 99 others); Tue, 15 Feb 2022 15:03:47 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243981AbiBOUDp (ORCPT ); Tue, 15 Feb 2022 15:03:45 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0310775C02 for ; Tue, 15 Feb 2022 12:03:14 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id c10so155531pfv.8 for ; Tue, 15 Feb 2022 12:03:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BYpYOt247YYcQkSbIW220dgIYhgVR6WY6sT8wWi/ZtE=; b=EJvqgsGqpY5ntsB8smDSnvlbX6MMh2tLmKHk2kpn+WLLX26Qg46icNudHQswUgDvDG 2XCYZgLfLV3ryQ7MFgZo/SptowPM72fkx86+kCCAcd0DDtlbTkL6uvbqPIJNRGFPanJ5 4xh874w3o9d/Mal+b4CGcSbfDAxCP1FsuU+TA= 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=BYpYOt247YYcQkSbIW220dgIYhgVR6WY6sT8wWi/ZtE=; b=RnoSsOTjH0T0Uql+fkF2xCPVnu4PCOsR3sF5cNO9WN9iRETmRMwhixTa0DXCkA4s1n SdooJQ0NhWIDMI+mkO395Xgg4fCJj5frZsKGGdfbYDIpstLmDngrLa2J2vF/zVnLBVdB n8yiYoWJBPnHCPXS11h5Z1XxH9v9oHLTIZqk6NjfMmKqmH6Q0dLuUd+RgBsgYiMro86T iQfy2UdLnrF3b7OTCSAaMmMQ2vUr49WT/33ELe0CBJjsdr9Jx2XwzvYPy+MrinZZnmNe 3cen4QSZi1lPTx/8gC8B7zC14NRGYRuVM339dJ7LrQrJelHNZW0d4TDUjmc+P7gA9sD2 RNBw== X-Gm-Message-State: AOAM5312+y8QWyFobVmEuPWDvM8Y/PweGb+wSkIUvz+L/opA/KpqwqWi 6PhdXHpD6zggenel5MdcLslXhg== X-Received: by 2002:a63:4854:: with SMTP id x20mr449831pgk.178.1644955393489; Tue, 15 Feb 2022 12:03:13 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q16sm42222151pfu.194.2022.02.15.12.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 12:03:13 -0800 (PST) Date: Tue, 15 Feb 2022 12:03:12 -0800 From: Kees Cook To: Sami Tolvanen Cc: Peter Zijlstra , Joao Moreira , X86 ML , hjl.tools@gmail.com, Josh Poimboeuf , andrew.cooper3@citrix.com, LKML , Nick Desaulniers , llvm@lists.linux.dev Subject: Re: [RFC][PATCH 6/6] objtool: Add IBT validation / fixups Message-ID: <202202151129.1A5C5FE42@keescook> References: <20211122170805.338489412@infradead.org> <6ebb0ab131c522f20c094294d49091fc@overdrivepizza.com> <202202081541.900F9E1B@keescook> <202202082003.FA77867@keescook> <9ea50c51ee8db366430c9dc697a83923@overdrivepizza.com> <20220211133803.GV23216@worktop.programming.kicks-ass.net> <20220214222550.GB23216@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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 15, 2022 at 08:56:03AM -0800, Sami Tolvanen wrote: > On Mon, Feb 14, 2022 at 2:25 PM Peter Zijlstra wrote: > > On Mon, Feb 14, 2022 at 01:38:18PM -0800, Sami Tolvanen wrote: > > > I'm fine with adding a trap mode that's used by default, but having > > > more helpful diagnostics when something fails is useful even in > > > production systems in my experience. This change results in a vmlinux > > > that's another 0.92% smaller. > > > > You can easily have the exception generate a nice warning, you can even > > have it continue. You really don't need a call for that. > > Sure, but wouldn't that require us to generate something like > __bug_table, so we know where the CFI specific traps are? It also means the trap handler needs to do a bunch of instruction decoding to find the address that was going to be jumped to, etc. > > > In this case the function has two indirect calls and Clang seems to > > > prefer to emit just one ud2. > > > > That will not allow you to recover from the exception. UD2 is not an > > unconditional fail. It should have an out-going edge in this case too. > > Yes, CFI failures are not recoverable in that code. In fact, LLVM > assumes that the llvm.trap intrinsic (i.e. ud2) never returns, but I > suppose we could just use an int3 instead. I assume that's sufficient > to stop speculation? Peter, is there a reason you want things in the specific order of: cmp, je-to-call, trap, call Isn't it more run-time efficient to have an out-of-line failure of the form: cmp, jne-to-trap, call, ...code..., trap, jmp-to-call I thought the static label stuff allowed the "default out of line" option, as far as pessimizing certain states, etc? The former is certainly code-size smaller, though, yes, but doesn't it waste space in the cache line for the unlikely case, etc? > > Also, you really should add a CS prefix to the retpoline thunk call if > > you insist on using r11 (or any of the higher regs). > > I actually didn't touch the retpoline thunk call, that's exactly the > code Clang normally generates. > > > > How would you like to deal with the 4-byte hashes in objtool? We > > > either need to annotate all function symbols in the kernel, or we need > > > a way to distinguish the hashes from random instructions, so we can > > > also have functions that don't have a type hash. > > > > Easiest would be to create a special section with all the hash offsets > > in I suppose. A bit like -mfentry-section=name. > > OK, I'll take a look. With 64-bit hashes I was planning to use a known > prefix, but that's not really an option with a 32-bit hash. 32-bit hashes would have both code size and runtime benefits: fewer instructions for the compare therefore a smaller set of instructions added. -- Kees Cook