CFI: std::thread::spawn fails the CFI check on linux-gnu (__pthread_get_minstack called through dlsym)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 43/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- linux, rust
- Lĩnh vực
- backend, operating-systems
Hướng nghiên cứu
Start with library/std/src/sys/thread/unix.rs, especially min_stack_size near line 1076, where the backtrace shows the failing indirect call. Read how it resolves __pthread_get_minstack through dlsym and compare the reported function type with glibc's definition. Reproduce with the minimal std::thread::spawn example and the supplied CFI flags; done means the Linux GNU build runs without a CFI failure while preserving the musl behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Discovered while building ClickHouse with CFI, which uses glibc (for now, we are in the process of switching to musl).
I tried the following project
src/main.rs:
fn main() {
let thread = std::thread::spawn(|| 1);
println!("{}", thread.join().unwrap());
}
Cargo.toml:
[package]
name = "minstack_cfi"
version = "0.1.0"
edition = "2021"
[profile.dev]
lto = "fat"
codegen-units = 1
Command:
RUSTFLAGS="-Clto -Ccodegen-units=1 -Zsanitizer=cfi" \
cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-gnu
I expected to see just 1, instead I get a SIGILL from CFI. With -Zsanitizer-cfi-diag -Zsanitizer-cfi-recover it reports:
library/std/src/lib.rs:1:1: runtime error: control flow integrity check for type fn(*const libc::pthread_attr_t) -> usize failed during indirect function call
nptl/nptl-stack.c:162:1: note: __pthread_get_minstack defined here
library/std/src/lib.rs:1:1: note: check failed in .../minstack_cfi, destination function located in /usr/lib/libc.so.6
If I build with musl it works fine:
$ RUSTFLAGS="-Clto -Ccodegen-units=1 -Zsanitizer=cfi -Ctarget-feature=-crt-static \
-Clink-self-contained=yes -Clink-arg=-static -Crelocation-model=static \
-Clinker=clang -Clink-arg=-fuse-ld=lld" cargo +nightly run -Zbuild-std --target x86_64-unknown-linux-musl
Compiling minstack_cfi v0.1.0 (/mnt/ch/ClickHouse/tmp/minstack_cfi)
warning: linker stderr: clang: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
|
= note: `#[warn(linker_messages)]` on by default
warning: `minstack_cfi` (bin "minstack_cfi") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.18s
Running `target/x86_64-unknown-linux-musl/debug/minstack_cfi`
1
Meta
rustc --version --verbose:
$ rustc +nightly --version --verbose
rustc 1.102.0-nightly (5f4effd57 2026-11-13)
binary: rustc
commit-hash: 5f4effd579500175af844241eb179e756190f1e7
commit-date: 2026-11-13
host: x86_64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.5
The lookup has been there since 2015, years before Rust had CFI so this is not a new issue.
Backtrace
(gdb) bt
#0 0x0000561956333632 in std::sys::thread::unix::min_stack_size (attr=0x7fffafd94f00) at src/sys/thread/unix.rs:1076
#1 0x00005619562eadf8 in std::sys::thread::unix::Thread::new (stack=2097152, init=0x56198b13bde0) at src/sys/thread/unix.rs:78
#2 0x0000561956364902 in std::thread::lifecycle::spawn_unchecked<minstack_cfi::main::{closure_env#0}, i32> (name=..., stack_size=..., no_hooks=false, scope_data=..., f=...)
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:116
#3 0x000056195636417a in std::thread::builder::Builder::spawn_unchecked<minstack_cfi::main::{closure_env#0}, i32> (self=..., f=...)
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/builder.rs:261
#4 0x000056195636403a in std::thread::builder::Builder::spawn<minstack_cfi::main::{closure_env#0}, i32> (self=..., f=...)
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/builder.rs:191
#5 0x00005619563628a6 in std::thread::functions::spawn<minstack_cfi::main::{closure_env#0}, i32> (f=...)
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/functions.rs:131
#6 0x000056195636278f in minstack_cfi::main () at src/main.rs:2
#7 0x000056195636276f in core::ops::function::FnOnce::call_once<fn(), ()> ()
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250
#8 0x000056195636270e in std::sys::backtrace::__rust_begin_short_backtrace<fn(), ()> (f=0x561956362778 <__ubsan_check_cfi_icall_jt>)
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166
#9 0x00005619563626ed in std::rt::lang_start::{closure#0}<()> () at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:206
#10 0x000056195633ff92 in core::ops::function::impls::{impl#2}::call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)>
(self=..., args=()) at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:287
#11 0x00005619562c4b73 in std::panicking::catch_unwind::do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (
data=0x7fffafd95660) at src/panicking.rs:573
#12 0x000056195636263b in __rust_try ()
#13 0x000056195628e453 in std::panicking::catch_unwind<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (f=...)
at src/panicking.rs:541
#14 0x000056195628e33a in std::panic::catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (f=...)
at src/panic.rs:359
#15 0x00005619562d6653 in std::rt::lang_start_internal::{closure#0} () at src/rt.rs:175
#16 0x00005619562c4a91 in std::panicking::catch_unwind::do_call<std::rt::lang_start_internal::{closure_env#0}, isize> (data=0x7fffafd957c8) at src/panicking.rs:573
#17 0x000056195636263b in __rust_try ()
#18 0x000056195628e3b0 in std::panicking::catch_unwind<isize, std::rt::lang_start_internal::{closure_env#0}> (f=...) at src/panicking.rs:541
#19 0x000056195628e30a in std::panic::catch_unwind<std::rt::lang_start_internal::{closure_env#0}, isize> (f=...) at src/panic.rs:359
#20 0x000056195632c686 in std::rt::lang_start_internal (main=..., argc=1, argv=0x7fffafd95a78, sigpipe=0) at src/rt.rs:171
#21 0x00005619563626b6 in std::rt::lang_start<()> (main=0x561956362778 <__ubsan_check_cfi_icall_jt>, argc=1, argv=0x7fffafd95a78, sigpipe=0)
at /home/raul/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:205
#22 0x00005619563661bb in main ()
#23 0x00007f6590427781 in __libc_start_call_main (main=main@entry=0x5619563661a0 <main>, argc=argc@entry=1, argv=argv@entry=0x7fffafd95a78) at ../sysdeps/nptl/libc_start_call_main.h:59
#24 0x00007f65904278b9 in __libc_start_main_impl (main=0x5619563661a0 <main>, argc=1, argv=0x7fffafd95a78, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffafd95a68) at ../csu/libc-start.c:372
#25 0x000056195626c5a5 in _start ()
- Ngôn ngữ chính
- Rust
- Star
- 122k
- Fork
- 16.7k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 515
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của rust-lang/rust
-
Remove unnecessary parentheses when suggesting to remove '&' from a patternCó thể đã có người làm @BartSimpson001 đã nhận 1 ngày trước. Đang mởA-diagnostics D-invalid-suggestion T-compiler
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`Có thể đã có người làm @ChrisDenton đã nhận 11 ngày trước. Đang mởA-filesystem C-bug O-windows T-libs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
rust-lang/rust#165504 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
relnotes relnotes-tracking-issue T-libs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của rust-lang/rust
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
bytecodealliance/wrpc#1785 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
2 advisory ignore entries no longer match anything (`quick-xml` already patched in `Cargo.lock`)Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
longbridge/nsh#2758 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
antithesishq/bombadil#473 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
libracoder/kiri#669 ·
Maintainer thường phản hồi trong vòng 1 ngày