Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2535450rdb; Wed, 21 Feb 2024 10:31:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXUro1Dr2i0BxwZyMS4X1psDEXbZK2vsrUphJBBnQBpSgowI6Hr8a2TZdi9ebRbePFLGuK2Fq8Nr6ZYuUr+pvFnxFr6rQGKOwedpqWsZQ== X-Google-Smtp-Source: AGHT+IHVPIhDpEj2u1mrurlkq+J7QKtr2/8nV/QEtHLYBynpyEvgkois0jWdKyOMINU003YIUocV X-Received: by 2002:a17:906:289b:b0:a3e:c3ee:33a5 with SMTP id o27-20020a170906289b00b00a3ec3ee33a5mr5132236ejd.45.1708540262440; Wed, 21 Feb 2024 10:31:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708540262; cv=pass; d=google.com; s=arc-20160816; b=YeWADO1dqNwV9WLKSD3WNSAeG4+tpZ4jcZ25ZCLyVHWHy6+46K90ruS9r2aZ7pGAoT E6DMHxM4vhN8rFG20yRrFHqJ8cdZzWy59tm/zFnVlzf5EDPxkSDHNzdMp41WJXDMeLVF ZPG9W5uYbu+By0BlPBhu3nfmUG1DiYcAySJfXctNT6OU07+sZRJ3qoaWimBMeXAxehJ7 uZyDnyAMgtTISFT3j6i/RW6IANomWkU9an0+Q6F6sNLnCS1YAh8sanOQ4GOUf1bio0bD FzhKBcRO2hvA0Jpuba7wUJ974kWpkhwJB6FVOWCcxLD/TwCHiEZ+g5wrX1BvI9KNQ8Y5 lnxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:references:message-id:subject:cc:to:from:date; bh=7TaZpQY2uWig9Jh8JuVHf8OXFZUFrp2yLgnoxxCd5M8=; fh=Ti5ZZv/TCaxmQmaVjh7GvemXmidmnGTf4TYwKcCKySM=; b=QLMIIgAG9441y1U4ow29Vyc0207ubWvGe8JIAPaUCoqvMsmd4dXiMZsGNv8lQhvKQY V9v1qwsdduGDa0g/B35a3vCFgAliRgGQMtrPXgig0xUANPjtn7qiprSZp4a5WrSu0ZoO 29ZrQKoCQ6Os+3DgowrxnVDXqUntJcOJGH7LUkx+EYi2rwq+MPk8B4oUnZuHqrCi56il W5ylAv7FpU6OxmQVHQrNFzOgg2h/ZOPWsrdVrXXJnoyOefUHByaQO0yj9ktr9BvN4oxR BVoNOkhQLLMsqPiMLjf1XxeNXu61lGzbwDsI4+ze/cW46Aqtb24UW7whXJtyBCljxrbE GWIw==; 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-75297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75297-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hd16-20020a170907969000b00a3e864d580esi3382909ejc.835.2024.02.21.10.31.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 10:31:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=libc.org); spf=pass (google.com: domain of linux-kernel+bounces-75297-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75297-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 08A041F290E6 for ; Wed, 21 Feb 2024 18:31:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 177B885936; Wed, 21 Feb 2024 18:30:45 +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 5362383CBB for ; Wed, 21 Feb 2024 18:30:39 +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=1708540244; cv=none; b=FNVfzUmpFG7A8ZeZ1hQa0jm2Y+W/KJ0kObaabqd/6bPdNUTb1BPHg7f3udTWEanlKqD9DMLk8JBgNthny4fswPdW8bWYiA0rohdwImB51pmwh2jSYLvA9f3vkU2Ii5cxCflQMbz/kpRE0QlL7YD1WecTvwGqsT1grXXr6qOzdKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708540244; c=relaxed/simple; bh=IQ9Hdi1C0K5tEBHBjujZgoxD3cUlRqBGyMd80ICd2vI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lDxDS9MBDeXWSuk75zuK3+A3i0gdiB3XBXw92kAy4gHxV3DfxPNMd7Riy+SX7prhzpHqM/P+iNeZYkKgHRt03dUkEUt26cLtkFjazotiu0kzrEcV/HIvrGkJ41zV7tv9t9R60ksOH62/K/zE06xyT0BboSc9/S0RzUqIpdfNnI4= 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 13:30:55 -0500 From: "dalias@libc.org" To: "Edgecombe, Rick P" Cc: "broonie@kernel.org" , "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" , "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" , "thiago.bauermann@linaro.org" , "linux-arm-kernel@lists.infradead.org" , "linux-mm@kvack.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: <20240221183055.GT4163@brightrain.aerifal.cx> References: <20240220185714.GO4163@brightrain.aerifal.cx> <9fc9c45ff6e14df80ad023e66ff7a978bd4ec91c.camel@intel.com> <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> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) On Wed, Feb 21, 2024 at 06:12:30PM +0000, Edgecombe, Rick P wrote: > On Wed, 2024-02-21 at 12:57 -0500, dalias@libc.org wrote: > > > This feels like it's getting complicated and I fear it may be an > > > uphill > > > struggle to get such code merged, at least for arm64.  My instinct > > > is > > > that it's going to be much more robust and generally tractable to > > > let > > > things run to some suitable synchronisation point and then disable > > > there, but if we're going to do that then userspace can hopefully > > > arrange to do the disabling itself through the standard disable > > > interface anyway.  Presumably it'll want to notice things being > > > disabled > > > at some point anyway?  TBH that's been how all the prior proposals > > > for > > > process wide disable I've seen were done. > > > > If it's possible to disable per-thread rather than per-process, some > > things are easier. Disabling on account of using alt stacks only > > needs > > to be done on the threads using those stacks. However, for dlopen > > purposes you need a way to disable shadow stack for the whole > > process. > > Initially this is only needed for the thread that called dlopen, but > > it needs to have propagated to any thread that synchronizes with > > completion of the call to dlopen by the time that synchronization > > occurs, and since that synchronization can happen in lots of > > different > > ways that are purely userspace (thanks to futexes being userspace in > > the uncontended case), I don't see any way to make it work without > > extremely invasive, high-cost checks. > > For glibc's use, we talked about a couple of options. > 1. A mode to start suppressing the #UD's from the shadow stack > instructions > 2. A mode to start suppressing #CPs (the exception that happens when > the shadow stack doesn't match). So the shadow stack instructions > continue to operate normally, but if the shadow stack gets mismatched > due to lack of support, the ret is emulated. It probably is safer (but > still not perfect), but the performance penalty of emulating every RET > after things get screwed up would be a significant down side. There > also needs to be clean handling of shadow stack #PFs. > 3. Per-thread locking that is used around all shadow stack operations > that could be sensitive to disabling. This could be maybe exposed to > apps in case they want to use shadow stack instructions manually. Then > during dlopen() it waits until it can cleanly disable shadow stack for > each thread. In each critical sections there are checks for whether > shadow stack is still enabled. > > 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. > 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. Is there some way folks have in mind to use option 2 to lazily disable shadow stack once the first SS-incompatible code is executed, when execution is then known not to be in the middle of a SS-critical section, instead of doing it right away? I don't see how this could work, since the SS-incompatible code could be running from a signal handler that interrupted an SS-critical section. > > If folks on the kernel side are not going to be amenable to doing the > > things that are easy for the kernel to make it work without breaking > > compatibility with existing interfaces, but that are impossible or > > near-impossible for userspace to do, this seems like a dead-end. And > > I > > suspect an operation to "disable shadow stack, but without making > > threads still in SS-critical sections crash" is going to be > > necessary.. > > I think we have to work through all the alternative before we can > accuse the kernel of not being amenable. Is there something that you > would like to see out of this conversation that is not happening? No, I was just interpreting "uphill battle". I really do not want to engage in an uphill battle for the sake of making it practical to support something that was never my goal to begin with. If I'm misreading this, or if others are willing to put the effort into that "battle", I'd be happy to be mistaken about "not amenable". Rich