Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust custom signal handler ignores first SIGSEGV #6759

Closed
Ecordonnier opened this issue Oct 1, 2024 · 1 comment · Fixed by #6806
Closed

Rust custom signal handler ignores first SIGSEGV #6759

Ecordonnier opened this issue Oct 1, 2024 · 1 comment · Fixed by #6806

Comments

@Ecordonnier
Copy link
Contributor

Ecordonnier commented Oct 1, 2024

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
Copy link
Contributor Author

I have a working fix. I just need a bit of time and I'll send a PR.

Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 21, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 21, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 21, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 21, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 21, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 25, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 25, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 25, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Ecordonnier added a commit to Ecordonnier/coreutils that referenced this issue Oct 25, 2024
Fixes uutils#6759

Test procedure (verifies that a single SIGSEGV stops a program):
```
ecordonnier@lj8k2dq3:~/dev/coreutils$ ./target/release/coreutils sleep 100 &
[1] 4175464
ecordonnier@lj8k2dq3:~/dev/coreutils$ kill -11 $(pidof coreutils)
ecordonnier@lj8k2dq3:~/dev/coreutils$
[1]+  Segmentation fault      (core dumped) ./target/release/coreutils sleep 100
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant