Skip to content

Commit 9dfb367

Browse files
thejhgregkh
authored andcommitted
Take mmap lock in cacheflush syscall
[ Upstream commit c26958c ] 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: 1000197 ("nios2: System calls handling") Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5917fdc commit 9dfb367

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎arch/nios2/kernel/sys_nios2.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len,
2222
unsigned int op)
2323
{
2424
struct vm_area_struct *vma;
25+
struct mm_struct *mm = current->mm;
2526

2627
if (len == 0)
2728
return 0;
@@ -34,16 +35,22 @@ asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len,
3435
if (addr + len < addr)
3536
return -EFAULT;
3637

38+
if (mmap_read_lock_killable(mm))
39+
return -EINTR;
40+
3741
/*
3842
* Verify that the specified address region actually belongs
3943
* to this process.
4044
*/
41-
vma = find_vma(current->mm, addr);
42-
if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
45+
vma = find_vma(mm, addr);
46+
if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) {
47+
mmap_read_unlock(mm);
4348
return -EFAULT;
49+
}
4450

4551
flush_cache_range(vma, addr, addr + len);
4652

53+
mmap_read_unlock(mm);
4754
return 0;
4855
}
4956

0 commit comments

Comments
 (0)