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 AB648C433F5 for ; Fri, 11 Feb 2022 17:54:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FE896B0078; Fri, 11 Feb 2022 12:54:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AEFE6B007B; Fri, 11 Feb 2022 12:54:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8F6E6B007D; Fri, 11 Feb 2022 12:54:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id D94B86B0078 for ; Fri, 11 Feb 2022 12:54:13 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 959DB95CBD for ; Fri, 11 Feb 2022 17:54:13 +0000 (UTC) X-FDA: 79131247986.22.E424F41 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf21.hostedemail.com (Postfix) with ESMTP id D92BE1C000D for ; Fri, 11 Feb 2022 17:54:12 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DE83EB82B58; Fri, 11 Feb 2022 17:54:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD776C340E9; Fri, 11 Feb 2022 17:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644602049; bh=FsUOrelQNqNyH3UASN+ZGpPm+zrcDvNiCyxLZ2cOLHU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=bA8qmWpkMliRzgJ3/D9pIM4YRzkVL/VClVeC1kecwl9UuEu9syCd/L1k3aZIdb/Am yJzGeOckMjikcxRadLMZQOTt7482bDcDmr5xONcdduo38eNseusJ5YGl01Ba8r8uq+ a78UFF2SXihbjHiopc9bXzu2qEamaXka5zQH2+tjJPjec1yKSU4p9OMPYD6Q5XzQoM h90D38uKF3vQCcxPEFHtZvTcp2hrfQtuQmLQcS9gswYckPW/dGTzmWWKMG/V1nez9W ith2h10B661UAiRqaSjRW3oYRJpETjWEcruoh5PyobYIhQ+5YwXBOS8m9vM00Ixt+J 5F6X4GojvoE3g== Message-ID: Date: Fri, 11 Feb 2022 09:54:07 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH 18/35] mm: Add guard pages around a shadow stack. Content-Language: en-US To: "Edgecombe, Rick P" , "Hansen, Dave" Cc: "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "peterz@infradead.org" , "rdunlap@infradead.org" , "keescook@chromium.org" , "Yu, Yu-cheng" , "dave.hansen@linux.intel.com" , "kirill.shutemov@linux.intel.com" , "Eranian, Stephane" , "linux-mm@kvack.org" , "fweimer@redhat.com" , "nadav.amit@gmail.com" , "jannh@google.com" , "linux-arch@vger.kernel.org" , "kcc@google.com" , "bp@alien8.de" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "Yang, Weijiang" , "linux-doc@vger.kernel.org" , "pavel@ucw.cz" , "arnd@arndb.de" , "Moreira, Joao" , "tglx@linutronix.de" , "mike.kravetz@oracle.com" , "x86@kernel.org" , "dave.martin@arm.com" , "john.allen@amd.com" , "mingo@redhat.com" , "Shankar, Ravi V" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> <20220130211838.8382-19-rick.p.edgecombe@intel.com> <4c216532-2b68-dd95-93f1-542df4786d7a@intel.com> From: Andy Lutomirski In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bA8qmWpk; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf21.hostedemail.com: domain of luto@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=luto@kernel.org X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D92BE1C000D X-Stat-Signature: kxfay3yqzyikk7wtcwox36i4pdmznun5 X-HE-Tag: 1644602052-522701 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: On 2/10/22 15:40, Edgecombe, Rick P wrote: > On Thu, 2022-02-10 at 15:07 -0800, Andy Lutomirski wrote: >> On Thu, Feb 10, 2022 at 2:44 PM Dave Hansen >> wrote: >>> >>> On 1/30/22 13:18, Rick Edgecombe wrote: >>>> INCSSP(Q/D) increments shadow stack pointer and 'pops and >>>> discards' the >>>> first and the last elements in the range, effectively touches >>>> those memory >>>> areas. >>>> >>>> The maximum moving distance by INCSSPQ is 255 * 8 = 2040 bytes >>>> and >>>> 255 * 4 = 1020 bytes by INCSSPD. Both ranges are far from >>>> PAGE_SIZE. >>>> Thus, putting a gap page on both ends of a shadow stack prevents >>>> INCSSP, >>>> CALL, and RET from going beyond. >>> >>> What is the downside of not applying this patch? The shadow stack >>> gap >>> is 1MB instead of 4k? >>> >>> That, frankly, doesn't seem too bad. How badly do we *need* this >>> patch? > > Like just using VM_SHADOW_STACK | VM_GROWSDOWN to get a regular stack > sized gap? I think it could work. It also simplifies the mm->stack_vm > accounting. Seems not crazy. Do we want automatically growing shadow stacks? I don't really like the historical unix behavior where the main thread has a sort-of-infinite stack and every other thread has a fixed stack. > > It would no longer get a gap at the end though. I don't think it's > needed. > I may have missed something about the oddball way the mm code works, but it seems if you have a gap at one end of every shadow stack, you automatically have a gap at the other end.