ExecuteTallyVM has a memory leak which will lead to nodes eventually crashing
The ExecuteTallyVM function allocates a C string for the log directory but never frees it, causing a small memory leak each time it runs. Over time, as the node processes blocks, this leak accumulates and can eventually exhaust memory, leading to degraded performance and node crashes.
Source: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/182
Found by
Boy2000, g, gxh191, tallo, zxriptor
Summary
The continuous memory allocation without freeing in execute.go will cause a memory leak for node operators as each block will lose a small amount of memory, eventually depleting the node's resources over extended operation periods.
Root Cause
In execute.go the configDirC C string is allocated with C.CString(LogDir) but never freed with C.free(unsafe.Pointer(configDirC)), unlike all other C string allocations in the same function.
Internal Pre-conditions
- The SEDA node is running and processing blocks
- The
ExecuteTallyVmfunction is called from theEndBlockfunction - The
LogDirglobal variable is set to a non-empty string path
External Pre-conditions
None
Attack Path
- The Tally module's
EndBlockfunction is called automatically at the end of each block - This calls
ProcessTallieswhich processes data requests ready for tallying - For each tally operation, the
FilterAndTallymethod is invoked - This ultimately executes the
ExecuteTallyVmfunction inexecute.go - Each execution allocates memory for
configDirCwithout freeing it - The allocated memory accumulates over time as each block is processed
- Eventually, after running for an extended period, the node will run out of memory
Impact
The SEDA node operators suffer a continuous memory leak that will eventually lead to degraded performance and potential node crashes. The amount of memory leaked per block is equal to the length of the LogDir string plus 1 byte (for the null terminator).
For a typical path length of ~30 bytes, /home/seda/.seda/tally-logs\00, a default MaxTalliesPerBlock of 100, and an average of 20 data requests per block, this will add up to ~3gb of allocated memory that is leaked each year. Longer paths, more data requests per block will result in a faster leakage and result in an eventual crash for all systems. Systems with lower specs will crash sooner rather than later
Mitigation
just like with all the other C.Cstring initializations in the function, add the line:
defer C.free(unsafe.Pointer(configDirC)
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/sedaprotocol/seda-wasm-vm/pull/60
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The C string allocated for the log directory is not freed, unlike other similar allocations in the same function.
Impact
The memory leak could degrade performance and eventually crash nodes, with the leak rate depending on path length and request volume.
What the attacker needed
SEDA node running and processing blocks; LogDir set to a non-empty string path
The fix
The issue was fixed by adding a defer statement to free the allocated C string, as done for other similar allocations.
How it was found
- The Tally module's EndBlock function is called automatically at the end of each block
- This calls ProcessTallies which processes data requests ready for tallying
- For each tally operation, the FilterAndTally method is invoked
- This ultimately executes the ExecuteTallyVm function in execute.go
- Each execution allocates memory for configDirC without freeing it
- The allocated memory accumulates over time as each block is processed
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program asks the computer for memory, it should give it back when done. Here, a small piece of memory is requested every time a block is processed but never returned. Over many blocks, this adds up and can make the node run out of memory and crash.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.