From patchwork Thu May 21 21:17:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 11564071 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DDAA1392 for ; Thu, 21 May 2020 21:17:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75C4F20814 for ; Thu, 21 May 2020 21:17:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75C4F20814 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 DD7DA8000A; Thu, 21 May 2020 17:17:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D877480007; Thu, 21 May 2020 17:17:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD97D8000B; Thu, 21 May 2020 17:17:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 9DBA68000A for ; Thu, 21 May 2020 17:17:41 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4DA658248047 for ; Thu, 21 May 2020 21:17:41 +0000 (UTC) X-FDA: 76841987922.03.scale50_7d33e36253713 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,yu-cheng.yu@intel.com,,RULES_HIT:30003:30051:30054:30056:30064,0,RBL:134.134.136.65:@intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: scale50_7d33e36253713 X-Filterd-Recvd-Size: 6705 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 May 2020 21:17:40 +0000 (UTC) IronPort-SDR: 35SAK4eB8g1zHHN07jsz6b7gpwpnoJInl3NOU4ocXs0SN38l8g46iQBQduLHsX5lrVn2bN7XOJ Y9g0n/p43ZKg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 14:17:38 -0700 IronPort-SDR: QzjXdsAulllbM+H3KzahOYdsWNjpt+dSWqSjlxG2oYkOvrg6jYVhj2c3CGUsM0/1vrz6YfEezg lyEjpkU/y8zA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,419,1583222400"; d="scan'208";a="440623120" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga005.jf.intel.com with ESMTP; 21 May 2020 14:17:37 -0700 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 , Weijiang Yang Cc: Yu-cheng Yu Subject: [RFC PATCH 1/5] x86/cet/shstk: Modify ARCH_X86_CET_ALLOC_SHSTK for 32-bit address range Date: Thu, 21 May 2020 14:17:16 -0700 Message-Id: <20200521211720.20236-2-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200521211720.20236-1-yu-cheng.yu@intel.com> References: <20200521211720.20236-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 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: Sometimes a 64-bit task might need to have a shadow stack allocated from within 32-bit address range. One example is selftests/x86/sigreturn. Currently arch_prctl(ARCH_X86_CET_ALLOC_SHSTK) takes a input parameter for the desired shadow stack size. Modify it and use bit[0] of the parameter to indicate the desire to allocate from 32-bit address range. Signed-off-by: Yu-cheng Yu --- arch/x86/include/asm/cet.h | 2 +- arch/x86/include/uapi/asm/prctl.h | 2 ++ arch/x86/kernel/cet.c | 19 ++++++++++++------- arch/x86/kernel/cet_prctl.c | 6 +++++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/cet.h b/arch/x86/include/asm/cet.h index f163c805a559..534b02785a39 100644 --- a/arch/x86/include/asm/cet.h +++ b/arch/x86/include/asm/cet.h @@ -22,7 +22,7 @@ struct cet_status { int prctl_cet(int option, u64 arg2); int cet_setup_shstk(void); int cet_setup_thread_shstk(struct task_struct *p); -int cet_alloc_shstk(unsigned long *arg); +int cet_alloc_shstk(unsigned long *arg, int map_32bit); void cet_disable_free_shstk(struct task_struct *p); int cet_verify_rstor_token(bool ia32, unsigned long ssp, unsigned long *new_ssp); void cet_restore_signal(struct sc_ext *sc); diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index d962f0ec9ccf..e254c6a21475 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -19,4 +19,6 @@ #define ARCH_X86_CET_LOCK 0x3003 #define ARCH_X86_CET_ALLOC_SHSTK 0x3004 +#define ARCH_X86_CET_ALLOC_SHSTK_32BIT 0x1UL + #endif /* _ASM_X86_PRCTL_H */ diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c index 92b8730c0b08..d6f93e1864b2 100644 --- a/arch/x86/kernel/cet.c +++ b/arch/x86/kernel/cet.c @@ -57,14 +57,19 @@ static unsigned long cet_get_shstk_addr(void) return ssp; } -static unsigned long alloc_shstk(unsigned long size) +static unsigned long alloc_shstk(unsigned long size, int map_32bit) { struct mm_struct *mm = current->mm; unsigned long addr, populate; + unsigned long map_flags; + + map_flags = MAP_ANONYMOUS | MAP_PRIVATE; + if (map_32bit) + map_flags |= MAP_32BIT; down_write(&mm->mmap_sem); - addr = do_mmap(NULL, 0, size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, - VM_SHSTK, 0, &populate, NULL); + addr = do_mmap(NULL, 0, size, PROT_READ, map_flags, VM_SHSTK, 0, + &populate, NULL); up_write(&mm->mmap_sem); if (populate) @@ -147,14 +152,14 @@ static int create_rstor_token(bool ia32, unsigned long ssp, return 0; } -int cet_alloc_shstk(unsigned long *arg) +int cet_alloc_shstk(unsigned long *arg, int map_32bit) { unsigned long len = *arg; unsigned long addr; unsigned long token; unsigned long ssp; - addr = alloc_shstk(round_up(len, PAGE_SIZE)); + addr = alloc_shstk(round_up(len, PAGE_SIZE), map_32bit); if (IS_ERR((void *)addr)) return PTR_ERR((void *)addr); @@ -185,7 +190,7 @@ int cet_setup_shstk(void) return -EOPNOTSUPP; size = round_up(min(rlimit(RLIMIT_STACK), 1UL << 32), PAGE_SIZE); - addr = alloc_shstk(size); + addr = alloc_shstk(size, 0); if (IS_ERR((void *)addr)) return PTR_ERR((void *)addr); @@ -226,7 +231,7 @@ int cet_setup_thread_shstk(struct task_struct *tsk) if (in_compat_syscall()) size /= 4; size = round_up(size, PAGE_SIZE); - addr = alloc_shstk(size); + addr = alloc_shstk(size, 0); if (IS_ERR((void *)addr)) { cet->shstk_base = 0; diff --git a/arch/x86/kernel/cet_prctl.c b/arch/x86/kernel/cet_prctl.c index a8e68fefd524..364ed2420202 100644 --- a/arch/x86/kernel/cet_prctl.c +++ b/arch/x86/kernel/cet_prctl.c @@ -35,12 +35,16 @@ static int handle_alloc_shstk(u64 arg2) unsigned long arg; unsigned long addr = 0; unsigned long size = 0; + int map_32bit; if (get_user(arg, (unsigned long __user *)arg2)) return -EFAULT; + map_32bit = (arg & ARCH_X86_CET_ALLOC_SHSTK_32BIT) ? 1 : 0; + arg &= ~(ARCH_X86_CET_ALLOC_SHSTK_32BIT); + size = arg; - err = cet_alloc_shstk(&arg); + err = cet_alloc_shstk(&arg, map_32bit); if (err) return err;