vma.c (49b1b8d6f6831026cb105b0eafa18f13db612d86) vma.c (40b88644dd92d99e572063893c2a247598c238d6)
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3/*
4 * VMA-specific functions.
5 */
6
7#include "vma_internal.h"
8#include "vma.h"

--- 827 unchanged lines hidden (view full) ---

836 * @mm: The mm_struct
837 * @start: The start address to munmap
838 * @len: The length of the range to munmap
839 * @uf: The userfaultfd list_head
840 * @unlock: set to true if the user wants to drop the mmap_lock on success
841 *
842 * This function takes a @mas that is either pointing to the previous VMA or set
843 * to MA_START and sets it up to remove the mapping(s). The @len will be
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3/*
4 * VMA-specific functions.
5 */
6
7#include "vma_internal.h"
8#include "vma.h"

--- 827 unchanged lines hidden (view full) ---

836 * @mm: The mm_struct
837 * @start: The start address to munmap
838 * @len: The length of the range to munmap
839 * @uf: The userfaultfd list_head
840 * @unlock: set to true if the user wants to drop the mmap_lock on success
841 *
842 * This function takes a @mas that is either pointing to the previous VMA or set
843 * to MA_START and sets it up to remove the mapping(s). The @len will be
844 * aligned and any arch_unmap work will be preformed.
844 * aligned.
845 *
846 * Return: 0 on success and drops the lock if so directed, error and leaves the
847 * lock held otherwise.
848 */
849int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm,
850 unsigned long start, size_t len, struct list_head *uf,
851 bool unlock)
852{
853 unsigned long end;
854 struct vm_area_struct *vma;
855
856 if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start)
857 return -EINVAL;
858
859 end = start + PAGE_ALIGN(len);
860 if (end == start)
861 return -EINVAL;
862
863 /*
845 *
846 * Return: 0 on success and drops the lock if so directed, error and leaves the
847 * lock held otherwise.
848 */
849int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm,
850 unsigned long start, size_t len, struct list_head *uf,
851 bool unlock)
852{
853 unsigned long end;
854 struct vm_area_struct *vma;
855
856 if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start)
857 return -EINVAL;
858
859 end = start + PAGE_ALIGN(len);
860 if (end == start)
861 return -EINVAL;
862
863 /*
864 * Check if memory is sealed before arch_unmap.
865 * Prevent unmapping a sealed VMA.
864 * Check if memory is sealed, prevent unmapping a sealed VMA.
866 * can_modify_mm assumes we have acquired the lock on MM.
867 */
868 if (unlikely(!can_modify_mm(mm, start, end)))
869 return -EPERM;
870
865 * can_modify_mm assumes we have acquired the lock on MM.
866 */
867 if (unlikely(!can_modify_mm(mm, start, end)))
868 return -EPERM;
869
871 /* arch_unmap() might do unmaps itself. */
872 arch_unmap(mm, start, end);
873
874 /* Find the first overlapping VMA */
875 vma = vma_find(vmi, end);
876 if (!vma) {
877 if (unlock)
878 mmap_write_unlock(mm);
879 return 0;
880 }
881

--- 885 unchanged lines hidden ---
870 /* Find the first overlapping VMA */
871 vma = vma_find(vmi, end);
872 if (!vma) {
873 if (unlock)
874 mmap_write_unlock(mm);
875 return 0;
876 }
877

--- 885 unchanged lines hidden ---