You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TMessageReader::Read allocates an unbounded wire-supplied length and underflows len - sizeof(TMessage) #39
TMessageReader::Read reads type and len from the socket and immediately calls NewHoldedMessage<TMessage>(type, len) and reads len - sizeof(TMessage) bytes (server.cpp#L25-L37):
len comes from the wire and has no upper bound: a peer or client can make the node allocate up to 4 GiB per frame (new char[len] in messages.h#L211-L218), and the same for each of the Nentries payload frames read recursively (server.cpp#L38-L46).
len >= sizeof(TMessage) is only an assert inside NewMessage. In a release build a smaller len makes len - sizeof(TMessage) wrap around (unsigned arithmetic) and the reader tries to read about 4 GiB into a tiny buffer: a heap overflow.
type is not checked against the known message types.
The same reader is used for client connections (server.cpp#L125), so any client that can connect can trigger this.
Scenario
A client connects and sends 8 bytes: type = 1, len = 0. In a build without asserts the node allocates 0 bytes and then reads 0 - sizeof(TMessage) (about 4 GiB) bytes into it. With len = 0xFFFFFFFF it allocates 4 GiB and waits for the data. Either way one unauthenticated connection takes the node down or exhausts its memory.
Expected
Validate type and len (known type, len >= sizeof(TMessage), and len bounded by a sane maximum) before allocating, and fail the connection with an error instead of allocating.
PR #31 (closed, not merged) has the reader fix in b36e5b1 (the core of that commit; the batch limits in the rest of it can follow separately). Tests that cover it: the reader cases of test/test_network_frames.cpp. Since the PR is closed, the fix would come as a separate small PR.
Activity