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 apps hit SIGSEGV randomly during syscalls, regression in Rust 1.71.0 and newer #131

Open
BarryBo opened this issue Oct 18, 2023 · 1 comment

Comments

@BarryBo
Copy link
Contributor

BarryBo commented Oct 18, 2023

In MUSL, __syscall_cp_c() polls for __pthread_self()->cancel not equal to zero, and if true, calls __cancel() to stop the thread. This code is all correct, but when Rust apps make a syscall, either the __pthread_self() pointer is bad, or the value of ->cancel is bad (0x10000 typeically), and the attempt to cancel the sole thread crashes with SIGSEGV.

This is only a problem for Rust apps built with Rust 1.71.0 or newer, Older builds of rustc don't repro the issue. I'll investigate.

Here is a typical callstack from a SIGSEGV during a syscall for open() in a single-threaded app that isn't using pthreads for anything:

(gdb) info stack
#0 0x00000000 in ?? ()
#1 0xbeec564e in pthread_exit () from target:/lib/ld-musl-armhf.so.1
#2 0xbeed70fa in ?? () from target:/lib/ld-musl-armhf.so.1
#3 0xbeed7156 in ?? () from target:/lib/ld-musl-armhf.so.1
#4 0xbeeaa3ca in open64 () from target:/lib/ld-musl-armhf.so.1
#5 0xbeeaa248 in __z_azsp_open () from target:/lib/ld-musl-armhf.so.1
#6 0x0002f916 in ADC_Open (id=0) at /opt/azurespheresdk/Sysroots/16/usr/include/applibs/adc_internal.h:24
#7 0x0003044c in ADC_Open_inline (id=0) at ../azure-sphere-sys/static_inline_helpers.c:30
#8 0x0001c4d8 in azure_sphere::applibs::adc::AdcController::new (controller_id=0)
at azure-sphere/src/applibs/adc.rs:63
#9 0x00016ca0 in allapis::main () at samples/allapis/src/main.rs:62

@BarryBo
Copy link
Contributor Author

BarryBo commented Oct 18, 2023

Rust 1.71.0 contains this commit: rust-lang/rust@4af36a4 "Upgrade to musl 1.2.3" the previous was musl 1.1.24.

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

No branches or pull requests

1 participant