-
Notifications
You must be signed in to change notification settings - Fork 37.7k
psbt: check that various indexes and amounts are within bounds #17156
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
Conversation
Concept ACK Thanks for addressing these issues quickly! :) Will test. |
fcb2421
to
545e0e5
Compare
With this patch applied the PSBT fuzzer appears to be unable to trigger the problematic conditions listed in the issue #17149. However, I noticed that using the following 202 byte input:
The following UBSan condition is triggered:
Might be worth tackling that one as well? |
What do I need to run in order to get the same error? |
Something like this:
|
Not sure how to translate the base16 seed into a binary seed with the command line, though |
:) |
:) |
I'm not really sure why that happens.
fixes the problem, but it's more signing code than not. ISTM we should see this elsewhere too but it doesn't seem like it. |
Isn't the difference that the move assignment operator is used in this case whereas the other non-warning cases you're referring to use the copy assignment operator? If I'm correct then these two should trigger the UBSan warning:
Whereas this won't trigger the UBSan warning:
Could that be the case? |
What I meant was that we should see this same error for any fuzzers that hit ProduceSignature. But I think we just don't have any fuzzers that reach ProduceSignature. |
I've added a commit which adds a copy constructor and copy |
@achow101 Good! Then we should be able to get rid of this UBSan suppression? :)
|
Judging from my testing we can get rid of both these UBSan suppressions as part of this PR: bitcoin/test/sanitizer_suppressions/ubsan Lines 1 to 2 in b8f041a
Great! |
9668444
to
db30e5b
Compare
ACK db30e5b assuming Travis is happy too -- diff looks correct |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
db30e5b
to
d447b94
Compare
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin#17156 (comment) and bitcoin#17510.
… within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of #17156, non-trivial due to crossing the refactor in #17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
- [0.19] wallet: Reset reused transactions cache bitcoin#18083 - 0.19: Backports bitcoin#17792 - psbt: handle unspendable psbts bitcoin#17524 - qt: Fix comparison function signature bitcoin#17634 - psbt: check that various indexes and amounts are within bounds bitcoin#17156 - [0.19] psbt: check that various indexes and amounts are within bounds bitcoin#18079 - [0.19] Final backports for 0.19.1 bitcoin#17988 - Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash bitcoin#17924 - qt: Fix deprecated QCharRef usage bitcoin#18101 - gui: Throttle GUI update pace when -reindex bitcoin#18121 - gui: Fix race in WalletModel::pollBalanceChanged bitcoin#18123 - gui: Fix unintialized WalletView::progressDialog bitcoin#18062 - Bugfix: GUI: Hide the HD/encrypt icons earlier so they get re-shown if another wallet is open bitcoin#18007 - bug-fix macos: give free bytes to F_PREALLOCATE bitcoin#17887 - test: add missing #include to fix compiler errors bitcoin#17980 - zmq: Fix due to invalid argument and multiple notifiers bitcoin#17445
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. This is a partial port of Core #17708. Pull request description: Ensure prevector data is appropriately aligned. Earlier discussion in #17530. In contrast to #17530, it does this without increase in size of any of the coin cache data structures (x86_64, clang) | Struct | (size,align) before | (size,align) after | | ---------------- | ------------------- | ------------------- | | Coin | 48, 8 | 48, 8 | | CCoinsCacheEntry | 56, 8 | 56, 8 | | CScript | 32, 1 | 32, 8 |
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin#17156 (comment) and bitcoin#17510.
Summary: ``` `#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. ``` Backport of core [[bitcoin/bitcoin#17708 | PR17708]]. Test Plan: With and without UBSAN: ninja check Reviewers: #bitcoin_abc, nakihito Reviewed By: nakihito Differential Revision: https://reviews.bitcoinabc.org/D5986
Summary: ``` `#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510. ``` Backport of core [[bitcoin/bitcoin#17708 | PR17708]]. Test Plan: With and without UBSAN: ninja check Reviewers: #bitcoin_abc, nakihito Reviewed By: nakihito Differential Revision: https://reviews.bitcoinabc.org/D5986
Summary: * Don't calculate tx fees for PSBTs with invalid money values In decodepsbt if an invalid amount is seen, don't calculate the fee but still show the invalid value in the decode. In analyze psbt, if an invalid amount is seen, set the next step to be the creator as the creator needs to remake the transaction so that it is valid. * psbt: check output index is within bounds before accessing This is a backport of Core [[bitcoin/bitcoin#17156 | PR17156]] Because we only have segwit style UTXO due to our signature algorithm, some checks and test case are not relevent to us. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: PiRK Differential Revision: https://reviews.bitcoinabc.org/D8092
… within bounds deaa6dd psbt: check output index is within bounds before accessing (Andrew Chow) f1ef7f0 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Fixes bitcoin#17149 Two classes of issues were found by the psbt fuzzer: values out of range and causing overflows, and prevout indexes being out of range. This PR fixes both. When accessing a specific output using the index given in the tx, check that it is actually a possible output before trying to access the output. When summing and checking amounts for `decodepsbt` and `analyzepsbt`, make sure that the values are actually valid money values.. Otherwise, stop summing and don't show the fee. For `analyzepsbt`, return that the next role is the Creator since the Creator needs to remake the transaction to be valid. ACKs for top commit: practicalswift: ACK deaa6dd -- only change since last ACK was the addition of tests gwillen: tested ACK deaa6dd, would also like to see this merged! Tree-SHA512: 06c36720bbb5a7ab1c29f7d15878bf9f0d3e5760c06bff479d412e1bf07bb3e0e9ab6cca820a4bfedaab71bfd7af813807e87cbcdf0af25cc3f66a53a06dbcfd
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510.
`#pragma pack(1)` prevents aligning the struct and its members to their required alignment. This can result in code that performs non-aligned reads and writes to integers and pointers, which is problematic on some architectures. It also triggers UBsan — see bitcoin/bitcoin#17156 (comment) and #17510.
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…and amounts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…and amounts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…and amounts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
Fixes #17149
Two classes of issues were found by the psbt fuzzer: values out of range and causing overflows, and prevout indexes being out of range. This PR fixes both.
When accessing a specific output using the index given in the tx, check that it is actually a possible output before trying to access the output.
When summing and checking amounts for
decodepsbt
andanalyzepsbt
, make sure that the values are actually valid money values.. Otherwise, stop summing and don't show the fee. Foranalyzepsbt
, return that the next role is the Creator since the Creator needs to remake the transaction to be valid.