Skip to content

fuzz: Stop nodes in process_message* fuzzers - #18875

Merged
maflcko merged 2 commits into
bitcoin:masterfrom
maflcko:2005-fuzzStopNodes
Jun 3, 2020
Merged

maflcko merged 2 commits into
bitcoin:masterfrom
maflcko:2005-fuzzStopNodes

Conversation

@maflcko

@maflcko maflcko commented May 4, 2020 •

Copy link
Copy Markdown
Member

Background is that I saw an integer overflow in net_processing

#30629113	REDUCE cov: 25793 ft: 142917 corp: 3421/2417Kb lim: 4096 exec/s: 89 rss: 614Mb L: 1719/4096 MS: 1 EraseBytes-
net_processing.cpp:977:25: runtime error: signed integer overflow: 2147483624 + 100 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net_processing.cpp:977:25 in 
net_processing.cpp:985:9: runtime error: signed integer overflow: -2147483572 - 100 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net_processing.cpp:985:9 in 

Telling from the line numbers, it looks like nMisbehavior wrapped around.

Fix that by calling StopNodes after each exec, which should clear the node state and thus nMisbehavior.

@fanquake fanquake added the Tests label May 5, 2020
@maflcko
maflcko force-pushed the 2005-fuzzStopNodes branch from fa987e3 to fa55e9b Compare May 10, 2020 11:44
@maflcko

maflcko commented May 10, 2020

Copy link
Copy Markdown
Member Author

Rebased. This can be tested with the following diff (observing a failure on master and a pass with this pull applied):

diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index a4d4953281..d68df49d34 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -804,6 +804,7 @@ void PeerLogicValidation::InitializeNode(CNode *pnode) {
     NodeId nodeid = pnode->GetId();
     {
         LOCK(cs_main);
+        assert(mapNodeState.find(nodeid) == mapNodeState.end());
         mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName), pnode->fInbound, pnode->m_manual_connection));
     }
     if(!pnode->fInbound)

@practicalswift

Copy link
Copy Markdown
Contributor

@MarcoFalke

Thanks for addressing this!

With this make-it-easy-to-reproduce patch applied …

diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index a4d495328..afa60d2e0 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -397,7 +397,7 @@ struct CNodeState {
         m_is_manual_connection (is_manual)
     {
         fCurrentlyConnected = false;
-        nMisbehavior = 0;
+        nMisbehavior = std::numeric_limits<int>::max() - 1000;
         fShouldBan = false;
         pindexBestKnownBlock = nullptr;
         hashLastUnknownBlock.SetNull();

… I'm still getting …

$ src/test/fuzz/process_message process_message/
net_processing.cpp:1021:25: runtime error: signed integer overflow: 2147483637 + 100 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net_processing.cpp:1021:25 in
net_processing.cpp:1029:9: runtime error: signed integer overflow: -2147483559 - 100 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net_processing.cpp:1029:9 in

… even with the suggested fix applied. What am I doing wrong? :)

@maflcko
maflcko force-pushed the 2005-fuzzStopNodes branch from fa16353 to fa17e3e Compare May 11, 2020 18:38
@maflcko

maflcko commented May 11, 2020 •

Copy link
Copy Markdown
Member Author

@practicalswift That is a separate issue in process_message. Fixed in 6666c82

@maflcko
maflcko force-pushed the 2005-fuzzStopNodes branch from fa17e3e to fab860a Compare May 12, 2020 11:28
@maflcko

maflcko commented Jun 2, 2020

Copy link
Copy Markdown
Member Author

@practicalswift Any chance you could test this again? 🙏

@practicalswift

Copy link
Copy Markdown
Contributor

@MarcoFalke

Sure! Confirming that I'm no longer able to reproduce the issue.

ACK fab860a

Thanks for fixing this issue!

@maflcko
maflcko merged commit 0f55294 into bitcoin:master Jun 3, 2020
@maflcko
maflcko deleted the 2005-fuzzStopNodes branch June 3, 2020 11:25
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 21, 2020
Summary:
```
Background is that I saw an integer overflow in net_processing

#30629113	REDUCE cov: 25793 ft: 142917 corp: 3421/2417Kb
lim: 4096exec/s: 89 rss: 614Mb L: 1719/4096 MS: 1 EraseBytes...
net_processing.cpp:977:25: runtime error: signed integer overflow:
2147483624 + 100 cannot be represented in type 'int'

UndefinedBehaviorSanitizer: undefined-behavior
net_processing.cpp:977:25 in
net_processing.cpp:985:9: runtime error: signed integer overflow:
-2147483572 - 100 cannot be represented in type 'int'
SUMMMARY: UndefinedBehaviorSanitizer: undefined-behavior
net_processing.cpp:985:9 in
```

Telling from the line numbers, it looks like nMisbehavior wrapped
around.

Fix that by calling StopNodes after each exec, which should clear the
node state and thus nMisbehavior.

Backport of core  [[bitcoin/bitcoin#18875 | PR18875]]

Test Plan:
  ninja bitcoin-fuzzers
  ./test/fuzz/test_runner.py <path_to_corpus>

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8710
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants