From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id F09D66B0006 for ; Thu, 7 Jun 2018 17:09:10 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id i1-v6so6027291pld.11 for ; Thu, 07 Jun 2018 14:09:10 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r14-v6sor12280950pgn.83.2018.06.07.14.09.09 for (Google Transport Security); Thu, 07 Jun 2018 14:09:09 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH 09/10] mm: Prevent madvise from changing shadow stack From: Nadav Amit In-Reply-To: <20180607143807.3611-10-yu-cheng.yu@intel.com> Date: Thu, 7 Jun 2018 14:09:05 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20180607143807.3611-1-yu-cheng.yu@intel.com> <20180607143807.3611-10-yu-cheng.yu@intel.com> Sender: owner-linux-mm@kvack.org List-ID: To: Yu-cheng Yu 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 Yu-cheng Yu wrote: > Signed-off-by: Yu-cheng Yu > --- > mm/madvise.c | 9 +++++++++ > 1 file changed, 9 insertions(+) >=20 > 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 =3D vma; >=20 > + /* > + * Don't do anything on shadow stack. > + */ > + if (vma->vm_flags & VM_SHSTK) { > + error =3D -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=E2=80=99t the test be done = inside the loop, potentially in madvise_vma() ?