The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
tech(KF-1): der positive Ende-zu-Ende-Beweis steht wieder — mit einem echten Binary
David62a41c85e230
diff --git a/src-tauri/examples/park.rs b/src-tauri/examples/park.rsnew file mode 100644index 00000000..7588b36d--- /dev/null+++ b/src-tauri/examples/park.rs@@ -0,0 +1,51 @@+//! A process that does nothing but stay alive — the stand-in the sweep tests+//! need, and nothing else.+//!+//! ── Why this exists as a real binary ──+//!+//! `remote::kill_orphaned_tunnels` identifies a leftover tunnel by+//! `Process::name()` plus its argv, so the test that proves the scan is wired+//! to real data needs a live process that is genuinely NAMED `cloudflared`.+//! On macOS `name()` comes from the executed file, so the stand-in has to BE a+//! file with that name — a symlink reports the resolved target and a shebang+//! script reports its interpreter (`bash`).+//!+//! The obvious shortcut, a copy of `/bin/sh` renamed to `cloudflared`, is what+//! the test used until 01.09.2026, and it is a trap: `/bin/sh` is a SIP+//! platform binary, and macOS SIGKILLs a copy of one shortly after exec.+//! Measured over 15 spawns: it lived 95–486 ms and was then killed, every+//! single time — `sleep 30` was never reached. The test only ever passed+//! because it looked inside that window, and under load it did not, which is+//! the flake that cost a day to find.+//!+//! A binary the toolchain compiles here is ad-hoc/linker-signed rather than+//! platform-signed, so none of that applies: measured over 15 spawns, a copy+//! of this crate's own test binary ran past a second and exited normally every+//! time, with no SIGKILL at all. So the stand-in is compiled rather than+//! borrowed.+//!+//! ── Why stdin and not a sleep ──+//!+//! Blocking on stdin makes the lifetime the test's to decide: the process+//! lives exactly as long as the pipe is open, ends the moment the test drops+//! it, and there is no timer that could outlive a failing test or leave an+//! orphan behind. `read_line` returns `Ok(0)` on EOF, which is the normal way+//! this exits.+//!+//! ── Why an example and not a bin ──+//!+//! `cargo test` builds examples, so it is there whenever the tests are, but it+//! is NOT part of the application: `cargo build --release` does not build it,+//! and the Tauri bundler copies the app binary and the resources named in+//! `tauri.conf.json`, never `target/release/examples/`. Both checked.+//!+//! It takes arguments and ignores them. That is deliberate — the test passes+//! `--url http://127.0.0.1:<port>` so the process carries the argv a real+//! quick tunnel carries, which is the half of the matcher this stand-in is+//! for.++fn main() {+ let mut sink = String::new();+ // EOF (the test closing the pipe) or any read error ends the process.+ let _ = std::io::stdin().read_line(&mut sink);+}diff --git a/src-tauri/src/commands/remote.rs b/src-tauri/src/commands/remote.rsindex 37c54b4f..19f07f63 100644--- a/src-tauri/src/commands/remote.rs+++ b/src-tauri/src/commands/remote.rs@@ -4079,14 +4079,20 @@ mod remote_hardening_tests {// a builtin, so there is no `sleep` grandchild to orphan, and closing the// pipe or killing the child ends it at once.//- // What that costs, stated plainly: a shebang's `name()` is the interpreter- // ("bash" on macOS), not the script, so this process cannot impersonate a- // cloudflared. The positive end-to-end hit — `find_stale_tunnels` returning- // a real process — is therefore no longer available as a gate on this- // platform. What replaces it is below, and the boundary is named in the- // report: the name half of the matcher is covered by the exhaustive pure- // tests above, the argv half is covered here on real data, and- // `find_stale_tunnels`'s body is the composition of exactly those two.+ // A shebang's `name()` is the interpreter ("bash" on macOS), not the+ // script, so THAT stand-in cannot impersonate a cloudflared — it carries a+ // real argv and a real name, which is what the three decomposed tests+ // below need, but not the name the sweep looks for.+ //+ // The positive end-to-end direction gets its own stand-in, and the reason+ // it is a different one is worth writing down: SIP kills copies of+ // PLATFORM binaries, not copies of anything. Measured the same way, 15+ // spawns of a copy of this crate's own (ad-hoc, linker-signed) test binary+ // ran past a second and exited normally every time, with no SIGKILL at+ // all. So `examples/park.rs` is compiled by the toolchain and copied under+ // the name `cloudflared` — a real process, really named that, really+ // publishing our port, found by the real sweep. See+ // `the_sweep_finds_a_real_cloudflared_by_its_argv`./// A live process with an argv we chose, that the OS will keep running.///@@ -4162,6 +4168,88 @@ mod remote_hardening_tests {}}+ /// A live process that really is NAMED `cloudflared`, publishing `port`.+ ///+ /// `examples/park.rs` compiled by this same toolchain, copied under the+ /// name the matcher reads. Ad-hoc/linker-signed rather than platform-+ /// signed, so none of the SIGKILL story above applies to it; it blocks on+ /// the stdin pipe this test holds, so it lives exactly as long as the test+ /// wants and leaves nothing behind.+ #[cfg(unix)]+ fn live_cloudflared(port: u16) -> (tempfile::TempDir, std::process::Child) {+ use std::process::{Command, Stdio};++ // target/<profile>/deps/<test binary> -> target/<profile>/examples/park+ let exe = std::env::current_exe().expect("current_exe");+ let park = exe+ .parent()+ .and_then(|deps| deps.parent())+ .map(|profile| profile.join("examples").join("park"))+ .expect("no target/<profile>/ above the test binary");+ assert!(+ park.is_file(),+ "{} is missing. It is `src-tauri/examples/park.rs`, which `cargo test` builds \+ alongside the tests; if it is gone, this test is not measuring the sweep.",+ park.display(),+ );++ let dir = tempfile::tempdir().expect("tempdir");+ let bin = dir.path().join("cloudflared");+ std::fs::copy(&park, &bin).expect("copy the stand-in");++ let child = Command::new(&bin)+ .args(["tunnel", "--url", &format!("http://127.0.0.1:{port}")])+ .stdin(Stdio::piped())+ .stdout(Stdio::null())+ .stderr(Stdio::null())+ .spawn()+ .expect("spawn the stand-in");+ (dir, child)+ }++ /// The positive end-to-end direction, and the one T-39 depends on: a real,+ /// live `cloudflared` publishing our port is FOUND by the sweep.+ ///+ /// Everything in it is real — the process, its name, its argv, the process+ /// table, the matcher. Nothing is substituted. It is asserted on a snapshot+ /// `checked_table` has already vouched for, so there is no clock and no+ /// retry standing in for a guarantee.+ #[cfg(unix)]+ #[test]+ fn the_sweep_finds_a_real_cloudflared_by_its_argv() {+ // Its own port, so that nothing it asserts can depend on what the other+ // stand-ins in this module happen to be doing at the same moment.+ let port: u16 = 61436;+ let (_dir, mut child) = live_cloudflared(port);+ let pid = child.id();+ let table = checked_table(pid);+ let _ = child.kill();+ let _ = child.wait();++ let sys = table.unwrap_or_else(|why| panic!("{why}"));+ let entry = sys+ .process(sysinfo::Pid::from_u32(pid))+ .expect("checked_table only returns a table containing this pid");++ // If this ever fails the rest means nothing: the stand-in would not be+ // impersonating a cloudflared at all.+ assert_eq!(+ entry.name().to_string_lossy(),+ "cloudflared",+ "the stand-in is not reported under the name the sweep matches on",+ );+ assert!(+ find_stale_tunnels(&sys, port).contains(&pid),+ "the sweep did not find a live cloudflared publishing {port} — this is exactly \+ the state the sweep was in while it reported 0 killed on every start. argv={:?}",+ crate::process_util::cmdline_of(entry),+ );+ assert!(+ !find_stale_tunnels(&sys, port + 1).contains(&pid),+ "a sweep for another port matched this tunnel",+ );+ }+/// The fifteen-month bug itself, on real data.////// `refresh_processes` does not fetch command lines, so `Process::cmd()`@@ -4266,45 +4354,6 @@ mod remote_hardening_tests {);}- /// SONDE (temporaer): ueberlebt eine Kopie eines SELBST KOMPILIERTEN- /// Binaries, oder toetet macOS sie wie die Kopie von /bin/sh?- #[cfg(unix)]- #[test]- #[ignore]- fn zz_selfbuilt_survives() {- use std::os::unix::fs::PermissionsExt;- use std::process::{Command, Stdio};- let me = std::env::current_exe().expect("current_exe");- let mut out = Vec::new();- for _ in 0..15 {- let dir = tempfile::tempdir().unwrap();- let bin = dir.path().join("cloudflared");- std::fs::copy(&me, &bin).unwrap();- std::fs::set_permissions(&bin, std::fs::Permissions::from_mode(0o755)).unwrap();- let t0 = std::time::Instant::now();- // Ein einzelner verschachtelter Test, der rund eine Sekunde laeuft —- // also weit ueber dem 95-486ms-Fenster, in dem die /bin/sh-Kopie starb.- let mut c = Command::new(&bin)- .args([- "--test-threads=1",- "--exact",- "commands::remote::remote_hardening_tests::stopping_the_tunnel_takes_its_children_with_it",- ])- .stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null())- .spawn().unwrap();- let mut res = None;- for _ in 0..1200 {- if let Ok(Some(st)) = c.try_wait() { res = Some(format!("{}ms/{st}", t0.elapsed().as_millis())); break; }- std::thread::sleep(std::time::Duration::from_millis(5));- }- match res {- Some(r) => out.push(r),- None => { out.push(">6000ms/lebt noch".into()); let _ = c.kill(); let _ = c.wait(); }- }- }- println!("SELBST-KOMPILIERT: {out:?}");- }-#[test]fn a_sweep_for_one_port_does_not_kill_the_tunnel_of_another() {// The port was matched as a substring, so `127.0.0.1:1143` was "found"