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=-23.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL 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 6A6F9C2D0E4 for ; Tue, 17 Nov 2020 18:40:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF0A6223C7 for ; Tue, 17 Nov 2020 18:40:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DHXFz+8v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727279AbgKQSkM (ORCPT ); Tue, 17 Nov 2020 13:40:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727210AbgKQSkM (ORCPT ); Tue, 17 Nov 2020 13:40:12 -0500 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17100C0613CF for ; Tue, 17 Nov 2020 10:40:12 -0800 (PST) Received: by mail-io1-xd42.google.com with SMTP id j12so22282393iow.0 for ; Tue, 17 Nov 2020 10:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XJjpIWurXoKndtQsey1wE4FF0urevJ+gcZzD20BZ6GA=; b=DHXFz+8v9XH77JeUP6pgZbDXUB4rvNLbAeuR9Ky2JSegDJ3UDw6HblPdTkifpSS+63 3kVrz/dSbZ7Iz5UlYJmOskYvAWs9PAexmnNl+/7HTI8aSsecgnk7wetnMUbcnj7WFWf5 l/g0YRYVEN8n2ZklZwiEv6n1LtvchkrTJ65FhZaLDV1YSSWl6SxjF0g286do4AV5lovd vA0tfTpKWOWj4zBxLJrgeYiFAecynMWXcl2ZdkSJ2KgaX+bFAV5Ar9BtduhELefUWnuy VdvkwfXN5DchEbSFKsbqCWLsTueAsuPkCO/b1ia76HkSCbGnQf4dItSLnL6oQdrXaKAx YcSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XJjpIWurXoKndtQsey1wE4FF0urevJ+gcZzD20BZ6GA=; b=KE3nmydHqTXHi7zoHe7pD7CAznyCxJ8Li8mzv31Bc3a+GpbXkJjqpGod+jrF3jhNlL 7IG3fmaXcb6SW+MBWizR8PbPp+bBq4m+jHjiuaa7mL6CNUDH9J+WPJ4LKwKTIFkJucqu aeC2PHpbN0jQ4O7pNTA0UIKd8kHYk0Lud6uaSArJqoVcHPvosYzG+MX0c+NXp8+YMILu V3S8tMYaCx2ckiY95IF6Vcr7OlygxxiR1fCGrwqVTzNDKqMLgZhx4pWE/MFQDITmpWPP QMdqrzPBEPRlQ4fTxOqNySpEg6xmzz/OKTC+czEKSN7uE+NmBkgBiATP85S1R2gr1Yq2 WmWw== X-Gm-Message-State: AOAM530uitFXi/UrPBrGY5k5Vkn/gvMGvKKX1iBRdXe+yp9zYHCljezU 80ZjfRDzMydjy65u/zuHp1xMBEHRbXlGWT3Wt96BmA== X-Google-Smtp-Source: ABdhPJweOknmYybC+K3gRbP2qioCOiAns0PcavbQZb0ARZAYxD8udKLes/O30Jr7eIfD5avGYJG+iPwPzJSo8JRhFUk= X-Received: by 2002:a5d:9cc7:: with SMTP id w7mr12457759iow.202.1605638411207; Tue, 17 Nov 2020 10:40:11 -0800 (PST) MIME-Version: 1.0 References: <20201014055106.25164-1-pcc@google.com> <20201117181431.GH15033@arm.com> In-Reply-To: <20201117181431.GH15033@arm.com> From: Peter Collingbourne Date: Tue, 17 Nov 2020 10:40:00 -0800 Message-ID: Subject: Re: [PATCH v2] arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS) To: Szabolcs Nagy Cc: Catalin Marinas , Evgenii Stepanov , Kostya Serebryany , Vincenzo Frascino , Dave Martin , Linux ARM , Kevin Brodsky , Andrey Konovalov , Will Deacon , Linux API , libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Tue, Nov 17, 2020 at 10:14 AM Szabolcs Nagy wrote: > > The 11/17/2020 17:29, Catalin Marinas wrote: > > Adding Szabolcs and libc-alpha. The original patch below and also here: > > > > https://lore.kernel.org/r/20201014055106.25164-1-pcc@google.com > > > > The patch looks fine to me but I'd like the glibc community to confirm > > that they are happy with this ABI addition. I'd also like Dave Martin to > > ack the patch since he was involved in the discussion for v1. > > > > Thanks. > > > > Catalin > > > > On Tue, Oct 13, 2020 at 10:51:06PM -0700, Peter Collingbourne wrote: > > > This prctl 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. > > > > > > Signed-off-by: Peter Collingbourne > > > Link: https://linux-review.googlesource.com/id/Ibc41a5e6a76b275efbaa126b31119dc197b927a5 > > > --- > > > This patch must be applied on top of Catalin's MTE series: > > > > > > git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux for-next/mte > > > > > > Alternatively the series with this patch on top may be > > > downloaded from Gerrit by following the link above. > ... > > > +Enabling and disabling keys > > > +--------------------------- > > > + > > > +The prctl PR_PAC_SET_ENABLED_KEYS allows the user program to control which > > > +PAC keys are enabled in a particular task. It takes two arguments, the > > > +first being a bitmask of PR_PAC_APIAKEY, PR_PAC_APIBKEY, PR_PAC_APDAKEY > > > +and PR_PAC_APDBKEY specifying which keys shall be affected by this prctl, > > > +and the second being a bitmask of the same bits specifying whether the key > > > +should be enabled or disabled. For example:: > > > + > > > + prctl(PR_PAC_SET_ENABLED_KEYS, > > > + PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY | PR_PAC_APDBKEY, > > > + PR_PAC_APIBKEY, 0, 0); > > > + > > > +disables all keys except the IB key. > > > + > > > +The main reason why this is useful is to enable a userspace ABI that uses PAC > > > +instructions 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. > > which keys are enabled by default when HWCAP_PACA is > set in AT_HWCAPS ? i think that would be useful to > point out here. For compatibility with previous kernel versions all keys are enabled by default at process startup. But I agree it would be useful to point it out here. > per process enable/disable was deemed costly to do when > pac support was added, did this change? (i'm happy if it > did, because even without a new PAC specific pointer ABI, > plain PAC-RET can cause problems if a process tries to do > its own DWARF unwinding but does not understand the new > opcode that toggles PAC status of the return address, > possibly in a third party library, so a way to opt-out of > PAC is useful. currently it's a kernel config option and > system wide on or off.) My understanding is that it was considered too expensive to do without a use case, but we did come up with one. In general we only need to update the system register on process switch as well as on entry/exit if we need to disable IA which is also needed by in-kernel PAC. I did benchmark a variant of the code sequences on existing non-PAC HW [1] which showed that the entry/exit overhead in the common case where IA is left enabled is expected to be low. But with the new Apple chips I think it should be possible to benchmark the real entry/exit code sequences on supporting HW in the enabled and disabled cases. Peter [1] https://lore.kernel.org/linux-arm-kernel/CAMn1gO7HCJiXEzDvBb-=T7znATqyaxE_t-zezqKL0dyXRCG-nQ@mail.gmail.com/ 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=-13.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 16040C5519F for ; Tue, 17 Nov 2020 18:41:31 +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 95A5D2222C for ; Tue, 17 Nov 2020 18:41:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cShuLC8B"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="DHXFz+8v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95A5D2222C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com 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:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+5F77MRPvMnnacDJYvaSUOhv0zfIIQ+UhNJfJkPh1Q8=; b=cShuLC8BusL4HlnKHrUGmifWA reJscrOy2tazPq33y6xjdKaZMglOcQzmEM1HaQ/p0U+Q6xgHuERSxSQgGLhYjqkQKSmWzNE+jh421 eqkdaCAZB8NVFND2K3gBgZbcUke8IbbU+MxIroHPLV7pASu/l5QO/qacazHM9+ofHV/nQDW1HbRMm sIJxr7YtY85ooRDOSWkH2GR+D8+2BnfLnAm7u6ogov4H5dA41s//ABRIK/S0MGuUtyf8ijmK6beyD +oXzANa0aJpxaH7KkL+WXq6Boo7wLkzyqt8gbF9PfI077CSOvS92sYyk+kL5Bl/2gEkerFlfgFLym IKb/xSDkw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kf5tq-0003Rh-8k; Tue, 17 Nov 2020 18:40:18 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kf5tn-0003Px-84 for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2020 18:40:16 +0000 Received: by mail-io1-xd42.google.com with SMTP id m9so22224341iox.10 for ; Tue, 17 Nov 2020 10:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XJjpIWurXoKndtQsey1wE4FF0urevJ+gcZzD20BZ6GA=; b=DHXFz+8v9XH77JeUP6pgZbDXUB4rvNLbAeuR9Ky2JSegDJ3UDw6HblPdTkifpSS+63 3kVrz/dSbZ7Iz5UlYJmOskYvAWs9PAexmnNl+/7HTI8aSsecgnk7wetnMUbcnj7WFWf5 l/g0YRYVEN8n2ZklZwiEv6n1LtvchkrTJ65FhZaLDV1YSSWl6SxjF0g286do4AV5lovd vA0tfTpKWOWj4zBxLJrgeYiFAecynMWXcl2ZdkSJ2KgaX+bFAV5Ar9BtduhELefUWnuy VdvkwfXN5DchEbSFKsbqCWLsTueAsuPkCO/b1ia76HkSCbGnQf4dItSLnL6oQdrXaKAx YcSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XJjpIWurXoKndtQsey1wE4FF0urevJ+gcZzD20BZ6GA=; b=Q8BhstyV+9MbM4aigcJN2bSkYzi/WG+5keXKrX+W25P/Z5cHMXgztD+Xt7X/4+XeoE 0IIAqcpR9Ru8aJWZN8E/anawGic5Q9UwOqS32x5osK8xy1ypxcjLyar9qVPPMpJsa+/m xy5jMnpBIN0PFtb/XlpgPw4dIg8oJFi+xsbKfCqxQ1/52889NPcQ+FlXl8BK1FLwWyvZ jNtqCGhVdo1CiBDwOT7lytq+qR5BgdXXXU2czu6vfldJmObcWwP4QdZxHWnh1Sq4Lk7p fzyj2OoWv0yHxQW/mWfDwGjRHJQX6bYJEDve5u9ZAabT1wUujCa2j86dlhpv2oJXjoUK 7WoA== X-Gm-Message-State: AOAM531+nja1u6oRyi49xKGLUXej05Gk2M40u3/v43bHEFfwY2CIXcLo Nj4gBdv2+XsVOM55AwEoWQDg/vUO7EBBoxWeF1p3Wg== X-Google-Smtp-Source: ABdhPJweOknmYybC+K3gRbP2qioCOiAns0PcavbQZb0ARZAYxD8udKLes/O30Jr7eIfD5avGYJG+iPwPzJSo8JRhFUk= X-Received: by 2002:a5d:9cc7:: with SMTP id w7mr12457759iow.202.1605638411207; Tue, 17 Nov 2020 10:40:11 -0800 (PST) MIME-Version: 1.0 References: <20201014055106.25164-1-pcc@google.com> <20201117181431.GH15033@arm.com> In-Reply-To: <20201117181431.GH15033@arm.com> From: Peter Collingbourne Date: Tue, 17 Nov 2020 10:40:00 -0800 Message-ID: Subject: Re: [PATCH v2] arm64: Introduce prctl(PR_PAC_{SET,GET}_ENABLED_KEYS) To: Szabolcs Nagy X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201117_134015_339247_D79EA987 X-CRM114-Status: GOOD ( 38.34 ) 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, Catalin Marinas , Kevin Brodsky , Linux API , Kostya Serebryany , Evgenii Stepanov , Andrey Konovalov , Vincenzo Frascino , Will Deacon , Dave Martin , Linux ARM 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, Nov 17, 2020 at 10:14 AM Szabolcs Nagy wrote: > > The 11/17/2020 17:29, Catalin Marinas wrote: > > Adding Szabolcs and libc-alpha. The original patch below and also here: > > > > https://lore.kernel.org/r/20201014055106.25164-1-pcc@google.com > > > > The patch looks fine to me but I'd like the glibc community to confirm > > that they are happy with this ABI addition. I'd also like Dave Martin to > > ack the patch since he was involved in the discussion for v1. > > > > Thanks. > > > > Catalin > > > > On Tue, Oct 13, 2020 at 10:51:06PM -0700, Peter Collingbourne wrote: > > > This prctl 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. > > > > > > Signed-off-by: Peter Collingbourne > > > Link: https://linux-review.googlesource.com/id/Ibc41a5e6a76b275efbaa126b31119dc197b927a5 > > > --- > > > This patch must be applied on top of Catalin's MTE series: > > > > > > git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux for-next/mte > > > > > > Alternatively the series with this patch on top may be > > > downloaded from Gerrit by following the link above. > ... > > > +Enabling and disabling keys > > > +--------------------------- > > > + > > > +The prctl PR_PAC_SET_ENABLED_KEYS allows the user program to control which > > > +PAC keys are enabled in a particular task. It takes two arguments, the > > > +first being a bitmask of PR_PAC_APIAKEY, PR_PAC_APIBKEY, PR_PAC_APDAKEY > > > +and PR_PAC_APDBKEY specifying which keys shall be affected by this prctl, > > > +and the second being a bitmask of the same bits specifying whether the key > > > +should be enabled or disabled. For example:: > > > + > > > + prctl(PR_PAC_SET_ENABLED_KEYS, > > > + PR_PAC_APIAKEY | PR_PAC_APIBKEY | PR_PAC_APDAKEY | PR_PAC_APDBKEY, > > > + PR_PAC_APIBKEY, 0, 0); > > > + > > > +disables all keys except the IB key. > > > + > > > +The main reason why this is useful is to enable a userspace ABI that uses PAC > > > +instructions 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. > > which keys are enabled by default when HWCAP_PACA is > set in AT_HWCAPS ? i think that would be useful to > point out here. For compatibility with previous kernel versions all keys are enabled by default at process startup. But I agree it would be useful to point it out here. > per process enable/disable was deemed costly to do when > pac support was added, did this change? (i'm happy if it > did, because even without a new PAC specific pointer ABI, > plain PAC-RET can cause problems if a process tries to do > its own DWARF unwinding but does not understand the new > opcode that toggles PAC status of the return address, > possibly in a third party library, so a way to opt-out of > PAC is useful. currently it's a kernel config option and > system wide on or off.) My understanding is that it was considered too expensive to do without a use case, but we did come up with one. In general we only need to update the system register on process switch as well as on entry/exit if we need to disable IA which is also needed by in-kernel PAC. I did benchmark a variant of the code sequences on existing non-PAC HW [1] which showed that the entry/exit overhead in the common case where IA is left enabled is expected to be low. But with the new Apple chips I think it should be possible to benchmark the real entry/exit code sequences on supporting HW in the enabled and disabled cases. Peter [1] https://lore.kernel.org/linux-arm-kernel/CAMn1gO7HCJiXEzDvBb-=T7znATqyaxE_t-zezqKL0dyXRCG-nQ@mail.gmail.com/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel