Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5953485rwb; Tue, 1 Aug 2023 10:05:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHAX2XR2nt1N3EUTf/xgoruT9IRnI0znkRjm+2O30+lL5YZv4d7QwcFYW+KzeQZ3heZ0gJ2 X-Received: by 2002:a05:6402:180f:b0:522:ae79:3ee6 with SMTP id g15-20020a056402180f00b00522ae793ee6mr3280454edy.10.1690909511064; Tue, 01 Aug 2023 10:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690909511; cv=none; d=google.com; s=arc-20160816; b=LlMah+JDHzmazV9zQez/S4PYvePzC0AFpcPbG1S2qEk4k5PqTax03TTrAJJ4kaDh3V +pJO5/Yxx1PTcQ6r4CJMIq0txLnkFmEysyqjGDHLQ0ssB7jujagy+SGbmcK8arknKV3M 2Hi9CvIm1JV9TOEy3K6ZWVK2Ce1iJVynV+aQAzLGr2OPD5nBBQku6HMO8i7FJMFjAkgd 62OF3yLiY1fUzJv+tEZKJDk1ASdIlV0Mj6uvOaYRPfpIgyZNuHaAsacf+o36GhMO/EUJ qT6h80/i74XtyME3gzDuxKvAC5pm6qqSpSy/+hJi+GFZyjhzH5P2Jnar+a9uTg6rB4fw XCTQ== 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=qVoiuKS0W2XXCf835vl3k9bPGKeXZoIa/3wT64gizf0=; fh=86YiweivM8l19t+tiaju6VSHxPpI4nc3szBc9CD94rM=; b=QQvxWqO9Yu8jVjkK6KdGTovJvcXHGBvTGPbyhMUqXmoRWkaPGgF4thUv8Y2UasHq0o 5rhUAluI/s4tl+1uu+3FP+quW2X2H8pN6LSbnlYVRUt1KOWj4O36XvOUT0uLWZs5YMRM naVECXWb9DJ4mfY3vfJA90AH+8CPPlhkcrkCE81oClqvuahL0cmYKD1QXH9HfE3PfwF8 +AJfN3EyPw+AquDrLUByR8OHpVXkXnCkPbJrtd6Vs+qERpChtdv5AGNcI0ThIoAkWOGQ Geu60J06qpQtjrv/2idZS/6FlfkLX0ntCtXEzEv/NVA8IykmXzGUlG04qoc+4QWytMpK +eCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HwuBZpEX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k14-20020aa7c38e000000b00521937ee981si8506864edq.402.2023.08.01.10.04.37; Tue, 01 Aug 2023 10:05:11 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HwuBZpEX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232579AbjHAQxU (ORCPT + 99 others); Tue, 1 Aug 2023 12:53:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjHAQxS (ORCPT ); Tue, 1 Aug 2023 12:53:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8667C2113; Tue, 1 Aug 2023 09:53:17 -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 2342461467; Tue, 1 Aug 2023 16:53:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C798C433C8; Tue, 1 Aug 2023 16:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690908796; bh=NHmRrolFzdbUCu0kGXaymHyZEubMVArK6rwqeVruN0U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HwuBZpEXBkB3CE/V4KajSW3gnSYxF2tTjPViqE5A2oIIqLhUA+0e+IblDugFg9Z2u S0Ck8LhYAevrbvQxgA14aPLtbGABfSIR5vcwXDlVxuid5aG3oZuIZ24GF4qCEi3IIi nquYYS/spIOcUnYGkTZSIhj8c7X3XZblzixj+fUIuO+4mRpF6xrStoQCv057iq9NcN OkLBQr9pYhByRIZ12cquz0en1ISm3gUO4XVCwiWtG4Ia+W8uhfhrgR05V3posavWjw w1nbmtetuo2DR+rp1snmcsOZM8YJBF3KIXGQdzz738GzV9sSr7MiaVVvVM4/dTLin+ 4LEATCs36iNcA== Date: Tue, 1 Aug 2023 19:52:21 +0300 From: Mike Rapoport To: Rick Edgecombe , Dave Hansen Cc: broonie@kernel.org, akpm@linux-foundation.org, andrew.cooper3@citrix.com, arnd@arndb.de, bp@alien8.de, bsingharora@gmail.com, christina.schimpe@intel.com, corbet@lwn.net, david@redhat.com, debug@rivosinc.com, dethoma@microsoft.com, eranian@google.com, esyr@redhat.com, fweimer@redhat.com, gorcunov@gmail.com, hjl.tools@gmail.com, hpa@zytor.com, jamorris@linux.microsoft.com, jannh@google.com, john.allen@amd.com, kcc@google.com, keescook@chromium.org, kirill.shutemov@linux.intel.com, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, luto@kernel.org, mike.kravetz@oracle.com, mingo@redhat.com, nadav.amit@gmail.com, oleg@redhat.com, pavel@ucw.cz, pengfei.xu@intel.com, peterz@infradead.org, rdunlap@infradead.org, szabolcs.nagy@arm.com, tglx@linutronix.de, torvalds@linux-foundation.org, weijiang.yang@intel.com, willy@infradead.org, x86@kernel.org, yu-cheng.yu@intel.com Subject: Re: [PATCH] x86/shstk: Move arch detail comment out of core mm Message-ID: <20230801165221.GA2607694@kernel.org> References: <20230706233248.445713-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230706233248.445713-1-rick.p.edgecombe@intel.com> 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,T_SCC_BODY_TEXT_LINE 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 Hi Dave, Rick, It seems it didn't get into the current tip. On Thu, Jul 06, 2023 at 04:32:48PM -0700, Rick Edgecombe wrote: > The comment around VM_SHADOW_STACK in mm.h refers to a lot of x86 > specific details that don't belong in a cross arch file. Remove these > out of core mm, and just leave the non-arch details. > > Since the comment includes some useful details that would be good to > retain in the source somewhere, put the arch specifics parts in > arch/x86/shstk.c near alloc_shstk(), where memory of this type is > allocated. Include a reference to the existence of the x86 details near > the VM_SHADOW_STACK definition mm.h. > > Signed-off-by: Rick Edgecombe > --- > arch/x86/kernel/shstk.c | 25 +++++++++++++++++++++++++ > include/linux/mm.h | 32 ++++++-------------------------- > 2 files changed, 31 insertions(+), 26 deletions(-) > > diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c > index b26810c7cd1c..47f5204b0fa9 100644 > --- a/arch/x86/kernel/shstk.c > +++ b/arch/x86/kernel/shstk.c > @@ -72,6 +72,31 @@ static int create_rstor_token(unsigned long ssp, unsigned long *token_addr) > return 0; > } > > +/* > + * VM_SHADOW_STACK will have a guard page. This helps userspace protect > + * itself from attacks. The reasoning is as follows: > + * > + * The shadow stack pointer(SSP) is moved by CALL, RET, and INCSSPQ. The > + * INCSSP instruction can increment the shadow stack pointer. It is the > + * shadow stack analog of an instruction like: > + * > + * addq $0x80, %rsp > + * > + * However, there is one important difference between an ADD on %rsp > + * and INCSSP. In addition to modifying SSP, INCSSP also reads from the > + * memory of the first and last elements that were "popped". It can be > + * thought of as acting like this: > + * > + * READ_ONCE(ssp); // read+discard top element on stack > + * ssp += nr_to_pop * 8; // move the shadow stack > + * READ_ONCE(ssp-8); // read+discard last popped stack element > + * > + * The maximum distance INCSSP can move the SSP is 2040 bytes, before > + * it would read the memory. Therefore a single page gap will be enough > + * to prevent any operation from shifting the SSP to an adjacent stack, > + * since it would have to land in the gap at least once, causing a > + * fault. > + */ > static unsigned long alloc_shstk(unsigned long addr, unsigned long size, > unsigned long token_offset, bool set_res_tok) > { > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 535c58d3b2e4..b647cf2e94ea 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -343,33 +343,13 @@ extern unsigned int kobjsize(const void *objp); > > #ifdef CONFIG_X86_USER_SHADOW_STACK > /* > - * This flag should not be set with VM_SHARED because of lack of support > - * core mm. It will also get a guard page. This helps userspace protect > - * itself from attacks. The reasoning is as follows: > + * VM_SHADOW_STACK should not be set with VM_SHARED because of lack of > + * support core mm. > * > - * The shadow stack pointer(SSP) is moved by CALL, RET, and INCSSPQ. The > - * INCSSP instruction can increment the shadow stack pointer. It is the > - * shadow stack analog of an instruction like: > - * > - * addq $0x80, %rsp > - * > - * However, there is one important difference between an ADD on %rsp > - * and INCSSP. In addition to modifying SSP, INCSSP also reads from the > - * memory of the first and last elements that were "popped". It can be > - * thought of as acting like this: > - * > - * READ_ONCE(ssp); // read+discard top element on stack > - * ssp += nr_to_pop * 8; // move the shadow stack > - * READ_ONCE(ssp-8); // read+discard last popped stack element > - * > - * The maximum distance INCSSP can move the SSP is 2040 bytes, before > - * it would read the memory. Therefore a single page gap will be enough > - * to prevent any operation from shifting the SSP to an adjacent stack, > - * since it would have to land in the gap at least once, causing a > - * fault. > - * > - * Prevent using INCSSP to move the SSP between shadow stacks by > - * having a PAGE_SIZE guard gap. > + * These VMAs will get a single end guard page. This helps userspace protect > + * itself from attacks. A single page is enough for current shadow stack archs > + * (x86). See the comments near alloc_shstk() in arch/x86/kernel/shstk.c > + * for more details on the guard size. > */ > # define VM_SHADOW_STACK VM_HIGH_ARCH_5 > #else > -- > 2.34.1 > -- Sincerely yours, Mike.