coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Rust custom signal handler ignores first SIGSEGV

Open Ecordonnier opened this issue 5 months ago • 0 comments

Rust adds a custom UNIX signal handler to Rust processes ( see https://github.com/rust-lang/rust/blob/8ac1525e091d3db28e67adcbbd6db1e1deaa37fb/src/libstd/sys/unix/stack_overflow.rs#L71-L92 ).

In the case of SIGSEGV (signal segmentation violation), the behavior of this custom signal handler is to ignore the first signal, and then restore the default signal handler. The default signal handler makes the process dump core, thus this means that rust processes need to receive two SIGSEGV in order to dump core, unlike standard C processes which dump core after one SIGSEGV.

This causes uutils-coreutils to behave differently than GNU coreutils:

Behavior of uutils-coreutils (process dumps core after two SIGSEGV signals):

~:/# /usr/bin/sleep --version
/usr/bin/sleep 0.0.27
~:/# /usr/bin/sleep 100 &
~:/# kill -11 $(pidof sleep)
~:/# kill -11 $(pidof sleep)
[1]+  Segmentation fault (core dumped) /usr/bin/sleep 100

Behavior of GNU coreutils (process dumps core after one SIGSEGV signal):

$ /usr/bin/sleep --version
sleep (GNU coreutils) 9.4
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jim Meyering and Paul Eggert.
ecordonnier@lj8k2dq3:~/dev/snapos$ /usr/bin/sleep 100 &
[1] 3627430
ecordonnier@lj8k2dq3:~/dev/snapos$ kill -11 $(pidof sleep)
ecordonnier@lj8k2dq3:~/dev/snapos$ 
[1]+  Segmentation fault      (core dumped) /usr/bin/sleep 100

(In case you're not familiar with coredumps, note that one easy way to check if a process has dumped core is to use coredumpctl list, available e.g. on Ubuntu with the apt package systemd-coredump. coredumps are also logged to the systemd journal and thus visible with journalctl).

Ecordonnier avatar Oct 01 '24 11:10 Ecordonnier