Lines Matching +full:protect +full:- +full:exec

1 // SPDX-License-Identifier: GPL-2.0-only
8 * X86-64 port
11 * CPU hotplug support - ashok.raj@intel.com
15 * This file handles the architecture-dependent parts of process handling..
78 if (regs->orig_ax != -1) in __show_regs()
79 pr_cont(" ORIG_RAX: %016lx\n", regs->orig_ax); in __show_regs()
84 log_lvl, regs->ax, regs->bx, regs->cx); in __show_regs()
86 log_lvl, regs->dx, regs->si, regs->di); in __show_regs()
88 log_lvl, regs->bp, regs->r8, regs->r9); in __show_regs()
90 log_lvl, regs->r10, regs->r11, regs->r12); in __show_regs()
92 log_lvl, regs->r13, regs->r14, regs->r15); in __show_regs()
122 log_lvl, regs->cs, ds, es, cr0); in __show_regs()
133 /* Only print out debug registers if they are in their non-default state. */ in __show_regs()
148 WARN_ON(dead_task->mm); in release_thread()
174 * - For events that occur in ring 3, FRED event delivery swaps in __rdgsbase_inactive()
176 * - ERETU (the FRED transition that returns to ring 3) also swaps in __rdgsbase_inactive()
181 * - Using LKGS, available with FRED, to modify other attributes in __rdgsbase_inactive()
184 * - Accessing the GS segment base address for a user thread as in __rdgsbase_inactive()
231 * not available. The goal is to be reasonably fast on non-FSGSBASE systems.
242 * be the pre-existing saved base or it could be zero. On AMD in save_base_legacy()
247 * context switch between 64-bit programs), and avoiding in save_base_legacy()
252 * To avoid leaking state, on non-X86_BUG_NULL_SEG CPUs, if we in save_base_legacy()
268 prev_p->thread.fsbase = 0; in save_base_legacy()
270 prev_p->thread.gsbase = 0; in save_base_legacy()
276 savesegment(fs, task->thread.fsindex); in save_fsgs()
277 savesegment(gs, task->thread.gsindex); in save_fsgs()
284 task->thread.fsbase = rdfsbase(); in save_fsgs()
285 task->thread.gsbase = __rdgsbase_inactive(); in save_fsgs()
287 save_base_legacy(task, task->thread.fsindex, FS); in save_fsgs()
288 save_base_legacy(task, task->thread.gsindex, GS); in save_fsgs()
293 * While a process is running,current->thread.fsbase and current->thread.gsbase
326 * The next task is using 64-bit TLS, is not using this in load_seg_legacy()
348 * Intel-style CPUs.) in load_seg_legacy()
381 prev->pkru = rdpkru(); in x86_pkru_load()
387 if (prev->pkru != next->pkru) in x86_pkru_load()
388 wrpkru(next->pkru); in x86_pkru_load()
396 if (unlikely(prev->fsindex || next->fsindex)) in x86_fsgsbase_load()
397 loadseg(FS, next->fsindex); in x86_fsgsbase_load()
398 if (unlikely(prev->gsindex || next->gsindex)) in x86_fsgsbase_load()
399 loadseg(GS, next->gsindex); in x86_fsgsbase_load()
402 wrfsbase(next->fsbase); in x86_fsgsbase_load()
403 __wrgsbase_inactive(next->gsbase); in x86_fsgsbase_load()
405 load_seg_legacy(prev->fsindex, prev->fsbase, in x86_fsgsbase_load()
406 next->fsindex, next->fsbase, FS); in x86_fsgsbase_load()
407 load_seg_legacy(prev->gsindex, prev->gsbase, in x86_fsgsbase_load()
408 next->gsindex, next->gsbase, GS); in x86_fsgsbase_load()
429 idx -= GDT_ENTRY_TLS_MIN; in x86_fsgsbase_read_task()
430 base = get_desc_base(&task->thread.tls_array[idx]); in x86_fsgsbase_read_task()
436 * If performance here mattered, we could protect the LDT in x86_fsgsbase_read_task()
440 mutex_lock(&task->mm->context.lock); in x86_fsgsbase_read_task()
441 ldt = task->mm->context.ldt; in x86_fsgsbase_read_task()
442 if (unlikely(!ldt || idx >= ldt->nr_entries)) in x86_fsgsbase_read_task()
445 base = get_desc_base(ldt->entries + idx); in x86_fsgsbase_read_task()
446 mutex_unlock(&task->mm->context.lock); in x86_fsgsbase_read_task()
492 (task->thread.fsindex == 0)) in x86_fsbase_read_task()
493 fsbase = task->thread.fsbase; in x86_fsbase_read_task()
495 fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex); in x86_fsbase_read_task()
507 (task->thread.gsindex == 0)) in x86_gsbase_read_task()
508 gsbase = task->thread.gsbase; in x86_gsbase_read_task()
510 gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex); in x86_gsbase_read_task()
519 task->thread.fsbase = fsbase; in x86_fsbase_write_task()
526 task->thread.gsbase = gsbase; in x86_gsbase_write_task()
549 regs->ip = new_ip; in start_thread_common()
550 regs->sp = new_sp; in start_thread_common()
551 regs->csx = _cs; in start_thread_common()
552 regs->ssx = _ss; in start_thread_common()
554 * Allow single-step trap and NMI when starting a new task, thus in start_thread_common()
555 * once the new task enters user space, single-step trap and NMI in start_thread_common()
559 * system call (exec, fork, clone, etc.). As such, if ptrace in start_thread_common()
567 * Paranoia: High-order 48 bits above the lowest 16 bit SS are in start_thread_common()
574 regs->fred_ss.swevent = true; in start_thread_common()
575 regs->fred_ss.nmi = true; in start_thread_common()
578 regs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED; in start_thread_common()
602 * - fold all the options into a flag word and test it with a single test.
603 * - could test fs/gs bitsliced
612 struct thread_struct *prev = &prev_p->thread; in __switch_to()
613 struct thread_struct *next = &next_p->thread; in __switch_to()
656 savesegment(es, prev->es); in __switch_to()
657 if (unlikely(next->es | prev->es)) in __switch_to()
658 loadsegment(es, next->es); in __switch_to()
660 savesegment(ds, prev->ds); in __switch_to()
661 if (unlikely(next->ds | prev->ds)) in __switch_to()
662 loadsegment(ds, next->ds); in __switch_to()
693 * SS, so the only way to get NULL is to re-enter the kernel in __switch_to()
701 * it previously had a different non-NULL value. in __switch_to()
722 task_pt_regs(current)->orig_ax = __NR_execve; in set_personality_64bit()
723 current_thread_info()->status &= ~TS_COMPAT; in set_personality_64bit()
724 if (current->mm) in set_personality_64bit()
725 __set_bit(MM_CONTEXT_HAS_VSYSCALL, &current->mm->context.flags); in set_personality_64bit()
731 current->personality &= ~READ_IMPLIES_EXEC; in set_personality_64bit()
737 if (current->mm) in __set_personality_x32()
738 current->mm->context.flags = 0; in __set_personality_x32()
740 current->personality &= ~READ_IMPLIES_EXEC; in __set_personality_x32()
745 * in_32bit_syscall() work during exec(). in __set_personality_x32()
749 task_pt_regs(current)->orig_ax = __NR_x32_execve | __X32_SYSCALL_BIT; in __set_personality_x32()
750 current_thread_info()->status &= ~TS_COMPAT; in __set_personality_x32()
757 if (current->mm) { in __set_personality_ia32()
762 __set_bit(MM_CONTEXT_UPROBE_IA32, &current->mm->context.flags); in __set_personality_ia32()
765 current->personality |= force_personality32; in __set_personality_ia32()
767 task_pt_regs(current)->orig_ax = __NR_ia32_execve; in __set_personality_ia32()
768 current_thread_info()->status |= TS_COMPAT; in __set_personality_ia32()
793 return (long)image->size; in prctl_map_vdso()
815 mm->context.lam_cr3_mask = X86_CR3_LAM_U57; in mm_enable_lam()
816 mm->context.untag_mask = ~GENMASK(62, 57); in mm_enable_lam()
819 * Even though the process must still be single-threaded at this in mm_enable_lam()
824 set_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags); in mm_enable_lam()
830 return -ENODEV; in prctl_enable_tagged_addr()
833 if (current->mm != mm) in prctl_enable_tagged_addr()
834 return -EINVAL; in prctl_enable_tagged_addr()
837 !test_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &mm->context.flags)) in prctl_enable_tagged_addr()
838 return -EINVAL; in prctl_enable_tagged_addr()
841 return -EINTR; in prctl_enable_tagged_addr()
847 if (test_bit(MM_CONTEXT_LOCK_LAM, &mm->context.flags)) { in prctl_enable_tagged_addr()
849 return -EBUSY; in prctl_enable_tagged_addr()
854 return -EINVAL; in prctl_enable_tagged_addr()
872 return -EPERM; in do_arch_prctl_64()
886 * On non-FSGSBASE systems, save_base_legacy() expects in do_arch_prctl_64()
889 task->thread.gsbase = arg2; in do_arch_prctl_64()
892 task->thread.gsindex = 0; in do_arch_prctl_64()
904 return -EPERM; in do_arch_prctl_64()
916 * On non-FSGSBASE systems, save_base_legacy() expects in do_arch_prctl_64()
919 task->thread.fsbase = arg2; in do_arch_prctl_64()
921 task->thread.fsindex = 0; in do_arch_prctl_64()
954 return put_user(task->mm->context.untag_mask, in do_arch_prctl_64()
957 return prctl_enable_tagged_addr(task->mm, arg2); in do_arch_prctl_64()
960 return -EINVAL; in do_arch_prctl_64()
961 set_bit(MM_CONTEXT_FORCE_TAGGED_SVA, &task->mm->context.flags); in do_arch_prctl_64()
976 ret = -EINVAL; in do_arch_prctl_64()
988 if (ret == -EINVAL) in SYSCALL_DEFINE2()
1003 return task_pt_regs(task)->sp; in KSTK_ESP()