policy: reject invalid CFeeRate values when deserializing #36816

Open
ryanofsky wants to merge 1 commit from pr/feerate-unser into master AGit
ryanofsky commented 2026-11-09 16:37:19 +00:00 (Migrated from github.com)

Problem: With the UnstableChain IPC interface from #29409 merged, an IPC client could make bitcoin-node hit an Assume failure (debug builds) or compute wrong fees (release builds) by passing a malformed feerate to broadcastTransaction, calculateIndividualBumpFees or calculateCombinedBumpFee. These methods take feerates as serialized Data fields, and CFeeRate deserialization reads the fee and size without the checks its constructors do, so it accepts a negative size, which fee calculations require to be positive, and a zero size with a nonzero fee, which compares as an infinite feerate. Nothing deserializes a CFeeRate on master today.

Solution: Make CFeeRate deserialization throw on values its constructors cannot produce, the same way other malformed serialized data is rejected. The change is a SER_READ check in src/policy/feerate.h plus a unit test. It is similar to #36520, which handles other invalid arguments to Chain IPC methods.

This issue was found by Project Loupe and passed on by instagibbs.

**Problem:** With the `UnstableChain` IPC interface from #29409 merged, an IPC client could make `bitcoin-node` hit an `Assume` failure (debug builds) or compute wrong fees (release builds) by passing a malformed feerate to `broadcastTransaction`, `calculateIndividualBumpFees` or `calculateCombinedBumpFee`. These methods take feerates as serialized `Data` fields, and `CFeeRate` deserialization reads the fee and size without the checks its constructors do, so it accepts a negative size, which fee calculations require to be positive, and a zero size with a nonzero fee, which compares as an infinite feerate. Nothing deserializes a `CFeeRate` on master today. **Solution:** Make `CFeeRate` deserialization throw on values its constructors cannot produce, the same way other malformed serialized data is rejected. The change is a `SER_READ` check in `src/policy/feerate.h` plus a unit test. It is similar to #36520, which handles other invalid arguments to `Chain` IPC methods. This issue was found by Project Loupe and passed on by instagibbs.
DrahtBot commented 2026-11-09 16:37:33 +00:00 (Migrated from github.com)

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

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36816 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36816.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36816#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--5faf32d7da4f0f540f40219e4f7537a3-->
maflcko commented 2026-11-09 16:49:00 +00:00 (Migrated from github.com)

Can the IPC client not still cause aborts via ftrapv or incorrect results, by just passing a feerate so large that it overflows later calculations?

Can the IPC client not still cause aborts via ftrapv or incorrect results, by just passing a feerate so large that it overflows later calculations?
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 1c6060e7f675 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:7eebed8027c96ac27bcd79eeb7a88e35799cd96eb8fbacf34d3257986a959f64:6952af7d31ef83bb85ac4ee73e8c979307f4998f73396eb2a639b474cdfe83e6 --> <!-- ralph-base:44901d8f64cb617714707bd025ecd83f108353c2 --> <!-- ralph-head:1c6060e7f6758f645bf5172cfc0ce2942a785b44 --> <!-- ralph-case:a0c38b9173b75cd141db6cb088c46dbf05ff14c049f46245697a572d87fe9054 --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`1c6060e7f675`](<https://git.fish.foo/bitcoin/bitcoin/commit/1c6060e7f6758f645bf5172cfc0ce2942a785b44>) · [Review report](<https://review.fish.foo/report/36816-1c6060e7f6758f645bf5172cfc0ce2942a785b44-2421-1.html>) · [Previous reports](<https://review.fish.foo/traces/36816/>) [permalink](<https://review.fish.foo/report/36816-1c6060e7f6758f645bf5172cfc0ce2942a785b44-2421-1.html>)
ryanofsky commented 2026-11-09 17:26:25 +00:00 (Migrated from github.com)

re: https://github.com/bitcoin/bitcoin/pull/36816#issuecomment-6745849877

Can the IPC client not still cause aborts via ftrapv or incorrect results, by just passing a feerate so large that it overflows later calculations?

This might be possible, and if it is, it seems like the type of fix that would belong in #36520, which adds extra error checking to IPC methods, since it's not specific to the CFeeRate class and could happen with other numeric arguments.

Or if you're suggesting the problem here does not necessarily need to be solved, and it's ok for debug builds to crash and release builds to produce bad results if they are given bad values, maybe that could make sense too.

This PR is narrower: it only rejects serialized values that CFeeRate's constructors can't produce, like a negative size, which hits Assume(size > 0) in FeeFrac::EvaluateFee. A feerate that's valid but too large for later calculations is a range problem, the same one RPC methods avoid by bounding feerates in ParseFeeRate, so I'd check it where the IPC method receives the value.

re: https://github.com/bitcoin/bitcoin/pull/36816#issuecomment-6745849877 > Can the IPC client not still cause aborts via ftrapv or incorrect results, by just passing a feerate so large that it overflows later calculations? This might be possible, and if it is, it seems like the type of fix that would belong in #36520, which adds extra error checking to IPC methods, since it's not specific to the CFeeRate class and could happen with other numeric arguments. Or if you're suggesting the problem here does not necessarily need to be solved, and it's ok for debug builds to crash and release builds to produce bad results if they are given bad values, maybe that could make sense too. This PR is narrower: it only rejects serialized values that CFeeRate's constructors can't produce, like a negative size, which hits `Assume(size > 0)` in `FeeFrac::EvaluateFee`. A feerate that's valid but too large for later calculations is a range problem, the same one RPC methods avoid by bounding feerates in `ParseFeeRate`, so I'd check it where the IPC method receives the value.
maflcko commented 2026-11-10 08:07:57 +00:00 (Migrated from github.com)

Ok, I see. Maybe turn this into a draft for now, given that it modifies dead/unreachable code and depends on https://github.com/bitcoin/bitcoin/pull/29409, which is not a draft, but again depends on https://github.com/bitcoin-core/libmultiprocess/pull/377?

Once the code is reachable, a small dummy test of the form https://github.com/bitcoin/bitcoin/pull/36093 could be added to this pull?

Ok, I see. Maybe turn this into a draft for now, given that it modifies [dead](https://github.com/bitcoin/bitcoin/pull/22962)/unreachable code and depends on https://github.com/bitcoin/bitcoin/pull/29409, which is not a draft, but again depends on https://github.com/bitcoin-core/libmultiprocess/pull/377? Once the code is reachable, a small dummy test of the form https://github.com/bitcoin/bitcoin/pull/36093 could be added to this pull?
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36816
No description provided.