1coredump selftest 2================= 3 4Background context 5------------------ 6 7`coredump` is a feature which dumps a process's memory space when the process terminates 8unexpectedly (e.g. due to segmentation fault), which can be useful for debugging. By default, 9`coredump` dumps the memory to the file named `core`, but this behavior can be changed by writing a 10different file name to `/proc/sys/kernel/core_pattern`. Furthermore, `coredump` can be piped to a 11user-space program by writing the pipe symbol (`|`) followed by the command to be executed to 12`/proc/sys/kernel/core_pattern`. For the full description, see `man 5 core`. 13 14The piped user program may be interested in reading the stack pointers of the crashed process. The 15crashed process's stack pointers can be read from `procfs`: it is the `kstkesp` field in 16`/proc/$PID/stat`. See `man 5 proc` for all the details. 17 18The problem 19----------- 20While a thread is active, the stack pointer is unsafe to read and therefore the `kstkesp` field 21reads zero. But when the thread is dead (e.g. during a coredump), this field should have valid 22value. 23 24However, this was broken in the past and `kstkesp` was zero even during coredump: 25 26* commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in /proc/PID/stat") changed kstkesp to 27 always be zero 28 29* commit fd7d56270b52 ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping") fixed it for the 30 coredumping thread. However, other threads in a coredumping process still had the problem. 31 32* commit cb8f381f1613 ("fs/proc/array.c: allow reporting eip/esp for all coredumping threads") fixed 33 for all threads in a coredumping process. 34 35* commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") broke it again 36 for the other threads in a coredumping process. 37 38The problem has been fixed now, but considering the history, it may appear again in the future. 39 40The goal of this test 41--------------------- 42This test detects problem with reading `kstkesp` during coredump by doing the following: 43 44#. Tell the kernel to execute the "stackdump" script when a coredump happens. This script 45 reads the stack pointers of all threads of crashed processes. 46 47#. Spawn a child process who creates some threads and then crashes. 48 49#. Read the output from the "stackdump" script, and make sure all stack pointer values are 50 non-zero. 51