From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Lutomirski Subject: Re: [PATCH v7 12/14] x86/vsyscall/64: Fixup shadow stack and branch tracking for vsyscall Date: Thu, 6 Jun 2019 13:27:43 -0700 Message-ID: References: <20190606200926.4029-1-yu-cheng.yu@intel.com> <20190606200926.4029-13-yu-cheng.yu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: In-Reply-To: <20190606200926.4029-13-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org To: Yu-cheng Yu 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 List-Id: linux-arch.vger.kernel.org On Thu, Jun 6, 2019 at 1:17 PM Yu-cheng Yu wrote: > > When emulating a RET, also unwind the task's shadow stack and cancel > the current branch tracking status. > > Signed-off-by: Yu-cheng Yu > --- > arch/x86/entry/vsyscall/vsyscall_64.c | 28 +++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c > index d9d81ad7a400..6869ef9d1e8b 100644 > --- a/arch/x86/entry/vsyscall/vsyscall_64.c > +++ b/arch/x86/entry/vsyscall/vsyscall_64.c > @@ -38,6 +38,8 @@ > #include > #include > #include > +#include > +#include > > #define CREATE_TRACE_POINTS > #include "vsyscall_trace.h" > @@ -92,6 +94,30 @@ static int addr_to_vsyscall_nr(unsigned long addr) > return nr; > } > > +void fixup_shstk(void) > +{ > +#ifdef CONFIG_X86_INTEL_SHADOW_STACK_USER > + u64 r; > + > + if (current->thread.cet.shstk_enabled) { > + rdmsrl(MSR_IA32_PL3_SSP, r); > + wrmsrl(MSR_IA32_PL3_SSP, r + 8); > + } > +#endif > +} > + > +void fixup_ibt(void) > +{ > +#ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER > + u64 r; > + > + if (current->thread.cet.ibt_enabled) { > + rdmsrl(MSR_IA32_U_CET, r); > + wrmsrl(MSR_IA32_U_CET, r & ~MSR_IA32_CET_WAIT_ENDBR); > + } > +#endif > +} These should be static. But please just inline them directly in their one call site. The code will be a lot easier to understand. --Andy From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kernel.org ([198.145.29.99]:59838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbfFFU15 (ORCPT ); Thu, 6 Jun 2019 16:27:57 -0400 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5E634208E4 for ; Thu, 6 Jun 2019 20:27:56 +0000 (UTC) Received: by mail-wm1-f51.google.com with SMTP id a15so1189111wmj.5 for ; Thu, 06 Jun 2019 13:27:56 -0700 (PDT) MIME-Version: 1.0 References: <20190606200926.4029-1-yu-cheng.yu@intel.com> <20190606200926.4029-13-yu-cheng.yu@intel.com> In-Reply-To: <20190606200926.4029-13-yu-cheng.yu@intel.com> From: Andy Lutomirski Date: Thu, 6 Jun 2019 13:27:43 -0700 Message-ID: Subject: Re: [PATCH v7 12/14] x86/vsyscall/64: Fixup shadow stack and branch tracking for vsyscall Content-Type: text/plain; charset="UTF-8" Sender: linux-arch-owner@vger.kernel.org List-ID: To: Yu-cheng Yu 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 Message-ID: <20190606202743.oWNjY8JFAjSnT7LjGDnA94L2fdZ9uZU3MUsiC8Li2eg@z> On Thu, Jun 6, 2019 at 1:17 PM Yu-cheng Yu wrote: > > When emulating a RET, also unwind the task's shadow stack and cancel > the current branch tracking status. > > Signed-off-by: Yu-cheng Yu > --- > arch/x86/entry/vsyscall/vsyscall_64.c | 28 +++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscall/vsyscall_64.c > index d9d81ad7a400..6869ef9d1e8b 100644 > --- a/arch/x86/entry/vsyscall/vsyscall_64.c > +++ b/arch/x86/entry/vsyscall/vsyscall_64.c > @@ -38,6 +38,8 @@ > #include > #include > #include > +#include > +#include > > #define CREATE_TRACE_POINTS > #include "vsyscall_trace.h" > @@ -92,6 +94,30 @@ static int addr_to_vsyscall_nr(unsigned long addr) > return nr; > } > > +void fixup_shstk(void) > +{ > +#ifdef CONFIG_X86_INTEL_SHADOW_STACK_USER > + u64 r; > + > + if (current->thread.cet.shstk_enabled) { > + rdmsrl(MSR_IA32_PL3_SSP, r); > + wrmsrl(MSR_IA32_PL3_SSP, r + 8); > + } > +#endif > +} > + > +void fixup_ibt(void) > +{ > +#ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER > + u64 r; > + > + if (current->thread.cet.ibt_enabled) { > + rdmsrl(MSR_IA32_U_CET, r); > + wrmsrl(MSR_IA32_U_CET, r & ~MSR_IA32_CET_WAIT_ENDBR); > + } > +#endif > +} These should be static. But please just inline them directly in their one call site. The code will be a lot easier to understand. --Andy