Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1104360rdg; Fri, 11 Aug 2023 09:49:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPNZuK7DwbXHEw4OyoUDRKqaSfcI8eD5XW8wclKkPoeF91RAJDo4TqG1hKdZKuc0XGPNfE X-Received: by 2002:a05:6a20:1447:b0:12f:eb74:72b6 with SMTP id a7-20020a056a20144700b0012feb7472b6mr2479832pzi.60.1691772547648; Fri, 11 Aug 2023 09:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772547; cv=none; d=google.com; s=arc-20160816; b=tYqAh3eHyiqxhsM8nz399AtfwqpcmU3lxtOhvkuDpQBdnCraj8Mt6jdRK2Giw2rGXG 5vAtNh4pQjOubVLMoDdtM2DsR61vLTXdUzXhi8S///Usuq2xCbqnOthYgDvWekC18NOt sEtmLokg1KgqS5MEf8+FWjaPLyvFy+zDlsGgzW5wqn9hbSMP921sd47zOIMhPyovf0Q2 IQTcYW0WW7x2sskUt06tmUVioYlP6ugOboxdiKSmAOmk/Lep78FGBm+D3SXc5IEtbZIj ymTzK0X0OT0mcaC4ERdqD1OTHBPAUqv53ZjqJ1J1kPjFvczW40h1QSF3N9I92A9I6heA DJxQ== 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; bh=8fjANWOstaIzcYa5Cg1g7lz2w2/b4n6P/2JqHwTYBtE=; fh=2wxoOguWzzWu+YGUlY4iG2KZkVCU8hdxOZfl5CjkbsQ=; b=kyDr3UL7y62wG4OfOyLIuz0wo7yoRFdegfWxNvgG9pC41gqDnkIybk0WapGYbBoCW0 57pLQFJKxRqq6v336AjTZYdZUAb+LBKg9nyTKN8AZBEU0gajxjUiz/33sDlQiNAiIJyV l1i2NDWJUNOOPdi8484cR3LmKj52NEYLGhNAGK6ezJ8A9Wp00/n/xS9NnZnQJAThLfF7 gy0hRSNEMIWvi9dWf5KMtQc3sL/xu/KeoxmksMpXZb95Xa57phD5/1Zr3zRyEe6q9BGQ bg5gffSHW83VBFhBUjTI4et4H+rSxCsqX96JOL9pSnl0kUknuZ33MryFxGbBDcGYpa3E cA1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv15-20020a056a00414f00b0068208d19b1dsi3562580pfb.153.2023.08.11.09.48.55; Fri, 11 Aug 2023 09:49:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjHKQ0N (ORCPT + 99 others); Fri, 11 Aug 2023 12:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjHKQ0M (ORCPT ); Fri, 11 Aug 2023 12:26:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECAF418F; Fri, 11 Aug 2023 09:26:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 87FA464ED5; Fri, 11 Aug 2023 16:26:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AFF3C433C7; Fri, 11 Aug 2023 16:26:05 +0000 (UTC) Date: Fri, 11 Aug 2023 17:26:03 +0100 From: Catalin Marinas To: Mark Brown Cc: Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , "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 Subject: Re: [PATCH v4 19/36] arm64/gcs: Allocate a new GCS for threads with GCS enabled Message-ID: References: <20230807-arm64-gcs-v4-0-68cfa37f9069@kernel.org> <20230807-arm64-gcs-v4-19-68cfa37f9069@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230807-arm64-gcs-v4-19-68cfa37f9069@kernel.org> X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=no 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 On Mon, Aug 07, 2023 at 11:00:24PM +0100, Mark Brown wrote: > diff --git a/arch/arm64/mm/gcs.c b/arch/arm64/mm/gcs.c > index b0a67efc522b..1e059c37088d 100644 > --- a/arch/arm64/mm/gcs.c > +++ b/arch/arm64/mm/gcs.c > @@ -8,6 +8,62 @@ > #include > #include > > +static unsigned long alloc_gcs(unsigned long addr, unsigned long size, > + unsigned long token_offset, bool set_res_tok) > +{ > + int flags = MAP_ANONYMOUS | MAP_PRIVATE; > + struct mm_struct *mm = current->mm; > + unsigned long mapped_addr, unused; > + > + if (addr) > + flags |= MAP_FIXED_NOREPLACE; > + > + mmap_write_lock(mm); > + mapped_addr = do_mmap(NULL, addr, size, PROT_READ, flags, > + VM_SHADOW_STACK | VM_WRITE, 0, &unused, NULL); Why not PROT_WRITE as well? I guess I need to check the x86 patches since the do_mmap() called here has a different prototype than what's in mainline. This gets confusing since currently the VM_* flags are derived from the PROT_* flags passed to mmap(). But you skip the PROT_WRITE in favour of adding VM_WRITE directly. I haven't followed the x86 discussion but did we run out of PROT_* bits for a PROT_SHADOW_STACK? > + mmap_write_unlock(mm); > + > + return mapped_addr; > +} > + > +static unsigned long gcs_size(unsigned long size) > +{ > + if (size) > + return PAGE_ALIGN(size); > + > + /* Allocate RLIMIT_STACK with limits of PAGE_SIZE..4G */ > + size = PAGE_ALIGN(min_t(unsigned long long, > + rlimit(RLIMIT_STACK), SZ_4G)); > + return max(PAGE_SIZE, size); > +} I saw Szabolcs commenting on the default size as well. Maybe we should go for RLIMIT_STACK/2 but let's see how the other sub-thread is going. > + > +unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, > + unsigned long clone_flags, size_t size) > +{ > + unsigned long addr; > + > + if (!system_supports_gcs()) > + return 0; > + > + if (!task_gcs_el0_enabled(tsk)) > + return 0; > + > + if ((clone_flags & (CLONE_VFORK | CLONE_VM)) != CLONE_VM) > + return 0; Is it safe for CLONE_VFORK not to get a new shadow stack? A syscall for exec could push something to the stack. I guess the GCS pointer in the parent stays the same, so it wouldn't matter. That said, I think this check should be somewhere higher up in the caller of gcs_alloc_thread_stack(). The copy_thread_gcs() function already does most of the above checks. Is the GCS allocation called from elsewhere as well? -- Catalin