From mboxrd@z Thu Jan 1 00:00:00 1970 From: "H.J. Lu" Subject: Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack Date: Thu, 7 Jun 2018 21:09:58 -0700 Message-ID: References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-7-yu-cheng.yu@intel.com> <1528403417.5265.35.camel@2b52.sc.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Andy Lutomirski Cc: Yu-cheng Yu , LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.com List-Id: linux-arch.vger.kernel.org On Thu, Jun 7, 2018 at 4:01 PM, Andy Lutomirski wrote: > On Thu, Jun 7, 2018 at 3:02 PM H.J. Lu wrote: >> >> On Thu, Jun 7, 2018 at 2:01 PM, Andy Lutomirski wrote: >> > On Thu, Jun 7, 2018 at 1:33 PM Yu-cheng Yu wrote: >> >> >> >> On Thu, 2018-06-07 at 11:48 -0700, Andy Lutomirski wrote: >> >> > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu wrote: >> >> > > >> >> > > The following operations are provided. >> >> > > >> >> > > ARCH_CET_STATUS: >> >> > > return the current CET status >> >> > > >> >> > > ARCH_CET_DISABLE: >> >> > > disable CET features >> >> > > >> >> > > ARCH_CET_LOCK: >> >> > > lock out CET features >> >> > > >> >> > > ARCH_CET_EXEC: >> >> > > set CET features for exec() >> >> > > >> >> > > ARCH_CET_ALLOC_SHSTK: >> >> > > allocate a new shadow stack >> >> > > >> >> > > ARCH_CET_PUSH_SHSTK: >> >> > > put a return address on shadow stack >> >> > > >> >> > > ARCH_CET_ALLOC_SHSTK and ARCH_CET_PUSH_SHSTK are intended only for >> >> > > the implementation of GLIBC ucontext related APIs. >> >> > >> >> > Please document exactly what these all do and why. I don't understand >> >> > what purpose ARCH_CET_LOCK and ARCH_CET_EXEC serve. CET is opt in for >> >> > each ELF program, so I think there should be no need for a magic >> >> > override. >> >> >> >> CET is initially enabled if the loader has CET capability. Then the >> >> loader decides if the application can run with CET. If the application >> >> cannot run with CET (e.g. a dependent library does not have CET), then >> >> the loader turns off CET before passing to the application. When the >> >> loader is done, it locks out CET and the feature cannot be turned off >> >> anymore until the next exec() call. >> > >> > Why is the lockout necessary? If user code enables CET and tries to >> > run code that doesn't support CET, it will crash. I don't see why we >> > need special code in the kernel to prevent a user program from calling >> > arch_prctl() and crashing itself. There are already plenty of ways to >> > do that :) >> >> On CET enabled machine, not all programs nor shared libraries are >> CET enabled. But since ld.so is CET enabled, all programs start >> as CET enabled. ld.so will disable CET if a program or any of its shared >> libraries aren't CET enabled. ld.so will lock up CET once it is done CET >> checking so that CET can't no longer be disabled afterwards. > > Yeah, I got that. No one has explained *why*. It is to prevent malicious code from disabling CET. > (Also, shouldn't the vDSO itself be marked as supporting CET?) No. vDSO is loaded by kernel. vDSO in CET kernel is CET compatible. -- H.J. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot0-f193.google.com ([74.125.82.193]:41109 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750773AbeFHEJ7 (ORCPT ); Fri, 8 Jun 2018 00:09:59 -0400 MIME-Version: 1.0 In-Reply-To: References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-7-yu-cheng.yu@intel.com> <1528403417.5265.35.camel@2b52.sc.intel.com> From: "H.J. Lu" Date: Thu, 7 Jun 2018 21:09:58 -0700 Message-ID: Subject: Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack Content-Type: text/plain; charset="UTF-8" Sender: linux-arch-owner@vger.kernel.org List-ID: To: Andy Lutomirski Cc: Yu-cheng Yu , LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.com Message-ID: <20180608040958.bXcV2wzgVEcVb7DUvQIMasv_yNsFVhDcGDqi8KSUIXw@z> On Thu, Jun 7, 2018 at 4:01 PM, Andy Lutomirski wrote: > On Thu, Jun 7, 2018 at 3:02 PM H.J. Lu wrote: >> >> On Thu, Jun 7, 2018 at 2:01 PM, Andy Lutomirski wrote: >> > On Thu, Jun 7, 2018 at 1:33 PM Yu-cheng Yu wrote: >> >> >> >> On Thu, 2018-06-07 at 11:48 -0700, Andy Lutomirski wrote: >> >> > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu wrote: >> >> > > >> >> > > The following operations are provided. >> >> > > >> >> > > ARCH_CET_STATUS: >> >> > > return the current CET status >> >> > > >> >> > > ARCH_CET_DISABLE: >> >> > > disable CET features >> >> > > >> >> > > ARCH_CET_LOCK: >> >> > > lock out CET features >> >> > > >> >> > > ARCH_CET_EXEC: >> >> > > set CET features for exec() >> >> > > >> >> > > ARCH_CET_ALLOC_SHSTK: >> >> > > allocate a new shadow stack >> >> > > >> >> > > ARCH_CET_PUSH_SHSTK: >> >> > > put a return address on shadow stack >> >> > > >> >> > > ARCH_CET_ALLOC_SHSTK and ARCH_CET_PUSH_SHSTK are intended only for >> >> > > the implementation of GLIBC ucontext related APIs. >> >> > >> >> > Please document exactly what these all do and why. I don't understand >> >> > what purpose ARCH_CET_LOCK and ARCH_CET_EXEC serve. CET is opt in for >> >> > each ELF program, so I think there should be no need for a magic >> >> > override. >> >> >> >> CET is initially enabled if the loader has CET capability. Then the >> >> loader decides if the application can run with CET. If the application >> >> cannot run with CET (e.g. a dependent library does not have CET), then >> >> the loader turns off CET before passing to the application. When the >> >> loader is done, it locks out CET and the feature cannot be turned off >> >> anymore until the next exec() call. >> > >> > Why is the lockout necessary? If user code enables CET and tries to >> > run code that doesn't support CET, it will crash. I don't see why we >> > need special code in the kernel to prevent a user program from calling >> > arch_prctl() and crashing itself. There are already plenty of ways to >> > do that :) >> >> On CET enabled machine, not all programs nor shared libraries are >> CET enabled. But since ld.so is CET enabled, all programs start >> as CET enabled. ld.so will disable CET if a program or any of its shared >> libraries aren't CET enabled. ld.so will lock up CET once it is done CET >> checking so that CET can't no longer be disabled afterwards. > > Yeah, I got that. No one has explained *why*. It is to prevent malicious code from disabling CET. > (Also, shouldn't the vDSO itself be marked as supporting CET?) No. vDSO is loaded by kernel. vDSO in CET kernel is CET compatible. -- H.J.