CFI: Fn closure called through dyn FnMut fails the CFI check
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 47/100
Línea de trabajo
Start by reproducing the minimal example with the nightly rustc command and CFI flags shown in the issue, then read the referenced Rust issues #144641 and #160230 for related context. The report identifies a mismatch in the CFI check for a closure called through dyn FnMut, but does not name the compiler source files or tests involved. Done means the reduced example runs without the CFI failure and a regression test covers it.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Found when running ClickHouse with CFI which includes the ipnet crate, version 2.12.0:
contrib/rust_vendor/ipnet-2.12.0/src/lib.rs:1:1: runtime error: control flow integrity check for type
fn(&mut dyn for<'a, 'b> FnMut(&'a mut parser::Parser<'b>) -> Option<ipnet::IpNet>, &mut parser::Parser<'_>) -> Option<ipnet::IpNet>
failed during indirect function call
note: <<ipnet::parser::Parser>::read_ip_net::{closure#0} as FnOnce<(&mut ipnet::parser::Parser,)>>::call_once::{shim:vtable#0} defined here
Original code in ipnet but it's reduced to this code:
fn main() {
let f = || std::env::args().count();
let mut b: Box<dyn FnMut() -> usize> = Box::new(f);
println!("{}", b());
}
I expected to see only the expected line (1), instead the binary crashes with SIGILL or, if we change cfi to show the warning instead of crashing, it shows a warning:
$ rustc +nightly --edition=2021 -Copt-level=1 -Clto -Ccodegen-units=1 \
-Zsanitizer=cfi -Zsanitizer-cfi-diag -Zsanitizer-cfi-recover \
-Cunsafe-allow-abi-mismatch=sanitizer fn_as_fnmut.rs
$ ./fn_as_fnmut
fn_as_fnmut.rs:1:1: runtime error: control flow integrity check for type fn(&mut dyn std::ops::FnMut() -> usize) -> usize failed during indirect function call
fn_as_fnmut.625fcbea4de00cd8-cgu.0: note: fn_as_fnmut::main::{closure#0} defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior fn_as_fnmut.rs:1:1
1
It seems related to https://github.com/rust-lang/rust/issues/144641 cc @rcvalle
https://github.com/rust-lang/rust/pull/160230 also looks related, but the repro fails with and without it
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
Also tested with:
nightly-2024-04-01nightly-2025-06-01- And
stable 1.100.0 (2026-11-09), with RUSTC_BOOTSTRAP=1
Backtrace
Core was generated by `./fn_as_fnmut'.
Program terminated with signal SIGILL, Illegal instruction.
#0 0x0000562447661b6e in fn_as_fnmut::main ()
(gdb) bt
#0 0x0000562447661b6e in fn_as_fnmut::main ()
#1 0x0000562447661b42 in std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()> ()
#2 0x0000562447661b59 in std::rt::lang_start::<()>::{closure#0} ()
#3 0x000056244769abd6 in core::ops::function::impls::{impl#2}::call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)>
() at library/core/src/ops/function.rs:287
#4 std::panicking::catch_unwind::do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> ()
at library/std/src/panicking.rs:573
#5 std::panicking::catch_unwind<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> () at library/std/src/panicking.rs:541
#6 std::panic::catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> () at library/std/src/panic.rs:359
#7 std::rt::lang_start_internal::{closure#0} () at library/std/src/rt.rs:175
#8 std::panicking::catch_unwind::do_call<std::rt::lang_start_internal::{closure_env#0}, isize> () at library/std/src/panicking.rs:573
#9 std::panicking::catch_unwind<isize, std::rt::lang_start_internal::{closure_env#0}> () at library/std/src/panicking.rs:541
#10 std::panic::catch_unwind<std::rt::lang_start_internal::{closure_env#0}, isize> () at library/std/src/panic.rs:359
#11 std::rt::lang_start_internal () at library/std/src/rt.rs:171
#12 0x0000562447661b94 in main ()
- Lenguaje dominante
- Rust
- Estrellas
- 122k
- Forks
- 16.7k
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 515
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/rust
-
Remove unnecessary parentheses when suggesting to remove '&' from a patternPosiblemente ocupada @BartSimpson001 la tomó hace 1 día. AbiertoA-diagnostics D-invalid-suggestion T-compiler
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`Posiblemente ocupada @ChrisDenton la tomó hace 11 días. AbiertoA-filesystem C-bug O-windows T-libs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
rust-lang/rust#165504 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
relnotes relnotes-tracking-issue T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rust
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
bytecodealliance/wrpc#1785 ·
Los mantenedores suelen responder en 1 día
-
2 advisory ignore entries no longer match anything (`quick-xml` already patched in `Cargo.lock`)Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
longbridge/nsh#2758 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
antithesishq/bombadil#473 ·
Los mantenedores suelen responder en 2 días
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
libracoder/kiri#669 ·
Los mantenedores suelen responder en 1 día