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:
w.f.Close()is called to flush the file descriptor.- In
w.rotate(),_ = os.Rename(w.path, w.path+".1")silently discards the error returned byos.Rename. - 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.pathremains unmoved on disk! - Then
w.open()is called:f, err := os.OpenFile(w.path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640)w.open()succeeds becausew.pathstill exists, and setsw.size = st.Size(). - On the very next log line (
w.Write(p)):
Becauseif w.size > 0 && w.size+int64(len(p)) > w.maxSize { w.rotate() }w.sizewas not reset and is already greater thanw.maxSize,rotate()is triggered on every single log call in a tight infinite I/O loop! - If
maxFiles == 0,rotate()silently executesos.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
- A node operator runs the node daemon with logging configured to disk.
- An external log collector (like Promtail, Filebeat, or
tail -f) monitors the log directory. - When the log file hits 64MB (
DefaultMaxSizeMB),w.rotate()is invoked. - Due to an open read lock or concurrent file lock,
os.Rename(w.path, w.path+".1")fails silently (_ = os.Rename(...)). w.pathis re-opened withw.size = 64MB.- For every subsequent log write (
node.Info, consensus votes, peer messages),w.size + len(p) > w.maxSizeevaluates to true:- The node enters an aggressive I/O thrashing loop:
Close() -> Rename (fail) -> Open() -> Write()on every single log event.
- The node enters an aggressive I/O thrashing loop:
- 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
- Validator Performance Degradation & Consensus Drop: Severe disk IOPS thrashing and CPU saturation lock the main process loop during logging events.
- 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.