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 C779BC2D0E8 for ; Wed, 25 Mar 2020 21:51:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8A0220775 for ; Wed, 25 Mar 2020 21:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727357AbgCYVvP (ORCPT ); Wed, 25 Mar 2020 17:51:15 -0400 Received: from mga14.intel.com ([192.55.52.115]:65091 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbgCYVvO (ORCPT ); Wed, 25 Mar 2020 17:51:14 -0400 IronPort-SDR: djFS2Wy2Bm0pYdKq90Kv16FTpCEzT3qGacrldRkPofD7BLTfivDxiwADK4KH3gQfJe67tkWQEH XYYarTIaPd7A== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.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 Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org 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