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=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 1B8E1C433E0 for ; Tue, 26 Jan 2021 12:52:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 C71B823109 for ; Tue, 26 Jan 2021 12:52:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C71B823109 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=A9FXFXJNg7H1q6+/+OI/6sSDwQtNN07uKI2bJSwe40I=; b=uEzn6lBoO/VTMwPJ5ZVv0rA5Y xR7X69Rp7El/K0IDrdvrZHAZuA8LykP+doaSjUEHc2d364htkyo93YPvXBC9TLbBO9WmaQi7jIgMT vJ9pOIrVfZVo2FF9EFPjJReD/sMrtJxLH9BeDxRvUPOJ8Gr7dN2rxycR7vqBNEJ6exqM7EPO4CIz6 G3uHKTSU2O8T5RBCkHzl3mDuuK0POk0aorEPxQ40ZZJA0fDbsWlNqtGgzfPbRXXo5knhtCPa2K0YJ DSy/JTj9qrRKtiPWb+FfYHUbLn6NTlg0guZfTbiITIwOmyqb+g62iMsxSnw6OaRs4PS3R/Mjsm88N L5YmHKtag==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l4NnU-0002tm-6Z; Tue, 26 Jan 2021 12:50:16 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l4Nn5-0002nE-OA for linux-arm-kernel@lists.infradead.org; Tue, 26 Jan 2021 12:49:56 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 96FC023109; Tue, 26 Jan 2021 12:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611665390; bh=xTKZZjPyyTa3jyDBmC3PhRNSWSN5FlJQnDqhElm3O2Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=p02hTXiVZ6moMxrw9NhBX3g5RorfBQjNq7GiFktAQSAhRIoDPhwyWCdi0EqojfwK+ 8SUxoIp5K4k/1JtuislUPTq4uxrsV+vKpv8mk1H6sRVpTBLHL++1nyKqidx6V+tAxg X3y5KduJwdD/QGXRAkhAquAHxiDUznhN26CFGI378on1lZHme25DW7op1eaTUGQSPR TH+C54jfIYrmZbVjAyKVKu7DyxFbsYrn/6K9XfGLycookYkrgMOuurWp6Xc0J2XF8s 39iELPsFll8PV35ZTzokUdVfBCGkm4DpEpMn2hsFNvRaYSeDhXN/inLZ1ZYOsry9/t Riz3AMHBTDlqA== Date: Tue, 26 Jan 2021 12:49:45 +0000 From: Will Deacon To: Peter Collingbourne Subject: Re: [PATCH v6 2/3] arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS) Message-ID: <20210126124945.GB29702@willie-the-truck> References: <295aec08a383cb9cb4a6062cf2ab21b4f59082b9.1609311499.git.pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <295aec08a383cb9cb4a6062cf2ab21b4f59082b9.1609311499.git.pcc@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210126_074951_968195_8419152F X-CRM114-Status: GOOD ( 24.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: libc-alpha@sourceware.org, Szabolcs Nagy , Catalin Marinas , Kevin Brodsky , linux-api@vger.kernel.org, Kostya Serebryany , Florian Weimer , Linux ARM , Andrey Konovalov , Vincenzo Frascino , Dave Martin , Evgenii Stepanov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Dec 29, 2020 at 10:59:14PM -0800, Peter Collingbourne wrote: > This change introduces a prctl that allows the user program to control > which PAC keys are enabled in a particular task. The main reason > why this is useful is to enable a userspace ABI that uses PAC to > sign and authenticate function pointers and other pointers exposed > outside of the function, while still allowing binaries conforming > to the ABI to interoperate with legacy binaries that do not sign or > authenticate pointers. > > The idea is that a dynamic loader or early startup code would issue > this prctl very early after establishing that a process may load legacy > binaries, but before executing any PAC instructions. > > This change adds a small amount of overhead to kernel entry and exit > due to additional required instruction sequences. > > On a DragonBoard 845c (Cortex-A75) with the powersave governor, the > overhead of similar instruction sequences was measured as 4.9ns when > simulating the common case where IA is left enabled, or 43.7ns when > simulating the uncommon case where IA is disabled. These numbers can > be seen as the worst case scenario, since in more realistic scenarios > a better performing governor would be used and a newer chip would be > used that would support PAC unlike Cortex-A75 and would be expected > to be faster than Cortex-A75. > > On an Apple M1 under a hypervisor, the overhead of the entry/exit > instruction sequences introduced by this patch was measured as 0.3ns > in the case where IA is left enabled, and 33.0ns in the case where > IA is disabled. > > Signed-off-by: Peter Collingbourne > Reviewed-by: Dave Martin > Link: https://linux-review.googlesource.com/id/Ibc41a5e6a76b275efbaa126b31119dc197b927a5 [...] > diff --git a/arch/arm64/kernel/pointer_auth.c b/arch/arm64/kernel/pointer_auth.c > index adb955fd9bdd..f03e5bfe4490 100644 > --- a/arch/arm64/kernel/pointer_auth.c > +++ b/arch/arm64/kernel/pointer_auth.c > @@ -46,3 +46,65 @@ int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg) > > return 0; > } > + > +static u64 arg_to_enxx_mask(unsigned long arg) > +{ > + u64 sctlr_enxx_mask = 0; > + > + WARN_ON(arg & ~PR_PAC_ENABLED_KEYS_MASK); > + if (arg & PR_PAC_APIAKEY) > + sctlr_enxx_mask |= SCTLR_ELx_ENIA; > + if (arg & PR_PAC_APIBKEY) > + sctlr_enxx_mask |= SCTLR_ELx_ENIB; > + if (arg & PR_PAC_APDAKEY) > + sctlr_enxx_mask |= SCTLR_ELx_ENDA; > + if (arg & PR_PAC_APDBKEY) > + sctlr_enxx_mask |= SCTLR_ELx_ENDB; > + return sctlr_enxx_mask; > +} > + > +int ptrauth_set_enabled_keys(struct task_struct *tsk, unsigned long keys, > + unsigned long enabled) > +{ > + u64 sctlr = tsk->thread.sctlr_user; > + > + if (!system_supports_address_auth()) > + return -EINVAL; > + > + if (is_compat_thread(task_thread_info(tsk))) > + return -EINVAL; > + > + if ((keys & ~PR_PAC_ENABLED_KEYS_MASK) || (enabled & ~keys)) > + return -EINVAL; > + > + sctlr &= ~arg_to_enxx_mask(keys); > + sctlr |= arg_to_enxx_mask(enabled); > + if (tsk == current) > + set_task_sctlr_el1(sctlr); > + else > + tsk->thread.sctlr_user = sctlr; Who synchronizes all these modifications to 'sctlr_user'? Seems like it gets hit by two independent prctl()s as well as ptrace. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel