fix(tx_pool): guard master node lookup before key_image_unlock dereference#193
Open
raw391 wants to merge 1 commit into
Open
fix(tx_pool): guard master node lookup before key_image_unlock dereference#193raw391 wants to merge 1 commit into
raw391 wants to merge 1 commit into
Conversation
…rence In tx_pool::add_tx, the key_image_unlock handler calls get_master_node_details(mnode_key) without first verifying that mnode_key is a registered master node. The accessor dereferences the iterator returned by find() unconditionally, so an unknown mnode_key causes a segfault. mnode_key is read from the incoming transactions tx_extra, so it is attacker-controlled. Patch (a) checks existence at the caller via is_master_node() before the lookup, and (b) makes the accessor throw on a missing key so other callsites of get_master_node_details cant hit the same shape. The caller already handles thrown exceptions as failed verification.
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.
In
tx_pool::add_tx, thekey_image_unlockhandler atcryptonote_core/tx_pool.cpp:264-298callsget_master_node_details(mnode_key)without first verifying thatmnode_keyexists in the master-node registry.mnode_keyis read from the incoming transactions extra field (get_master_node_pubkey_from_tx_extra) and is attacker-controlled. The accessor atmaster_node_list.cpp:876-880dereferencesfind()unconditionally:For an unknown
mnode_keythe iterator equalsend()and the dereference is undefined behaviour. A peer that relays atxtype::key_image_unlocktransaction carrying an arbitrary master node pubkey reaches this path before any expensive validation.Patch adds the existence check at the caller via the existing
is_master_nodewrapper (master_node_list.h:433), which is already used elsewhere in the codebase:It also makes the accessor throw on a missing key, matching the early-return pattern at
master_node_list.cpp:660-661:master_node_info master_node_list::state_t::get_master_node_details(crypto::public_key mnode_key) { auto it = master_nodes_infos.find(mnode_key); + if (it == master_nodes_infos.end()) + throw std::invalid_argument("get_master_node_details: master node not found"); return *it->second; }The caller guard is the actual fix. The accessor throw is so other call sites of
get_master_node_detailsare not left with the same shape.