Skip to content

Conversation

@stickies-v
Copy link
Contributor

Avoid out-of-bounds user input for PeerManager::Options by safely clamping -maxorphantx and -blockreconstructionextratxn, and avoid platform-specific behaviour by changing PeerManager::Options::max_extra_txs from size_t to a uint32_t. Addresses #27499 (review).

Also documents all PeerManager::Options members, addressing #27499 (comment).

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 25, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK dergoegge, glozow

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@DrahtBot DrahtBot added the P2P label Jul 25, 2023
@stickies-v stickies-v changed the title Net processing: clamp PeerManager::Options user input net processing: clamp PeerManager::Options user input Jul 25, 2023
Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

utACK 128ad03792cd4aeeaf32807d07f01e3f85adaf28

Thanks for the followup

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

Concept ACK

@stickies-v stickies-v force-pushed the 2023-07/peerman-opts-check-bounds branch from 128ad03 to 547fa52 Compare July 25, 2023 20:53
Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

Code review ACK 547fa52

@DrahtBot DrahtBot requested a review from glozow August 7, 2023 13:35

if (auto value{argsman.GetIntArg("-maxorphantx")}) {
options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value));
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max())));
Copy link
Member

Choose a reason for hiding this comment

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

unrelated: May be good to write a clang-tidy plugin to enforce the limits are compile-time constants and in range to avoid silent UB at runtime?

The in-range one can be submitted to upstream and the other check can be done in this repo.


if (auto value{argsman.GetIntArg("-maxorphantx")}) {
options.max_orphan_txs = uint32_t(std::max(int64_t{0}, *value));
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max())));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
options.max_orphan_txs = uint32_t((std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max())));
options.max_orphan_txs = uint32_t(std::clamp<int64_t>(*value, 0, std::numeric_limits<uint32_t>::max()));

nit, if you re-touch?

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

reACK 547fa52

@glozow glozow merged commit 0d9a13d into bitcoin:master Aug 9, 2023
@stickies-v stickies-v deleted the 2023-07/peerman-opts-check-bounds branch August 9, 2023 12:43
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 9, 2023
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jul 12, 2024
Summary:
Document PeerManager::Options members.

Clamp -maxorphantx to uint32_t bounds.

Clamp -blockreconstructionextratxn to uint32_t bounds.
Also changes max_extra_txs into a uint32_t to avoid platform-specific behaviour.

-maxaddrtosend is hidden option used only for tests,  so we only do minimal boundary checks.

This is a backport of [[ bitcoin/bitcoin#28149 | core#28149 ]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16456
roqqit pushed a commit to doged-io/doged that referenced this pull request Aug 1, 2024
Summary:
Document PeerManager::Options members.

Clamp -maxorphantx to uint32_t bounds.

Clamp -blockreconstructionextratxn to uint32_t bounds.
Also changes max_extra_txs into a uint32_t to avoid platform-specific behaviour.

-maxaddrtosend is hidden option used only for tests,  so we only do minimal boundary checks.

This is a backport of [[ bitcoin/bitcoin#28149 | core#28149 ]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D16456
@bitcoin bitcoin locked and limited conversation to collaborators Aug 8, 2024
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.

5 participants