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=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 AB8A4C4727E for ; Fri, 25 Sep 2020 16:48:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4C2A521D7A for ; Fri, 25 Sep 2020 16:48:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C2A521D7A 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 A58786B0081; Fri, 25 Sep 2020 12:48:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2FFD6B0087; Fri, 25 Sep 2020 12:48:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9460A6B0088; Fri, 25 Sep 2020 12:48:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0206.hostedemail.com [216.40.44.206]) by kanga.kvack.org (Postfix) with ESMTP id 8020E6B0081 for ; Fri, 25 Sep 2020 12:48:06 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 471ED180AD806 for ; Fri, 25 Sep 2020 16:48:06 +0000 (UTC) X-FDA: 77302166172.05.oven10_2504e1127169 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 2D74618014932 for ; Fri, 25 Sep 2020 16:48:06 +0000 (UTC) X-HE-Tag: oven10_2504e1127169 X-Filterd-Recvd-Size: 4873 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Fri, 25 Sep 2020 16:48:04 +0000 (UTC) IronPort-SDR: PQDPhIj1GIiiwbiN7c76HMKBOiBjqsUwpZT+iUmUPoel7EiAyn7u23nKXUGFFT+ePccyEPnea0 SnNVvHNHZuRw== X-IronPort-AV: E=McAfee;i="6000,8403,9755"; a="162477807" X-IronPort-AV: E=Sophos;i="5.77,302,1596524400"; d="scan'208";a="162477807" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 09:48:02 -0700 IronPort-SDR: XbYr2jPVpT1Wf6fIuRpAKebBnup6ZoThBmfiO9H5MEW0vAntBNX4+b0Tc3QLEpvPIPzUkLk/qB wcEFkVXs16qQ== X-IronPort-AV: E=Sophos;i="5.77,302,1596524400"; d="scan'208";a="336806828" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.213.161.229]) ([10.213.161.229]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 09:47:59 -0700 Subject: Re: [PATCH v13 8/8] x86/vsyscall/64: Fixup Shadow Stack and Indirect Branch Tracking for vsyscall emulation To: Andy Lutomirski Cc: X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , LKML , "open list:DOCUMENTATION" , Linux-MM , linux-arch , Linux API , Arnd Bergmann , 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 , Pengfei Xu References: <20200925145804.5821-1-yu-cheng.yu@intel.com> <20200925145804.5821-9-yu-cheng.yu@intel.com> From: "Yu, Yu-cheng" Message-ID: Date: Fri, 25 Sep 2020 09:47:55 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US 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 9/25/2020 9:31 AM, Andy Lutomirski wrote: > On Fri, Sep 25, 2020 at 7:58 AM Yu-cheng Yu wrote: >> [...] >> @@ -286,6 +289,37 @@ bool emulate_vsyscall(unsigned long error_code, >> /* Emulate a ret instruction. */ >> regs->ip = caller; >> regs->sp += 8; >> + >> +#ifdef CONFIG_X86_CET >> + if (tsk->thread.cet.shstk_size || tsk->thread.cet.ibt_enabled) { >> + struct cet_user_state *cet; >> + struct fpu *fpu; >> + >> + fpu = &tsk->thread.fpu; >> + fpregs_lock(); >> + >> + if (!test_thread_flag(TIF_NEED_FPU_LOAD)) { >> + copy_fpregs_to_fpstate(fpu); >> + set_thread_flag(TIF_NEED_FPU_LOAD); >> + } >> + >> + cet = get_xsave_addr(&fpu->state.xsave, XFEATURE_CET_USER); >> + if (!cet) { >> + fpregs_unlock(); >> + goto sigsegv; > > I *think* your patchset tries to keep cet.shstk_size and > cet.ibt_enabled in sync with the MSR, in which case it should be > impossible to get here, but a comment and a warning would be much > better than a random sigsegv. Yes, it should be impossible to get here. I will add a comment and a warning, but still do sigsegv. Should this happen, and the function return, the app gets a control-protection fault. Why not let it fail early? > > Shouldn't we have a get_xsave_addr_or_allocate() that will never > return NULL but instead will mark the state as in use and set up the > init state if the feature was previously not in use? > We already have a static __raw_xsave_addr(), which returns a pointer to the requested xstate. Maybe we can export __raw_xsave_addr(), if that is needed.