Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp884864pxb; Wed, 27 Oct 2021 14:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2+Yii66/rgl6LHI+XV6cFVflseByZ8ZJJXEOSutTozaLQkB8b0c6/QF5hhUqRaMRC9eAN X-Received: by 2002:a17:907:971e:: with SMTP id jg30mr48066ejc.375.1635370034209; Wed, 27 Oct 2021 14:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635370034; cv=none; d=google.com; s=arc-20160816; b=WYtGFaCOIA9Rb/UlaNxHMzMlUIUU29HRvrpZCQsV4WDFtXeRZQGNQilDodp8EnTo1d eHRmea0gQTAYtc4UIl/CsXBWyn0HVSARRCBi4GnBmljtXs84KeHpA5z4820c7MQxrAcj dBAS2V0KHAhUia4Y3jMqv3wnO7aVQSkm62uikiIlNYmEUVU8Hr2eiT9Tia7LbwXLfuud LKKq9Sp2FAb644H93JUomr/+JZNcUZnxm8jpj3ep5+eg9HBSHvUiJljXOWqMeiurxwIk ideK1WuhB/rbxBeabsWeCfB8VSb7bwShyB+OITVxuFPgqtJFQKJSxn0yJDQs7h7JBwu+ jVmw== 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; bh=yN2teGkhwGxcRkojOBp0l+LivSFLzuueRKemObooTYw=; b=iayHqrNqZfyWw6h4gbya0+WEN8MlNborSSZKvc34YPYbsevxZofKtckfrJIZttxRCL y8qio4aSHdF18Vw38bAF6hNxoWckh2xTF2IyOg6FhmjCCBuzZ0BUkutegz6DDVOYx+va Uae3qX1Bvms5hStL+65ql+e2YnU1VhlJUrF8lFGwzRAbreBHeT2PYsi3TImbE/bZAtsE PgQKogeQxFaKue/4C6SxBcUg4DnrNzQwp0CZ2umzsFqSUToDuL9sdj3eqLwGi5n2AS2D Ox7IiXACqS+RPqsI8dbLeBQ4kvHBvLnlrYfzzedBXRt9gzNJyaPBkElDdm7Alz2NjyEy Oe8g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u30si1179071edi.273.2021.10.27.14.26.51; Wed, 27 Oct 2021 14:27:14 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236264AbhJ0MHs (ORCPT + 97 others); Wed, 27 Oct 2021 08:07:48 -0400 Received: from foss.arm.com ([217.140.110.172]:42596 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237257AbhJ0MHr (ORCPT ); Wed, 27 Oct 2021 08:07:47 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 892C31FB; Wed, 27 Oct 2021 05:05:21 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.72.240]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 71BEA3F73D; Wed, 27 Oct 2021 05:05:18 -0700 (PDT) Date: Wed, 27 Oct 2021 13:05:15 +0100 From: Mark Rutland To: Peter Zijlstra Cc: Sami Tolvanen , x86@kernel.org, Kees Cook , Josh Poimboeuf , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, ardb@kernel.org Subject: Re: [PATCH v5 00/15] x86: Add support for Clang CFI Message-ID: <20211027120515.GC54628@C02TD0UTHF1T.local> References: <20211013181658.1020262-1-samitolvanen@google.com> <20211026201622.GG174703@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211026201622.GG174703@worktop.programming.kicks-ass.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 10:16:22PM +0200, Peter Zijlstra wrote: > On Wed, Oct 13, 2021 at 11:16:43AM -0700, Sami Tolvanen wrote: > > This series adds support for Clang's Control-Flow Integrity (CFI) > > checking to x86_64. With CFI, the compiler injects a runtime > > check before each indirect function call to ensure the target is > > a valid function with the correct static type. This restricts > > possible call targets and makes it more difficult for an attacker > > to exploit bugs that allow the modification of stored function > > pointers. For more details, see: > > > > https://clang.llvm.org/docs/ControlFlowIntegrity.html > > So, if I understand this right, the compiler emits, for every function > two things: 1) the actual funcion and 2) a jump-table entry. > > Then, every time the address of a function is taken, 2) is given instead > of the expected 1), right? Yes, and we had to bodge around this with function_nocfi() to get the actual function address. Really there should be a compiler intrinsic or attribute for this, given the compiler has all the releveant information available. On arm64 we had to us inine asm to generate the addres... Taking a step back, it'd be nicer if we didn't have the jump-table shim at all, and had some SW landing pad (e.g. a NOP with some magic bytes) in the callees that the caller could check for. Then function pointers would remain callable in call cases, and we could explcitly add landing pads to asm to protect those. I *think* that's what the grsecurity folk do, but I could be mistaken. > But how does this work with things like static_call(), which we give a > function address (now a jump-table entry) and use that to write direct > call instructions? > > Should not this jump-table thingy get converted to an actual function > address somewhere around arch_static_call_transform() ? This also seems > relevant for arm64 (which already has CLANG_CFI supported) given: > > https://lkml.kernel.org/r/20211025122102.46089-3-frederic@kernel.org Ugh, yeah, we'll need to do the function_nocfi() dance somewhere... Thanks, Mark.