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>
37 * Do a signal return; undo the signal stack. These are aligned to 128-bit.
54 unsigned long limit; /* largest allowed size */ member
71 sizeof(user->sigframe->uc.uc_mcontext.__reserved); in init_user_layout()
74 user->size = offsetof(struct rt_sigframe, uc.uc_mcontext.__reserved); in init_user_layout()
76 user->limit = user->size + reserved_size; in init_user_layout()
78 user->limit -= TERMINATOR_SIZE; in init_user_layout()
79 user->limit -= EXTRA_CONTEXT_SIZE; in init_user_layout()
85 return round_up(max(user->size, sizeof(struct rt_sigframe)), 16); in sigframe_size()
89 * Sanity limit on the approximate maximum size of signal frame we'll
91 * not taken into account. This limit is not a guarantee and is
101 if (padded_size > user->limit - user->size && in __sigframe_alloc()
102 !user->extra_offset && in __sigframe_alloc()
106 user->limit += EXTRA_CONTEXT_SIZE; in __sigframe_alloc()
107 ret = __sigframe_alloc(user, &user->extra_offset, in __sigframe_alloc()
110 user->limit -= EXTRA_CONTEXT_SIZE; in __sigframe_alloc()
115 user->size += TERMINATOR_SIZE; in __sigframe_alloc()
121 user->limit = SIGFRAME_MAXSZ - TERMINATOR_SIZE; in __sigframe_alloc()
125 if (padded_size > user->limit - user->size) in __sigframe_alloc()
126 return -ENOMEM; in __sigframe_alloc()
128 *offset = user->size; in __sigframe_alloc()
129 user->size += padded_size; in __sigframe_alloc()
150 /* Un-reserve the space reserved for the terminator: */ in sigframe_alloc_end()
151 user->limit += TERMINATOR_SIZE; in sigframe_alloc_end()
153 ret = sigframe_alloc(user, &user->end_offset, in sigframe_alloc_end()
159 user->limit = user->size; in sigframe_alloc_end()
166 char __user *base = (char __user *)user->sigframe; in apply_user_offset()
174 &current->thread.uw.fpsimd_state; in preserve_fpsimd_context()
178 err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs)); in preserve_fpsimd_context()
179 __put_user_error(fpsimd->fpsr, &ctx->fpsr, err); in preserve_fpsimd_context()
180 __put_user_error(fpsimd->fpcr, &ctx->fpcr, err); in preserve_fpsimd_context()
183 __put_user_error(FPSIMD_MAGIC, &ctx->head.magic, err); in preserve_fpsimd_context()
184 __put_user_error(sizeof(struct fpsimd_context), &ctx->head.size, err); in preserve_fpsimd_context()
186 return err ? -EFAULT : 0; in preserve_fpsimd_context()
196 __get_user_error(magic, &ctx->head.magic, err); in restore_fpsimd_context()
197 __get_user_error(size, &ctx->head.size, err); in restore_fpsimd_context()
199 return -EFAULT; in restore_fpsimd_context()
201 return -EINVAL; in restore_fpsimd_context()
204 err = __copy_from_user(fpsimd.vregs, ctx->vregs, in restore_fpsimd_context()
206 __get_user_error(fpsimd.fpsr, &ctx->fpsr, err); in restore_fpsimd_context()
207 __get_user_error(fpsimd.fpcr, &ctx->fpcr, err); in restore_fpsimd_context()
215 return err ? -EFAULT : 0; in restore_fpsimd_context()
230 u16 reserved[ARRAY_SIZE(ctx->__reserved)]; in preserve_sve_context()
232 unsigned int vl = task_get_sve_vl(current); in preserve_sve_context()
235 if (thread_sm_enabled(&current->thread)) { in preserve_sve_context()
236 vl = task_get_sme_vl(current); in preserve_sve_context()
245 __put_user_error(SVE_MAGIC, &ctx->head.magic, err); in preserve_sve_context()
247 &ctx->head.size, err); in preserve_sve_context()
248 __put_user_error(vl, &ctx->vl, err); in preserve_sve_context()
249 __put_user_error(flags, &ctx->flags, err); in preserve_sve_context()
250 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved)); in preserve_sve_context()
251 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved)); in preserve_sve_context()
260 current->thread.sve_state, in preserve_sve_context()
264 return err ? -EFAULT : 0; in preserve_sve_context()
274 if (__copy_from_user(&sve, user->sve, sizeof(sve))) in restore_sve_fpsimd_context()
275 return -EFAULT; in restore_sve_fpsimd_context()
279 return -EINVAL; in restore_sve_fpsimd_context()
281 vl = task_get_sme_vl(current); in restore_sve_fpsimd_context()
284 return -EINVAL; in restore_sve_fpsimd_context()
286 vl = task_get_sve_vl(current); in restore_sve_fpsimd_context()
290 return -EINVAL; in restore_sve_fpsimd_context()
292 if (sve.head.size <= sizeof(*user->sve)) { in restore_sve_fpsimd_context()
294 current->thread.svcr &= ~SVCR_SM_MASK; in restore_sve_fpsimd_context()
301 return -EINVAL; in restore_sve_fpsimd_context()
310 fpsimd_flush_task_state(current); in restore_sve_fpsimd_context()
313 sve_alloc(current, true); in restore_sve_fpsimd_context()
314 if (!current->thread.sve_state) { in restore_sve_fpsimd_context()
316 return -ENOMEM; in restore_sve_fpsimd_context()
319 err = __copy_from_user(current->thread.sve_state, in restore_sve_fpsimd_context()
320 (char __user const *)user->sve + in restore_sve_fpsimd_context()
324 return -EFAULT; in restore_sve_fpsimd_context()
327 current->thread.svcr |= SVCR_SM_MASK; in restore_sve_fpsimd_context()
333 /* restore_sigframe() already checked that user->fpsimd != NULL. */ in restore_sve_fpsimd_context()
334 err = __copy_from_user(fpsimd.vregs, user->fpsimd->vregs, in restore_sve_fpsimd_context()
336 __get_user_error(fpsimd.fpsr, &user->fpsimd->fpsr, err); in restore_sve_fpsimd_context()
337 __get_user_error(fpsimd.fpcr, &user->fpsimd->fpcr, err); in restore_sve_fpsimd_context()
343 return err ? -EFAULT : 0; in restore_sve_fpsimd_context()
351 return -EINVAL; in restore_sve_fpsimd_context()
354 /* Turn any non-optimised out attempts to use this into a link error: */
364 u16 reserved[ARRAY_SIZE(ctx->__reserved)]; in preserve_za_context()
365 unsigned int vl = task_get_sme_vl(current); in preserve_za_context()
368 if (thread_za_enabled(&current->thread)) in preserve_za_context()
375 __put_user_error(ZA_MAGIC, &ctx->head.magic, err); in preserve_za_context()
377 &ctx->head.size, err); in preserve_za_context()
378 __put_user_error(vl, &ctx->vl, err); in preserve_za_context()
379 BUILD_BUG_ON(sizeof(ctx->__reserved) != sizeof(reserved)); in preserve_za_context()
380 err |= __copy_to_user(&ctx->__reserved, reserved, sizeof(reserved)); in preserve_za_context()
389 current->thread.za_state, in preserve_za_context()
393 return err ? -EFAULT : 0; in preserve_za_context()
402 if (__copy_from_user(&za, user->za, sizeof(za))) in restore_za_context()
403 return -EFAULT; in restore_za_context()
405 if (za.vl != task_get_sme_vl(current)) in restore_za_context()
406 return -EINVAL; in restore_za_context()
408 if (za.head.size <= sizeof(*user->za)) { in restore_za_context()
409 current->thread.svcr &= ~SVCR_ZA_MASK; in restore_za_context()
416 return -EINVAL; in restore_za_context()
425 fpsimd_flush_task_state(current); in restore_za_context()
428 sme_alloc(current); in restore_za_context()
429 if (!current->thread.za_state) { in restore_za_context()
430 current->thread.svcr &= ~SVCR_ZA_MASK; in restore_za_context()
432 return -ENOMEM; in restore_za_context()
435 err = __copy_from_user(current->thread.za_state, in restore_za_context()
436 (char __user const *)user->za + in restore_za_context()
440 return -EFAULT; in restore_za_context()
443 current->thread.svcr |= SVCR_ZA_MASK; in restore_za_context()
449 /* Turn any non-optimised out attempts to use these into a link error: */
458 struct sigcontext __user *const sc = &sf->uc.uc_mcontext; in parse_user_sigframe()
460 char __user *base = (char __user *)&sc->__reserved; in parse_user_sigframe()
462 size_t limit = sizeof(sc->__reserved); in parse_user_sigframe() local
466 user->fpsimd = NULL; in parse_user_sigframe()
467 user->sve = NULL; in parse_user_sigframe()
468 user->za = NULL; in parse_user_sigframe()
483 if (limit - offset < sizeof(*head)) in parse_user_sigframe()
490 __get_user_error(magic, &head->magic, err); in parse_user_sigframe()
491 __get_user_error(size, &head->size, err); in parse_user_sigframe()
495 if (limit - offset < size) in parse_user_sigframe()
508 if (user->fpsimd) in parse_user_sigframe()
511 if (size < sizeof(*user->fpsimd)) in parse_user_sigframe()
514 user->fpsimd = (struct fpsimd_context __user *)head; in parse_user_sigframe()
525 if (user->sve) in parse_user_sigframe()
528 if (size < sizeof(*user->sve)) in parse_user_sigframe()
531 user->sve = (struct sve_context __user *)head; in parse_user_sigframe()
538 if (user->za) in parse_user_sigframe()
541 if (size < sizeof(*user->za)) in parse_user_sigframe()
544 user->za = (struct za_context __user *)head; in parse_user_sigframe()
559 __get_user_error(extra_datap, &extra->datap, err); in parse_user_sigframe()
560 __get_user_error(extra_size, &extra->size, err); in parse_user_sigframe()
566 if (limit - offset - size < TERMINATOR_SIZE) in parse_user_sigframe()
572 __get_user_error(end_magic, &end->magic, err); in parse_user_sigframe()
573 __get_user_error(end_size, &end->size, err); in parse_user_sigframe()
594 if (extra_size > sfp + SIGFRAME_MAXSZ - userp) in parse_user_sigframe()
602 limit = extra_size; in parse_user_sigframe()
604 if (!access_ok(base, limit)) in parse_user_sigframe()
616 if (limit - offset < size) in parse_user_sigframe()
626 return -EINVAL; in parse_user_sigframe()
636 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); in restore_sigframe()
641 __get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], in restore_sigframe()
643 __get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); in restore_sigframe()
644 __get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); in restore_sigframe()
645 __get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); in restore_sigframe()
652 err |= !valid_user_regs(&regs->user_regs, current); in restore_sigframe()
658 return -EINVAL; in restore_sigframe()
677 /* Always make any pending restarted system calls return -EINTR */ in SYSCALL_DEFINE0()
678 current->restart_block.fn = do_no_restart_syscall; in SYSCALL_DEFINE0()
681 * Since we stacked the signal on a 128-bit boundary, then 'sp' should in SYSCALL_DEFINE0()
684 if (regs->sp & 15) in SYSCALL_DEFINE0()
687 frame = (struct rt_sigframe __user *)regs->sp; in SYSCALL_DEFINE0()
695 if (restore_altstack(&frame->uc.uc_stack)) in SYSCALL_DEFINE0()
698 return regs->regs[0]; in SYSCALL_DEFINE0()
701 arm64_notify_segfault(regs->sp); in SYSCALL_DEFINE0()
709 * this task; otherwise, generates a layout for the current state
718 err = sigframe_alloc(user, &user->fpsimd_offset, in setup_sigframe_layout()
725 if (add_all || current->thread.fault_code) { in setup_sigframe_layout()
726 err = sigframe_alloc(user, &user->esr_offset, in setup_sigframe_layout()
736 thread_sm_enabled(&current->thread)) { in setup_sigframe_layout()
740 vl = thread_get_cur_vl(&current->thread); in setup_sigframe_layout()
745 err = sigframe_alloc(user, &user->sve_offset, in setup_sigframe_layout()
758 vl = task_get_sme_vl(current); in setup_sigframe_layout()
760 if (thread_za_enabled(&current->thread)) in setup_sigframe_layout()
763 err = sigframe_alloc(user, &user->za_offset, in setup_sigframe_layout()
776 struct rt_sigframe __user *sf = user->sigframe; in setup_sigframe()
779 __put_user_error(regs->regs[29], &user->next_frame->fp, err); in setup_sigframe()
780 __put_user_error(regs->regs[30], &user->next_frame->lr, err); in setup_sigframe()
783 __put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], in setup_sigframe()
785 __put_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); in setup_sigframe()
786 __put_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); in setup_sigframe()
787 __put_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); in setup_sigframe()
789 __put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err); in setup_sigframe()
791 err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); in setup_sigframe()
795 apply_user_offset(user, user->fpsimd_offset); in setup_sigframe()
800 if (err == 0 && user->esr_offset) { in setup_sigframe()
802 apply_user_offset(user, user->esr_offset); in setup_sigframe()
804 __put_user_error(ESR_MAGIC, &esr_ctx->head.magic, err); in setup_sigframe()
805 __put_user_error(sizeof(*esr_ctx), &esr_ctx->head.size, err); in setup_sigframe()
806 __put_user_error(current->thread.fault_code, &esr_ctx->esr, err); in setup_sigframe()
811 err == 0 && user->sve_offset) { in setup_sigframe()
813 apply_user_offset(user, user->sve_offset); in setup_sigframe()
818 if (system_supports_sme() && err == 0 && user->za_offset) { in setup_sigframe()
820 apply_user_offset(user, user->za_offset); in setup_sigframe()
824 if (err == 0 && user->extra_offset) { in setup_sigframe()
825 char __user *sfp = (char __user *)user->sigframe; in setup_sigframe()
827 apply_user_offset(user, user->extra_offset); in setup_sigframe()
846 extra_size = sfp + round_up(user->size, 16) - userp; in setup_sigframe()
848 __put_user_error(EXTRA_MAGIC, &extra->head.magic, err); in setup_sigframe()
849 __put_user_error(EXTRA_CONTEXT_SIZE, &extra->head.size, err); in setup_sigframe()
850 __put_user_error(extra_datap, &extra->datap, err); in setup_sigframe()
851 __put_user_error(extra_size, &extra->size, err); in setup_sigframe()
854 __put_user_error(0, &end->magic, err); in setup_sigframe()
855 __put_user_error(0, &end->size, err); in setup_sigframe()
861 apply_user_offset(user, user->end_offset); in setup_sigframe()
863 __put_user_error(0, &end->magic, err); in setup_sigframe()
864 __put_user_error(0, &end->size, err); in setup_sigframe()
881 sp = sp_top = sigsp(regs->sp, ksig); in get_sigframe()
883 sp = round_down(sp - sizeof(struct frame_record), 16); in get_sigframe()
884 user->next_frame = (struct frame_record __user *)sp; in get_sigframe()
886 sp = round_down(sp, 16) - sigframe_size(user); in get_sigframe()
887 user->sigframe = (struct rt_sigframe __user *)sp; in get_sigframe()
892 if (!access_ok(user->sigframe, sp_top - sp)) in get_sigframe()
893 return -EFAULT; in get_sigframe()
903 regs->regs[0] = usig; in setup_return()
904 regs->sp = (unsigned long)user->sigframe; in setup_return()
905 regs->regs[29] = (unsigned long)&user->next_frame->fp; in setup_return()
906 regs->pc = (unsigned long)ka->sa.sa_handler; in setup_return()
920 regs->pstate &= ~PSR_BTYPE_MASK; in setup_return()
921 regs->pstate |= PSR_BTYPE_C; in setup_return()
925 regs->pstate &= ~PSR_TCO_BIT; in setup_return()
932 * FPSIMD register state - flush the saved FPSIMD in setup_return()
935 if (current->thread.svcr & SVCR_SM_MASK) in setup_return()
936 memset(&current->thread.uw.fpsimd_state, 0, in setup_return()
937 sizeof(current->thread.uw.fpsimd_state)); in setup_return()
939 current->thread.svcr &= ~(SVCR_ZA_MASK | in setup_return()
944 if (ka->sa.sa_flags & SA_RESTORER) in setup_return()
945 sigtramp = ka->sa.sa_restorer; in setup_return()
947 sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp); in setup_return()
949 regs->regs[30] = (unsigned long)sigtramp; in setup_return()
966 __put_user_error(0, &frame->uc.uc_flags, err); in setup_rt_frame()
967 __put_user_error(NULL, &frame->uc.uc_link, err); in setup_rt_frame()
969 err |= __save_altstack(&frame->uc.uc_stack, regs->sp); in setup_rt_frame()
972 setup_return(regs, &ksig->ka, &user, usig); in setup_rt_frame()
973 if (ksig->ka.sa.sa_flags & SA_SIGINFO) { in setup_rt_frame()
974 err |= copy_siginfo_to_user(&frame->info, &ksig->info); in setup_rt_frame()
975 regs->regs[1] = (unsigned long)&frame->info; in setup_rt_frame()
976 regs->regs[2] = (unsigned long)&frame->uc; in setup_rt_frame()
988 regs->regs[8] = __NR_restart_syscall; in setup_restart_syscall()
997 int usig = ksig->sig; in handle_signal()
1006 if (ksig->ka.sa.sa_flags & SA_SIGINFO) in handle_signal()
1017 ret |= !valid_user_regs(&regs->user_regs, current); in handle_signal()
1029 * the kernel can handle, and then we build all the user-level signal handling
1030 * stack-frames in one go after that.
1043 continue_addr = regs->pc; in do_signal()
1044 restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4); in do_signal()
1045 retval = regs->regs[0]; in do_signal()
1057 case -ERESTARTNOHAND: in do_signal()
1058 case -ERESTARTSYS: in do_signal()
1059 case -ERESTARTNOINTR: in do_signal()
1060 case -ERESTART_RESTARTBLOCK: in do_signal()
1061 regs->regs[0] = regs->orig_x0; in do_signal()
1062 regs->pc = restart_addr; in do_signal()
1077 if (regs->pc == restart_addr && in do_signal()
1078 (retval == -ERESTARTNOHAND || in do_signal()
1079 retval == -ERESTART_RESTARTBLOCK || in do_signal()
1080 (retval == -ERESTARTSYS && in do_signal()
1082 syscall_set_return_value(current, regs, -EINTR, 0); in do_signal()
1083 regs->pc = continue_addr; in do_signal()
1094 if (syscall && regs->pc == restart_addr) { in do_signal()
1095 if (retval == -ERESTART_RESTARTBLOCK) in do_signal()
1097 user_rewind_single_step(current); in do_signal()
1120 (void __user *)NULL, current); in do_notify_resume()
1164 * Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as