From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E79F6C00528 for ; Tue, 1 Aug 2023 17:32:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A1EB94003C; Tue, 1 Aug 2023 13:32:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82A7F940010; Tue, 1 Aug 2023 13:32:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A44B94003C; Tue, 1 Aug 2023 13:32:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 574DB940010 for ; Tue, 1 Aug 2023 13:32:52 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F03FC1A0B13 for ; Tue, 1 Aug 2023 17:32:51 +0000 (UTC) X-FDA: 81076230942.12.16E88D8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 395EB1207CA for ; Tue, 1 Aug 2023 16:53:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HwuBZpEX; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690908798; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qVoiuKS0W2XXCf835vl3k9bPGKeXZoIa/3wT64gizf0=; b=wiWvXKtO5xnvIs1UTFp9Rn4lfBh8M9FAgmDA9TmxDEeqATb2fo/eDw+QTAwGDo+zkI/+TW 0IlvymORXc3kpK/oWHOVadQi8Vh9lzR3d3si3ozCRwILRIs/kWCD1dFyZMDgBFOYSYC5KA lTBEm4rGLIkkav/1289Jzamx4/fHXe4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=HwuBZpEX; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690908798; a=rsa-sha256; cv=none; b=HF62Uc4bmkj9gxrq9xknGg59yR7tfj+rQvwh05/34ixRE+F5dogsmpjX2f6B8VHxxmy9fi D0ok6b5uRvsxpnjZOxPmjgowxIb+1M3D689x8UeH3KaYMtg935nhcJNqYdJtzTZJAco3Eg 9a9XI2HQaA6OfNGGXcgqQ7OfGsnetgk= 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 265C56163B; 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 395EB1207CA X-Stat-Signature: an8q4zqjqnfwxomczjcs119mktbqo4ug X-Rspam-User: X-HE-Tag: 1690908797-721014 X-HE-Meta: U2FsdGVkX18ngadJsCZ6RNLC6jCriP6rBNrCe6wj0GPCx0lZV1uJmS8eDVDXlCnMCPzx/WZsrOPrYhuhNn/YVARaO31ouICvB5+UHq7A4aZm0AEkcoU5SDNzzg1oeIJmc8GHEnWankXR3QOUh8z93hHoBS3fi7OqVvrpaMsGgvEpLmcFMrxLybzXzzZarzGbVFTk7D97GomVsjeUKKntBPHmu/JTelVPof0LQvA/zUaQ8NZkkxXI63/W7OzMBrr9PU3A87+1nceTaJHp5Bb4kaXg7tguDYUrxAXEdXuxbZM1A6a48q3GOfj7aZmkBtYSufJfk/i+pciW6IZYYQavmagsMeowLvvcBnKdt2e+qBbMRpLNKbY6ObPaaaXz9QDE1vDT5bnBBS4GCXPxwDvW8NQtefyIyibO+Lmzh4cVZLrrpjG4qjG9oWZsWUNaqeAdDgp/bezl++Il8Qo6RINSRHelCLQP5XfdeEMW27HAqrkitMtTKbJFpCk3r1MhhhgCGuXHgpzwZrqg5/LymUJceB1H5YXU3/kM/F2m7aiqJYUUlAaYPAP0ybGbiwnizrmjgxPQk1AdJY20ubVrcp0yUJGFllZownbMS7PHgD5EQohoH0cHC73BTrohOfHGlD6Uf+8RTyyMHa103a/Uk2p+9wQkO0bGLf/PVtoBLtm34BJCkRgr3XS1k1dDSIbRShPtfjJZaAvsoHCIpnxWgBINPnrtVBA39ralgACBHNYzAzbLG1Txcsyci77JslFOtZzoIildQfdxCwtNghlq7pD6xmPXqnvGg+xTKtKFQmmMFk6p3BMYciYK+nGixv999WwKrHQXalMW45Xk7PnkB22Tn1HjsCX1wyonfxfA5KcGw+AXdwAYKORJxCreI/rDFRGkg18P5EUxgwkpBEc3eBNPLG8AmEY/twLRZxq/k45BZ/PO3OnPOa0XVPrqPT5VslcwrSnskFFvQ0DD1tNyQCQ LjYtprY4 yCTmywZQmqAg/JnsTfuPgIg1KVZOdEESDHtm1fvMJzI06endWUT1S6V+Uev7dlaAh8SL9WkgVHl+VIucuyWg0nfVarA2SG7qlhA0fgX6TsdeU8pCoTsFiGrqcVRtfQDhBk+UxM6cqx+1cNvaimMtcJJ0KMJhHZpfU60EPnrN1gDncNd3X2TPT67XNCsv/XeTKzviVJcLpZ8b08XZStWdA1kDNwRRs7ZIVERnaA/39FjT7r3hy/kQ1OQNkXIjxFmCapR7TgJmgD7QKhKBF5yOX2HBn4Rgtjh3jxyjuasMsLueep6crNW/Ur1umqfmd0CmaeXtCK3Gh2N5leospVL48UFarUtIJ/Xye0uEgT8l+tCilSjjDdakkCxEt529mpMc+PN4C X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.