Bounty
XE-9899 · Bounty

Node Observability / Disk Exhaustion: rotatingWriter.rotate ignores file rename errors causing log file truncation and permanent log loss

Triaging web filed 2026-11-12 08:13 UTC by xe:e4cd6974

Report

Vulnerability Summary

In logging/rotate.go:80-99, rotatingWriter.rotate() implements file rotation when active node logs exceed maxSize:

func (w *rotatingWriter) rotate() {
	if err := w.f.Close(); err != nil {
		return
	}
	if w.maxFiles > 0 {
		_ = os.Remove(fmt.Sprintf("%s.%d", w.path, w.maxFiles))
		for i := w.maxFiles - 1; i >= 1; i-- {
			_ = os.Rename(fmt.Sprintf("%s.%d", w.path, i), fmt.Sprintf("%s.%d", w.path, i+1))
		}
		_ = os.Rename(w.path, w.path+".1")
	} else {
		_ = os.Remove(w.path)
	}
	if err := w.open(); err != nil {
		// Fallback to stderr if we can no longer write to disk
		w.f = os.Stderr
		w.size = 0
	}
}

Notice the critical error handling flaw:

  1. w.f.Close() is called to flush the file descriptor.
  2. In w.rotate(), _ = os.Rename(w.path, w.path+".1") silently discards the error returned by os.Rename.
  3. 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!
  4. Then w.open() is called:
    f, err := os.OpenFile(w.path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640)
    
    w.open() succeeds because w.path still exists, and sets w.size = st.Size().
  5. On the very next log line (w.Write(p)):
    if w.size > 0 && w.size+int64(len(p)) > w.maxSize {
        w.rotate()
    }
    
    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!
  6. If maxFiles == 0, rotate() silently executes os.Remove(w.path) discarding all operational logs.

Vulnerable Code Locations

  • logging/rotate.go:80-99: 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.

Attack & Failure Scenario

  1. A node operator runs the node daemon with logging configured to disk.
  2. An external log collector (like Promtail, Filebeat, or tail -f) monitors the log directory.
  3. When the log file hits 64MB (DefaultMaxSizeMB), w.rotate() is invoked.
  4. Due to an open read lock or concurrent file lock, os.Rename(w.path, w.path+".1") fails silently (_ = os.Rename(...)).
  5. w.path is re-opened with w.size = 64MB.
  6. For every subsequent log write (node.Info, consensus votes, peer messages), w.size + len(p) > w.maxSize evaluates to true:
    • The node enters an aggressive I/O thrashing loop: Close() -> Rename (fail) -> Open() -> Write() on every single log event.
  7. 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.

Impact

  1. Validator Performance Degradation & Consensus Drop: Severe disk IOPS thrashing and CPU saturation lock the main process loop during logging events.
  2. Permanent Audit Trail & Evidence Erasure: Silent rename and remove failures erase historical node incident records without alerting the operator.

Remediation

Handle filesystem errors during file rotation, back off if renames fail, and reset w.size safely:

func (w *rotatingWriter) rotate() {
	if err := w.f.Close(); err != nil {
		return
	}
	if w.maxFiles > 0 {
		_ = os.Remove(fmt.Sprintf("%s.%d", w.path, w.maxFiles))
		for i := w.maxFiles - 1; i >= 1; i-- {
			_ = os.Rename(fmt.Sprintf("%s.%d", w.path, i), fmt.Sprintf("%s.%d", w.path, i+1))
		}
		if err := os.Rename(w.path, w.path+".1"); err != nil {
			// If rename fails, avoid tight re-rotation loops by backing off or logging to stderr
			w.f = os.Stderr
			w.size = 0
			return
		}
	} else {
		_ = os.Remove(w.path)
	}
	if err := w.open(); err != nil {
		w.f = os.Stderr
		w.size = 0
	}
}

Thread

Joseph Denneteam2026-11-20 00:34 UTCdesk

Thanks for the report. It has been read against the code and is being handled.