From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Weimer Subject: Re: [PATCH 04/10] x86/cet: Handle thread shadow stack Date: Thu, 7 Jun 2018 21:47:22 +0200 Message-ID: <3c1bdf85-0c52-39ed-a799-e26ac0e52391@redhat.com> References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-5-yu-cheng.yu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Andy Lutomirski , Yu-cheng Yu Cc: LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H. J. Lu" , "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 06/07/2018 08:21 PM, Andy Lutomirski wrote: > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu wrote: >> >> When fork() specifies CLONE_VM but not CLONE_VFORK, the child >> needs a separate program stack and a separate shadow stack. >> This patch handles allocation and freeing of the thread shadow >> stack. > > Aha -- you're trying to make this automatic. I'm not convinced this > is a good idea. The Linux kernel has a long and storied history of > enabling new hardware features in ways that are almost entirely > useless for userspace. > > Florian, do you have any thoughts on how the user/kernel interaction > for the shadow stack should work? I have not looked at this in detail, have not played with the emulator, and have not been privy to any discussions before these patches have been posted, however … I believe that we want as little code in userspace for shadow stack management as possible. One concern I have is that even with the code we arguably need for various kinds of stack unwinding, we might have unwittingly built a generic trampoline that leads to full CET bypass. I also expect that we'd only have donor mappings in userspace anyway, and that the memory is not actually accessible from userspace if it is used for a shadow stack. > My intuition would be that all > shadow stack management should be entirely controlled by userspace -- > newly cloned threads (with CLONE_VM) should have no shadow stack > initially, and newly started processes should have no shadow stack > until they ask for one. If the new thread doesn't have a shadow stack, we need to disable signals around clone, and we are very likely forced to rewrite the early thread setup in assembler, to avoid spurious calls (including calls to thunks to get EIP on i386). I wouldn't want to do this If we can avoid it. Just using C and hoping to get away with it doesn't sound greater, either. And obviously there is the matter that the initial thread setup code ends up being that universal trampoline. Thanks, Florian From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34988 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753017AbeFGTr2 (ORCPT ); Thu, 7 Jun 2018 15:47:28 -0400 Subject: Re: [PATCH 04/10] x86/cet: Handle thread shadow stack References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-5-yu-cheng.yu@intel.com> From: Florian Weimer Message-ID: <3c1bdf85-0c52-39ed-a799-e26ac0e52391@redhat.com> Date: Thu, 7 Jun 2018 21:47:22 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Andy Lutomirski , Yu-cheng Yu Cc: LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H. J. Lu" , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.com Message-ID: <20180607194722.U-wjGeedvo91ojAopX1dlKzWIogyTR4nvI8b-7nbe3s@z> On 06/07/2018 08:21 PM, Andy Lutomirski wrote: > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu wrote: >> >> When fork() specifies CLONE_VM but not CLONE_VFORK, the child >> needs a separate program stack and a separate shadow stack. >> This patch handles allocation and freeing of the thread shadow >> stack. > > Aha -- you're trying to make this automatic. I'm not convinced this > is a good idea. The Linux kernel has a long and storied history of > enabling new hardware features in ways that are almost entirely > useless for userspace. > > Florian, do you have any thoughts on how the user/kernel interaction > for the shadow stack should work? I have not looked at this in detail, have not played with the emulator, and have not been privy to any discussions before these patches have been posted, however … I believe that we want as little code in userspace for shadow stack management as possible. One concern I have is that even with the code we arguably need for various kinds of stack unwinding, we might have unwittingly built a generic trampoline that leads to full CET bypass. I also expect that we'd only have donor mappings in userspace anyway, and that the memory is not actually accessible from userspace if it is used for a shadow stack. > My intuition would be that all > shadow stack management should be entirely controlled by userspace -- > newly cloned threads (with CLONE_VM) should have no shadow stack > initially, and newly started processes should have no shadow stack > until they ask for one. If the new thread doesn't have a shadow stack, we need to disable signals around clone, and we are very likely forced to rewrite the early thread setup in assembler, to avoid spurious calls (including calls to thunks to get EIP on i386). I wouldn't want to do this If we can avoid it. Just using C and hoping to get away with it doesn't sound greater, either. And obviously there is the matter that the initial thread setup code ends up being that universal trampoline. Thanks, Florian