Compare commits

...
1 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 52b7c3f2a1 review wave 5: third-round findings (unreachable column, races, panics, DoS)
Third review round (over the wave 3/4 fixes) surfaced further findings, mostly in
new code paths; this clears them:

- HIGH the fully-built "Boards" column (Column::Hashboards: renderer, sort/filter
  logic, tests, a self-test check) was missing from ALL_COLUMNS, so it was
  unreachable in the UI and its self-test check was dead. Added to ALL_COLUMNS
  (opt-in; Health still shows composite board health by default) and the self-test
  now makes it visible -- the dot-sentinel check is live again.
- HIGH apply_pools() could start a pool write during a restore-to-stock (it sets
  self.action directly, bypassing start_action's guard) -> same restore guard.
- HIGH superseding an in-flight action/pools job left the old miners' Health cells
  frozen on the "…ing" label forever (the replaced handle's drain never runs) ->
  clear the superseded action's op-status.
- HIGH clean_antminer() byte-sliced a miner-supplied model string without a
  char-boundary check (panic DoS) -> use get(..9).
- MED access-probe errors were silently discarded -> surfaced in the indicator.
- MED the pool-password file was briefly world-readable before chmod -> created
  0600 from the start (OpenOptions mode).
- MED a miner-controlled log response was buffered unbounded (OOM DoS) -> capped.
- MED the language-menu id range was hardcoded (and 790-794 collided with the
  pool-preset / fw-preset dialog ids!) -> derived from Lang::all() and moved the
  dialog ids to a clear block.
- LOW restore_vnish now sends the unlock body via stdin (password off argv), and
  the LuxOS restore treats a reboot-dropped/empty reply as success.

Remaining round-3 findings are the previously-accepted perf tradeoffs (bulk-serial
writes, per-tick refill, per-render health recompute, linear upsert), documented
in code and in code-review-report.md.

99 tests + clippy-clean + selftest green (Boards-column check now live).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6
2026-09-22 19:53:56 -06:00
6 changed files with 122 additions and 41 deletions
+6 -2
View File
@@ -223,10 +223,14 @@ fn curl(args: &[&str], stdin_data: Option<&[u8]>) -> Result<String, String> {
let _ = si.write_all(data);
} // dropping `si` closes the pipe so curl stops reading the config/body
}
let mut stdout = child.stdout.take().ok_or("no curl stdout")?;
let stdout = child.stdout.take().ok_or("no curl stdout")?;
let reader = std::thread::spawn(move || {
// Bound the buffer: a miner-controlled response must not exhaust memory
// (round 18 #12). The viewer only keeps the last MAX_LOG_BYTES anyway, so
// read a small multiple of that and drop the rest.
const READ_CAP: u64 = (MAX_LOG_BYTES as u64) * 8; // 2 MiB
let mut buf = Vec::new();
let _ = stdout.read_to_end(&mut buf);
let _ = stdout.take(READ_CAP).read_to_end(&mut buf);
buf
});
let timeout = Duration::from_secs(20);
+6 -1
View File
@@ -1030,10 +1030,15 @@ pub enum Column {
/// Every column, in registry order. Ip first, then the default-visible set
/// (UI-SPEC order), then all remaining metrics.
pub const ALL_COLUMNS: [Column; 46] = [
pub const ALL_COLUMNS: [Column; 47] = [
Column::Ip,
Column::Hashrate,
Column::Health,
// The detailed per-board dot column (round 11 #10). Not in DEFAULT_VISIBLE
// (the Health column shows composite board health by default), but it belongs
// in ALL_COLUMNS so it is selectable in the column picker (round 18 #12: it
// was accidentally omitted, making the column unreachable).
Column::Hashboards,
Column::Power,
Column::ChipTemp,
Column::Cooling,
+7 -4
View File
@@ -135,10 +135,13 @@ fn clean_antminer(id: &str) -> String {
// asic-rs "Unknown" models pass the raw vendor string through with the brand
// still in it (e.g. "ANTMINER S19 (88)", a NoPIC S19); drop a redundant
// leading brand word so the Model column never repeats the Brand column.
let id = if id.len() >= 9 && id[..9].eq_ignore_ascii_case("ANTMINER ") {
id[9..].trim_start()
} else {
id
// `get(..9)` returns None (rather than panicking) when byte 9 is not a UTF-8
// char boundary, so a multibyte miner-supplied model string can't crash here
// (round 18 #12). The prefix is 9 ASCII bytes, so a real match implies a
// boundary at 9 and the following `id[9..]` is safe.
let id = match id.get(..9) {
Some(p) if p.eq_ignore_ascii_case("ANTMINER ") => id[9..].trim_start(),
_ => id,
};
let bytes = id.as_bytes();
// Base = leading letters then digits ("S19", "KS5", "L3", "Z15"). Without a
+20 -9
View File
@@ -82,23 +82,34 @@ pub fn save_all(field: PoolField, values: &[String]) -> std::io::Result<usize> {
if let Some(dir) = p.parent() {
let _ = std::fs::create_dir_all(dir);
}
std::fs::write(&p, out.join("\n"))?;
// The password list can hold a pool password; keep every saved list owner-only
// (round 18 #12).
restrict_permissions(&p);
// The password list can hold a pool password, so write it owner-only from the
// moment it is created -- never briefly world-readable (round 18 #12).
write_private(&p, out.join("\n").as_bytes())?;
Ok(out.len())
}
/// Best-effort tighten a config file to owner-only (0600) on Unix. A no-op
/// elsewhere; a failure is ignored (the file still exists, just not restricted).
fn restrict_permissions(path: &std::path::Path) {
/// Write `data` to `path` with owner-only (0600) permissions from creation on
/// Unix, so a secret is never momentarily world-readable between write and chmod.
/// `mode()` only takes effect when the file is created, so an already-existing
/// file is also re-tightened; elsewhere this is a plain write.
fn write_private(path: &std::path::Path, data: &[u8]) -> std::io::Result<()> {
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
use std::io::Write;
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
let mut f = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.open(path)?;
let _ = std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600));
f.write_all(data)
}
#[cfg(not(unix))]
let _ = path;
{
std::fs::write(path, data)
}
}
/// Trim every value, then drop empties, values equal to a built-in preset, and
+38 -17
View File
@@ -121,15 +121,19 @@ fn restore_one(t: &RestoreTarget, vnish_pass: &str, ssh_user: &str, ssh_pass: &s
/// VNish: unlock -> bearer -> firmware/remove (self-restores + reboots ~3 s).
fn restore_vnish(ip: &str, pass: &str) -> (bool, String) {
// serde-encode the body so a password with a quote/backslash can't break or
// inject into the JSON (round 18 #12).
// serde-encode the body so a password with a quote/backslash can't break the
// JSON, and send it via stdin (-d @-) so the password never appears on curl's
// argv / the process list (round 18 #12).
let body = serde_json::json!({ "pw": pass }).to_string();
let unlock = match curl(&[
"-s", "--connect-timeout", "5", "--max-time", "9",
"-X", "POST", "-H", "Content-Type: application/json",
"-d", &body,
&format!("http://{ip}/api/v1/unlock"),
]) {
let unlock = match curl(
&[
"-s", "--connect-timeout", "5", "--max-time", "9",
"-X", "POST", "-H", "Content-Type: application/json",
"-d", "@-",
&format!("http://{ip}/api/v1/unlock"),
],
Some(body.as_bytes()),
) {
Ok(s) => s,
Err(e) => return (false, format!("unlock request failed: {e}")),
};
@@ -140,11 +144,14 @@ fn restore_vnish(ip: &str, pass: &str) -> (bool, String) {
let Some(token) = token else {
return (false, "VNish unlock rejected (wrong web password?)".into());
};
match curl(&[
"-s", "--connect-timeout", "5", "--max-time", "12",
"-X", "POST", "-H", &format!("Authorization: Bearer {token}"),
&format!("http://{ip}/api/v1/firmware/remove"),
]) {
match curl(
&[
"-s", "--connect-timeout", "5", "--max-time", "12",
"-X", "POST", "-H", &format!("Authorization: Bearer {token}"),
&format!("http://{ip}/api/v1/firmware/remove"),
],
None,
) {
// The miner reverts + reboots after ~3 s; the response is {"after":N}.
Ok(resp) if resp.contains("after") => (true, "reverting to stock (~3 s)".into()),
Ok(resp) => (false, format!("firmware/remove returned: {}", resp.trim())),
@@ -218,7 +225,7 @@ fn restore_braiins(ip: &str, user: &str, pass: &str) -> (bool, String) {
&target,
"uninstall.sh || /sbin/uninstall.sh",
]);
match run_with_timeout(cmd, Duration::from_secs(60)) {
match run_with_timeout(cmd, Duration::from_secs(60), None) {
Ok(out) => classify_braiins(
&String::from_utf8_lossy(&out.stdout),
&String::from_utf8_lossy(&out.stderr),
@@ -308,10 +315,10 @@ struct CmdOutput {
/// curl with a wall-clock cap. Errors only when the run produced no output and
/// timed out (a black-holed host); otherwise returns stdout even on a non-zero
/// exit (curl prints useful bodies/status on failures).
fn curl(args: &[&str]) -> Result<String, String> {
fn curl(args: &[&str], stdin_data: Option<&[u8]>) -> Result<String, String> {
let mut cmd = Command::new("curl");
cmd.args(args);
let out = run_with_timeout(cmd, Duration::from_secs(15))?;
let out = run_with_timeout(cmd, Duration::from_secs(15), stdin_data)?;
if out.timed_out && out.stdout.is_empty() {
return Err("timed out".into());
}
@@ -321,10 +328,24 @@ fn curl(args: &[&str]) -> Result<String, String> {
/// Run a command with a hard wall-clock timeout, capturing stdout, stderr, and
/// the exit code. Both pipes are drained on their own threads so a child that
/// writes a lot to stderr can never deadlock against a full pipe (round 18 #12).
fn run_with_timeout(mut cmd: Command, timeout: Duration) -> Result<CmdOutput, String> {
/// `stdin_data`, when set, is written to the child's stdin and the pipe closed
/// (used to feed a request body without putting a secret on argv).
fn run_with_timeout(
mut cmd: Command,
timeout: Duration,
stdin_data: Option<&[u8]>,
) -> Result<CmdOutput, String> {
cmd.stdout(std::process::Stdio::piped());
cmd.stderr(std::process::Stdio::piped());
if stdin_data.is_some() {
cmd.stdin(std::process::Stdio::piped());
}
let mut child = cmd.spawn().map_err(|e| format!("spawn: {e}"))?;
if let Some(data) = stdin_data {
if let Some(mut si) = child.stdin.take() {
let _ = si.write_all(data);
} // dropping `si` closes the pipe
}
let mut stdout = child.stdout.take().ok_or("no stdout")?;
let mut stderr = child.stderr.take().ok_or("no stderr")?;
let out_reader = std::thread::spawn(move || {
+45 -8
View File
@@ -22,7 +22,7 @@ pub const ID_PRESETS: i32 = 108;
pub const ID_EXPORT: i32 = 109;
// Settings menu (round 15 #13): the toolbar button + its menu items.
pub const ID_SETTINGS: i32 = 110;
const ID_LANG_BASE: i32 = 790; // one id per language (790 + index)
const ID_LANG_BASE: i32 = 790; // one id per language (790 + Lang index); reserves 790..790+Lang::all().len()
const ID_LOGS_OPEN: i32 = 796; // open the Logs page
const ID_LOGS_REFRESH: i32 = 797;
const ID_LOGS_CLEAR: i32 = 798;
@@ -86,12 +86,14 @@ const ID_CTX_POOLS: i32 = 736;
const ID_POOLS_OK: i32 = 788;
const ID_POOLS_CANCEL: i32 = 789;
// Pool-preset manager dialog (round 18 #8b): edit the whole saved list at once.
const ID_POOL_PRESETS_SAVE: i32 = 790;
const ID_POOL_PRESETS_CANCEL: i32 = 791;
// NB: 790-795 belong to the language menu (ID_LANG_BASE + Lang index), so these
// live in a separate high block to avoid an id collision (round 18 #12).
const ID_POOL_PRESETS_SAVE: i32 = 1001;
const ID_POOL_PRESETS_CANCEL: i32 = 1002;
// Firmware profile/preset selector dialog (round 18 / roadmap G3).
const ID_FWPRESET_OK: i32 = 792;
const ID_FWPRESET_CANCEL: i32 = 793;
const ID_FWPRESET_CHOICE: i32 = 794;
const ID_FWPRESET_OK: i32 = 1003;
const ID_FWPRESET_CANCEL: i32 = 1004;
const ID_FWPRESET_CHOICE: i32 = 1005;
// Pool-field "+" dropdown buttons (round 15 #1): 12 buttons (3 rows x 4 fields),
// id = base + row*4 + field. The dropdown menu items use their own id range.
const ID_POOL_PLUS_BASE: i32 = 800;
@@ -1834,6 +1836,13 @@ impl App {
wx_rs::set_status_text("firmware flash in progress -- wait for it to finish");
return;
}
// A restore-to-stock is reverting + rebooting miners; writing pools mid-
// revert could hit a unit in an undefined state (round 18 #12 -- this path
// sets self.action directly, so it needs the same guard as start_action).
if self.restore.is_some() {
wx_rs::set_status_text("restore-to-stock in progress -- wait for it to finish");
return;
}
// Collect the raw rows: (address, account, worker_template, password).
let mut rows: Vec<(String, String, String, String)> = Vec::new();
for row in 0..3usize {
@@ -1881,6 +1890,12 @@ impl App {
let ips: Vec<String> = targets.iter().map(|t| t.ip.clone()).collect();
if let Some(old) = self.action.take() {
old.stop();
// Clear the superseded action's in-flight status so its Health cells
// don't stay frozen on the old label (round 18 #12).
let stale = std::mem::take(&mut self.action_targets);
for ip in stale {
self.op_status.remove(&ip);
}
}
self.pools_dialog.close(1);
self.action_targets = ips.clone();
@@ -1907,6 +1922,13 @@ impl App {
}
if let Some(old) = self.action.take() {
old.stop();
// The superseded action's drain will never run again, so clear its
// miners' in-flight status or their Health cells stay frozen on the old
// "…ing" label forever (round 18 #12).
let stale = std::mem::take(&mut self.action_targets);
for ip in stale {
self.op_status.remove(&ip);
}
}
// Progress shows in each miner's Health cell (round 15 #8), not the scan
// line; the bottom-right indicator still surfaces failures at the end.
@@ -2207,6 +2229,7 @@ impl App {
let mut done = false;
let mut changed = false;
let mut op_clear: Vec<String> = Vec::new();
let mut errors: Vec<String> = Vec::new();
loop {
match h.rx.try_recv() {
Ok(scan::AccessProbeMsg::Started { total }) => {
@@ -2220,6 +2243,9 @@ impl App {
changed = true;
}
}
if let Some(e) = &error {
errors.push(format!("{ip}: {e}"));
}
status = Some(match (&locked, &error) {
(_, Some(e)) => format!("access {ip}: {e}"),
(Some(true), _) => format!("access {ip}: locked"),
@@ -2250,6 +2276,12 @@ impl App {
}
if done {
self.access_probe = None;
// Probe errors (a miner the check could not run against) were being
// dropped entirely; surface them in the failure indicator (round 18 #12).
if !errors.is_empty() {
self.set_error_indicator(&format!("access check: {} failed", errors.len()));
crate::logs::log(format!("access check errors: {}", errors.join("; ")));
}
}
// Operation progress stays out of the bottom-left scan line (round 15 #8);
// per-miner status shows in the Health column.
@@ -2269,7 +2301,7 @@ impl App {
return None;
}
// Settings menu Language items (round 15 #13).
if (ID_LANG_BASE..ID_LANG_BASE + 6).contains(&id) {
if (ID_LANG_BASE..ID_LANG_BASE + crate::i18n::Lang::all().len() as i32).contains(&id) {
self.set_language((id - ID_LANG_BASE) as usize);
return None;
}
@@ -4212,7 +4244,12 @@ impl App {
pub fn run_fixture_selftest(&mut self) -> bool {
self.rows = crate::fixtures::bench_fleet();
self.view = ViewState::default();
self.fill_rows();
// Show the detailed per-board Boards column so its dot-sentinel rendering
// is actually exercised (round 18 #12: it is opt-in, not default-visible,
// so without this the Boards check below was dead). rebuild_table (not
// fill_rows) so the widget's columns match the changed visible set.
self.view.visible.insert(crate::model::Column::Hashboards);
self.rebuild_table();
let mut ok = true;
let mut check = |name: &str, pass: bool, detail: String| {