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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14CABC35247 for ; Wed, 5 Feb 2020 18:20:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD30324658 for ; Wed, 5 Feb 2020 18:20:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD30324658 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8EA1B6B0032; Wed, 5 Feb 2020 13:20:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BF46B000D; Wed, 5 Feb 2020 13:20:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7767B6B0036; Wed, 5 Feb 2020 13:20:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id 51DA96B000E for ; Wed, 5 Feb 2020 13:20:31 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E87F6181AC9CC for ; Wed, 5 Feb 2020 18:20:30 +0000 (UTC) X-FDA: 76456888620.14.jeans93_78d46d72edf51 X-HE-Tag: jeans93_78d46d72edf51 X-Filterd-Recvd-Size: 4116 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 5 Feb 2020 18:20:30 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2020 10:20:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,406,1574150400"; d="scan'208";a="279447765" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by FMSMGA003.fm.intel.com with ESMTP; 05 Feb 2020 10:20:25 -0800 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , x86-patch-review@intel.com Cc: Yu-cheng Yu Subject: [RFC PATCH v9 07/27] Add guard pages around a Shadow Stack. Date: Wed, 5 Feb 2020 10:19:15 -0800 Message-Id: <20200205181935.3712-8-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200205181935.3712-1-yu-cheng.yu@intel.com> References: <20200205181935.3712-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: INCSSPD/INCSSPQ instruction is used to unwind a Shadow Stack (SHSTK). It performs 'pop and discard' of the first and last element from SHSTK in th= e range specified in the operand. The maximum value of the operand is 255, and the maximum moving distance of the SHSTK pointer is 255 * 4 for INCSSPD, 255 * 8 for INCSSPQ. Since SHSTK has a fixed size, creating a guard page above prevents INCSSP/RET from moving beyond. Likewise, creating a guard page below prevents CALL from underflowing the SHSTK. Signed-off-by: Yu-cheng Yu --- include/linux/mm.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index b5145fbe102e..75de07674649 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2464,9 +2464,15 @@ static inline struct vm_area_struct * find_vma_int= ersection(struct mm_struct * m static inline unsigned long vm_start_gap(struct vm_area_struct *vma) { unsigned long vm_start =3D vma->vm_start; + unsigned long gap =3D 0; =20 - if (vma->vm_flags & VM_GROWSDOWN) { - vm_start -=3D stack_guard_gap; + if (vma->vm_flags & VM_GROWSDOWN) + gap =3D stack_guard_gap; + else if (vma->vm_flags & VM_SHSTK) + gap =3D PAGE_SIZE; + + if (gap !=3D 0) { + vm_start -=3D gap; if (vm_start > vma->vm_start) vm_start =3D 0; } @@ -2476,9 +2482,15 @@ static inline unsigned long vm_start_gap(struct vm= _area_struct *vma) static inline unsigned long vm_end_gap(struct vm_area_struct *vma) { unsigned long vm_end =3D vma->vm_end; + unsigned long gap =3D 0; + + if (vma->vm_flags & VM_GROWSUP) + gap =3D stack_guard_gap; + else if (vma->vm_flags & VM_SHSTK) + gap =3D PAGE_SIZE; =20 - if (vma->vm_flags & VM_GROWSUP) { - vm_end +=3D stack_guard_gap; + if (gap !=3D 0) { + vm_end +=3D gap; if (vm_end < vma->vm_end) vm_end =3D -PAGE_SIZE; } --=20 2.21.0