{"id":"XE-9899","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":730,"title":"Node Observability / Disk Exhaustion: rotatingWriter.rotate ignores file rename errors causing log file truncation and permanent log loss","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T08:13:35.316641+00:00","updated_at":"2026-11-20T00:37:23.291462+00:00","source_created_at":null,"told_at":"2026-11-20T00:34:15.428591+00:00","status_changed_at":"2026-11-20T00:34:14.712596+00:00","url":"https://bounty.xe.network/XE-9899","body":"## Vulnerability Summary\n\nIn `logging/rotate.go:80-99`, `rotatingWriter.rotate()` implements file rotation when active node logs exceed `maxSize`:\n\n```go\nfunc (w *rotatingWriter) rotate() {\n\tif err := w.f.Close(); err != nil {\n\t\treturn\n\t}\n\tif w.maxFiles > 0 {\n\t\t_ = os.Remove(fmt.Sprintf(\"%s.%d\", w.path, w.maxFiles))\n\t\tfor i := w.maxFiles - 1; i >= 1; i-- {\n\t\t\t_ = os.Rename(fmt.Sprintf(\"%s.%d\", w.path, i), fmt.Sprintf(\"%s.%d\", w.path, i+1))\n\t\t}\n\t\t_ = os.Rename(w.path, w.path+\".1\")\n\t} else {\n\t\t_ = os.Remove(w.path)\n\t}\n\tif err := w.open(); err != nil {\n\t\t// Fallback to stderr if we can no longer write to disk\n\t\tw.f = os.Stderr\n\t\tw.size = 0\n\t}\n}\n```\n\nNotice the critical error handling flaw:\n1. `w.f.Close()` is called to flush the file descriptor.\n2. In `w.rotate()`, `_ = os.Rename(w.path, w.path+\".1\")` silently discards the error returned by `os.Rename`.\n3. If `os.Rename(w.path, w.path+\".1\")` fails (for example, on Windows/POSIX filesystems under file lock contention, permission mismatch, or if a monitoring daemon/tail holds a read handle on the destination), `w.path` **remains unmoved on disk**!\n4. Then `w.open()` is called:\n   ```go\n   f, err := os.OpenFile(w.path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640)\n   ```\n   `w.open()` succeeds because `w.path` still exists, and sets `w.size = st.Size()`.\n5. On the very next log line (`w.Write(p)`):\n   ```go\n   if w.size > 0 && w.size+int64(len(p)) > w.maxSize {\n       w.rotate()\n   }\n   ```\n   Because `w.size` was not reset and is already greater than `w.maxSize`, `rotate()` is triggered on **every single log call in a tight infinite I/O loop**!\n6. If `maxFiles == 0`, `rotate()` silently executes `os.Remove(w.path)` discarding all operational logs.\n\n---\n\n## Vulnerable Code Locations\n\n- `logging/rotate.go:80-99`:\n  `rotate()` executes file rotation without checking return values of filesystem operations (`os.Remove`, `os.Rename`), leading to unhandled loop rotation states and silent file corruption.\n\n---\n\n## Attack & Failure Scenario\n\n1. A node operator runs the node daemon with logging configured to disk.\n2. An external log collector (like Promtail, Filebeat, or `tail -f`) monitors the log directory.\n3. When the log file hits 64MB (`DefaultMaxSizeMB`), `w.rotate()` is invoked.\n4. Due to an open read lock or concurrent file lock, `os.Rename(w.path, w.path+\".1\")` fails silently (`_ = os.Rename(...)`).\n5. `w.path` is re-opened with `w.size = 64MB`.\n6. For every subsequent log write (`node.Info`, consensus votes, peer messages), `w.size + len(p) > w.maxSize` evaluates to true:\n   - The node enters an aggressive I/O thrashing loop: `Close() -> Rename (fail) -> Open() -> Write()` on every single log event.\n7. CPU utilization spikes to 100%, disk I/O operations per second (IOPS) are saturated, and consensus message processing freezes, causing the validator to drop off the network.\n\n---\n\n## Impact\n\n1. **Validator Performance Degradation & Consensus Drop**:\n   Severe disk IOPS thrashing and CPU saturation lock the main process loop during logging events.\n2. **Permanent Audit Trail & Evidence Erasure**:\n   Silent rename and remove failures erase historical node incident records without alerting the operator.\n\n---\n\n## Remediation\n\nHandle filesystem errors during file rotation, back off if renames fail, and reset `w.size` safely:\n```go\nfunc (w *rotatingWriter) rotate() {\n\tif err := w.f.Close(); err != nil {\n\t\treturn\n\t}\n\tif w.maxFiles > 0 {\n\t\t_ = os.Remove(fmt.Sprintf(\"%s.%d\", w.path, w.maxFiles))\n\t\tfor i := w.maxFiles - 1; i >= 1; i-- {\n\t\t\t_ = os.Rename(fmt.Sprintf(\"%s.%d\", w.path, i), fmt.Sprintf(\"%s.%d\", w.path, i+1))\n\t\t}\n\t\tif err := os.Rename(w.path, w.path+\".1\"); err != nil {\n\t\t\t// If rename fails, avoid tight re-rotation loops by backing off or logging to stderr\n\t\t\tw.f = os.Stderr\n\t\t\tw.size = 0\n\t\t\treturn\n\t\t}\n\t} else {\n\t\t_ = os.Remove(w.path)\n\t}\n\tif err := w.open(); err != nil {\n\t\tw.f = os.Stderr\n\t\tw.size = 0\n\t}\n}\n```","patch_refs":[],"thread":[{"id":13291,"source":"desk","source_ref":"reply:11313","author":"Joseph Denne","team":true,"body":"Thanks for the report. It has been read against the code and is being handled.","created_at":"2026-11-20T00:34:15.415487+00:00"}]}