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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14D3DC04A6A for ; Wed, 9 Aug 2023 14:24:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75D736B0071; Wed, 9 Aug 2023 10:24:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 70E2E6B0072; Wed, 9 Aug 2023 10:24:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D5DC6B0075; Wed, 9 Aug 2023 10:24:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4EBB76B0071 for ; Wed, 9 Aug 2023 10:24:25 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 21DB6B274D for ; Wed, 9 Aug 2023 14:24:25 +0000 (UTC) X-FDA: 81104786490.08.CAA2ADE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 189AF1C0022 for ; Wed, 9 Aug 2023 14:24:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691591063; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=osKhn2zbAJeWckhkpW/6Rm7/NmktrR2Rx3tg7Xf46xo=; b=MhLcynIJMpDlQwXeHfnBAL0A6+CMZvDWV+/PgjFFtbmpNLbigrZ+5JZmlhPU6JL4PkhoS2 NQewQgwrrDzrQ2+7x7K/jr4XbfUj1IGPGiCxq//XaHWI2OTm4ew7dm1ggSzAEDHRm8pOZo HE1d8m+haSfbET84dhCVoisRFBr/FLo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691591063; a=rsa-sha256; cv=none; b=YGHxTib+EwyB4Qn04x6ttYjaBEcFZ7A8ZQkpMP5Yedr8jzq9bKbPMkuhpdhGlJfomTS7eR g7BYsTmCSfFjs7d+2t4GZnkqOrN0nQ7A5dqCRsgnQQtUggD/M833cYc0Qhi33CLxxOLuKG 2cEQORE0BHVvI4R7LvMbsdS5yyLevNE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 20C1363A4C; Wed, 9 Aug 2023 14:24:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEDFEC433CA; Wed, 9 Aug 2023 14:24:16 +0000 (UTC) Date: Wed, 9 Aug 2023 15:24:14 +0100 From: Catalin Marinas To: Mark Brown Cc: Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v4 03/36] arm64/gcs: Document the ABI for Guarded Control Stacks Message-ID: References: <20230807-arm64-gcs-v4-0-68cfa37f9069@kernel.org> <20230807-arm64-gcs-v4-3-68cfa37f9069@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230807-arm64-gcs-v4-3-68cfa37f9069@kernel.org> X-Rspamd-Queue-Id: 189AF1C0022 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: tyouombj65derf1pitgmowmhmffozsaq X-HE-Tag: 1691591062-129300 X-HE-Meta: U2FsdGVkX1+D5JKH5b02pJqEw34rjXAST94yGLtZgE5C6P90x1n8wYJp5pljTT/nNsYIbnc5Ue0RY34S8utTVH4z6my0XNcq/OtnDEQld3WZ2W3lgRDTQDKAtWGBSBOgmp7cJVmiMBr8gM3NqxGGNAwg7f2Qd7tcOWj5reZil/x23xgSZsercz9wvpu3cEg0M+sDMbhkpBca5c8kLPPdaSGkeJldQH+KXVtLCGRGSXrhqbTIKt/uvho5ldiwPADWipc6fNkdl+vH3Y+OhnN4nxIyNIz7j4XV4aXULiEX1DkUxqG06gvS6YfgMUeS9bKaWTtXbfJ4f64y4bJjo5Y2mv0/n8Zx+xjzeYp8023cEHgs3fZukHILzUUJDd0lVOBAvqXpEF78ziazVE5fkqxyEGyMLTkULOOiEZwjj5tvOCgd2EOm0ci2mHMxOPbByS5niFXfD7fWlp8kv/cO8sMSqwRU8ff5yqltVALHgNK5kMNctIjv/Vu8MCDs+7bmedI17sbwkCV37eVgjyQv7ClleRC5uItZXrXmvMOBAbHlWaTXFJW6xka7QCNuPjST97MW8guY7gURheu7UDdIP/qa3CCb7IG8MEEiRzn+J/j+x92Do21V6MyoJvp4GjWMy4DlNVEPGSwUd0d1hYmHRUaE16i4EskXH6CkZrC65ZRvathhCp+GYuu/mCogzUQVEHIe/MtJ9ShCeYcgBEccOGizo5ICgPq7icGr6rfR0759G9LD5nvj31x+91+N+AT6EVEgLM3HLC1/WMjpc/1D4NeDuQJglJhQ8h4B5Ke1uLsVKOo218IoZjjZBYISJOZyUbhXWyEn7oeBxJwnzcsJWF8FQlqYvSEcEtev+8t/U3/8clu6yyM0zftc/MwSThRPD4SzKg5GrFBVuo5xUNDkmisjmbZCOj7pD5WgGqpUGPTU0vAFTtAjDY7mrY7Hbxkzo5dNSFZY/xOBW9tZNeTueBl LppOG48U mYFQJIyWjRG4Q60WVFbv5d6F3t0RQEDLjo00+Wawb+sSnFe+s85msV7QT/dlq9dECqMYFJS0BGqwv7tTbsgha3iERQCVkgHxwalqyFksmJX0NGhwNkMu+OglfwnUIk69hBJlvTFKw+sW/Oik3vAuALWEFWorWgJ7RkRyUA257Ng+kHfxZi7o/tMZSfW4cu4Vt38VMYz3/H1xemCW9A/Gx4rDrNT62jNz2Jcf9WLDSQ6JHNGJpEP8Ttik+bdq2el+w029vX32MjfLRp/qx+YhOCdVNHvSd2xwUWvUiFdrMEo2T8JAhJdo8fmPAdtVv9kO78nfd6zSWsXU/ZGP6PATbto2t/fz8hdgCY+ep2wpL2x6MvS1yFQDh/4mhU18yzMEvzG/7t/5OfwS8kwxO/OhM61wheVtshe8pogYthMCNXL9f+OucqjoF49KVse9i3/XXll3ctGZYW0sZ0n/SvoPU18WfLxYPIBgwOzTDg6VsFT1cY34= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Aug 07, 2023 at 11:00:08PM +0100, Mark Brown wrote: > +2. Enabling and disabling Guarded Control Stacks > +------------------------------------------------- > + > +* GCS is enabled and disabled for a thread via the PR_SET_SHADOW_STACK_STATUS > + prctl(), this takes a single flags argument specifying which GCS features > + should be used. > + > +* When set PR_SHADOW_STACK_ENABLE flag allocates a Guarded Control Stack for The 'for' at the end of the line above is not needed. > + and enables GCS for the thread, enabling the functionality controlled by > + GCSPRE0_EL1.{nTR, RVCHKEN, PCRSEL}. This should be GCSCRE0_EL1. > +* When set the PR_SHADOW_STACK_PUSH flag enables the functionality controlled > + by GCSCRE0_EL1.PUSHMEn, allowing explicit GCS pushes. > + > +* When set the PR_SHADOW_STACK_WRITE flag enables the functionality controlled > + by GCSCRE0_EL1.STREn, allowing explicit stores to the Guarded Control Stack. > + > +* Any unknown flags will cause PR_SET_SHADOW_STACK_STATUS to return -EINVAL. > + > +* PR_LOCK_SHADOW_STACK_STATUS is passed a bitmask of features with the same > + values as used for PR_SET_SHADOW_STACK_STATUS. Any future changes to the > + status of the specified GCS mode bits will be rejected. > + > +* PR_LOCK_SHADOW_STACK_STATUS allows any bit to be locked, this allows > + userspace to prevent changes to any future features. I presume a new lock prctl() won't allow unlocking but can only extend the lock. I haven't looked at the patches yet but it may be worth spelling this out. > +* PR_SET_SHADOW_STACK_STATUS and PR_LOCK_SHADOW_STACK_STATUS affect only the > + thread the called them, any other running threads will be unaffected. s/the called/that called/ > +* New threads inherit the GCS configuration of the thread that created them. > + > +* GCS is disabled on exec(). > + > +* The current GCS configuration for a thread may be read with the > + PR_GET_SHADOW_STACK_STATUS prctl(), this returns the same flags that > + are passed to PR_SET_SHADOW_STACK_STATUS. > + > +* If GCS is disabled for a thread after having previously been enabled then > + the stack will remain allocated for the lifetime of the thread. Sorry if this has been discussed in other threads. What is the issue with unmapping/freeing of the shadow stack? > At present > + any attempt to reenable GCS for the thread will be rejected, this may be > + revisited in future. What's the rationale here? Is it that function returns won't work? > +3. Allocation of Guarded Control Stacks > +---------------------------------------- > + > +* When GCS is enabled for a thread a new Guarded Control Stack will be > + allocated for it of size RLIMIT_STACK / 2 or 2 gigabytes, whichever is > + smaller. Is this number based on the fact that a function call would only push the LR to GCS while standard function prologue pushes at least two registers? > +* When GCS is disabled for a thread the Guarded Control Stack initially > + allocated for that thread will be freed. Note carefully that if the > + stack has been switched this may not be the stack currently in use by > + the thread. Does this not contradict an earlier statement that the GCS is not freed for a thread when disabled? > +4. Signal handling > +-------------------- > + > +* A new signal frame record gcs_context encodes the current GCS mode and > + pointer for the interrupted context on signal delivery. This will always > + be present on systems that support GCS. > + > +* The record contains a flag field which reports the current GCS configuration > + for the interrupted context as PR_GET_SHADOW_STACK_STATUS would. > + > +* The signal handler is run with the same GCS configuration as the interrupted > + context. > + > +* When GCS is enabled for the interrupted thread a signal handling specific > + GCS cap token will be written to the GCS, this is an architectural GCS cap > + token with bit 63 set. The GCSPR_EL0 reported in the signal frame will > + point to this cap token. I lost track of the GCS spec versions. Has the valid cap token format been updated? What I have in my spec (though most likely old) is: An entry in the Guarded control stack is defined as a Valid cap entry, if bits [63:12] of the value are same as bits [63:12] of the address where the entry is stored and bits [11:0] contain a Valid cap token. The other bits in the code look fine to me so far but I haven't looked at the code yet. -- Catalin