Pp deserialization denial of service issue
The peer-to-peer message deserialisation code reads array lengths from the incoming stream without any upper bound, so a malformed request can declare a huge number of elements. An attacker could send such a request to exhaust Node.js memory and crash the node, causing a remote denial of service.
- Disclosed after under an hour
34364 - [BC - Insight] pp deserialization denial of service issue
Submitted on Aug 10th 2024 at 16:46:07 UTC by @gln for Boost | Shardeum: Core
Report ID: #34364
Report type: Blockchain/DLT
Report severity: Insight
Target: https://github.com/shardeum/shardus-core/tree/dev
Impacts:
- RPC API crash affecting projects with greater than or equal to 25% of the market capitalization on top of the respective layer
- Unintended chain split (network partition)
Description
Brief/Intro
When parsing incoming p2p messages, the code does not have any upper bounds check on sizes of incoming arrays.
Malformed p2p requests could trigger out of memory issue in nodejs and crash the server.
Vulnerability Details
Let's look at the code https://github.com/shardeum/shardus-core/blob/dev/src/types/GetTrieHashesReq.ts#L25
export function deserializeGetTrieHashesReq(stream: VectorBufferStream): GetTrieHashesRequest {
const version = stream.readUInt8()
if (version > cGetTrieHashesReqVersion) {
throw new Error('Unsupported version in deserializeGetTrieHashesReq')
}
const length = stream.readUInt32()
const radixList = []
for (let i = 0; i < length; i++) {
radixList.push(stream.readString())
}
return { radixList }
}
Another similar example from https://github.com/shardeum/shardus-core/blob/dev/src/types/RequestStateForTxReq.ts#L26
export function deserializeRequestStateForTxReq(stream: VectorBufferStream): RequestStateForTxReq {
const version = stream.readUInt8()
if (version !== cRequestStateForTxReqVersion) {
throw new Error('Unsupported version')
}
const txid = stream.readString()
const timestamp = parseInt(stream.readString())
const keysLength = stream.readUInt32()
const keys = new Array<string>(keysLength)
for (let i = 0; i < keysLength; i++) {
keys[i] = stream.readString()
}
return { txid, timestamp, keys }
}
Here there is no upper-bound limit on keysLength variable.
Attacker could send the large number of keys and trigger out of memory error in nodejs.
Impact Details
Remote denial of service issues (remote crash, requires restart).
Proof of Concept
How to reproduce:
- get proof of concept by using provided gist link
- set memory limit :
$ ulimit -Sv 2000000
``
3) run poc:
$ node test1.js
... FATAL ERROR: Scavenger: semi-space copy Allocation failed - JavaScript heap out of memory ----- Native stack trace -----
1: 0xb84bd6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node] 1: 0xb84bd6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node] 2: 0xefec30 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 1: 0xb84bd6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node] 2: 0xefec30 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 2: 0xefec30 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 3: 0xefef17 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node] 4: 0x1110925 [node] 5: 0x11a2566 heap::base::SlotCallbackResult v8::internal::Scavenger::EvacuateShortcutCandidatev8::internal::FullHeapObjectSlot(v8::internal::Map, v8::internal::FullHeapObjectSlot, v8::internal::ConsString, int) [node] 6: 0x11a71e9 heap::base::SlotCallbackResult v8::internal::Scavenger::ScavengeObjectv8::internal::FullHeapObjectSlot(v8::internal::FullHeapObjectSlot, v8::internal::HeapObject) [node] ... ...
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 deserialisation functions read a length field from the network stream and use it to allocate or loop without checking it against a sane maximum.
Impact
A remote attacker could crash a node by causing an out-of-memory error, leading to a denial of service that requires a restart and potentially a network partition.
What the attacker needed
Ability to send p2p messages to a node
How it was found
- Obtain the proof-of-concept script from the provided gist link.
- Set a memory limit for the process using ulimit.
- Run the proof-of-concept script with Node.js.
- Observe the fatal out-of-memory error and crash.
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 two nodes talk to each other, they send messages that include a number saying how many items follow. The code trusts that number and tries to create that many items in memory. If someone sends a very large number, the program runs out of memory and crashes.
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.