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=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 93FD7C43331 for ; Wed, 25 Mar 2020 21:51:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 620AD20737 for ; Wed, 25 Mar 2020 21:51:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 620AD20737 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 D5D886B0008; Wed, 25 Mar 2020 17:51:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0D4F6B000A; Wed, 25 Mar 2020 17:51:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFBE26B000C; Wed, 25 Mar 2020 17:51:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id A4FFF6B0008 for ; Wed, 25 Mar 2020 17:51:16 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AACE0181355DA for ; Wed, 25 Mar 2020 21:51:16 +0000 (UTC) X-FDA: 76635230952.28.field02_b1108ee0ae3b X-HE-Tag: field02_b1108ee0ae3b X-Filterd-Recvd-Size: 4534 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Mar 2020 21:51:15 +0000 (UTC) IronPort-SDR: RMuYpMeEpEHWzU+Eq/DEFH/sEjtZN182BLr46Q9A6ZNlNeZXUB2z6OVt2VOMu3sawcRPE69pJT aajSHkiYPKxg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2020 14:51:14 -0700 IronPort-SDR: 6xgudFIjy1CzWRRc48LtFdeAxHVrlYFfTo63YZE4NYbvMjdkFxHVPJPGrO+UNQp0Xr2jTj3nKa WTzhXN/fIh5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,305,1580803200"; d="scan'208";a="238631971" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga007.fm.intel.com with ESMTP; 25 Mar 2020 14:51:14 -0700 Message-ID: Subject: Re: [RFC PATCH v9 25/27] x86/cet/shstk: Handle thread Shadow Stack From: Yu-cheng Yu To: Kees Cook Cc: 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 , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , x86-patch-review@intel.com Date: Wed, 25 Mar 2020 14:51:13 -0700 In-Reply-To: <202002251324.5D515260@keescook> References: <20200205181935.3712-1-yu-cheng.yu@intel.com> <20200205181935.3712-26-yu-cheng.yu@intel.com> <202002251324.5D515260@keescook> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 Tue, 2020-02-25 at 13:29 -0800, Kees Cook wrote: > On Wed, Feb 05, 2020 at 10:19:33AM -0800, Yu-cheng Yu wrote: > > [...] > > A 64-bit SHSTK has a fixed size of RLIMIT_STACK. A compat-mode thread SHSTK > > has a fixed size of 1/4 RLIMIT_STACK. This allows more threads to share a > > 32-bit address space. > > I am not understanding this part. :) Entries are sizeof(unsigned long), > yes? A 1/2 RLIMIT_STACK would cover 32-bit, but 1/4 is less, so why does > that provide for more threads? Each thread has a separate shadow stack. If each shadow stack is smaller, the address space can accommodate more shadow stack allocations. > >[...] > > diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c > > index cba5c7656aab..5b45abda80a1 100644 > > --- a/arch/x86/kernel/cet.c > > +++ b/arch/x86/kernel/cet.c > > @@ -170,6 +170,47 @@ int cet_setup_shstk(void) > > return 0; > > } > > > > +int cet_setup_thread_shstk(struct task_struct *tsk) > > +{ > > + unsigned long addr, size; > > + struct cet_user_state *state; > > + struct cet_status *cet = &tsk->thread.cet; > > + > > + if (!cet->shstk_enabled) > > + return 0; > > + > > + state = get_xsave_addr(&tsk->thread.fpu.state.xsave, > > + XFEATURE_CET_USER); > > + > > + if (!state) > > + return -EINVAL; > > + > > + size = rlimit(RLIMIT_STACK); > > Is SHSTK incompatible with RLIM_INFINITY stack rlimits? I will change it to: size = min(rlimit(RLIMIT_STACK), 4 GB); > > > + > > + /* > > + * Compat-mode pthreads share a limited address space. > > + * If each function call takes an average of four slots > > + * stack space, we need 1/4 of stack size for shadow stack. > > + */ > > + if (in_compat_syscall()) > > + size /= 4; > > + > > + addr = alloc_shstk(size); > > I assume it'd fail here, but I worry about Stack Clash style attacks. > I'd like to see test cases that make sure the SHSTK gap is working > correctly. I will work on some tests. Thanks, Yu-cheng