| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/arch/arm/kernel/process.c |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 1996-2000 Russell King - Converted to ARM. |
|---|
| 5 | 6 | * Original Copyright (C) 1995 Linus Torvalds |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | #include <stdarg.h> |
|---|
| 12 | 9 | |
|---|
| .. | .. |
|---|
| 39 | 36 | #include <asm/tls.h> |
|---|
| 40 | 37 | #include <asm/vdso.h> |
|---|
| 41 | 38 | |
|---|
| 42 | | -#ifdef CONFIG_STACKPROTECTOR |
|---|
| 39 | +#include "signal.h" |
|---|
| 40 | + |
|---|
| 41 | +#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK) |
|---|
| 43 | 42 | #include <linux/stackprotector.h> |
|---|
| 44 | 43 | unsigned long __stack_chk_guard __read_mostly; |
|---|
| 45 | 44 | EXPORT_SYMBOL(__stack_chk_guard); |
|---|
| .. | .. |
|---|
| 72 | 71 | arm_pm_idle(); |
|---|
| 73 | 72 | else |
|---|
| 74 | 73 | cpu_do_idle(); |
|---|
| 75 | | - local_irq_enable(); |
|---|
| 74 | + raw_local_irq_enable(); |
|---|
| 76 | 75 | } |
|---|
| 77 | 76 | |
|---|
| 78 | 77 | void arch_cpu_idle_prepare(void) |
|---|
| .. | .. |
|---|
| 93 | 92 | { |
|---|
| 94 | 93 | ledtrig_cpu(CPU_LED_IDLE_END); |
|---|
| 95 | 94 | idle_notifier_call_chain(IDLE_END); |
|---|
| 96 | | -} |
|---|
| 97 | | - |
|---|
| 98 | | -/* |
|---|
| 99 | | - * dump a block of kernel memory from around the given address |
|---|
| 100 | | - */ |
|---|
| 101 | | -static void show_data(unsigned long addr, int nbytes, const char *name) |
|---|
| 102 | | -{ |
|---|
| 103 | | - int i, j; |
|---|
| 104 | | - int nlines; |
|---|
| 105 | | - u32 *p; |
|---|
| 106 | | - |
|---|
| 107 | | - /* |
|---|
| 108 | | - * don't attempt to dump non-kernel addresses or |
|---|
| 109 | | - * values that are probably just small negative numbers |
|---|
| 110 | | - */ |
|---|
| 111 | | - if (addr < PAGE_OFFSET || addr > -256UL) |
|---|
| 112 | | - return; |
|---|
| 113 | | - |
|---|
| 114 | | - printk("\n%s: %#lx:\n", name, addr); |
|---|
| 115 | | - |
|---|
| 116 | | - /* |
|---|
| 117 | | - * round address down to a 32 bit boundary |
|---|
| 118 | | - * and always dump a multiple of 32 bytes |
|---|
| 119 | | - */ |
|---|
| 120 | | - p = (u32 *)(addr & ~(sizeof(u32) - 1)); |
|---|
| 121 | | - nbytes += (addr & (sizeof(u32) - 1)); |
|---|
| 122 | | - nlines = (nbytes + 31) / 32; |
|---|
| 123 | | - |
|---|
| 124 | | - |
|---|
| 125 | | - for (i = 0; i < nlines; i++) { |
|---|
| 126 | | - /* |
|---|
| 127 | | - * just display low 16 bits of address to keep |
|---|
| 128 | | - * each line of the dump < 80 characters |
|---|
| 129 | | - */ |
|---|
| 130 | | - printk("%04lx ", (unsigned long)p & 0xffff); |
|---|
| 131 | | - for (j = 0; j < 8; j++) { |
|---|
| 132 | | - u32 data; |
|---|
| 133 | | - if (probe_kernel_address(p, data)) { |
|---|
| 134 | | - pr_cont(" ********"); |
|---|
| 135 | | - } else { |
|---|
| 136 | | - pr_cont(" %08x", data); |
|---|
| 137 | | - } |
|---|
| 138 | | - ++p; |
|---|
| 139 | | - } |
|---|
| 140 | | - pr_cont("\n"); |
|---|
| 141 | | - } |
|---|
| 142 | | -} |
|---|
| 143 | | - |
|---|
| 144 | | -static void show_extra_register_data(struct pt_regs *regs, int nbytes) |
|---|
| 145 | | -{ |
|---|
| 146 | | - mm_segment_t fs; |
|---|
| 147 | | - |
|---|
| 148 | | - fs = get_fs(); |
|---|
| 149 | | - set_fs(KERNEL_DS); |
|---|
| 150 | | - show_data(regs->ARM_pc - nbytes, nbytes * 2, "PC"); |
|---|
| 151 | | - show_data(regs->ARM_lr - nbytes, nbytes * 2, "LR"); |
|---|
| 152 | | - show_data(regs->ARM_sp - nbytes, nbytes * 2, "SP"); |
|---|
| 153 | | - show_data(regs->ARM_ip - nbytes, nbytes * 2, "IP"); |
|---|
| 154 | | - show_data(regs->ARM_fp - nbytes, nbytes * 2, "FP"); |
|---|
| 155 | | - show_data(regs->ARM_r0 - nbytes, nbytes * 2, "R0"); |
|---|
| 156 | | - show_data(regs->ARM_r1 - nbytes, nbytes * 2, "R1"); |
|---|
| 157 | | - show_data(regs->ARM_r2 - nbytes, nbytes * 2, "R2"); |
|---|
| 158 | | - show_data(regs->ARM_r3 - nbytes, nbytes * 2, "R3"); |
|---|
| 159 | | - show_data(regs->ARM_r4 - nbytes, nbytes * 2, "R4"); |
|---|
| 160 | | - show_data(regs->ARM_r5 - nbytes, nbytes * 2, "R5"); |
|---|
| 161 | | - show_data(regs->ARM_r6 - nbytes, nbytes * 2, "R6"); |
|---|
| 162 | | - show_data(regs->ARM_r7 - nbytes, nbytes * 2, "R7"); |
|---|
| 163 | | - show_data(regs->ARM_r8 - nbytes, nbytes * 2, "R8"); |
|---|
| 164 | | - show_data(regs->ARM_r9 - nbytes, nbytes * 2, "R9"); |
|---|
| 165 | | - show_data(regs->ARM_r10 - nbytes, nbytes * 2, "R10"); |
|---|
| 166 | | - set_fs(fs); |
|---|
| 167 | 95 | } |
|---|
| 168 | 96 | |
|---|
| 169 | 97 | void __show_regs(struct pt_regs *regs) |
|---|
| .. | .. |
|---|
| 223 | 151 | if ((domain & domain_mask(DOMAIN_USER)) == |
|---|
| 224 | 152 | domain_val(DOMAIN_USER, DOMAIN_NOACCESS)) |
|---|
| 225 | 153 | segment = "none"; |
|---|
| 226 | | - else if (fs == get_ds()) |
|---|
| 154 | + else if (fs == KERNEL_DS) |
|---|
| 227 | 155 | segment = "kernel"; |
|---|
| 228 | 156 | else |
|---|
| 229 | 157 | segment = "user"; |
|---|
| .. | .. |
|---|
| 257 | 185 | printk("Control: %08x%s\n", ctrl, buf); |
|---|
| 258 | 186 | } |
|---|
| 259 | 187 | #endif |
|---|
| 260 | | - |
|---|
| 261 | | - show_extra_register_data(regs, 128); |
|---|
| 262 | 188 | } |
|---|
| 263 | 189 | |
|---|
| 264 | 190 | void show_regs(struct pt_regs * regs) |
|---|
| .. | .. |
|---|
| 301 | 227 | |
|---|
| 302 | 228 | asmlinkage void ret_from_fork(void) __asm__("ret_from_fork"); |
|---|
| 303 | 229 | |
|---|
| 304 | | -int |
|---|
| 305 | | -copy_thread(unsigned long clone_flags, unsigned long stack_start, |
|---|
| 306 | | - unsigned long stk_sz, struct task_struct *p) |
|---|
| 230 | +int copy_thread(unsigned long clone_flags, unsigned long stack_start, |
|---|
| 231 | + unsigned long stk_sz, struct task_struct *p, unsigned long tls) |
|---|
| 307 | 232 | { |
|---|
| 308 | 233 | struct thread_info *thread = task_thread_info(p); |
|---|
| 309 | 234 | struct pt_regs *childregs = task_pt_regs(p); |
|---|
| .. | .. |
|---|
| 320 | 245 | thread->cpu_domain = get_domain(); |
|---|
| 321 | 246 | #endif |
|---|
| 322 | 247 | |
|---|
| 323 | | - if (likely(!(p->flags & PF_KTHREAD))) { |
|---|
| 248 | + if (likely(!(p->flags & (PF_KTHREAD | PF_IO_WORKER)))) { |
|---|
| 324 | 249 | *childregs = *current_pt_regs(); |
|---|
| 325 | 250 | childregs->ARM_r0 = 0; |
|---|
| 326 | 251 | if (stack_start) |
|---|
| .. | .. |
|---|
| 337 | 262 | clear_ptrace_hw_breakpoint(p); |
|---|
| 338 | 263 | |
|---|
| 339 | 264 | if (clone_flags & CLONE_SETTLS) |
|---|
| 340 | | - thread->tp_value[0] = childregs->ARM_r3; |
|---|
| 265 | + thread->tp_value[0] = tls; |
|---|
| 341 | 266 | thread->tp_value[1] = get_tpuser(); |
|---|
| 342 | 267 | |
|---|
| 343 | 268 | thread_notify(THREAD_NOTIFY_COPY, thread); |
|---|
| 269 | + |
|---|
| 270 | +#ifdef CONFIG_STACKPROTECTOR_PER_TASK |
|---|
| 271 | + thread->stack_canary = p->stack_canary; |
|---|
| 272 | +#endif |
|---|
| 344 | 273 | |
|---|
| 345 | 274 | return 0; |
|---|
| 346 | 275 | } |
|---|
| .. | .. |
|---|
| 353 | 282 | elf_core_copy_regs(elfregs, task_pt_regs(t)); |
|---|
| 354 | 283 | return 1; |
|---|
| 355 | 284 | } |
|---|
| 356 | | - |
|---|
| 357 | | -/* |
|---|
| 358 | | - * fill in the fpe structure for a core dump... |
|---|
| 359 | | - */ |
|---|
| 360 | | -int dump_fpu (struct pt_regs *regs, struct user_fp *fp) |
|---|
| 361 | | -{ |
|---|
| 362 | | - struct thread_info *thread = current_thread_info(); |
|---|
| 363 | | - int used_math = thread->used_cp[1] | thread->used_cp[2]; |
|---|
| 364 | | - |
|---|
| 365 | | - if (used_math) |
|---|
| 366 | | - memcpy(fp, &thread->fpstate.soft, sizeof (*fp)); |
|---|
| 367 | | - |
|---|
| 368 | | - return used_math != 0; |
|---|
| 369 | | -} |
|---|
| 370 | | -EXPORT_SYMBOL(dump_fpu); |
|---|
| 371 | 285 | |
|---|
| 372 | 286 | unsigned long get_wchan(struct task_struct *p) |
|---|
| 373 | 287 | { |
|---|
| .. | .. |
|---|
| 391 | 305 | return frame.pc; |
|---|
| 392 | 306 | } while (count ++ < 16); |
|---|
| 393 | 307 | return 0; |
|---|
| 394 | | -} |
|---|
| 395 | | - |
|---|
| 396 | | -unsigned long arch_randomize_brk(struct mm_struct *mm) |
|---|
| 397 | | -{ |
|---|
| 398 | | - return randomize_page(mm->brk, 0x02000000); |
|---|
| 399 | 308 | } |
|---|
| 400 | 309 | |
|---|
| 401 | 310 | #ifdef CONFIG_MMU |
|---|
| .. | .. |
|---|
| 508 | 417 | npages = 1; /* for sigpage */ |
|---|
| 509 | 418 | npages += vdso_total_pages; |
|---|
| 510 | 419 | |
|---|
| 511 | | - if (down_write_killable(&mm->mmap_sem)) |
|---|
| 420 | + if (mmap_write_lock_killable(mm)) |
|---|
| 512 | 421 | return -EINTR; |
|---|
| 513 | 422 | hint = sigpage_addr(mm, npages); |
|---|
| 514 | 423 | addr = get_unmapped_area(NULL, hint, npages << PAGE_SHIFT, 0, 0); |
|---|
| .. | .. |
|---|
| 535 | 444 | arm_install_vdso(mm, addr + PAGE_SIZE); |
|---|
| 536 | 445 | |
|---|
| 537 | 446 | up_fail: |
|---|
| 538 | | - up_write(&mm->mmap_sem); |
|---|
| 447 | + mmap_write_unlock(mm); |
|---|
| 539 | 448 | return ret; |
|---|
| 540 | 449 | } |
|---|
| 541 | 450 | #endif |
|---|