From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 122CE2C979 for ; Wed, 21 Feb 2024 20:06:36 +0100 (CET) Received: (qmail 31898 invoked by uid 550); 21 Feb 2024 19:03:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 31875 invoked from network); 21 Feb 2024 19:03:14 -0000 Date: Wed, 21 Feb 2024 14:06:39 -0500 From: "dalias@libc.org" To: "Edgecombe, Rick P" Cc: "linux-arch@vger.kernel.org" , "suzuki.poulose@arm.com" , "Szabolcs.Nagy@arm.com" , "musl@lists.openwall.com" , "linux-fsdevel@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "kvmarm@lists.linux.dev" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "catalin.marinas@arm.com" , "broonie@kernel.org" , "oliver.upton@linux.dev" , "palmer@dabbelt.com" , "debug@rivosinc.com" , "aou@eecs.berkeley.edu" , "shuah@kernel.org" , "arnd@arndb.de" , "maz@kernel.org" , "oleg@redhat.com" , "fweimer@redhat.com" , "keescook@chromium.org" , "james.morse@arm.com" , "ebiederm@xmission.com" , "will@kernel.org" , "brauner@kernel.org" , "hjl.tools@gmail.com" , "linux-kselftest@vger.kernel.org" , "paul.walmsley@sifive.com" , "ardb@kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-mm@kvack.org" , "thiago.bauermann@linaro.org" , "akpm@linux-foundation.org" , "sorear@fastmail.com" , "linux-doc@vger.kernel.org" Message-ID: <20240221190639.GU4163@brightrain.aerifal.cx> References: <20240220235415.GP4163@brightrain.aerifal.cx> <20240221012736.GQ4163@brightrain.aerifal.cx> <20240221145800.GR4163@brightrain.aerifal.cx> <4a3809e8-61b2-4341-a868-292ba6e64e8a@sirena.org.uk> <20240221175717.GS4163@brightrain.aerifal.cx> <20240221183055.GT4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Re: [PATCH v8 00/38] arm64/gcs: Provide support for GCS in userspace On Wed, Feb 21, 2024 at 06:53:44PM +0000, Edgecombe, Rick P wrote: > On Wed, 2024-02-21 at 13:30 -0500, dalias@libc.org wrote: > > > 3 is the cleanest and safest I think, and it was thought it might > > > not > > > need kernel help, due to a scheme Florian had to direct signals to > > > specific threads. It's my preference at this point. > > > > The operations where the shadow stack has to be processed need to be > > executable from async-signal context, so this imposes a requirement > > to > > block all signals around the lock. This makes all longjmps a heavy, > > multi-syscall operation rather than O(1) userspace operation. I do > > not > > think this is an acceptable implementation, especially when there are > > clearly superior alternatives without that cost or invasiveness. > > That is a good point. Could the per-thread locks be nestable to address > this? We just need to know if a thread *might* be using shadow stacks. > So we really just need a per-thread count. Due to arbitrarily nestable signal frames, no, this does not suffice. An interrupted operation using the lock could be arbitrarily delayed, even never execute again, making any call to dlopen deadlock. > > > 1 and 2 are POCed here, if you are interested: > > > https://github.com/rpedgeco/linux/commits/shstk_suppress_rfc/ > > > > I'm not clear why 2 (suppression of #CP) is desirable at all. If > > shadow stack is being disabled, it should just be disabled, with > > minimal fault handling to paper over any racing operations at the > > moment it's disabled. Leaving it on with extreme slowness to make it > > not actually do anything does not seem useful. > > The benefit is that code that is using shadow stack instructions won't > crash if it relies on them working. For example RDSSP turns into a NOP > if shadow stack is disabled, and the intrinsic is written such that a > NULL pointer is returned if shadow stack is disabled. The shadow stack > is normally readable, and this happens in glibc sometimes. So if there > was code like: > > long foo = *(long *)_get_ssp(); > > ...then it could suddenly read a NULL pointer if shadow stack got > disabled. (notice, it's not even a "shadow stack access" fault-wise. So > it was looked at as somewhat more robust. But neither 1 or 2 are > perfect for apps that are manually using shadow stack instructions. It's fine to turn RDSSP into an actual emulated read of the SSP, or at least an emulated load of zero so that uninitialized data is not left in the target register. If doing the latter, code working with the shadow stack just needs to be prepared for the possibility that it could be async-disabled, and check the return value. I have not looked at all the instructions that become #UD but I suspect they all have reasonable trivial ways to implement a "disabled" version of them that userspace can act upon reasonably. Rich