Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp881706pxb; Wed, 27 Oct 2021 14:23:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3kqOXc45/SIQd/q4sd+bYE1vuS60bwjdAz4KP6PcEJpyAw+hRgOgPYcONaRCSHUc1TXmW X-Received: by 2002:a17:906:d296:: with SMTP id ay22mr20970ejb.483.1635369812140; Wed, 27 Oct 2021 14:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369812; cv=none; d=google.com; s=arc-20160816; b=cRz/sKbvUJ/lmkBqkFrdIHl6UtV6C2/zvOcA6N0eJDJXaLbTIaQrdV8f1Q1kVfXIZI AExNY/78AQDqxwXYqzFkSC/m8J5DRejzTYE6Yj+3ndapozOiuDbDkUiWZshA23BvvMG9 kYVEp1z1n9MHWMefhFLOWmiTOW2NVdRL2gArPpV0mQbVFnXnFkSm0VaFZzFlT+TIzIuH kgKljJY/bRGQvlH/e7MJ+5gNokbjqRkuCLi8WExnvjDSIjaIQzQ7RxwKp9TK/lPh+pQV J8zYH5hiHSHGLHTcGbArntWbLCKxHDrXO+3dXT7mPp9jOofIatK+dgBAjEI62nyLS4PP L9fw== 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=kjEt7cLdB7cPY697Uxk7dOM1bUF1hgkDJORd+L3Zemw=; b=MY8qnO8oUhF0oqMScHAUcfurxuRvyB+pbVkR0qxipkHeKGQzqaVBfbl+BoX4C+tdYl idderYZKcbD85bDeGuHA8UGKiqiQXNLO6yLf43xBRwZSB8LWyv8v1F60nXtK/i5anifg 8ctVap+bd7/ralKTwTVnNDUJ3P4m+mONpSjbLYRHOZ/K6n8GibkL9izsnNL2bV7hftoM O0ljrFtHF7ZlDZo+XYT+WHxB1Nybq4q+P8oHcb0kl8Fjx7ZJPlYEAUO/ZWWVOlJ7qPqY U9v5qLmFk7gMHghxUowhkEGxPpPs17l6fWqigfWmJGGBsr7TQmrUdM85elE8ySJSOuFo d5rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=EjvrI8xm; 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 g4si1299389ejk.215.2021.10.27.14.22.55; Wed, 27 Oct 2021 14:23:32 -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; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=EjvrI8xm; 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 S239100AbhJ0KUP (ORCPT + 97 others); Wed, 27 Oct 2021 06:20:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231910AbhJ0KUO (ORCPT ); Wed, 27 Oct 2021 06:20:14 -0400 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 06956C061570; Wed, 27 Oct 2021 03:17:48 -0700 (PDT) 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=kjEt7cLdB7cPY697Uxk7dOM1bUF1hgkDJORd+L3Zemw=; b=EjvrI8xmrCQvizKIITT1kd5sfX Cwh5JtTCAqtPJJENlQ9U04/4v8GsIXNQvHTW3qFvxwiccJAMJV50vqxuAjtELdXSD/BWkC9DGCeQu 5GjyaEsphuI6PG2zbE4fI3p0JZHAYsehpR2XfgzX5HIduZLhYsGphLQs+z1XPKTIouDXUfXfIx2LZ hhIVSi1Sc8xcJMHcl9b5hxp6B7FpSzmYhUvJ8p9FDyLaI3AeWuO6j+To0Y2ZHLEYzEXZWhxI91SRU KwSD/LJ1/7N1s4cBUGMFzrntaq83hbtPtk7PsBSszHjxg/j4Q1EY+iYYZd00cz7nxC0QpdGsgdR/A xJxXMVlw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mffzm-00CX9d-Lr; Wed, 27 Oct 2021 10:17:22 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 50F2D30031A; Wed, 27 Oct 2021 12:17:21 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 355282B41AF5C; Wed, 27 Oct 2021 12:17:21 +0200 (CEST) Date: Wed, 27 Oct 2021 12:17:21 +0200 From: Peter Zijlstra To: David Laight 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" , "mark.rutland@arm.com" Subject: Re: [PATCH v5 00/15] x86: Add support for Clang CFI Message-ID: References: <20211013181658.1020262-1-samitolvanen@google.com> <20211026201622.GG174703@worktop.programming.kicks-ass.net> <7ebed28b73bb48cd9b69e9097f0aa613@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7ebed28b73bb48cd9b69e9097f0aa613@AcuMS.aculab.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 27, 2021 at 10:02:56AM +0000, David Laight wrote: > From: Peter Zijlstra > > Sent: 26 October 2021 21:16 > > > > 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? > > > > 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 > > > > Or am I still not understanding this CFI thing? > > From what I remember the compiler adds code prior to every jump indirect > to check that the function address is in the list of valid functions > (with a suitable prototype - or some similar check). It definitely mucks about with the address too; see here: https://lkml.kernel.org/r/YW6a67fGzM2AyHot@hirez.programming.kicks-ass.net I'm thinking static_call() wants the real actual function address before it writes instructions.