From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by sourceware.org (Postfix) with ESMTPS id 2F640384A00F for ; Tue, 17 Nov 2020 18:40:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2F640384A00F Received: by mail-io1-xd43.google.com with SMTP id t8so22193181iov.8 for ; Tue, 17 Nov 2020 10:40:12 -0800 (PST) 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=CyAGu0GO9bNrbqJussF90CtLVDgtI1zknhEcQRU4pbgGmM+TmqDZtz8o7PrjN//pH1 scENft9iXjed3ywaAq2iVv1R6uFkwoFTjJx3TGn2iJtWrV57prjuxRwvKmPah6D4HaDB wV/lOnf00w4Hdwavp31d59hnl3TZ5Bjb9Dk8oy7S8Dno0dvd7ZeJJWXkBjYTAd28Wt4r o15MDFrS3deTF3WdDMKjLGhkzlpJmmpwV0CjoWW/q1Q14ONT/dJZ639gzZoP2a2y5aUe n//akpMVSwQGXW5knub/VOw2SxcAfhvqCV2aKjCsNlV0aBhiMhxUxoCKHmAWC1xceaYI 7nqA== X-Gm-Message-State: AOAM532WvieBFSy4vVzFFYwyAy/IvDcNhe+cB6VlBvrYnHNcSEzkqh7r 7wtLUUGKn/2bFclRsc41jbRnSDEhC8FUFq2y/nl6JQ== 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" X-Spam-Status: No, score=-18.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Nov 2020 18:40:14 -0000 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/