fix(uptime_proof): validate version-list sizes before fixed-array writes#195
Open
raw391 wants to merge 2 commits into
Open
fix(uptime_proof): validate version-list sizes before fixed-array writes#195raw391 wants to merge 2 commits into
raw391 wants to merge 2 commits into
Conversation
The Proof deserializer at uptime_proof.cpp:44-89 reads three version lists (v, sv, lv) from a peer-supplied bt-encoded blob and writes each into a fixed-size array (version[], storage_server_version[], belnet_version[]) without checking the list size first. A peer that sends a list with more entries than the array can hold writes past the end of the struct. This deserializer runs on every incoming uptime proof before any signature check downstream, so a malformed proof reaches this loop without prior validation. Adds an exact-size check before each write loop. The constructor already wraps everything in try/catch, so the throw becomes a cleanly-rejected proof rather than a corruption.
The invalid_argument throw added in the previous commit propagates out of std::make_unique<uptime_proof::Proof>. Wrap at the caller in core::handle_btencoded_uptime_proof so a malformed proof becomes a rejected proof rather than a propagating exception.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Proof::Proof(const std::string& serialized_proof)deserializer atsrc/cryptonote_core/uptime_proof.cpp:44-89reads three version lists (v,sv,lv) from a bt-encoded peer-supplied blob into three fixed-size 3-element arrays (version[],storage_server_version[],belnet_version[]) without first checking that each bt_list has 3 entries:A peer that sends a proof whose
vlist has more than 3 entries walks past the end ofversion[]into adjacent members of theProofstruct on the heap (the constructor is invoked viastd::make_uniqueatcryptonote_core.cpp:1994). The constructor runs before any signature check downstream.Patch adds an exact-size guard before each write loop, and wraps the
make_uniquecall site in try/catch so a malformed proof becomes a rejected proof rather than a propagating exception:const bt_list& bt_version = var::get<bt_list>(bt_proof.at("v")); + if (bt_version.size() != version.size()) + throw std::invalid_argument("uptime proof: invalid mnode_version list size"); int k = 0; for (bt_value const &i: bt_version){ version[k++] = static_cast<uint16_t>(get_int<unsigned>(i)); }(Plus matching guards for
svandlv.)bool core::handle_btencoded_uptime_proof(...) { crypto::x25519_public_key pkey = {}; - auto proof = std::make_unique<uptime_proof::Proof>(req.proof); + std::unique_ptr<uptime_proof::Proof> proof; + try + { + proof = std::make_unique<uptime_proof::Proof>(req.proof); + } + catch (const std::exception &e) + { + MWARNING("Failed to parse uptime proof: " << e.what()); + return false; + } proof->sig = tools::make_from_guts<crypto::signature>(req.sig);Exact-match (
!=) rather than>because a short list would leave the trailing array slots uninitialized.