Lines Matching +full:current +full:- +full:limit

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 1995-2009 Russell King
24 #include <asm/debug-monitors.h>
38 * Do a signal return; undo the signal stack. These are aligned to 128-bit.
55 unsigned long limit; /* largest allowed size */ member
74 sizeof(user->sigframe->uc.uc_mcontext.__reserved); in init_user_layout()
77 user->size = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved); in init_user_layout()
79 user->limit = user->size + reserved_size; in init_user_layout()
81 user->limit -= TERMINATOR_SIZE; in init_user_layout()
82 user->limit -= EXTRA_CONTEXT_SIZE; in init_user_layout()
88 return round_up(max(user->size, sizeof(struct rt_sigframe)), 16); in sigframe_size()
92 * Sanity limit on the approximate maximum size of signal frame we'll
94 * not taken into account. This limit is not a guarantee and is
104 if (padded_size > user->limit - user->size && in __sigframe_alloc()
105 !user->extra_offset && in __sigframe_alloc()
109 user->limit += EXTRA_CONTEXT_SIZE; in __sigframe_alloc()
110 ret = __sigframe_alloc(user, &user->extra_offset, in __sigframe_alloc()
113 user->limit -= EXTRA_CONTEXT_SIZE; in __sigframe_alloc()
118 user->size += TERMINATOR_SIZE; in __sigframe_alloc()
124 user->limit = SIGFRAME_MAXSZ - TERMINATOR_SIZE; in __sigframe_alloc()
128 if (padded_size > user->limit - user->size) in __sigframe_alloc()
129 return -ENOMEM; in __sigframe_alloc()
131 *offset = user->size; in __sigframe_alloc()
132 user->size += padded_size; in __sigframe_alloc()
153 /* Un-reserve the space reserved for the terminator: */ in sigframe_alloc_end()
154 user->limit += TERMINATOR_SIZE; in sigframe_alloc_end()
156 ret = sigframe_alloc(user, &user->end_offset, in sigframe_alloc_end()
162 user->limit = user->size; in sigframe_alloc_end()
169 char __user *base = (char __user *)user->sigframe; in apply_user_offset()
190 &current->thread.uw.fpsimd_state; in preserve_fpsimd_context()
194 err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs)); in preserve_fpsimd_context()
195 __put_user_error(fpsimd->fpsr, &ctx->fpsr, err); in preserve_fpsimd_context()
196 __put_user_error(fpsimd->fpcr, &ctx->fpcr, err); in preserve_fpsimd_context()
199 __put_user_error(FPSIMD_MAGIC, &ctx->head.magic, err); in preserve_fpsimd_context()
200 __put_user_error(sizeof(struct fpsimd_context), &ctx->head.size, err); in preserve_fpsimd_context()
202 return err ? -EFAULT : 0; in preserve_fpsimd_context()
211 if (user->fpsimd_size != sizeof(struct fpsimd_context)) in restore_fpsimd_context()
212 return -EINVAL; in restore_fpsimd_context()
215 err = __copy_from_user(fpsimd.vregs, &(user->fpsimd->vregs), in restore_fpsimd_context()
217 __get_user_error(fpsimd.fpsr, &(user->fpsimd->fpsr), err); in restore_fpsimd_context()
218 __get_user_error(fpsimd.fpcr, &(user->fpsimd->fpcr), err); in restore_fpsimd_context()
221 current->thread.fp_type = FP_STATE_FPSIMD; in restore_fpsimd_context()
227 return err ? -EFAULT : 0; in restore_fpsimd_context()
236 u16 reserved[ARRAY_SIZE(ctx->__reserved)]; in preserve_sve_context()
238 unsigned int vl = task_get_sve_vl(current); in preserve_sve_context()
241 if (thread_sm_enabled(&current->thread)) { in preserve_sve_context()
242 vl = task_get_sme_vl(current); in preserve_sve_context()
245 } else if (current->thread.fp_type == FP_STATE_SVE) { in preserve_sve_context()
251 __put_user_error(SVE_MAGIC, &ctx->head.magic, err); in preserve_sve_context()
253 &ctx->head.size, err); in preserve_sve_context()
254 __put_user_error(vl, &ctx->vl, err); in preserve_sve_context()
255 __put_user_error(flags, &ctx->flags, err); in preserve_sve_context()
256 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved)); in preserve_sve_context()
257 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved)); in preserve_sve_context()
266 current->thread.sve_state, in preserve_sve_context()
270 return err ? -EFAULT : 0; in preserve_sve_context()
280 if (user->sve_size < sizeof(*user->sve)) in restore_sve_fpsimd_context()
281 return -EINVAL; in restore_sve_fpsimd_context()
283 __get_user_error(user_vl, &(user->sve->vl), err); in restore_sve_fpsimd_context()
284 __get_user_error(flags, &(user->sve->flags), err); in restore_sve_fpsimd_context()
290 return -EINVAL; in restore_sve_fpsimd_context()
292 vl = task_get_sme_vl(current); in restore_sve_fpsimd_context()
300 return -EINVAL; in restore_sve_fpsimd_context()
302 vl = task_get_sve_vl(current); in restore_sve_fpsimd_context()
306 return -EINVAL; in restore_sve_fpsimd_context()
308 if (user->sve_size == sizeof(*user->sve)) { in restore_sve_fpsimd_context()
310 current->thread.svcr &= ~SVCR_SM_MASK; in restore_sve_fpsimd_context()
311 current->thread.fp_type = FP_STATE_FPSIMD; in restore_sve_fpsimd_context()
317 if (user->sve_size < SVE_SIG_CONTEXT_SIZE(vq)) in restore_sve_fpsimd_context()
318 return -EINVAL; in restore_sve_fpsimd_context()
327 fpsimd_flush_task_state(current); in restore_sve_fpsimd_context()
330 sve_alloc(current, true); in restore_sve_fpsimd_context()
331 if (!current->thread.sve_state) { in restore_sve_fpsimd_context()
333 return -ENOMEM; in restore_sve_fpsimd_context()
336 err = __copy_from_user(current->thread.sve_state, in restore_sve_fpsimd_context()
337 (char __user const *)user->sve + in restore_sve_fpsimd_context()
341 return -EFAULT; in restore_sve_fpsimd_context()
344 current->thread.svcr |= SVCR_SM_MASK; in restore_sve_fpsimd_context()
347 current->thread.fp_type = FP_STATE_SVE; in restore_sve_fpsimd_context()
351 /* restore_sigframe() already checked that user->fpsimd != NULL. */ in restore_sve_fpsimd_context()
352 err = __copy_from_user(fpsimd.vregs, user->fpsimd->vregs, in restore_sve_fpsimd_context()
354 __get_user_error(fpsimd.fpsr, &user->fpsimd->fpsr, err); in restore_sve_fpsimd_context()
355 __get_user_error(fpsimd.fpcr, &user->fpsimd->fpcr, err); in restore_sve_fpsimd_context()
361 return err ? -EFAULT : 0; in restore_sve_fpsimd_context()
369 return -EINVAL; in restore_sve_fpsimd_context()
372 /* Turn any non-optimised out attempts to use this into a link error: */
383 current->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); in preserve_tpidr2_context()
385 __put_user_error(TPIDR2_MAGIC, &ctx->head.magic, err); in preserve_tpidr2_context()
386 __put_user_error(sizeof(*ctx), &ctx->head.size, err); in preserve_tpidr2_context()
387 __put_user_error(current->thread.tpidr2_el0, &ctx->tpidr2, err); in preserve_tpidr2_context()
397 if (user->tpidr2_size != sizeof(*user->tpidr2)) in restore_tpidr2_context()
398 return -EINVAL; in restore_tpidr2_context()
400 __get_user_error(tpidr2_el0, &user->tpidr2->tpidr2, err); in restore_tpidr2_context()
410 u16 reserved[ARRAY_SIZE(ctx->__reserved)]; in preserve_za_context()
411 unsigned int vl = task_get_sme_vl(current); in preserve_za_context()
414 if (thread_za_enabled(&current->thread)) in preserve_za_context()
421 __put_user_error(ZA_MAGIC, &ctx->head.magic, err); in preserve_za_context()
423 &ctx->head.size, err); in preserve_za_context()
424 __put_user_error(vl, &ctx->vl, err); in preserve_za_context()
425 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved)); in preserve_za_context()
426 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved)); in preserve_za_context()
435 current->thread.sme_state, in preserve_za_context()
439 return err ? -EFAULT : 0; in preserve_za_context()
448 if (user->za_size < sizeof(*user->za)) in restore_za_context()
449 return -EINVAL; in restore_za_context()
451 __get_user_error(user_vl, &(user->za->vl), err); in restore_za_context()
455 if (user_vl != task_get_sme_vl(current)) in restore_za_context()
456 return -EINVAL; in restore_za_context()
458 if (user->za_size == sizeof(*user->za)) { in restore_za_context()
459 current->thread.svcr &= ~SVCR_ZA_MASK; in restore_za_context()
465 if (user->za_size < ZA_SIG_CONTEXT_SIZE(vq)) in restore_za_context()
466 return -EINVAL; in restore_za_context()
475 fpsimd_flush_task_state(current); in restore_za_context()
478 sme_alloc(current, true); in restore_za_context()
479 if (!current->thread.sme_state) { in restore_za_context()
480 current->thread.svcr &= ~SVCR_ZA_MASK; in restore_za_context()
482 return -ENOMEM; in restore_za_context()
485 err = __copy_from_user(current->thread.sme_state, in restore_za_context()
486 (char __user const *)user->za + in restore_za_context()
490 return -EFAULT; in restore_za_context()
493 current->thread.svcr |= SVCR_ZA_MASK; in restore_za_context()
501 u16 reserved[ARRAY_SIZE(ctx->__reserved)]; in preserve_zt_context()
503 if (WARN_ON(!thread_za_enabled(&current->thread))) in preserve_zt_context()
504 return -EINVAL; in preserve_zt_context()
508 __put_user_error(ZT_MAGIC, &ctx->head.magic, err); in preserve_zt_context()
510 &ctx->head.size, err); in preserve_zt_context()
511 __put_user_error(1, &ctx->nregs, err); in preserve_zt_context()
512 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved)); in preserve_zt_context()
513 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved)); in preserve_zt_context()
521 thread_zt_state(&current->thread), in preserve_zt_context()
524 return err ? -EFAULT : 0; in preserve_zt_context()
533 if (!thread_za_enabled(&current->thread)) in restore_zt_context()
534 return -EINVAL; in restore_zt_context()
536 if (user->zt_size != ZT_SIG_CONTEXT_SIZE(1)) in restore_zt_context()
537 return -EINVAL; in restore_zt_context()
539 if (__copy_from_user(&nregs, &(user->zt->nregs), sizeof(nregs))) in restore_zt_context()
540 return -EFAULT; in restore_zt_context()
543 return -EINVAL; in restore_zt_context()
552 fpsimd_flush_task_state(current); in restore_zt_context()
555 err = __copy_from_user(thread_zt_state(&current->thread), in restore_zt_context()
556 (char __user const *)user->zt + in restore_zt_context()
560 return -EFAULT; in restore_zt_context()
567 /* Turn any non-optimised out attempts to use these into a link error: */
580 struct sigcontext __user *const sc = &sf->uc.uc_mcontext; in parse_user_sigframe()
582 char __user *base = (char __user *)&sc->__reserved; in parse_user_sigframe()
584 size_t limit = sizeof(sc->__reserved); in parse_user_sigframe() local
588 user->fpsimd = NULL; in parse_user_sigframe()
589 user->sve = NULL; in parse_user_sigframe()
590 user->tpidr2 = NULL; in parse_user_sigframe()
591 user->za = NULL; in parse_user_sigframe()
592 user->zt = NULL; in parse_user_sigframe()
607 if (limit - offset < sizeof(*head)) in parse_user_sigframe()
614 __get_user_error(magic, &head->magic, err); in parse_user_sigframe()
615 __get_user_error(size, &head->size, err); in parse_user_sigframe()
619 if (limit - offset < size) in parse_user_sigframe()
632 if (user->fpsimd) in parse_user_sigframe()
635 user->fpsimd = (struct fpsimd_context __user *)head; in parse_user_sigframe()
636 user->fpsimd_size = size; in parse_user_sigframe()
647 if (user->sve) in parse_user_sigframe()
650 user->sve = (struct sve_context __user *)head; in parse_user_sigframe()
651 user->sve_size = size; in parse_user_sigframe()
658 if (user->tpidr2) in parse_user_sigframe()
661 user->tpidr2 = (struct tpidr2_context __user *)head; in parse_user_sigframe()
662 user->tpidr2_size = size; in parse_user_sigframe()
669 if (user->za) in parse_user_sigframe()
672 user->za = (struct za_context __user *)head; in parse_user_sigframe()
673 user->za_size = size; in parse_user_sigframe()
680 if (user->zt) in parse_user_sigframe()
683 user->zt = (struct zt_context __user *)head; in parse_user_sigframe()
684 user->zt_size = size; in parse_user_sigframe()
699 __get_user_error(extra_datap, &extra->datap, err); in parse_user_sigframe()
700 __get_user_error(extra_size, &extra->size, err); in parse_user_sigframe()
706 if (limit - offset - size < TERMINATOR_SIZE) in parse_user_sigframe()
712 __get_user_error(end_magic, &end->magic, err); in parse_user_sigframe()
713 __get_user_error(end_size, &end->size, err); in parse_user_sigframe()
734 if (extra_size > sfp + SIGFRAME_MAXSZ - userp) in parse_user_sigframe()
742 limit = extra_size; in parse_user_sigframe()
744 if (!access_ok(base, limit)) in parse_user_sigframe()
756 if (limit - offset < size) in parse_user_sigframe()
766 return -EINVAL; in parse_user_sigframe()
776 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); in restore_sigframe()
781 __get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], in restore_sigframe()
783 __get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); in restore_sigframe()
784 __get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); in restore_sigframe()
785 __get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); in restore_sigframe()
792 err |= !valid_user_regs(&regs->user_regs, current); in restore_sigframe()
798 return -EINVAL; in restore_sigframe()
823 /* Always make any pending restarted system calls return -EINTR */ in SYSCALL_DEFINE0()
824 current->restart_block.fn = do_no_restart_syscall; in SYSCALL_DEFINE0()
827 * Since we stacked the signal on a 128-bit boundary, then 'sp' should in SYSCALL_DEFINE0()
830 if (regs->sp & 15) in SYSCALL_DEFINE0()
833 frame = (struct rt_sigframe __user *)regs->sp; in SYSCALL_DEFINE0()
841 if (restore_altstack(&frame->uc.uc_stack)) in SYSCALL_DEFINE0()
844 return regs->regs[0]; in SYSCALL_DEFINE0()
847 arm64_notify_segfault(regs->sp); in SYSCALL_DEFINE0()
855 * this task; otherwise, generates a layout for the current state
864 err = sigframe_alloc(user, &user->fpsimd_offset, in setup_sigframe_layout()
871 if (add_all || current->thread.fault_code) { in setup_sigframe_layout()
872 err = sigframe_alloc(user, &user->esr_offset, in setup_sigframe_layout()
881 if (add_all || current->thread.fp_type == FP_STATE_SVE || in setup_sigframe_layout()
882 thread_sm_enabled(&current->thread)) { in setup_sigframe_layout()
886 vl = thread_get_cur_vl(&current->thread); in setup_sigframe_layout()
891 err = sigframe_alloc(user, &user->sve_offset, in setup_sigframe_layout()
898 err = sigframe_alloc(user, &user->tpidr2_offset, in setup_sigframe_layout()
911 vl = task_get_sme_vl(current); in setup_sigframe_layout()
913 if (thread_za_enabled(&current->thread)) in setup_sigframe_layout()
916 err = sigframe_alloc(user, &user->za_offset, in setup_sigframe_layout()
923 if (add_all || thread_za_enabled(&current->thread)) { in setup_sigframe_layout()
924 err = sigframe_alloc(user, &user->zt_offset, in setup_sigframe_layout()
938 struct rt_sigframe __user *sf = user->sigframe; in setup_sigframe()
941 __put_user_error(regs->regs[29], &user->next_frame->fp, err); in setup_sigframe()
942 __put_user_error(regs->regs[30], &user->next_frame->lr, err); in setup_sigframe()
945 __put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], in setup_sigframe()
947 __put_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); in setup_sigframe()
948 __put_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); in setup_sigframe()
949 __put_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); in setup_sigframe()
951 __put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err); in setup_sigframe()
953 err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); in setup_sigframe()
957 apply_user_offset(user, user->fpsimd_offset); in setup_sigframe()
962 if (err == 0 && user->esr_offset) { in setup_sigframe()
964 apply_user_offset(user, user->esr_offset); in setup_sigframe()
966 __put_user_error(ESR_MAGIC, &esr_ctx->head.magic, err); in setup_sigframe()
967 __put_user_error(sizeof(*esr_ctx), &esr_ctx->head.size, err); in setup_sigframe()
968 __put_user_error(current->thread.fault_code, &esr_ctx->esr, err); in setup_sigframe()
973 err == 0 && user->sve_offset) { in setup_sigframe()
975 apply_user_offset(user, user->sve_offset); in setup_sigframe()
982 apply_user_offset(user, user->tpidr2_offset); in setup_sigframe()
987 if (system_supports_sme() && err == 0 && user->za_offset) { in setup_sigframe()
989 apply_user_offset(user, user->za_offset); in setup_sigframe()
994 if (system_supports_sme2() && err == 0 && user->zt_offset) { in setup_sigframe()
996 apply_user_offset(user, user->zt_offset); in setup_sigframe()
1000 if (err == 0 && user->extra_offset) { in setup_sigframe()
1001 char __user *sfp = (char __user *)user->sigframe; in setup_sigframe()
1003 apply_user_offset(user, user->extra_offset); in setup_sigframe()
1022 extra_size = sfp + round_up(user->size, 16) - userp; in setup_sigframe()
1024 __put_user_error(EXTRA_MAGIC, &extra->head.magic, err); in setup_sigframe()
1025 __put_user_error(EXTRA_CONTEXT_SIZE, &extra->head.size, err); in setup_sigframe()
1026 __put_user_error(extra_datap, &extra->datap, err); in setup_sigframe()
1027 __put_user_error(extra_size, &extra->size, err); in setup_sigframe()
1030 __put_user_error(0, &end->magic, err); in setup_sigframe()
1031 __put_user_error(0, &end->size, err); in setup_sigframe()
1037 apply_user_offset(user, user->end_offset); in setup_sigframe()
1039 __put_user_error(0, &end->magic, err); in setup_sigframe()
1040 __put_user_error(0, &end->size, err); in setup_sigframe()
1057 sp = sp_top = sigsp(regs->sp, ksig); in get_sigframe()
1059 sp = round_down(sp - sizeof(struct frame_record), 16); in get_sigframe()
1060 user->next_frame = (struct frame_record __user *)sp; in get_sigframe()
1062 sp = round_down(sp, 16) - sigframe_size(user); in get_sigframe()
1063 user->sigframe = (struct rt_sigframe __user *)sp; in get_sigframe()
1068 if (!access_ok(user->sigframe, sp_top - sp)) in get_sigframe()
1069 return -EFAULT; in get_sigframe()
1079 regs->regs[0] = usig; in setup_return()
1080 regs->sp = (unsigned long)user->sigframe; in setup_return()
1081 regs->regs[29] = (unsigned long)&user->next_frame->fp; in setup_return()
1082 regs->pc = (unsigned long)ka->sa.sa_handler; in setup_return()
1096 regs->pstate &= ~PSR_BTYPE_MASK; in setup_return()
1097 regs->pstate |= PSR_BTYPE_C; in setup_return()
1101 regs->pstate &= ~PSR_TCO_BIT; in setup_return()
1108 * FPSIMD register state - flush the saved FPSIMD in setup_return()
1111 if (current->thread.svcr & SVCR_SM_MASK) { in setup_return()
1112 memset(&current->thread.uw.fpsimd_state, 0, in setup_return()
1113 sizeof(current->thread.uw.fpsimd_state)); in setup_return()
1114 current->thread.fp_type = FP_STATE_FPSIMD; in setup_return()
1117 current->thread.svcr &= ~(SVCR_ZA_MASK | in setup_return()
1122 if (ka->sa.sa_flags & SA_RESTORER) in setup_return()
1123 sigtramp = ka->sa.sa_restorer; in setup_return()
1125 sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp); in setup_return()
1127 regs->regs[30] = (unsigned long)sigtramp; in setup_return()
1144 __put_user_error(0, &frame->uc.uc_flags, err); in setup_rt_frame()
1145 __put_user_error(NULL, &frame->uc.uc_link, err); in setup_rt_frame()
1147 err |= __save_altstack(&frame->uc.uc_stack, regs->sp); in setup_rt_frame()
1150 setup_return(regs, &ksig->ka, &user, usig); in setup_rt_frame()
1151 if (ksig->ka.sa.sa_flags & SA_SIGINFO) { in setup_rt_frame()
1152 err |= copy_siginfo_to_user(&frame->info, &ksig->info); in setup_rt_frame()
1153 regs->regs[1] = (unsigned long)&frame->info; in setup_rt_frame()
1154 regs->regs[2] = (unsigned long)&frame->uc; in setup_rt_frame()
1166 regs->regs[8] = __NR_restart_syscall; in setup_restart_syscall()
1175 int usig = ksig->sig; in handle_signal()
1184 if (ksig->ka.sa.sa_flags & SA_SIGINFO) in handle_signal()
1195 ret |= !valid_user_regs(&regs->user_regs, current); in handle_signal()
1207 * the kernel can handle, and then we build all the user-level signal handling
1208 * stack-frames in one go after that.
1221 continue_addr = regs->pc; in do_signal()
1222 restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4); in do_signal()
1223 retval = regs->regs[0]; in do_signal()
1235 case -ERESTARTNOHAND: in do_signal()
1236 case -ERESTARTSYS: in do_signal()
1237 case -ERESTARTNOINTR: in do_signal()
1238 case -ERESTART_RESTARTBLOCK: in do_signal()
1239 regs->regs[0] = regs->orig_x0; in do_signal()
1240 regs->pc = restart_addr; in do_signal()
1255 if (regs->pc == restart_addr && in do_signal()
1256 (retval == -ERESTARTNOHAND || in do_signal()
1257 retval == -ERESTART_RESTARTBLOCK || in do_signal()
1258 (retval == -ERESTARTSYS && in do_signal()
1260 syscall_set_return_value(current, regs, -EINTR, 0); in do_signal()
1261 regs->pc = continue_addr; in do_signal()
1272 if (syscall && regs->pc == restart_addr) { in do_signal()
1273 if (retval == -ERESTART_RESTARTBLOCK) in do_signal()
1275 user_rewind_single_step(current); in do_signal()
1298 (void __user *)NULL, current); in do_notify_resume()
1342 * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as