From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Zijlstra Subject: Re: [RFC PATCH 1/9] kernel: add support for patchable function pointers Date: Fri, 5 Oct 2018 15:57:28 +0200 Message-ID: <20181005135728.GR19272@hirez.programming.kicks-ass.net> References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005081333.15018-2-ard.biesheuvel@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-kernel@vger.kernel.org, "Jason A . Donenfeld" , Eric Biggers , Samuel Neves , Andy Lutomirski , Arnd Bergmann , Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Kees Cook , "Martin K. Petersen" , Greg Kroah-Hartman , Andrew Morton , Rich To: Ard Biesheuvel Return-path: Content-Disposition: inline In-Reply-To: <20181005081333.15018-2-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-crypto.vger.kernel.org On Fri, Oct 05, 2018 at 10:13:25AM +0200, Ard Biesheuvel wrote: > Add a function pointer abstraction that can be implemented by the arch > in a manner that avoids the downsides of function pointers, i.e., the > fact that they are typically located in a writable data section, and > their vulnerability to Spectre like defects. > > The FFP (or fast function pointer) is callable as a function, since > the generic incarnation is simply that. However, due to the fact that > C does not distinguish between functions and function pointers at the > call site, the architecture can instead emit it as a patchable sequence > of instructions consisting of ordinary branches. This is basically a static_key, except for indirection function calls? So why not call the thing static_func or static_call or something like that? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 350D4C00449 for ; Fri, 5 Oct 2018 13:58:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE009206B2 for ; Fri, 5 Oct 2018 13:58:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="o9nd7nhh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE009206B2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728643AbeJEU5M (ORCPT ); Fri, 5 Oct 2018 16:57:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:38472 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728278AbeJEU5L (ORCPT ); Fri, 5 Oct 2018 16:57:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; 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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=icoPfttjeff5yY2o/Haqd75W+rJ7k66AdEgbHZsvZdQ=; b=o9nd7nhh2WiVbQs1DdQiuYphs seUdvLWCxp4QN3r6XTlPbH0TjUKivXKBEUMzDpwh/YP5vR42vfXOs3h1R6wQ1jtnbtNAgx7OkQMa7 GOHyGIdJ82TTwSAlMhLjzS9lLT3uJ2kDTQQvYsAf/1XBRYK6AakQt2f6AmnIuA/M0nCkjFXshEJcC xZYvI5Gi8JZ6zug3fkgvbZIwSfTsbQn8Lb6O7VA8ksT/5hUuoMbrt3Qe6BhrGLYCs3HdhwYwgQx2v dZD4beQj8LOKRgzhaxS/Tff68AGvofZjxmEZoFdmuWX+uxXnebDdwCh3g7wdn/JNi7mwh5frOfRXC JhOY3goog==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g8Qbi-0005pU-Pi; Fri, 05 Oct 2018 13:57:31 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5078A202631DA; Fri, 5 Oct 2018 15:57:28 +0200 (CEST) Date: Fri, 5 Oct 2018 15:57:28 +0200 From: Peter Zijlstra To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, "Jason A . Donenfeld" , Eric Biggers , Samuel Neves , Andy Lutomirski , Arnd Bergmann , Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Kees Cook , "Martin K. Petersen" , Greg Kroah-Hartman , Andrew Morton , Richard Weinberger , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [RFC PATCH 1/9] kernel: add support for patchable function pointers Message-ID: <20181005135728.GR19272@hirez.programming.kicks-ass.net> References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005081333.15018-2-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181005081333.15018-2-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 05, 2018 at 10:13:25AM +0200, Ard Biesheuvel wrote: > Add a function pointer abstraction that can be implemented by the arch > in a manner that avoids the downsides of function pointers, i.e., the > fact that they are typically located in a writable data section, and > their vulnerability to Spectre like defects. > > The FFP (or fast function pointer) is callable as a function, since > the generic incarnation is simply that. However, due to the fact that > C does not distinguish between functions and function pointers at the > call site, the architecture can instead emit it as a patchable sequence > of instructions consisting of ordinary branches. This is basically a static_key, except for indirection function calls? So why not call the thing static_func or static_call or something like that? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE68BC00449 for ; Fri, 5 Oct 2018 14:01:56 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C3B6206B2 for ; Fri, 5 Oct 2018 14:01:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="o9nd7nhh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C3B6206B2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42RWds714ZzDrRP for ; Sat, 6 Oct 2018 00:01:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="o9nd7nhh"; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=peterz@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42RWYd2C8yzDrRP for ; Fri, 5 Oct 2018 23:58:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; 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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=icoPfttjeff5yY2o/Haqd75W+rJ7k66AdEgbHZsvZdQ=; b=o9nd7nhh2WiVbQs1DdQiuYphs seUdvLWCxp4QN3r6XTlPbH0TjUKivXKBEUMzDpwh/YP5vR42vfXOs3h1R6wQ1jtnbtNAgx7OkQMa7 GOHyGIdJ82TTwSAlMhLjzS9lLT3uJ2kDTQQvYsAf/1XBRYK6AakQt2f6AmnIuA/M0nCkjFXshEJcC xZYvI5Gi8JZ6zug3fkgvbZIwSfTsbQn8Lb6O7VA8ksT/5hUuoMbrt3Qe6BhrGLYCs3HdhwYwgQx2v dZD4beQj8LOKRgzhaxS/Tff68AGvofZjxmEZoFdmuWX+uxXnebDdwCh3g7wdn/JNi7mwh5frOfRXC JhOY3goog==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g8Qbi-0005pU-Pi; Fri, 05 Oct 2018 13:57:31 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5078A202631DA; Fri, 5 Oct 2018 15:57:28 +0200 (CEST) Date: Fri, 5 Oct 2018 15:57:28 +0200 From: Peter Zijlstra To: Ard Biesheuvel Subject: Re: [RFC PATCH 1/9] kernel: add support for patchable function pointers Message-ID: <20181005135728.GR19272@hirez.programming.kicks-ass.net> References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005081333.15018-2-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181005081333.15018-2-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason A . Donenfeld" , Catalin Marinas , Will Deacon , Samuel Neves , Paul Mackerras , Herbert Xu , Richard Weinberger , Eric Biggers , Ingo Molnar , Kees Cook , Arnd Bergmann , Andy Lutomirski , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, "Martin K. Petersen" , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, Oct 05, 2018 at 10:13:25AM +0200, Ard Biesheuvel wrote: > Add a function pointer abstraction that can be implemented by the arch > in a manner that avoids the downsides of function pointers, i.e., the > fact that they are typically located in a writable data section, and > their vulnerability to Spectre like defects. > > The FFP (or fast function pointer) is callable as a function, since > the generic incarnation is simply that. However, due to the fact that > C does not distinguish between functions and function pointers at the > call site, the architecture can instead emit it as a patchable sequence > of instructions consisting of ordinary branches. This is basically a static_key, except for indirection function calls? So why not call the thing static_func or static_call or something like that? From mboxrd@z Thu Jan 1 00:00:00 1970 From: peterz@infradead.org (Peter Zijlstra) Date: Fri, 5 Oct 2018 15:57:28 +0200 Subject: [RFC PATCH 1/9] kernel: add support for patchable function pointers In-Reply-To: <20181005081333.15018-2-ard.biesheuvel@linaro.org> References: <20181005081333.15018-1-ard.biesheuvel@linaro.org> <20181005081333.15018-2-ard.biesheuvel@linaro.org> Message-ID: <20181005135728.GR19272@hirez.programming.kicks-ass.net> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Fri, Oct 05, 2018 at 10:13:25AM +0200, Ard Biesheuvel wrote: > Add a function pointer abstraction that can be implemented by the arch > in a manner that avoids the downsides of function pointers, i.e., the > fact that they are typically located in a writable data section, and > their vulnerability to Spectre like defects. > > The FFP (or fast function pointer) is callable as a function, since > the generic incarnation is simply that. However, due to the fact that > C does not distinguish between functions and function pointers at the > call site, the architecture can instead emit it as a patchable sequence > of instructions consisting of ordinary branches. This is basically a static_key, except for indirection function calls? So why not call the thing static_func or static_call or something like that?