Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Security fix 1 - drop unknown getdata messages #312

Merged
merged 4 commits into from
Sep 12, 2024

Conversation

Naviabheeman
Copy link
Contributor

Port fixes from bitcoin:
PR 18808 - Drop unknown types in getdata
PR 19109 - Only allow getdata of recently announced invs
Add functional test to verify that unknown get data does not halt the peer and transitions that were not in recently announced invs are not replied

@@ -298,6 +299,7 @@ def on_reject(self, message): pass
def on_sendcmpct(self, message): pass
def on_sendheaders(self, message): pass
def on_tx(self, message): pass
#def on_notfound(self, message): pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to add this commented out line.

@@ -44,6 +45,10 @@
static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
/** Minimum time between orphan transactions expire time checks in seconds */
static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
/** How long to cache transactions in mapRelay for normal relay */
static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME = std::chrono::minutes{15};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant you added is unreferenced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, even in bitcoin it's not used. It was defined by PR 18808. But after the logic was changed, this became unused. I'll remove it.

@@ -251,6 +265,9 @@ struct CNodeState {
*/
bool fSupportsDesiredCmpctVersion;

//! A rolling bloom filter of all announced tx CInvs to this peer.
CRollingBloomFilter vRecentlyAnnouncedInvs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the name the same makes it easier to track changes in Bitcoin.

Suggested change
CRollingBloomFilter vRecentlyAnnouncedInvs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001};
CRollingBloomFilter m_recently_announced_invs = CRollingBloomFilter{INVENTORY_MAX_RECENT_RELAY, 0.000001};

}

CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, mempool_req, now);
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like Bitcoin, put it inside the if(tx) branch, otherwise it will not be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand the change. do you mean move the variable int nSendFlags inside if?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

@Naviabheeman Naviabheeman force-pushed the securityFix1_unknown_getdata branch from 6dd7081 to ca0bf4d Compare September 11, 2024 06:30
@azuchi azuchi merged commit 042d7cd into chaintope:master Sep 12, 2024
10 checks passed
@Naviabheeman Naviabheeman deleted the securityFix1_unknown_getdata branch February 20, 2025 05:51
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants