-
Notifications
You must be signed in to change notification settings - Fork 37.7k
fix uninitialized variable nMinerConfirmationWindow #17449
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
I find it scary, that a bug like this can be introduced. I am wondering if there are not any tools that check the code for references to uninitialized variables? |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
Fixes what? Both are already initialized.. |
It's used for the computation of
The tests are being run in various sanitizers, and valgrind can do this IIRC. I'm surprised it wasn't caught. ACK 6fcd798 Should fix #16697. |
@promag It looks like
This code was introduced in fdb3e8f in PR #16713 which was merged in to Really fascinating that this 1.) wasn't caught automatically by our static and dynamic analysis, 2.) wasn't caught by our review process and 3.) was unnoticed in |
@bitcoinVBR Thanks a lot for reporting this! What an excellent first time contribution! Hope to see more great contributions from you. Sorry about the initial misunderstanding in your original PR #17433 :) |
Port to rust when? 😄 |
Oh! |
Worth noting is that the read of
|
ACK 6fcd798 |
Good catch. If there is no unit test that instantiates the main / testnet chain, that'd explain why sanitizer CI checks don't notice it. But it seems that quite a few do, for example:
|
@laanwj I think there might be a more subtle issue here too - note that I think we might be chasing two issues here where the uninitialised read is the first one :) |
We have functional tests that run on the testnet chain. So this should have been caught by a sanitizer (assuming one was enabled) |
I don't think we have the memory sanitizer enabled anywhere |
Thanks! I'm happy to help. I actually only found this bug because of my work on BitcoinV. I'll continue to keep an eye out for anything fishy. |
Compiler writers get a lot of heat for exploiting UB to the fullest for optimisation purposes, but in this case it seems like we got really lucky -- they "fixed" our code (assuming Clang Look at the Clang
:) |
@jonatack The output you posted from the testing of PR #16713 in #16713 (comment) ...
... could it be the case that you happened to test with Clang with the project default optimisation level |
@practicalswift I tried gcc 9.2.1 and it happened to optimize out the bug for me as well. Though running the same binary in valgrind still jells at me, so I can't make any sense out of that. |
@MarcoFalke What is the output of |
It was with gcc version 8.3.0 (Debian 8.3.0-6) with no optimisation flags. |
The default is O2 for Bitcoin Core |
I'd prefer to just hard code the consensus.MinBIP9WarningHeight = 483840; // segwit activation height + miner confirmation window Hard-coding the value means that even if the member initializations are moved around again,
|
I was about to suggest that the members should be marked |
@bitcoinVBR Could you please adjust the patch as suggested by @jnewbery and then squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits |
The Bitcoin Core project does not have any official bounty program AFAIK, but the is nothing stopping individuals from donating to other individuals who they think have done valuable security research. (Aside: My personal view is that we could do a much better job recognising good security research: especially the non-glamorous kind of low-level security research. As an example: if we had a proper incentive structure in place I guess someone would be running Shameless plug: People interested in running |
edb6b76 fix uninitialized variable nMinerConfirmationWindow (NullFunctor) Pull request description: It is used for the computation of `BIP9WarningHeight`, and by that time it isn't initialized. ACKs for top commit: jnewbery: utACK edb6b76 promag: ACK edb6b76, commit description could be cleaned up though. MarcoFalke: ACK edb6b76, used python3 to do the addition locally 📍 practicalswift: ACK edb6b76, used `clang++ -O2` on the previous version^W^W^W^W^W^W`bc` to verify the addition locally 🏓 Sjors: Code review ACK edb6b76. Nit: commit description has duplicate text. Tree-SHA512: 6fa0be0ecfbfd5d537f2c5b4a9333c76530c1f3182f777330cc7939b0496e37b75d8f8810cdaf471a9bd3247b425f2e239578300dfa0d5a87cd14a6ccfafa619
fix uninitialized variable hard code the MinBIP9WarningHeight fix uninitialized var hard code the MinBIP9WarningHeight instead Github-Pull: #17449 Rebased-From: edb6b76 Tree-SHA512: 6192940e5e13ad1176aa380da9f3287ff1eb0c8c2a78571a6c45fe0e100417452c8503b9ffc5c8b2a89c4a5e8811b9d2bfec95366e1de00f3365ba06959e9a9a
Change version to 0.19.0.1. Add the following two PRs: - #17368 cli: fix -getinfo output when compiled with no wallet - #17449 fix uninitialized variable nMinerConfirmationWindow Add the following author: - NullFunctor (bitcoinVBR on gh) Tree-SHA512: f37b822555f2069c999721eede9156250d780e8906cd2e3294e7dfefc0225fff65ee3af4614fca081dcdccfab4a2a980192156621f005aa529bba00058da5c9a
Maybe you can get funding for such a thing from one of the exchanges or companies in the space, that's always how developer funding has worked, but the 'bitcoin core' project is a loose name for people contributing to an open source project, and does not manage funds, and should not manage funds, and will never have an "official incentive structure". |
Agree 100% if we are talking monetary reward. Note that incentive structure does not necessarily imply monetary reward: giving proper credit and treating researchers nicely goes a surprisingly long way when it comes to attracting security research :) To bring this on-topic again (sorry, my fault!): I hope we can make this a good example by making sure @bitcoinVBR is properly credited for allowing us to ship 0.19.0 without an "optimisation unstable" |
As all contributors to the release, they've been added to the authors list in 0.19.0.1 (as NullFunctor, as that's the name on their git mail address, @bitcoinVBR: if you want to be credited under a different name let me know) and this PR has been added to the changelog. This is not a security issue so I'm not sure why you bring that up. It doesn't matter either, bugs are bugs. All people that contribute deserve credit. |
Backported to 0.19 in 6ec0dc1. |
ACK on the rebase 6ec0dc1. |
Updated the BIP9 warning height in chain params for Namecoin's segwit activation height (see bitcoin/bitcoin#17449).
Updated the BIP9 warning height in chain params for Namecoin's segwit activation height (see bitcoin/bitcoin#17449).
Updated the BIP9 warning height in chain params for Xaya's segwit activation height (see bitcoin/bitcoin#17449).
Updated the BIP9 warning height in chain params for Xaya's segwit activation height (see bitcoin/bitcoin#17449). Fixes #101 through the upstream patch in 50cd27e.
fix uninitialized variable hard code the MinBIP9WarningHeight fix uninitialized var hard code the MinBIP9WarningHeight instead Github-Pull: bitcoin#17449 Rebased-From: edb6b76 Tree-SHA512: 6192940e5e13ad1176aa380da9f3287ff1eb0c8c2a78571a6c45fe0e100417452c8503b9ffc5c8b2a89c4a5e8811b9d2bfec95366e1de00f3365ba06959e9a9a
Change version to 0.19.0.1. Add the following two PRs: - bitcoin#17368 cli: fix -getinfo output when compiled with no wallet - bitcoin#17449 fix uninitialized variable nMinerConfirmationWindow Add the following author: - NullFunctor (bitcoinVBR on gh) Tree-SHA512: f37b822555f2069c999721eede9156250d780e8906cd2e3294e7dfefc0225fff65ee3af4614fca081dcdccfab4a2a980192156621f005aa529bba00058da5c9a
fix uninitialized variable hard code the MinBIP9WarningHeight fix uninitialized var hard code the MinBIP9WarningHeight instead Github-Pull: bitcoin#17449 Rebased-From: edb6b76 Tree-SHA512: 6192940e5e13ad1176aa380da9f3287ff1eb0c8c2a78571a6c45fe0e100417452c8503b9ffc5c8b2a89c4a5e8811b9d2bfec95366e1de00f3365ba06959e9a9a
Change version to 0.19.0.1. Add the following two PRs: - bitcoin#17368 cli: fix -getinfo output when compiled with no wallet - bitcoin#17449 fix uninitialized variable nMinerConfirmationWindow Add the following author: - NullFunctor (bitcoinVBR on gh) Tree-SHA512: f37b822555f2069c999721eede9156250d780e8906cd2e3294e7dfefc0225fff65ee3af4614fca081dcdccfab4a2a980192156621f005aa529bba00058da5c9a
Looks like |
@ajtowns Worth mentioning from a dynamic analysis perspective is that both Valgrind and MemorySanitizer ( |
It is used for the computation of
BIP9WarningHeight
, and by that time it isn't initialized.