Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

exit: Add and use make_task_dead.

There are two big uses of do_exit. The first is it's design use to be
the guts of the exit(2) system call. The second use is to terminate
a task after something catastrophic has happened like a NULL pointer
in kernel code.

Add a function make_task_dead that is initialy exactly the same as
do_exit to cover the cases where do_exit is called to handle
catastrophic failure. In time this can probably be reduced to just a
light wrapper around do_task_dead. For now keep it exactly the same so
that there will be no behavioral differences introducing this new
concept.

Replace all of the uses of do_exit that use it for catastraphic
task cleanup with make_task_dead to make it clear what the code
is doing.

As part of this rename rewind_stack_do_exit
rewind_stack_and_make_dead.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+63 -56
+3 -3
arch/alpha/kernel/traps.c
··· 190 190 local_irq_enable(); 191 191 while (1); 192 192 } 193 - do_exit(SIGSEGV); 193 + make_task_dead(SIGSEGV); 194 194 } 195 195 196 196 #ifndef CONFIG_MATHEMU ··· 575 575 576 576 printk("Bad unaligned kernel access at %016lx: %p %lx %lu\n", 577 577 pc, va, opcode, reg); 578 - do_exit(SIGSEGV); 578 + make_task_dead(SIGSEGV); 579 579 580 580 got_exception: 581 581 /* Ok, we caught the exception, but we don't want it. Is there ··· 630 630 local_irq_enable(); 631 631 while (1); 632 632 } 633 - do_exit(SIGSEGV); 633 + make_task_dead(SIGSEGV); 634 634 } 635 635 636 636 /*
+1 -1
arch/alpha/mm/fault.c
··· 204 204 printk(KERN_ALERT "Unable to handle kernel paging request at " 205 205 "virtual address %016lx\n", address); 206 206 die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16); 207 - do_exit(SIGKILL); 207 + make_task_dead(SIGKILL); 208 208 209 209 /* We ran out of memory, or some other thing happened to us that 210 210 made us unable to handle the page fault gracefully. */
+1 -1
arch/arm/kernel/traps.c
··· 333 333 if (panic_on_oops) 334 334 panic("Fatal exception"); 335 335 if (signr) 336 - do_exit(signr); 336 + make_task_dead(signr); 337 337 } 338 338 339 339 /*
+1 -1
arch/arm/mm/fault.c
··· 111 111 show_pte(KERN_ALERT, mm, addr); 112 112 die("Oops", regs, fsr); 113 113 bust_spinlocks(0); 114 - do_exit(SIGKILL); 114 + make_task_dead(SIGKILL); 115 115 } 116 116 117 117 /*
+1 -1
arch/arm64/kernel/traps.c
··· 235 235 raw_spin_unlock_irqrestore(&die_lock, flags); 236 236 237 237 if (ret != NOTIFY_STOP) 238 - do_exit(SIGSEGV); 238 + make_task_dead(SIGSEGV); 239 239 } 240 240 241 241 static void arm64_show_signal(int signo, const char *str)
+1 -1
arch/arm64/mm/fault.c
··· 302 302 show_pte(addr); 303 303 die("Oops", regs, esr); 304 304 bust_spinlocks(0); 305 - do_exit(SIGKILL); 305 + make_task_dead(SIGKILL); 306 306 } 307 307 308 308 #ifdef CONFIG_KASAN_HW_TAGS
+1 -1
arch/csky/abiv1/alignment.c
··· 294 294 __func__, opcode, rz, rx, imm, addr); 295 295 show_regs(regs); 296 296 bust_spinlocks(0); 297 - do_exit(SIGKILL); 297 + make_dead_task(SIGKILL); 298 298 } 299 299 300 300 force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *)addr);
+1 -1
arch/csky/kernel/traps.c
··· 109 109 if (panic_on_oops) 110 110 panic("Fatal exception"); 111 111 if (ret != NOTIFY_STOP) 112 - do_exit(SIGSEGV); 112 + make_dead_task(SIGSEGV); 113 113 } 114 114 115 115 void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)
+1 -1
arch/csky/mm/fault.c
··· 67 67 pr_alert("Unable to handle kernel paging request at virtual " 68 68 "addr 0x%08lx, pc: 0x%08lx\n", addr, regs->pc); 69 69 die(regs, "Oops"); 70 - do_exit(SIGKILL); 70 + make_task_dead(SIGKILL); 71 71 } 72 72 73 73 static inline void mm_fault_error(struct pt_regs *regs, unsigned long addr, vm_fault_t fault)
+1 -1
arch/h8300/kernel/traps.c
··· 106 106 dump(fp); 107 107 108 108 spin_unlock_irq(&die_lock); 109 - do_exit(SIGSEGV); 109 + make_dead_task(SIGSEGV); 110 110 } 111 111 112 112 static int kstack_depth_to_print = 24;
+1 -1
arch/h8300/mm/fault.c
··· 51 51 printk(" at virtual address %08lx\n", address); 52 52 if (!user_mode(regs)) 53 53 die("Oops", regs, error_code); 54 - do_exit(SIGKILL); 54 + make_dead_task(SIGKILL); 55 55 56 56 return 1; 57 57 }
+1 -1
arch/hexagon/kernel/traps.c
··· 214 214 panic("Fatal exception"); 215 215 216 216 oops_exit(); 217 - do_exit(err); 217 + make_dead_task(err); 218 218 return 0; 219 219 } 220 220
+1 -1
arch/ia64/kernel/mca_drv.c
··· 176 176 spin_unlock(&mca_bh_lock); 177 177 178 178 /* This process is about to be killed itself */ 179 - do_exit(SIGKILL); 179 + make_task_dead(SIGKILL); 180 180 } 181 181 182 182 /**
+1 -1
arch/ia64/kernel/traps.c
··· 85 85 if (panic_on_oops) 86 86 panic("Fatal exception"); 87 87 88 - do_exit(SIGSEGV); 88 + make_task_dead(SIGSEGV); 89 89 return 0; 90 90 } 91 91
+1 -1
arch/ia64/mm/fault.c
··· 259 259 regs = NULL; 260 260 bust_spinlocks(0); 261 261 if (regs) 262 - do_exit(SIGKILL); 262 + make_task_dead(SIGKILL); 263 263 return; 264 264 265 265 out_of_memory:
+1 -1
arch/m68k/kernel/traps.c
··· 1131 1131 pr_crit("%s: %08x\n", str, nr); 1132 1132 show_registers(fp); 1133 1133 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); 1134 - do_exit(SIGSEGV); 1134 + make_task_dead(SIGSEGV); 1135 1135 } 1136 1136 1137 1137 asmlinkage void set_esp0(unsigned long ssp)
+1 -1
arch/m68k/mm/fault.c
··· 48 48 pr_alert("Unable to handle kernel access"); 49 49 pr_cont(" at virtual address %p\n", addr); 50 50 die_if_kernel("Oops", regs, 0 /*error_code*/); 51 - do_exit(SIGKILL); 51 + make_task_dead(SIGKILL); 52 52 } 53 53 54 54 return 1;
+2 -2
arch/microblaze/kernel/exceptions.c
··· 44 44 pr_warn("Oops: %s, sig: %ld\n", str, err); 45 45 show_regs(fp); 46 46 spin_unlock_irq(&die_lock); 47 - /* do_exit() should take care of panic'ing from an interrupt 47 + /* make_task_dead() should take care of panic'ing from an interrupt 48 48 * context so we don't handle it here 49 49 */ 50 - do_exit(err); 50 + make_task_dead(err); 51 51 } 52 52 53 53 /* for user application debugging */
+1 -1
arch/mips/kernel/traps.c
··· 422 422 if (regs && kexec_should_crash(current)) 423 423 crash_kexec(regs); 424 424 425 - do_exit(sig); 425 + make_task_dead(sig); 426 426 } 427 427 428 428 extern struct exception_table_entry __start___dbe_table[];
+1 -1
arch/nds32/kernel/fpu.c
··· 223 223 } 224 224 } else if (fpcsr & FPCSR_mskRIT) { 225 225 if (!user_mode(regs)) 226 - do_exit(SIGILL); 226 + make_task_dead(SIGILL); 227 227 si_signo = SIGILL; 228 228 } 229 229
+4 -4
arch/nds32/kernel/traps.c
··· 141 141 142 142 bust_spinlocks(0); 143 143 spin_unlock_irq(&die_lock); 144 - do_exit(SIGSEGV); 144 + make_task_dead(SIGSEGV); 145 145 } 146 146 147 147 EXPORT_SYMBOL(die); ··· 240 240 pr_emerg("unhandled_interruption\n"); 241 241 show_regs(regs); 242 242 if (!user_mode(regs)) 243 - do_exit(SIGKILL); 243 + make_task_dead(SIGKILL); 244 244 force_sig(SIGKILL); 245 245 } 246 246 ··· 251 251 addr, type); 252 252 show_regs(regs); 253 253 if (!user_mode(regs)) 254 - do_exit(SIGKILL); 254 + make_task_dead(SIGKILL); 255 255 force_sig(SIGKILL); 256 256 } 257 257 ··· 278 278 pr_emerg("Reserved Instruction\n"); 279 279 show_regs(regs); 280 280 if (!user_mode(regs)) 281 - do_exit(SIGILL); 281 + make_task_dead(SIGILL); 282 282 force_sig(SIGILL); 283 283 } 284 284
+2 -2
arch/nios2/kernel/traps.c
··· 37 37 show_regs(regs); 38 38 spin_unlock_irq(&die_lock); 39 39 /* 40 - * do_exit() should take care of panic'ing from an interrupt 40 + * make_task_dead() should take care of panic'ing from an interrupt 41 41 * context so we don't handle it here 42 42 */ 43 - do_exit(err); 43 + make_task_dead(err); 44 44 } 45 45 46 46 void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr)
+1 -1
arch/openrisc/kernel/traps.c
··· 212 212 __asm__ __volatile__("l.nop 1"); 213 213 do {} while (1); 214 214 #endif 215 - do_exit(SIGSEGV); 215 + make_task_dead(SIGSEGV); 216 216 } 217 217 218 218 /* This is normally the 'Oops' routine */
+1 -1
arch/parisc/kernel/traps.c
··· 269 269 panic("Fatal exception"); 270 270 271 271 oops_exit(); 272 - do_exit(SIGSEGV); 272 + make_task_dead(SIGSEGV); 273 273 } 274 274 275 275 /* gdb uses break 4,8 */
+4 -4
arch/powerpc/kernel/traps.c
··· 245 245 246 246 if (panic_on_oops) 247 247 panic("Fatal exception"); 248 - do_exit(signr); 248 + make_task_dead(signr); 249 249 } 250 250 NOKPROBE_SYMBOL(oops_end); 251 251 ··· 792 792 void die_mce(const char *str, struct pt_regs *regs, long err) 793 793 { 794 794 /* 795 - * The machine check wants to kill the interrupted context, but 796 - * do_exit() checks for in_interrupt() and panics in that case, so 797 - * exit the irq/nmi before calling die. 795 + * The machine check wants to kill the interrupted context, 796 + * but make_task_dead() checks for in_interrupt() and panics 797 + * in that case, so exit the irq/nmi before calling die. 798 798 */ 799 799 if (in_nmi()) 800 800 nmi_exit();
+1 -1
arch/riscv/kernel/traps.c
··· 54 54 if (panic_on_oops) 55 55 panic("Fatal exception"); 56 56 if (ret != NOTIFY_STOP) 57 - do_exit(SIGSEGV); 57 + make_task_dead(SIGSEGV); 58 58 } 59 59 60 60 void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)
+1 -1
arch/riscv/mm/fault.c
··· 31 31 32 32 bust_spinlocks(0); 33 33 die(regs, "Oops"); 34 - do_exit(SIGKILL); 34 + make_task_dead(SIGKILL); 35 35 } 36 36 37 37 static inline void no_context(struct pt_regs *regs, unsigned long addr)
+1 -1
arch/s390/kernel/dumpstack.c
··· 224 224 if (panic_on_oops) 225 225 panic("Fatal exception: panic_on_oops"); 226 226 oops_exit(); 227 - do_exit(SIGSEGV); 227 + make_task_dead(SIGSEGV); 228 228 }
+1 -1
arch/s390/kernel/nmi.c
··· 175 175 "malfunction (code 0x%016lx).\n", mcck.mcck_code); 176 176 printk(KERN_EMERG "mcck: task: %s, pid: %d.\n", 177 177 current->comm, current->pid); 178 - do_exit(SIGSEGV); 178 + make_task_dead(SIGSEGV); 179 179 } 180 180 } 181 181
+1 -1
arch/sh/kernel/traps.c
··· 57 57 if (panic_on_oops) 58 58 panic("Fatal exception"); 59 59 60 - do_exit(SIGSEGV); 60 + make_task_dead(SIGSEGV); 61 61 } 62 62 63 63 void die_if_kernel(const char *str, struct pt_regs *regs, long err)
+1 -3
arch/sparc/kernel/traps_32.c
··· 86 86 } 87 87 printk("Instruction DUMP:"); 88 88 instruction_dump ((unsigned long *) regs->pc); 89 - if(regs->psr & PSR_PS) 90 - do_exit(SIGKILL); 91 - do_exit(SIGSEGV); 89 + make_task_dead((regs->psr & PSR_PS) ? SIGKILL : SIGSEGV); 92 90 } 93 91 94 92 void do_hw_interrupt(struct pt_regs *regs, unsigned long type)
+1 -3
arch/sparc/kernel/traps_64.c
··· 2559 2559 } 2560 2560 if (panic_on_oops) 2561 2561 panic("Fatal exception"); 2562 - if (regs->tstate & TSTATE_PRIV) 2563 - do_exit(SIGKILL); 2564 - do_exit(SIGSEGV); 2562 + make_task_dead((regs->tstate & TSTATE_PRIV)? SIGKILL : SIGSEGV); 2565 2563 } 2566 2564 EXPORT_SYMBOL(die_if_kernel); 2567 2565
+3 -3
arch/x86/entry/entry_32.S
··· 1248 1248 SYM_CODE_END(asm_exc_nmi) 1249 1249 1250 1250 .pushsection .text, "ax" 1251 - SYM_CODE_START(rewind_stack_do_exit) 1251 + SYM_CODE_START(rewind_stack_and_make_dead) 1252 1252 /* Prevent any naive code from trying to unwind to our caller. */ 1253 1253 xorl %ebp, %ebp 1254 1254 1255 1255 movl PER_CPU_VAR(cpu_current_top_of_stack), %esi 1256 1256 leal -TOP_OF_KERNEL_STACK_PADDING-PTREGS_SIZE(%esi), %esp 1257 1257 1258 - call do_exit 1258 + call make_task_dead 1259 1259 1: jmp 1b 1260 - SYM_CODE_END(rewind_stack_do_exit) 1260 + SYM_CODE_END(rewind_stack_and_make_dead) 1261 1261 .popsection
+3 -3
arch/x86/entry/entry_64.S
··· 1429 1429 #endif 1430 1430 1431 1431 .pushsection .text, "ax" 1432 - SYM_CODE_START(rewind_stack_do_exit) 1432 + SYM_CODE_START(rewind_stack_and_make_dead) 1433 1433 UNWIND_HINT_FUNC 1434 1434 /* Prevent any naive code from trying to unwind to our caller. */ 1435 1435 xorl %ebp, %ebp ··· 1438 1438 leaq -PTREGS_SIZE(%rax), %rsp 1439 1439 UNWIND_HINT_REGS 1440 1440 1441 - call do_exit 1442 - SYM_CODE_END(rewind_stack_do_exit) 1441 + call make_task_dead 1442 + SYM_CODE_END(rewind_stack_and_make_dead) 1443 1443 .popsection
+2 -2
arch/x86/kernel/dumpstack.c
··· 351 351 } 352 352 NOKPROBE_SYMBOL(oops_begin); 353 353 354 - void __noreturn rewind_stack_do_exit(int signr); 354 + void __noreturn rewind_stack_and_make_dead(int signr); 355 355 356 356 void oops_end(unsigned long flags, struct pt_regs *regs, int signr) 357 357 { ··· 386 386 * reuse the task stack and that existing poisons are invalid. 387 387 */ 388 388 kasan_unpoison_task_stack(current); 389 - rewind_stack_do_exit(signr); 389 + rewind_stack_and_make_dead(signr); 390 390 } 391 391 NOKPROBE_SYMBOL(oops_end); 392 392
+1 -1
arch/xtensa/kernel/traps.c
··· 552 552 if (panic_on_oops) 553 553 panic("Fatal exception"); 554 554 555 - do_exit(err); 555 + make_task_dead(err); 556 556 }
+1
include/linux/sched/task.h
··· 59 59 extern void sched_dead(struct task_struct *p); 60 60 61 61 void __noreturn do_task_dead(void); 62 + void __noreturn make_task_dead(int signr); 62 63 63 64 extern void proc_caches_init(void); 64 65
+9
kernel/exit.c
··· 884 884 } 885 885 EXPORT_SYMBOL_GPL(do_exit); 886 886 887 + void __noreturn make_task_dead(int signr) 888 + { 889 + /* 890 + * Take the task off the cpu after something catastrophic has 891 + * happened. 892 + */ 893 + do_exit(signr); 894 + } 895 + 887 896 void complete_and_exit(struct completion *comp, long code) 888 897 { 889 898 if (comp)
+2 -1
tools/objtool/check.c
··· 168 168 "panic", 169 169 "do_exit", 170 170 "do_task_dead", 171 + "make_task_dead", 171 172 "__module_put_and_exit", 172 173 "complete_and_exit", 173 174 "__reiserfs_panic", ··· 176 175 "fortify_panic", 177 176 "usercopy_abort", 178 177 "machine_real_restart", 179 - "rewind_stack_do_exit", 178 + "rewind_stack_and_make_dead" 180 179 "kunit_try_catch_throw", 181 180 "xen_start_kernel", 182 181 "cpu_bringup_and_idle",