From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu-cheng Yu Subject: Re: [PATCH 09/10] mm: Prevent madvise from changing shadow stack Date: Thu, 07 Jun 2018 14:18:08 -0700 Message-ID: <1528406288.5794.1.camel@2b52.sc.intel.com> References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-10-yu-cheng.yu@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Nadav Amit Cc: Linux Kernel Mailing List , linux-doc@vger.kernel.org, "open list:MEMORY MANAGEMENT" , linux-arch@vger.kernel.org, the arch/x86 maintainers , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz List-Id: linux-arch.vger.kernel.org On Thu, 2018-06-07 at 14:09 -0700, Nadav Amit wrote: > Yu-cheng Yu wrote: > > > Signed-off-by: Yu-cheng Yu > > --- > > mm/madvise.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index 4d3c922ea1a1..2a6988badd6b 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -839,6 +839,14 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) > > if (vma && start > vma->vm_start) > > prev = vma; > > > > + /* > > + * Don't do anything on shadow stack. > > + */ > > + if (vma->vm_flags & VM_SHSTK) { > > + error = -EINVAL; > > + goto out_no_plug; > > + } > > + > > blk_start_plug(&plug); > > for (;;) { > > /* Still start < end. */ > > What happens if the madvise() revolves multiple VMAs, the first one is not > VM_SHSTK, but the another one is? Shouldn’t the test be done inside the > loop, potentially in madvise_vma() ? > I will fix it. Thanks! From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com ([192.55.52.93]:28726 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbeFGVVU (ORCPT ); Thu, 7 Jun 2018 17:21:20 -0400 Message-ID: <1528406288.5794.1.camel@2b52.sc.intel.com> Subject: Re: [PATCH 09/10] mm: Prevent madvise from changing shadow stack From: Yu-cheng Yu Date: Thu, 07 Jun 2018 14:18:08 -0700 In-Reply-To: References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-10-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Nadav Amit Cc: Linux Kernel Mailing List , linux-doc@vger.kernel.org, "open list:MEMORY MANAGEMENT" , linux-arch@vger.kernel.org, the arch/x86 maintainers , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Message-ID: <20180607211808.NuQ_eegADwfZl8J8wEUC3dP3IPiG58T6yKYvCrIB-aI@z> On Thu, 2018-06-07 at 14:09 -0700, Nadav Amit wrote: > Yu-cheng Yu wrote: > > > Signed-off-by: Yu-cheng Yu > > --- > > mm/madvise.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index 4d3c922ea1a1..2a6988badd6b 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -839,6 +839,14 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) > > if (vma && start > vma->vm_start) > > prev = vma; > > > > + /* > > + * Don't do anything on shadow stack. > > + */ > > + if (vma->vm_flags & VM_SHSTK) { > > + error = -EINVAL; > > + goto out_no_plug; > > + } > > + > > blk_start_plug(&plug); > > for (;;) { > > /* Still start < end. */ > > What happens if the madvise() revolves multiple VMAs, the first one is not > VM_SHSTK, but the another one is? Shouldn’t the test be done inside the > loop, potentially in madvise_vma() ? > I will fix it. Thanks!