Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2585492rdb; Wed, 21 Feb 2024 12:18:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZqH1wKnYOs+GZoo2unRMqrpjKlXouTDrdcMXHfXTMD89dQDbWutcTzg+aZLBjet/a5zt/LWo3bs/Y33YPog4mbSxNbD1GtB5DtOTCTQ== X-Google-Smtp-Source: AGHT+IHKeg228u9X4Kp3kCA+oZhr7hwhepawbck0pDsop3j/r6krDmSLpWPdJvJRKd7CX+dUD4NL X-Received: by 2002:a17:902:bb81:b0:1d9:9e4f:c0d5 with SMTP id m1-20020a170902bb8100b001d99e4fc0d5mr16239090pls.40.1708546729101; Wed, 21 Feb 2024 12:18:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708546729; cv=pass; d=google.com; s=arc-20160816; b=gEomodn0vwA98OnyXMmQFsj8L44cv/qWxdXdNkQDaaaE0ui3HiAfxNbZCTfu7j1aIe BU/mr3fhR/g13wZwQkiGtghENgEwcxxqDm+Cr5CzeoFL5bXbL8oEtf8kPfWJNx5trvrK fJu7HEIf9TBTMlOiLiBdmOwN0UOcQkpWeJibacRAXtcT3CtVBhX8GW20GfbqlxZ2zLyk p13e4PtN2iBlsTf7Dr47AT3t7FdOKPZb3HxMbIBRgHp2bJG1yrer2TDXX9KKzej4yXtA 635SvkwsphB36C3TUf+GNcRWLZGb20J6cNWemdYOprLtXWxHH8t/5ovW41hFHO4zNkQW S/0A== 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=FbyLp+xC3EzTYXjhQ8fik1wSF4YmttbOjmUVU/GKl3A=; fh=HzVMq8ygnsrE/BRujzgaRwJbI9iHJEbPm+DcoNH6z5o=; b=ETdDRRyiyLpnomFiiSlShVZR3j2FezUYLiO4GsaYZBtpJnoMW4IxBsQpRvv07onRbs 5F8y6ellATROiACpQccRZf2+0uNwZyTP8T0sx9ydD15ic8ZYNRRDRu4NJli1KL9psmXT ucNW49f/t5LfEcPkOepkC5zynJt7bEnRTiXxR5+EYIJ8dw/tIlGX9PWReFlh6cxidgYk YtYwrOukRjFj4wDcJirha477aLeYLxNs0QH1EjJVE1PDOkwlOhcTnZ7LcKnU2juZzay/ xqjrZ5oZ8Oub/rQHN2Q6HHQMbCwgtFf2vtgjCgY8O4OBTkdKoG8AhUhtL3EIBqV6tr39 wgyA==; 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-75452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75452-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j2-20020a170902da8200b001d9727a7409si8674450plx.551.2024.02.21.12.18.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 12:18:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=libc.org); spf=pass (google.com: domain of linux-kernel+bounces-75452-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75452-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 C4F9D285D4E for ; Wed, 21 Feb 2024 20:18:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5EE0686AE6; Wed, 21 Feb 2024 20:18:25 +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 8C75586AF1 for ; Wed, 21 Feb 2024 20:18:22 +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=1708546704; cv=none; b=bIpHtUBAYC3ETe0xfDZ7H5cBLi6DyWYnapjkrk8+hEy8NSPdWyMoEM6uOjwYi5sI1DVo0SZD275v31XZEwy5CTAeChPxp+W5RgWb3ddkO2dBrDqssXhhpSFwNCgCfoyT/X8RVfFOkv5PISqhqkWEHU6TyB1J2T5VmgOnMi6ahP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708546704; c=relaxed/simple; bh=fxZvJOJiXDTvbkMu2Yj2fcSV/FlmP4uoP83ryrj44dk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h+LFF8iYpeaWUiENX6+0Q9sH8Wa0/JQAr7TMI/3JfWufSariv/QqjdOfz8s9NMMYley4pEvq4OMgs6dyT5dbyWkeKUO2tnfJup3abWLs7ryRTghxZqd6Xifm5Ei4fpgr6UYXF1RagMLPiICc5HLQRQX9tqCU/CJVvvVtwoKCi9I= 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 15:18:37 -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: <20240221201837.GW4163@brightrain.aerifal.cx> References: <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> <20240221190639.GU4163@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 07:22:21PM +0000, Edgecombe, Rick P wrote: > On Wed, 2024-02-21 at 14:06 -0500, dalias@libc.org wrote: > > 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. > > Doh! Yep, it is not robust to this. The only thing that could be done > would be a timeout in dlopen(). Which would make the whole thing just > better than nothing. > > > > > > > > > > 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. > > We can't intercept RDSSP, but it becomes a NOP by default. (disclaimer > x86-only knowledge). OK, then I think the contract just has to be that userspace, in a process that might dynamically disable shadow stack, needs to do something like xor %reg,%reg before rdssp so that the outcome is deterministic in disabled case. > > 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. > > This would have to be thought through functionally and performance > wise. I'm not opposed if can come up with a fully fleshed out plan. How > serious are you in pursuing musl support, if we had something like > this? Up til this thread, my position was pretty much "nope" because it looked like it could not be done in a way compatible with existing interface requirements. However, what's been discussed here, contingent on a dynamic-disable (ideally allowing choice of per-thread or global, to minimize loss of hardening properties), Personally, I believe shadow stack has very low hardening value relative to cost/complexity, and my leaning would be just to ignore it. However, I also know it becomes marketing pressure, including pressure on distros that use musl -- "Why doesn't [distro] do shadow stack?? I thought you were security oriented!!!" -- and if it can be done in a non-breaking and non-invasive way, I think it's reasonable to pursue and make something work. > HJ, any thoughts on whether glibc would use this as well? > > It is probably worth mentioning that from the security side (as Mark > mentioned there is always tension in the tradeoffs on these features), > permissive mode is seen by some as something that weakens security too > much. Apps could call dlopen() on a known unsupported DSO before doing > ROP. I don't know if you have any musl users with specific shadow stack > use cases to ask about this. Yes, this is potentially an argument for something like the option 2, if there's a way to leave SS enabled but then trap when something goes wrong, detect if it went wrong via SS-incompatible library code, and lazily disable SS, otherwise terminate. But I just realized, I'm not even sure why shared libraries need to be explicitly SS-compatible. Unless they're doing their own asm stack switches, shouldn't they just work by default? And since I don't understand this reason, I also don't understand what the failure mode is when an incompatible library is loaded, and thus whether it would be possible to detect and attribute the failure to the library, or whether the library would induce failure somewhere else. Anyway, a mechanism to allow the userspace implementation to disable SS doesn't inherently expose a means to do that. A system integrator doing maximum hardening might choose to build all libraries as SS-compatible, or to patch the loader to refuse to load incompatible libraries. Rich