CFI: Fn closure called through dyn FnMut fails the CFI check

オープン
#166,062 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
47/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
compilers, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

A-ABI A-control-flow-integrity A-dyn-trait C-bug requires-nightly T-compiler

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-01
  • nightly-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 ()

主要言語
Rust
スター
122k
フォーク
16.7k
平均マージ
2日 16時間
マージ済み PR(30日)
515

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-lang/rust のほかの issue

rust-lang/rust の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。