-
Notifications
You must be signed in to change notification settings - Fork 1.2k
llmq/signing_shares: guard quorumMember indexing with Assume() to avoid OOB writes; improve ToInvString() safety #6866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||||||||||||||||||
#include <net_processing.h> | ||||||||||||||||||||||
#include <netmessagemaker.h> | ||||||||||||||||||||||
#include <spork.h> | ||||||||||||||||||||||
#include <util/check.h> | ||||||||||||||||||||||
#include <util/irange.h> | ||||||||||||||||||||||
#include <util/thread.h> | ||||||||||||||||||||||
#include <util/time.h> | ||||||||||||||||||||||
|
@@ -93,7 +94,9 @@ std::string CBatchedSigShares::ToInvString() const | |||||||||||||||||||||
// we use 400 here no matter what the real size is. We don't really care about that size as we just want to call ToString() | ||||||||||||||||||||||
inv.Init(400); | ||||||||||||||||||||||
for (const auto& sigShare : sigShares) { | ||||||||||||||||||||||
inv.inv[sigShare.first] = true; | ||||||||||||||||||||||
if (Assume(sigShare.first < inv.inv.size())) { | ||||||||||||||||||||||
inv.inv[sigShare.first] = true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return inv.ToString(); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -1088,7 +1091,7 @@ void CSigSharesManager::CollectSigSharesToAnnounce(const CConnman& connman, | |||||||||||||||||||||
|
||||||||||||||||||||||
auto& session = nodeState.GetOrCreateSessionFromShare(*sigShare); | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (session.knows.inv[quorumMember]) { | ||||||||||||||||||||||
if (Assume(quorumMember < session.knows.inv.size()) && session.knows.inv[quorumMember]) { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how this can ever happen because invalid sigshare received from another peer shouldn't get this far. We check it in
We shouldn't create invalid sigshares ourselves either. But anyway... I think we should
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I'm looking at it again; what if we wrap these raw datastructs like Would this be better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internal logic won't be able to clean things up though so we could end up in a half-processed state which can potentially cause issues down the line I guess. |
||||||||||||||||||||||
// he already knows that one | ||||||||||||||||||||||
continue; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
@@ -1099,8 +1102,12 @@ void CSigSharesManager::CollectSigSharesToAnnounce(const CConnman& connman, | |||||||||||||||||||||
assert(llmq_params_opt.has_value()); | ||||||||||||||||||||||
inv.Init(llmq_params_opt->size); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
inv.inv[quorumMember] = true; | ||||||||||||||||||||||
session.knows.inv[quorumMember] = true; | ||||||||||||||||||||||
if (Assume(quorumMember < inv.inv.size())) { | ||||||||||||||||||||||
inv.inv[quorumMember] = true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+1105
to
+1107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Would rather drop all potentially invalid data and
Suggested change
|
||||||||||||||||||||||
if (Assume(quorumMember < session.knows.inv.size())) { | ||||||||||||||||||||||
session.knows.inv[quorumMember] = true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+1108
to
+1110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just checked it above, no extra
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.