2 * mpx.c - Memory Protection eXtensions
4 * Copyright (c) 2014, Intel Corporation.
5 * Qiaowei Ren <qiaowei.ren@intel.com>
6 * Dave Hansen <dave.hansen@intel.com>
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
10 #include <linux/syscalls.h>
11 #include <linux/sched/sysctl.h>
16 #include <asm/mmu_context.h>
18 #include <asm/processor.h>
19 #include <asm/fpu-internal.h>
21 static const char *mpx_mapping_name(struct vm_area_struct
*vma
)
26 static struct vm_operations_struct mpx_vma_ops
= {
27 .name
= mpx_mapping_name
,
30 static int is_mpx_vma(struct vm_area_struct
*vma
)
32 return (vma
->vm_ops
== &mpx_vma_ops
);
36 * This is really a simplified "vm_mmap". it only handles MPX
37 * bounds tables (the bounds directory is user-allocated).
39 * Later on, we use the vma->vm_ops to uniquely identify these
42 static unsigned long mpx_mmap(unsigned long len
)
45 unsigned long addr
, pgoff
;
46 struct mm_struct
*mm
= current
->mm
;
48 struct vm_area_struct
*vma
;
50 /* Only bounds table and bounds directory can be allocated here */
51 if (len
!= MPX_BD_SIZE_BYTES
&& len
!= MPX_BT_SIZE_BYTES
)
54 down_write(&mm
->mmap_sem
);
56 /* Too many mappings? */
57 if (mm
->map_count
> sysctl_max_map_count
) {
62 /* Obtain the address to map to. we verify (or select) it and ensure
63 * that it represents a valid section of the address space.
65 addr
= get_unmapped_area(NULL
, 0, len
, 0, MAP_ANONYMOUS
| MAP_PRIVATE
);
66 if (addr
& ~PAGE_MASK
) {
71 vm_flags
= VM_READ
| VM_WRITE
| VM_MPX
|
72 mm
->def_flags
| VM_MAYREAD
| VM_MAYWRITE
| VM_MAYEXEC
;
74 /* Set pgoff according to addr for anon_vma */
75 pgoff
= addr
>> PAGE_SHIFT
;
77 ret
= mmap_region(NULL
, addr
, len
, vm_flags
, pgoff
);
78 if (IS_ERR_VALUE(ret
))
81 vma
= find_vma(mm
, ret
);
86 vma
->vm_ops
= &mpx_vma_ops
;
88 if (vm_flags
& VM_LOCKED
) {
89 up_write(&mm
->mmap_sem
);
90 mm_populate(ret
, len
);
95 up_write(&mm
->mmap_sem
);
105 static int get_reg_offset(struct insn
*insn
, struct pt_regs
*regs
,
110 static const int regoff
[] = {
111 offsetof(struct pt_regs
, ax
),
112 offsetof(struct pt_regs
, cx
),
113 offsetof(struct pt_regs
, dx
),
114 offsetof(struct pt_regs
, bx
),
115 offsetof(struct pt_regs
, sp
),
116 offsetof(struct pt_regs
, bp
),
117 offsetof(struct pt_regs
, si
),
118 offsetof(struct pt_regs
, di
),
120 offsetof(struct pt_regs
, r8
),
121 offsetof(struct pt_regs
, r9
),
122 offsetof(struct pt_regs
, r10
),
123 offsetof(struct pt_regs
, r11
),
124 offsetof(struct pt_regs
, r12
),
125 offsetof(struct pt_regs
, r13
),
126 offsetof(struct pt_regs
, r14
),
127 offsetof(struct pt_regs
, r15
),
130 int nr_registers
= ARRAY_SIZE(regoff
);
132 * Don't possibly decode a 32-bit instructions as
133 * reading a 64-bit-only register.
135 if (IS_ENABLED(CONFIG_X86_64
) && !insn
->x86_64
)
140 regno
= X86_MODRM_RM(insn
->modrm
.value
);
141 if (X86_REX_B(insn
->rex_prefix
.value
) == 1)
146 regno
= X86_SIB_INDEX(insn
->sib
.value
);
147 if (X86_REX_X(insn
->rex_prefix
.value
) == 1)
152 regno
= X86_SIB_BASE(insn
->sib
.value
);
153 if (X86_REX_B(insn
->rex_prefix
.value
) == 1)
158 pr_err("invalid register type");
163 if (regno
> nr_registers
) {
164 WARN_ONCE(1, "decoded an instruction with an invalid register");
167 return regoff
[regno
];
171 * return the address being referenced be instruction
172 * for rm=3 returning the content of the rm reg
173 * for rm!=3 calculates the address using SIB and Disp
175 static void __user
*mpx_get_addr_ref(struct insn
*insn
, struct pt_regs
*regs
)
177 unsigned long addr
, base
, indx
;
178 int addr_offset
, base_offset
, indx_offset
;
181 insn_get_modrm(insn
);
183 sib
= insn
->sib
.value
;
185 if (X86_MODRM_MOD(insn
->modrm
.value
) == 3) {
186 addr_offset
= get_reg_offset(insn
, regs
, REG_TYPE_RM
);
189 addr
= regs_get_register(regs
, addr_offset
);
191 if (insn
->sib
.nbytes
) {
192 base_offset
= get_reg_offset(insn
, regs
, REG_TYPE_BASE
);
196 indx_offset
= get_reg_offset(insn
, regs
, REG_TYPE_INDEX
);
200 base
= regs_get_register(regs
, base_offset
);
201 indx
= regs_get_register(regs
, indx_offset
);
202 addr
= base
+ indx
* (1 << X86_SIB_SCALE(sib
));
204 addr_offset
= get_reg_offset(insn
, regs
, REG_TYPE_RM
);
207 addr
= regs_get_register(regs
, addr_offset
);
209 addr
+= insn
->displacement
.value
;
211 return (void __user
*)addr
;
213 return (void __user
*)-1;
216 static int mpx_insn_decode(struct insn
*insn
,
217 struct pt_regs
*regs
)
219 unsigned char buf
[MAX_INSN_SIZE
];
220 int x86_64
= !test_thread_flag(TIF_IA32
);
224 not_copied
= copy_from_user(buf
, (void __user
*)regs
->ip
, sizeof(buf
));
225 nr_copied
= sizeof(buf
) - not_copied
;
227 * The decoder _should_ fail nicely if we pass it a short buffer.
228 * But, let's not depend on that implementation detail. If we
229 * did not get anything, just error out now.
233 insn_init(insn
, buf
, nr_copied
, x86_64
);
234 insn_get_length(insn
);
236 * copy_from_user() tries to get as many bytes as we could see in
237 * the largest possible instruction. If the instruction we are
238 * after is shorter than that _and_ we attempt to copy from
239 * something unreadable, we might get a short read. This is OK
240 * as long as the read did not stop in the middle of the
241 * instruction. Check to see if we got a partial instruction.
243 if (nr_copied
< insn
->length
)
246 insn_get_opcode(insn
);
248 * We only _really_ need to decode bndcl/bndcn/bndcu
249 * Error out on anything else.
251 if (insn
->opcode
.bytes
[0] != 0x0f)
253 if ((insn
->opcode
.bytes
[1] != 0x1a) &&
254 (insn
->opcode
.bytes
[1] != 0x1b))
263 * If a bounds overflow occurs then a #BR is generated. This
264 * function decodes MPX instructions to get violation address
265 * and set this address into extended struct siginfo.
267 * Note that this is not a super precise way of doing this.
268 * Userspace could have, by the time we get here, written
269 * anything it wants in to the instructions. We can not
270 * trust anything about it. They might not be valid
271 * instructions or might encode invalid registers, etc...
273 * The caller is expected to kfree() the returned siginfo_t.
275 siginfo_t
*mpx_generate_siginfo(struct pt_regs
*regs
,
276 struct xsave_struct
*xsave_buf
)
278 struct bndreg
*bndregs
, *bndreg
;
279 siginfo_t
*info
= NULL
;
284 err
= mpx_insn_decode(&insn
, regs
);
289 * We know at this point that we are only dealing with
292 insn_get_modrm(&insn
);
293 bndregno
= X86_MODRM_REG(insn
.modrm
.value
);
298 /* get the bndregs _area_ of the xsave structure */
299 bndregs
= get_xsave_addr(xsave_buf
, XSTATE_BNDREGS
);
304 /* now go select the individual register in the set of 4 */
305 bndreg
= &bndregs
[bndregno
];
307 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
313 * The registers are always 64-bit, but the upper 32
314 * bits are ignored in 32-bit mode. Also, note that the
315 * upper bounds are architecturally represented in 1's
318 * The 'unsigned long' cast is because the compiler
319 * complains when casting from integers to different-size
322 info
->si_lower
= (void __user
*)(unsigned long)bndreg
->lower_bound
;
323 info
->si_upper
= (void __user
*)(unsigned long)~bndreg
->upper_bound
;
324 info
->si_addr_lsb
= 0;
325 info
->si_signo
= SIGSEGV
;
327 info
->si_code
= SEGV_BNDERR
;
328 info
->si_addr
= mpx_get_addr_ref(&insn
, regs
);
330 * We were not able to extract an address from the instruction,
331 * probably because there was something invalid in it.
333 if (info
->si_addr
== (void *)-1) {
339 /* info might be NULL, but kfree() handles that */
344 static __user
void *task_get_bounds_dir(struct task_struct
*tsk
)
346 struct bndcsr
*bndcsr
;
348 if (!cpu_feature_enabled(X86_FEATURE_MPX
))
349 return MPX_INVALID_BOUNDS_DIR
;
352 * The bounds directory pointer is stored in a register
353 * only accessible if we first do an xsave.
355 fpu_save_init(&tsk
->thread
.fpu
);
356 bndcsr
= get_xsave_addr(&tsk
->thread
.fpu
.state
->xsave
, XSTATE_BNDCSR
);
358 return MPX_INVALID_BOUNDS_DIR
;
361 * Make sure the register looks valid by checking the
364 if (!(bndcsr
->bndcfgu
& MPX_BNDCFG_ENABLE_FLAG
))
365 return MPX_INVALID_BOUNDS_DIR
;
368 * Lastly, mask off the low bits used for configuration
369 * flags, and return the address of the bounds table.
371 return (void __user
*)(unsigned long)
372 (bndcsr
->bndcfgu
& MPX_BNDCFG_ADDR_MASK
);
375 int mpx_enable_management(struct task_struct
*tsk
)
377 void __user
*bd_base
= MPX_INVALID_BOUNDS_DIR
;
378 struct mm_struct
*mm
= tsk
->mm
;
382 * runtime in the userspace will be responsible for allocation of
383 * the bounds directory. Then, it will save the base of the bounds
384 * directory into XSAVE/XRSTOR Save Area and enable MPX through
385 * XRSTOR instruction.
387 * fpu_xsave() is expected to be very expensive. Storing the bounds
388 * directory here means that we do not have to do xsave in the unmap
389 * path; we can just use mm->bd_addr instead.
391 bd_base
= task_get_bounds_dir(tsk
);
392 down_write(&mm
->mmap_sem
);
393 mm
->bd_addr
= bd_base
;
394 if (mm
->bd_addr
== MPX_INVALID_BOUNDS_DIR
)
397 up_write(&mm
->mmap_sem
);
401 int mpx_disable_management(struct task_struct
*tsk
)
403 struct mm_struct
*mm
= current
->mm
;
405 if (!cpu_feature_enabled(X86_FEATURE_MPX
))
408 down_write(&mm
->mmap_sem
);
409 mm
->bd_addr
= MPX_INVALID_BOUNDS_DIR
;
410 up_write(&mm
->mmap_sem
);
415 * With 32-bit mode, MPX_BT_SIZE_BYTES is 4MB, and the size of each
416 * bounds table is 16KB. With 64-bit mode, MPX_BT_SIZE_BYTES is 2GB,
417 * and the size of each bounds table is 4MB.
419 static int allocate_bt(long __user
*bd_entry
)
421 unsigned long expected_old_val
= 0;
422 unsigned long actual_old_val
= 0;
423 unsigned long bt_addr
;
427 * Carve the virtual space out of userspace for the new
430 bt_addr
= mpx_mmap(MPX_BT_SIZE_BYTES
);
431 if (IS_ERR((void *)bt_addr
))
432 return PTR_ERR((void *)bt_addr
);
434 * Set the valid flag (kinda like _PAGE_PRESENT in a pte)
436 bt_addr
= bt_addr
| MPX_BD_ENTRY_VALID_FLAG
;
439 * Go poke the address of the new bounds table in to the
440 * bounds directory entry out in userspace memory. Note:
441 * we may race with another CPU instantiating the same table.
442 * In that case the cmpxchg will see an unexpected
445 * This can fault, but that's OK because we do not hold
446 * mmap_sem at this point, unlike some of the other part
447 * of the MPX code that have to pagefault_disable().
449 ret
= user_atomic_cmpxchg_inatomic(&actual_old_val
, bd_entry
,
450 expected_old_val
, bt_addr
);
455 * The user_atomic_cmpxchg_inatomic() will only return nonzero
456 * for faults, *not* if the cmpxchg itself fails. Now we must
457 * verify that the cmpxchg itself completed successfully.
460 * We expected an empty 'expected_old_val', but instead found
461 * an apparently valid entry. Assume we raced with another
462 * thread to instantiate this table and desclare succecss.
464 if (actual_old_val
& MPX_BD_ENTRY_VALID_FLAG
) {
469 * We found a non-empty bd_entry but it did not have the
470 * VALID_FLAG set. Return an error which will result in
471 * a SEGV since this probably means that somebody scribbled
472 * some invalid data in to a bounds table.
474 if (expected_old_val
!= actual_old_val
) {
480 vm_munmap(bt_addr
& MPX_BT_ADDR_MASK
, MPX_BT_SIZE_BYTES
);
485 * When a BNDSTX instruction attempts to save bounds to a bounds
486 * table, it will first attempt to look up the table in the
487 * first-level bounds directory. If it does not find a table in
488 * the directory, a #BR is generated and we get here in order to
489 * allocate a new table.
491 * With 32-bit mode, the size of BD is 4MB, and the size of each
492 * bound table is 16KB. With 64-bit mode, the size of BD is 2GB,
493 * and the size of each bound table is 4MB.
495 static int do_mpx_bt_fault(struct xsave_struct
*xsave_buf
)
497 unsigned long bd_entry
, bd_base
;
498 struct bndcsr
*bndcsr
;
500 bndcsr
= get_xsave_addr(xsave_buf
, XSTATE_BNDCSR
);
504 * Mask off the preserve and enable bits
506 bd_base
= bndcsr
->bndcfgu
& MPX_BNDCFG_ADDR_MASK
;
508 * The hardware provides the address of the missing or invalid
509 * entry via BNDSTATUS, so we don't have to go look it up.
511 bd_entry
= bndcsr
->bndstatus
& MPX_BNDSTA_ADDR_MASK
;
513 * Make sure the directory entry is within where we think
516 if ((bd_entry
< bd_base
) ||
517 (bd_entry
>= bd_base
+ MPX_BD_SIZE_BYTES
))
520 return allocate_bt((long __user
*)bd_entry
);
523 int mpx_handle_bd_fault(struct xsave_struct
*xsave_buf
)
526 * Userspace never asked us to manage the bounds tables,
529 if (!kernel_managing_mpx_tables(current
->mm
))
532 if (do_mpx_bt_fault(xsave_buf
)) {
533 force_sig(SIGSEGV
, current
);
535 * The force_sig() is essentially "handling" this
536 * exception, so we do not pass up the error
537 * from do_mpx_bt_fault().
544 * A thin wrapper around get_user_pages(). Returns 0 if the
545 * fault was resolved or -errno if not.
547 static int mpx_resolve_fault(long __user
*addr
, int write
)
553 gup_ret
= get_user_pages(current
, current
->mm
, (unsigned long)addr
,
554 nr_pages
, write
, force
, NULL
, NULL
);
556 * get_user_pages() returns number of pages gotten.
557 * 0 means we failed to fault in and get anything,
558 * probably because 'addr' is bad.
562 /* Other error, return it */
565 /* must have gup'd a page and gup_ret>0, success */
570 * Get the base of bounds tables pointed by specific bounds
573 static int get_bt_addr(struct mm_struct
*mm
,
574 long __user
*bd_entry
, unsigned long *bt_addr
)
579 if (!access_ok(VERIFY_READ
, (bd_entry
), sizeof(*bd_entry
)))
586 ret
= get_user(*bt_addr
, bd_entry
);
591 ret
= mpx_resolve_fault(bd_entry
, need_write
);
593 * If we could not resolve the fault, consider it
594 * userspace's fault and error out.
600 valid_bit
= *bt_addr
& MPX_BD_ENTRY_VALID_FLAG
;
601 *bt_addr
&= MPX_BT_ADDR_MASK
;
604 * When the kernel is managing bounds tables, a bounds directory
605 * entry will either have a valid address (plus the valid bit)
606 * *OR* be completely empty. If we see a !valid entry *and* some
607 * data in the address field, we know something is wrong. This
608 * -EINVAL return will cause a SIGSEGV.
610 if (!valid_bit
&& *bt_addr
)
613 * Do we have an completely zeroed bt entry? That is OK. It
614 * just means there was no bounds table for this memory. Make
615 * sure to distinguish this from -EINVAL, which will cause
625 * Free the backing physical pages of bounds table 'bt_addr'.
626 * Assume start...end is within that bounds table.
628 static int zap_bt_entries(struct mm_struct
*mm
,
629 unsigned long bt_addr
,
630 unsigned long start
, unsigned long end
)
632 struct vm_area_struct
*vma
;
633 unsigned long addr
, len
;
636 * Find the first overlapping vma. If vma->vm_start > start, there
637 * will be a hole in the bounds table. This -EINVAL return will
640 vma
= find_vma(mm
, start
);
641 if (!vma
|| vma
->vm_start
> start
)
645 * A NUMA policy on a VM_MPX VMA could cause this bouds table to
646 * be split. So we need to look across the entire 'start -> end'
647 * range of this bounds table, find all of the VM_MPX VMAs, and
651 while (vma
&& vma
->vm_start
< end
) {
653 * We followed a bounds directory entry down
654 * here. If we find a non-MPX VMA, that's bad,
655 * so stop immediately and return an error. This
656 * probably results in a SIGSEGV.
658 if (!is_mpx_vma(vma
))
661 len
= min(vma
->vm_end
, end
) - addr
;
662 zap_page_range(vma
, addr
, len
, NULL
);
665 addr
= vma
->vm_start
;
671 static int unmap_single_bt(struct mm_struct
*mm
,
672 long __user
*bd_entry
, unsigned long bt_addr
)
674 unsigned long expected_old_val
= bt_addr
| MPX_BD_ENTRY_VALID_FLAG
;
675 unsigned long actual_old_val
= 0;
682 ret
= user_atomic_cmpxchg_inatomic(&actual_old_val
, bd_entry
,
683 expected_old_val
, 0);
688 ret
= mpx_resolve_fault(bd_entry
, need_write
);
690 * If we could not resolve the fault, consider it
691 * userspace's fault and error out.
697 * The cmpxchg was performed, check the results.
699 if (actual_old_val
!= expected_old_val
) {
701 * Someone else raced with us to unmap the table.
702 * There was no bounds table pointed to by the
703 * directory, so declare success. Somebody freed
709 * Something messed with the bounds directory
710 * entry. We hold mmap_sem for read or write
711 * here, so it could not be a _new_ bounds table
712 * that someone just allocated. Something is
713 * wrong, so pass up the error and SIGSEGV.
719 * Note, we are likely being called under do_munmap() already. To
720 * avoid recursion, do_munmap() will check whether it comes
721 * from one bounds table through VM_MPX flag.
723 return do_munmap(mm
, bt_addr
, MPX_BT_SIZE_BYTES
);
727 * If the bounds table pointed by bounds directory 'bd_entry' is
728 * not shared, unmap this whole bounds table. Otherwise, only free
729 * those backing physical pages of bounds table entries covered
730 * in this virtual address region start...end.
732 static int unmap_shared_bt(struct mm_struct
*mm
,
733 long __user
*bd_entry
, unsigned long start
,
734 unsigned long end
, bool prev_shared
, bool next_shared
)
736 unsigned long bt_addr
;
739 ret
= get_bt_addr(mm
, bd_entry
, &bt_addr
);
741 * We could see an "error" ret for not-present bounds
742 * tables (not really an error), or actual errors, but
743 * stop unmapping either way.
748 if (prev_shared
&& next_shared
)
749 ret
= zap_bt_entries(mm
, bt_addr
,
750 bt_addr
+MPX_GET_BT_ENTRY_OFFSET(start
),
751 bt_addr
+MPX_GET_BT_ENTRY_OFFSET(end
));
752 else if (prev_shared
)
753 ret
= zap_bt_entries(mm
, bt_addr
,
754 bt_addr
+MPX_GET_BT_ENTRY_OFFSET(start
),
755 bt_addr
+MPX_BT_SIZE_BYTES
);
756 else if (next_shared
)
757 ret
= zap_bt_entries(mm
, bt_addr
, bt_addr
,
758 bt_addr
+MPX_GET_BT_ENTRY_OFFSET(end
));
760 ret
= unmap_single_bt(mm
, bd_entry
, bt_addr
);
766 * A virtual address region being munmap()ed might share bounds table
767 * with adjacent VMAs. We only need to free the backing physical
768 * memory of these shared bounds tables entries covered in this virtual
771 static int unmap_edge_bts(struct mm_struct
*mm
,
772 unsigned long start
, unsigned long end
)
775 long __user
*bde_start
, *bde_end
;
776 struct vm_area_struct
*prev
, *next
;
777 bool prev_shared
= false, next_shared
= false;
779 bde_start
= mm
->bd_addr
+ MPX_GET_BD_ENTRY_OFFSET(start
);
780 bde_end
= mm
->bd_addr
+ MPX_GET_BD_ENTRY_OFFSET(end
-1);
783 * Check whether bde_start and bde_end are shared with adjacent
786 * We already unliked the VMAs from the mm's rbtree so 'start'
787 * is guaranteed to be in a hole. This gets us the first VMA
788 * before the hole in to 'prev' and the next VMA after the hole
791 next
= find_vma_prev(mm
, start
, &prev
);
792 if (prev
&& (mm
->bd_addr
+ MPX_GET_BD_ENTRY_OFFSET(prev
->vm_end
-1))
795 if (next
&& (mm
->bd_addr
+ MPX_GET_BD_ENTRY_OFFSET(next
->vm_start
))
800 * This virtual address region being munmap()ed is only
801 * covered by one bounds table.
803 * In this case, if this table is also shared with adjacent
804 * VMAs, only part of the backing physical memory of the bounds
805 * table need be freeed. Otherwise the whole bounds table need
808 if (bde_start
== bde_end
) {
809 return unmap_shared_bt(mm
, bde_start
, start
, end
,
810 prev_shared
, next_shared
);
814 * If more than one bounds tables are covered in this virtual
815 * address region being munmap()ed, we need to separately check
816 * whether bde_start and bde_end are shared with adjacent VMAs.
818 ret
= unmap_shared_bt(mm
, bde_start
, start
, end
, prev_shared
, false);
821 ret
= unmap_shared_bt(mm
, bde_end
, start
, end
, false, next_shared
);
828 static int mpx_unmap_tables(struct mm_struct
*mm
,
829 unsigned long start
, unsigned long end
)
832 long __user
*bd_entry
, *bde_start
, *bde_end
;
833 unsigned long bt_addr
;
836 * "Edge" bounds tables are those which are being used by the region
837 * (start -> end), but that may be shared with adjacent areas. If they
838 * turn out to be completely unshared, they will be freed. If they are
839 * shared, we will free the backing store (like an MADV_DONTNEED) for
840 * areas used by this region.
842 ret
= unmap_edge_bts(mm
, start
, end
);
844 /* non-present tables are OK */
847 /* Success, or no tables to unmap */
856 * Only unmap the bounds table that are
858 * 2. not at the edges of the mapping, even if full aligned
860 bde_start
= mm
->bd_addr
+ MPX_GET_BD_ENTRY_OFFSET(start
);
861 bde_end
= mm
->bd_addr
+ MPX_GET_BD_ENTRY_OFFSET(end
-1);
862 for (bd_entry
= bde_start
+ 1; bd_entry
< bde_end
; bd_entry
++) {
863 ret
= get_bt_addr(mm
, bd_entry
, &bt_addr
);
868 /* No table here, try the next one */
874 * Note: we are being strict here.
875 * Any time we run in to an issue
876 * unmapping tables, we stop and
882 ret
= unmap_single_bt(mm
, bd_entry
, bt_addr
);
891 * Free unused bounds tables covered in a virtual address region being
892 * munmap()ed. Assume end > start.
894 * This function will be called by do_munmap(), and the VMAs covering
895 * the virtual address region start...end have already been split if
896 * necessary, and the 'vma' is the first vma in this range (start -> end).
898 void mpx_notify_unmap(struct mm_struct
*mm
, struct vm_area_struct
*vma
,
899 unsigned long start
, unsigned long end
)
904 * Refuse to do anything unless userspace has asked
905 * the kernel to help manage the bounds tables,
907 if (!kernel_managing_mpx_tables(current
->mm
))
910 * This will look across the entire 'start -> end' range,
911 * and find all of the non-VM_MPX VMAs.
913 * To avoid recursion, if a VM_MPX vma is found in the range
914 * (start->end), we will not continue follow-up work. This
915 * recursion represents having bounds tables for bounds tables,
916 * which should not occur normally. Being strict about it here
917 * helps ensure that we do not have an exploitable stack overflow.
920 if (vma
->vm_flags
& VM_MPX
)
923 } while (vma
&& vma
->vm_start
< end
);
925 ret
= mpx_unmap_tables(mm
, start
, end
);
927 force_sig(SIGSEGV
, current
);