Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp109067imm; Thu, 30 Aug 2018 09:26:45 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda5JTFT8s5miuj7eAeNUNJNMzDHpDObUHa9D3TITnrv7JGNLWSQ5B1gR9okeQb6UQMBGH6b X-Received: by 2002:a62:586:: with SMTP id 128-v6mr11239352pff.80.1535646405929; Thu, 30 Aug 2018 09:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535646405; cv=none; d=google.com; s=arc-20160816; b=CuZ6GkdTLY5mTS+F5J2EY+Nz6JnMntJBxSD3H/viCk0Lijvx741Pp+zYSfC50ZzLt0 N0bwiapPZlfepEilW5tnm/Y8Oo3xOxnte7q6j2fH5EsN56GJvnr/8HTm01ClOE2u7zHN 6caZJ1ZWzq8b7kfJO4Mb2q/guZB96XamxXaAOUICpDXdxn+HujoqpxauMK8M1glC9/yN gRjHSz5ZgLkoVOE5RjF4jDwYVNeefwAOlyTsz43yAxc4vhgiGtX0Rlb8K+ZtfLtGXZ6R GmlddnrSJvCfZcHXuAwa2OtRLybqneSU/iCJ/w12s22/LsiOaT3jBH1/UrRVLAvXhOzE A80A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=R3boZPnO1RcvQPXj4qdStgremX1RSp1lcDKeB9nk/F4=; b=IMCvX8TkGJ2uxVt8ci12Z8fWaNSNYmWJuUtzFSPLinDtw+0cZMR8qzt+XGBQsmOx+p UbWsH2QvACEIaRUntK2LotEUSnnZ9WWzKED5twaTLLeQyOMi77fHVMPOWTV6YuXxt+t5 gSAnUX1QbH5rxVtntg5lbWj07xywsm9etxpBph1uLwRRQJOys2pYEf+8Bx7SyDbab9BI cN56I+FoNw84dJXLNMoPk6p3nQVLP5GfwC2I+TcnDOgVnwVFqKQRt2RYh5OmsBJzGCiB xyzygb5fAVIoBohiQ+MHQyU2oIUJDzmjcSpPMJfnDXIpQfeQ4GiO7RF2PoZctaBI1ZHv sjFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3-v6si7110162pld.114.2018.08.30.09.26.30; Thu, 30 Aug 2018 09:26:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727592AbeH3U2K (ORCPT + 99 others); Thu, 30 Aug 2018 16:28:10 -0400 Received: from mga14.intel.com ([192.55.52.115]:63242 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeH3U2K (ORCPT ); Thu, 30 Aug 2018 16:28:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Aug 2018 09:25:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,307,1531810800"; d="scan'208";a="81589067" Received: from 2b52.sc.intel.com ([143.183.136.52]) by fmsmga002.fm.intel.com with ESMTP; 30 Aug 2018 09:25:10 -0700 Message-ID: <1535646055.26689.10.camel@intel.com> Subject: Re: [RFC PATCH v3 18/24] x86/cet/shstk: User-mode shadow stack support From: Yu-cheng Yu To: Jann Horn Cc: the arch/x86 maintainers , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Date: Thu, 30 Aug 2018 09:20:55 -0700 In-Reply-To: References: <20180830143904.3168-1-yu-cheng.yu@intel.com> <20180830143904.3168-19-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-08-30 at 18:10 +0200, Jann Horn wrote: > On Thu, Aug 30, 2018 at 4:44 PM Yu-cheng Yu > wrote: > > > > > > This patch adds basic shadow stack enabling/disabling routines. > > A task's shadow stack is allocated from memory with VM_SHSTK > > flag set and read-only protection.  The shadow stack is > > allocated to a fixed size of RLIMIT_STACK. > > > > Signed-off-by: Yu-cheng Yu > [...] > > > > +static int set_shstk_ptr(unsigned long addr) > > +{ > > +       u64 r; > > + > > +       if (!cpu_feature_enabled(X86_FEATURE_SHSTK)) > > +               return -1; > > + > > +       if ((addr >= TASK_SIZE_MAX) || (!IS_ALIGNED(addr, 4))) > > +               return -1; > > + > > +       rdmsrl(MSR_IA32_U_CET, r); > > +       wrmsrl(MSR_IA32_PL3_SSP, addr); > > +       wrmsrl(MSR_IA32_U_CET, r | MSR_IA32_CET_SHSTK_EN); > > +       return 0; > > +} > Here's a really stupid question: Where is the logic for switching > those MSRs on task switch? MSR_IA32_PL3_SSP contains a userspace > pointer, so it has to be switched on task switch, right? I'm sure > I'm > missing something obvious, but grepping for places that set > MSR_IA32_PL3_SSP to nonzero values through the entire patchset, I > only > see set_shstk_ptr(), which is called from: > >  - cet_setup_shstk() (called from arch_setup_features(), which is > called from load_elf_binary()) >  - cet_restore_signal() (called on signal handler return) >  - cet_setup_signal() (called from signal handling code) The MSR is in the XSAVES buffer and switched by XSAVES/XRSTORS. Yu-cheng