Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp378688rdb; Fri, 6 Oct 2023 06:23:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGR4rAG4SincBxy4mLX1pXipNmW8dwkSFgVKP7QWXa3tWtsf2EoG+nNwXcL07Q9sH7g/g1d X-Received: by 2002:a05:6358:279e:b0:134:e458:688d with SMTP id l30-20020a056358279e00b00134e458688dmr7104986rwb.15.1696598618828; Fri, 06 Oct 2023 06:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696598618; cv=none; d=google.com; s=arc-20160816; b=FuVgzU92u5GW69AV/UMXK9WUjvuXGZN3scDTRRjH2Vfnq3GSkNeodAWTqgWWGnBxxo txV1mnvEU0WVm2KjQVjReFiBX+dsv8jiJISmnZVXA2LWDXxKkDUirCBgWZciyh+3p8GN vr/EDmF5dHJNPyPW8W7Ue3rD5PLQ5qC4a3E624KwOWh9vUm1lCuZm4RW4+9lTn4Dpa15 3HtHT+uAQmAM84FiLJIzKQGDsWeqPexaJnfOaslykewb0C79dnBWkME0m0p+OVJnIeaN ZElKaeE92+mfeR25CKlVrH0fkj0Ikw70XpLLCZBvUVNm4P30v8fGor0XFSBTyu8zAf+w QvAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cjyyJuiBEmN/zEDBVr9JAjFL+r95tcpVq5ej/W0iL/Y=; fh=DV8MINyO2oSpDuumpwIWH5MwGiYEDJgbyECSGjqh4n0=; b=L6sUPgu5UfdKrvtYAMVThOZuA7YnKj0UuQPobmZiPWbACnL5Oi4ZfwvjvtWTDhc7eM 7/PW0n0CNuVLisoTDZBw+Xf0AJYGFwUEUJXKvIN18s6hJ0Z4jwc5du4/J3R8HIgJEjD8 v71rXINEVakGTh3Z1qsODPrlMNgVoCaik2fPnuQNjo2mvgYtQfp2usN9vyKHshXKhjuY sT/ezktD0Yot4sWcq/+fV7I1aNhIbX/wLnR4ct4YY3/dkG2sA1L6xmIu3V+Xdj9IZZ8D gPsHpL6bgAK0SnLgJ0ppEFAjptMiSjvrVcgq9r2ifpiJ+BXjFVhSt0/0rzqGyY/1SxXe fi7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r7kN1bhY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id i22-20020a056a00225600b0068fcccf5c79si1440294pfu.220.2023.10.06.06.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 06:23:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r7kN1bhY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E677180CF50D; Fri, 6 Oct 2023 06:23:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232345AbjJFNXa (ORCPT + 99 others); Fri, 6 Oct 2023 09:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbjJFNX3 (ORCPT ); Fri, 6 Oct 2023 09:23:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57B8E83; Fri, 6 Oct 2023 06:23:28 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B6A1C433C8; Fri, 6 Oct 2023 13:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696598608; bh=EaTnbJI4I15tCsE5PAEOFEMV2gEpZ5O8xv29SdDb+qM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r7kN1bhYCxtxsrayiH2/Qvakhgo3xCg+wGyDWqoba/ZC5pHVgpQDCCyLUBMq5h54g ECPy9lW5VnfDNKExrrh7fEdQi/U/bsZ892xqQHM3S72mb56W82U4MfmqpjVIrrIJyB qr4LzQDOov95/YlKhpIXNX+7KimqRGoyORxBH1I2m/XYsnYxcLtqw4e1YjQNFIDBA5 tnW4b6DBxOSfdtiaDHBr9QAGaSCEQWZ729s1flrAd+bmsOCjhqUZ+msIzUEQjcpObI fcYAdK0dvdOg+7/O/AD46RjkpZyTdrX3BsQGRWK8UKSyIfp93PxVJs9Zo8bm/vRFfv hsYBCwh6ppprg== Date: Fri, 6 Oct 2023 14:23:18 +0100 From: Mark Brown To: "Eric W. Biederman" Cc: Catalin Marinas , Szabolcs Nagy , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , "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, Florian Weimer , Christian Brauner Subject: Re: [PATCH v4 03/36] arm64/gcs: Document the ABI for Guarded Control Stacks Message-ID: References: <43ec219d-bf20-47b8-a5f8-32bc3b64d487@sirena.org.uk> <38edb5c3-367e-4ab7-8cb7-aa1a5c0e330c@sirena.org.uk> <638a7be5-6662-471d-a3ce-0de0ac768e99@sirena.org.uk> <87y1ggylvq.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Ji8GpeD8VVTZwCCT" Content-Disposition: inline In-Reply-To: <87y1ggylvq.fsf@email.froward.int.ebiederm.org> X-Cookie: Rome wasn't burnt in a day. X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 06:23:37 -0700 (PDT) --Ji8GpeD8VVTZwCCT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Oct 06, 2023 at 07:29:45AM -0500, Eric W. Biederman wrote: > Mark Brown writes: > >> It's not just the default size that I dislike (I think the x86 > >> RLIMIT_STACK or clone3() stack_size is probably good enough) but the > >> kernel allocating the shadow stack and inserting it into the user > >> address space. The actual thread stack is managed by the user but the > >> shadow stack is not (and we don't do this very often). Anyway, I don't > >> have a better solution for direct uses of clone() or clone3(), other > >> than running those threads with the shadow stack disabled. Not sure > >> that's desirable. > > Running threads with the shadow stack disabled if they don't explicitly > > request it feels like it's asking for trouble - as well as the escape > > route from the protection it'd provide I'd expect there to be trouble > > for things that do stack pivots, potentially random issues if there's a > > mix of ways threads are started. It's going to be a tradeoff whatever > > we do. > Something I haven't seen in the discussion is that one of the ways I > have seen a non-libc clone used is to implement a fork with flags. > That is a new mm is created, and effectively a new process. Which > makes the characterization different. > In general creating a thread with clone and bypassing libc is > incompatible with pthreads, and the caller gets to keep both pieces. > As long as there is enough information code can detect that > shadow stacks are in use, and the code is able to create their own > I don't see why it shouldn't be the callers responsibility. > On the other hand I don't see the maintainer of clone Christian Brauner > or the libc folks especially Florian cc'd on this thread. So I really > don't think you have the right folks in on this conversation. Well, copying them in now. The discussion here is about allocation of shadow stacks for the arm64 implementation of the feature (the arm64 feature is called Guarded Control Stack in the architecture). These maintain a second copy of the stack with only the return targets in memory allocated with special protections so userspace can't write to it directly and use this when doing returns to ensure that the returns haven't been redirected. These shadow stacks can be allocated directly by userspace using a new system call map_shadow_stack(), doing this via mmap() was extensively discussed but it was concluded that this was very likely to lead to security problems so we've got this new syscall that ensures that shadow stack memory is never accessible to userspace via other means. The x86 implementation that has already been merged into mainline will allocate a new shadow stack for newly created threads when the creating thread has one. There was a suggestion to have arm64 diverge and require that threads be created with clone3() and manualy provide a shadow stack but then concerns were raised that as well as the issues with divergence this would be too disruptive for adoption due to non-libc thread creation. It's not controversial that it'd be good to have clone3() by able to explicitly specify a shadow stack, just if it should be required. --Ji8GpeD8VVTZwCCT Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmUgCkUACgkQJNaLcl1U h9DirQf/ftVM53t8n7Iz/c70/XaZOa6o2/1qaxs00hlLIEkmuVk5LjL0TViJlfRw qIRUvbR8y9MkOCjJOTAErDvidq4rFwmPiuk9mFZViDpRkDxpG13xvHCHIqZ4NPUe Eve09ZqsJK5dCaW8G4/FCkSIZF2yD1lGttWRhYwckUPBSHMVZevuylvin7vdrWAr sPCe3qp4gWYgplUtfxKadGeowpldz9LRCbARrBYB1jqSXcJbskcDd0L3KUH9ElFv kYT+Iyoh0j36gEZFuwWXioYTEbQcD5qsqcftvc5LW0vRiUlKo/MUND/c07YdRoBy DfP12K7+lLpdbS17lq6f6DfTuLAwcg== =J8v2 -----END PGP SIGNATURE----- --Ji8GpeD8VVTZwCCT--