diff options
author | Jann Horn <jannh@google.com> | 2021-02-19 14:59:35 +0800 |
---|---|---|
committer | Ley Foon Tan <ley.foon.tan@intel.com> | 2021-02-19 15:01:59 +0800 |
commit | c26958cb5a0d9053d1358258827638773f3d36ed (patch) | |
tree | 26c85414097e72c6a4462d50f7fe23a5044a134f /arch/nios2 | |
parent | f40ddce88593482919761f74910f42f4b84c004b (diff) | |
download | linux-stable-c26958cb5a0d9053d1358258827638773f3d36ed.tar.gz linux-stable-c26958cb5a0d9053d1358258827638773f3d36ed.tar.bz2 linux-stable-c26958cb5a0d9053d1358258827638773f3d36ed.zip |
Take mmap lock in cacheflush syscall
We need to take the mmap lock around find_vma() and subsequent use of the
VMA. Otherwise, we can race with concurrent operations like munmap(), which
can lead to use-after-free accesses to freed VMAs.
Fixes: 1000197d8013 ("nios2: System calls handling")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com>
Diffstat (limited to 'arch/nios2')
-rw-r--r-- | arch/nios2/kernel/sys_nios2.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/arch/nios2/kernel/sys_nios2.c b/arch/nios2/kernel/sys_nios2.c index cd390ec4f88b..b1ca85699952 100644 --- a/arch/nios2/kernel/sys_nios2.c +++ b/arch/nios2/kernel/sys_nios2.c @@ -22,6 +22,7 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, unsigned int op) { struct vm_area_struct *vma; + struct mm_struct *mm = current->mm; if (len == 0) return 0; @@ -34,16 +35,22 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, if (addr + len < addr) return -EFAULT; + if (mmap_read_lock_killable(mm)) + return -EINTR; + /* * Verify that the specified address region actually belongs * to this process. */ - vma = find_vma(current->mm, addr); - if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) + vma = find_vma(mm, addr); + if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) { + mmap_read_unlock(mm); return -EFAULT; + } flush_cache_range(vma, addr, addr + len); + mmap_read_unlock(mm); return 0; } |