Message ID | 20180607143807.3611-11-yu-cheng.yu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu <yu-cheng.yu@intel.com> wrote: blocking remap_file_pages() seems reasonable. I'm not sure what's wrong with munmap().
On Thu, 2018-06-07 at 11:50 -0700, Andy Lutomirski wrote: > On Thu, Jun 7, 2018 at 7:41 AM Yu-cheng Yu <yu-cheng.yu@intel.com> wrote: > > blocking remap_file_pages() seems reasonable. I'm not sure what's > wrong with munmap(). Yes, maybe we don't need to block munmap(). If the shadow stack is unmapped, the application gets a fault. I will remove the patch.
diff --git a/mm/mmap.c b/mm/mmap.c index fc41c0543d7f..e7d1fcb7ec58 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2810,6 +2810,16 @@ EXPORT_SYMBOL(vm_munmap); SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) { + struct vm_area_struct *vma; + + /* Do not munmap shadow stack */ + down_read(¤t->mm->mmap_sem); + vma = find_vma(current->mm, addr); + if (vma && (vma->vm_flags & VM_SHSTK)) { + up_read(¤t->mm->mmap_sem); + return -EINVAL; + } + up_read(¤t->mm->mmap_sem); profile_munmap(addr); return vm_munmap(addr, len); } @@ -2851,6 +2861,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, if (!vma || !(vma->vm_flags & VM_SHARED)) goto out; + if (vma->vm_flags & VM_SHSTK) + goto out; + if (start < vma->vm_start) goto out;
Signed-off-by: Yu-cheng Yu <yu-cheng.yu@intel.com> --- mm/mmap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)