Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2552809rdb; Wed, 21 Feb 2024 11:07:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXlVSKtTN4twKT+XeTzRssKoMhqP0RmtZAPmws+H/iuM2ubjaAu7m6+LcxnvUPn7qJh4qxbWlwrcm/xjhvuL9n8eYRRHYpsnOlt93sTrQ== X-Google-Smtp-Source: AGHT+IHXIn2fEpJAr3To6Lueiq16SVPnd0WvzScGjpiqQOizRlMJEgprxhFJ05557ZiskQtPBCNU X-Received: by 2002:a05:6358:ca2:b0:17b:62ac:1dd7 with SMTP id o34-20020a0563580ca200b0017b62ac1dd7mr2129256rwj.12.1708542423077; Wed, 21 Feb 2024 11:07:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708542423; cv=pass; d=google.com; s=arc-20160816; b=ux14tFuhqbydQESaDk1306bomdVLdc35/4Hv3NS4EufrOKILNZTxNCz4wBjLSZ5sez J4AGy0r9LyNEaefJUJUCcOqHGbk13cDJdWSwgySNYVGi1izzHOfsXUcEneBMT0ujxXhE 7zKRhxSJZePg6uY0dPATl6xvLElpGFyrINqZRkA7yTEJDFMJoY2nbfxgDsmL5PjmPVsP FMHfrmgXJR1cyM9j9FWlPm8U+BZdC6Oswgk3E1+HBXHr0EIGGPwcKqn/877juaqymrsP rKJ1rqn8v8aJKsxdvEjsr/rdsKizz5iMuRxi+Q8VHLLsHxwXUTvRW4Q6eLJGkyr0Xn0q 74xA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date; bh=xAktgdcemPcGw59oner9mxgVxm5gS0p5bunxuxd7a14=; fh=HzVMq8ygnsrE/BRujzgaRwJbI9iHJEbPm+DcoNH6z5o=; b=lf0ErEH1BeN07ErIVAo+GWTQs1D0xheuhWPlFzdvJHBsxOnRuN5W5vFwmLRwW6JCjq sYVR2hyDW3ZtaGgigqnBebuLotk8ggGCuua9sJzC8+ROYfM21SP2qg4YS/e0g+UiqBF7 UVSkryI6uxrEnIW4f98eQPJ5Y19XvmYBv8AiCXTL6WbQP19sVY0ALlERMMWyk3iKFY45 AvNiA8JcFy5tEPqkwpX8tqs/weCLA7kEnd29/oH1kfH+6NdE5G3n/a2b40jXwwz3zYyD 0nxPL7jvjs3quJU8+qokIrr7bDyaW/xisn68PUi4mx6tig1RTM9mcdNj9+3NeWicZWdO RqEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=libc.org); spf=pass (google.com: domain of linux-kernel+bounces-75342-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75342-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i195-20020a636dcc000000b005d5d74411fasi8762170pgc.207.2024.02.21.11.07.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 11:07:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75342-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=libc.org); spf=pass (google.com: domain of linux-kernel+bounces-75342-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75342-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C01F1284DBA for ; Wed, 21 Feb 2024 19:07:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21BCC8664C; Wed, 21 Feb 2024 19:06:47 +0000 (UTC) Received: from brightrain.aerifal.cx (brightrain.aerifal.cx [104.156.224.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB39E86130 for ; Wed, 21 Feb 2024 19:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=104.156.224.86 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708542402; cv=none; b=gsrvHNv8t7B7WSVdPlaZbEVsFfb1071cJoRrTrNrixbGbu8waYuMidpyfR/9AxZRGpgbNhuTjzkyhCpPTT6XHgzzZcwy/ZdYECryZLduN28nZMSqbKViyAaN0doTLpjm+IRkSpxJRZaVeddErqrWztQSex8yorj0jch7NJnEjyY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708542402; c=relaxed/simple; bh=tMAboUzIpbI8r0aCkLKiq7wam/35ifq+uf2tH3/h5q4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qD3BfcNw9YVIKaLHic8bOdmVJWV1iDIKom2pdYBb2iJu8fLmuOb9mov7LzDbIMelfdcJy+FOlY5dZFP5/IR8R3BrRa9XoL6747kQTYyNzUdgsC9y2osOh1gpQqCygNBtfs7pIPq9cqAO6hue53MLzxH+5vr2LXuAbq/o33E2+5g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=libc.org; spf=pass smtp.mailfrom=libc.org; arc=none smtp.client-ip=104.156.224.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=libc.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=libc.org 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" Subject: Re: [musl] Re: [PATCH v8 00/38] arm64/gcs: Provide support for GCS in userspace 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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) 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