Message ID | 20230119212317.8324-21-rick.p.edgecombe@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 91533C46467 for <linux-mm@archiver.kernel.org>; Thu, 19 Jan 2023 21:24:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DC19900005; Thu, 19 Jan 2023 16:24:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 43F6B900002; Thu, 19 Jan 2023 16:24:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CC55900005; Thu, 19 Jan 2023 16:24:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 02105900002 for <linux-mm@kvack.org>; Thu, 19 Jan 2023 16:24:00 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CE10F409D2 for <linux-mm@kvack.org>; Thu, 19 Jan 2023 21:23:59 +0000 (UTC) X-FDA: 80372826198.29.406BC5E Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf16.hostedemail.com (Postfix) with ESMTP id C7F19180010 for <linux-mm@kvack.org>; Thu, 19 Jan 2023 21:23:57 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Qd4w3FiI; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674163438; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=YWVE+Ni8aNDtLo7tgyffJpW9kI97N/rM06lnRUBkkSk=; b=yUv6edfnPpX9JHMq0Kbl7FWQCRs1IuGESW3AgaTPxG4199ekW8ZKy77w7QzApdeD/G2kvU wqv4Vh1mQVmGKrQ0A1bZDJ/1Q1u8RPxaWeI5w/pZpFMckjxgIh06z28rMeb/tWx/y1IfoM X4FjkTHQZ/2PGaLTOqJq3D9mQMlydN0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Qd4w3FiI; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674163438; a=rsa-sha256; cv=none; b=6YgOP35XmwOBnPuIcU7+ukk7bIIpaZkD6A8jFTeyOkTnpMzWzeUYW9wJoma/z7o9ks9s0f Df9PKQLAqMRzrgCCbZbWrjva56zTwV5rcg1KjJ1MV8YmHihTgNfYhRwtyEvp9z7jmy2o9J sCcFDWsCZ2vCqejZMR5mR2BxaUHFGNg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674163437; x=1705699437; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=+3N34QEERZNcvQNJAARc1au4ZPtrpENbiq/H3U3EHgE=; b=Qd4w3FiIkTcGjfGVzZ4mHGfPY+JXQCmc3Ab1W00CzHm/dFnWN3DuvDbz M8Np47kLoaZeHmsEexJ/CKxO45oynaFr+XI8a3r6pFPcPU5+w9eLt9cW4 M3j6JGn6VO6cCRAtrbtSCLIvR92pbcDXoACWK9OD5xLrWsGpdSad8BCzh P/0JXafqUbaOhr2KTX7eMilbAuvx+zuDHidNLfgh8AwPj0ECmjb4MB0oI wH55JpSJqaQ2UWwJ+jGiFo14Tbd6FhZ6ULTySibRHFb1g3T9FnElzhOlF YDfzR4wulfHzkcSkip56Xyqs7+F9LAJJcW5diuc3CHTI552DLwTDs+6tn w==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="323119638" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="323119638" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:57 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="989139093" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="989139093" Received: from hossain3-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.252.128.187]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:55 -0800 From: Rick Edgecombe <rick.p.edgecombe@intel.com> To: x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, 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 <arnd@arndb.de>, Andy Lutomirski <luto@kernel.org>, Balbir Singh <bsingharora@gmail.com>, Borislav Petkov <bp@alien8.de>, Cyrill Gorcunov <gorcunov@gmail.com>, Dave Hansen <dave.hansen@linux.intel.com>, Eugene Syromiatnikov <esyr@redhat.com>, Florian Weimer <fweimer@redhat.com>, "H . J . Lu" <hjl.tools@gmail.com>, Jann Horn <jannh@google.com>, Jonathan Corbet <corbet@lwn.net>, Kees Cook <keescook@chromium.org>, Mike Kravetz <mike.kravetz@oracle.com>, Nadav Amit <nadav.amit@gmail.com>, Oleg Nesterov <oleg@redhat.com>, Pavel Machek <pavel@ucw.cz>, Peter Zijlstra <peterz@infradead.org>, Randy Dunlap <rdunlap@infradead.org>, Weijiang Yang <weijiang.yang@intel.com>, "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>, John Allen <john.allen@amd.com>, kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu <yu-cheng.yu@intel.com> Subject: [PATCH v5 20/39] mm: Add guard pages around a shadow stack. Date: Thu, 19 Jan 2023 13:22:58 -0800 Message-Id: <20230119212317.8324-21-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230119212317.8324-1-rick.p.edgecombe@intel.com> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C7F19180010 X-Stat-Signature: zh177x1cajtf5p7safpzhfa7rxcd4orj X-Rspam-User: X-HE-Tag: 1674163437-508952 X-HE-Meta: U2FsdGVkX19oyGSeTa1oD34bim7Y6ek5scNCGJEQ9JiFAvfaKSfvVhOrNWruiWGN704jhjpIF3S502J43TibijilajSzQSjwzWPtfYCHhU79oUrLs9QDW9WGyAm2FTLOEbusk0dtp67E5XCk8uk3vML2EYRWQTFZ1MFuoWg5Y29Yow763I0hxefh3KkrJ7w5aLndvLGmcdeCyNPlK10z8vBd3/MZsDeLRa+VjFSUMfGciJsWI9s2bq2zk6Vm3LfCkdtSpSNILiDTXqTC3c7/yvMpOThzvfbdUuHC3VcHzCwbz/pXt2ypMNALaAN9GjI4jeMxr4kzzxLcmLXlLWlqLbn+UlkvlFktTt6LDCCXr65ele6G/vS3D4X8USTmZE0pd6nGZTXgB5oBko/J0SJvtJmtzRosg/89tLM1BVL2HktuALDi6evOIsc9BNjcpZ2YC0ZVLFNhMrw3jF3PMs5Wzel4BtxgI+B0tz0tL3ZvfSbGkeZQbqNg7HbKf0YvNMurgirhZvGx6OO5MizZRQUPny33jPcA9FpdUoRxSXKBUGRjxQ60/W+GbydGZ93oOec/oB/tdIHKmDhAxQ02y8Hu+PJSlqBsoSQ6tu314DgkJijJhhoJkNGgWNj70eJTJloVAZc7P93mFWtMAPBZx3jognGNOr8G83GZgishb9gb6HPNXcrWRblWfyrGTp9FBiBRpjTMnXBt89cKKoOIlDmPI1HEm7pXGA/P+pzCN9llaBA3EVkQNRbEjbdUEBZfvgITeP5n8jbftU5eVjFrPDtOT0QbPwAOun13TNai3HZaEdIakPOlnVfpwn2TUFL4BdrmQnuAU64mFJSh2plrmjfcOMxcOg8BC1+Ibb/iJJMuat2PXjqF5bwPaYUtG33hTPRXIF+RyKrjmoMhh1JMWWV5j8YvU4D7GDcKF5npwm3JMJBcryMb4A3DDHg6N9pT/NXGYtOlm8gDREzcX+H6W5x nxuHi4I+ T+D5+zgQONJ7zaP5G1I6GJdobV2J+tV2O6cCyZLmRHBhy9DPiMVEUPpaPeNxiJPrO08pt5x9IgktPAiBt+ohtigwh5pFgd2sK8rnFImH+DWje4qWIcPKNiygFBUDuXDU2AGHX5NwZuo3QMgGtfyFyo6WvF1kwRXURsmYtkMt4vlyEOL8A4fo9ka39uwmNZzHTq8bI2M+QYXKEbjWdt4KgAzclHoIfJY7TCrZa4u7jN2FMF9ioqah7YvhnHxmkOUhMUOUWhJ5BQ2hsCJDz7dkhbxSblQmLC3wlc6DU 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: <linux-mm.kvack.org> |
Series |
Shadow stacks for userspace
|
expand
|
diff --git a/include/linux/mm.h b/include/linux/mm.h index 139a682d243b..3f980d4823ad 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2987,15 +2987,36 @@ struct vm_area_struct *vma_lookup(struct mm_struct *mm, unsigned long addr) return mtree_load(&mm->mm_mt, addr); } +static inline unsigned long stack_guard_start_gap(struct vm_area_struct *vma) +{ + if (vma->vm_flags & VM_GROWSDOWN) + return stack_guard_gap; + + /* + * Shadow stack pointer is moved by CALL, RET, and INCSSPQ. + * INCSSPQ moves shadow stack pointer up to 255 * 8 = ~2 KB + * and touches the first and the last element in the range, which + * triggers a page fault if the range is not in a shadow stack. + * Because of this, creating 4-KB guard pages around a shadow + * stack prevents these instructions from going beyond. + * + * Creation of VM_SHADOW_STACK is tightly controlled, so a vma + * can't be both VM_GROWSDOWN and VM_SHADOW_STACK + */ + if (vma->vm_flags & VM_SHADOW_STACK) + return PAGE_SIZE; + + return 0; +} + static inline unsigned long vm_start_gap(struct vm_area_struct *vma) { + unsigned long gap = stack_guard_start_gap(vma); unsigned long vm_start = vma->vm_start; - if (vma->vm_flags & VM_GROWSDOWN) { - vm_start -= stack_guard_gap; - if (vm_start > vma->vm_start) - vm_start = 0; - } + vm_start -= gap; + if (vm_start > vma->vm_start) + vm_start = 0; return vm_start; }