From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu-cheng Yu Subject: Re: [RFC PATCH v9 05/27] x86/cet/shstk: Add Kconfig option for user-mode Shadow Stack protection Date: Fri, 06 Mar 2020 10:37:13 -0800 Message-ID: <070d9d78981f0aad2baf740233e8dfc32ecd29d7.camel@intel.com> References: <20200205181935.3712-1-yu-cheng.yu@intel.com> <20200205181935.3712-6-yu-cheng.yu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Dave Hansen , x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, linux-arch-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Arnd Bergmann , Andy Lutomirski , 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 Wed, 2020-02-26 at 10:05 -0800, Dave Hansen wrote: > On 2/5/20 10:19 AM, Yu-cheng Yu wrote: > > +# Check assembler Shadow Stack suppot > > ^ support > > > +ifdef CONFIG_X86_INTEL_SHADOW_STACK_USER > > + ifeq ($(call as-instr, saveprevssp, y),) > > + $(error CONFIG_X86_INTEL_SHADOW_STACK_USER not supported by the assembler) > > + endif > > +endif > > Is this *just* looking for instruction support in the assembler? > > We usually just .byte them, like this for pkeys: > > asm volatile(".byte 0x0f,0x01,0xee\n\t" > : "=a" (pkru), "=d" (edx) > : "c" (ecx)); > > That way everybody with old toolchains can still build the kernel (and > run/test code with your config option on, btw...). We used to do this for CET instructions, but after adding kernel-mode instructions and inserting ENDBR's, the code becomes cluttered. I also found an earlier discussion on the ENDBR: https://lore.kernel.org/lkml/CALCETrVRH8LeYoo7V1VBPqg4WS0Enxtizt=T7dPvgoeWfJrdzA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org/ It makes sense to let the user know early on that the system cannot support CET and cannot build a CET-enabled kernel. One thing we can do is to disable CET in Kconfig and not in kernel build, which I will do in the next version. Yu-cheng From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Message-ID: <070d9d78981f0aad2baf740233e8dfc32ecd29d7.camel@intel.com> Subject: Re: [RFC PATCH v9 05/27] x86/cet/shstk: Add Kconfig option for user-mode Shadow Stack protection From: Yu-cheng Yu Date: Fri, 06 Mar 2020 10:37:13 -0800 In-Reply-To: References: <20200205181935.3712-1-yu-cheng.yu@intel.com> <20200205181935.3712-6-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org To: Dave Hansen , 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 , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , x86-patch-review@intel.com List-ID: Message-ID: <20200306183713.3_CCJDGQ3WPjQZgcgemhJ6h6boS22ih9lC7oyXpcHEM@z> On Wed, 2020-02-26 at 10:05 -0800, Dave Hansen wrote: > On 2/5/20 10:19 AM, Yu-cheng Yu wrote: > > +# Check assembler Shadow Stack suppot > > ^ support > > > +ifdef CONFIG_X86_INTEL_SHADOW_STACK_USER > > + ifeq ($(call as-instr, saveprevssp, y),) > > + $(error CONFIG_X86_INTEL_SHADOW_STACK_USER not supported by the assembler) > > + endif > > +endif > > Is this *just* looking for instruction support in the assembler? > > We usually just .byte them, like this for pkeys: > > asm volatile(".byte 0x0f,0x01,0xee\n\t" > : "=a" (pkru), "=d" (edx) > : "c" (ecx)); > > That way everybody with old toolchains can still build the kernel (and > run/test code with your config option on, btw...). We used to do this for CET instructions, but after adding kernel-mode instructions and inserting ENDBR's, the code becomes cluttered. I also found an earlier discussion on the ENDBR: https://lore.kernel.org/lkml/CALCETrVRH8LeYoo7V1VBPqg4WS0Enxtizt=T7dPvgoeWfJrdzA@mail.gmail.com/ It makes sense to let the user know early on that the system cannot support CET and cannot build a CET-enabled kernel. One thing we can do is to disable CET in Kconfig and not in kernel build, which I will do in the next version. Yu-cheng