dash/test/functional/test_framework
MarcoFalke 11eefa21d4 Merge #18515: test: add BIP37 remote crash bug [CVE-2013-5700] test to p2p_filter.py
0ed2d8e07d3806d78d03a77d2153f22f9d733a07 test: add BIP37 remote crash bug [CVE-2013-5700] test to p2p_filter.py (Sebastian Falbesoner)

Pull request description:

  Integrates the missing message type `filteradd` to the test framework and checks that the BIP37 implementation is not vulnerable to the "remote crash bug" [CVE-2013-5700](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-5700) anymore. Prior to v.0.8.4, it was possible to trigger a division-by-zero error on the following line in the function `CBloomFilter::Hash()`:
  f0d6487e29/src/bloom.cpp (L45)
  By setting a zero-length filter via `filterload`, `vData.size()` is 0, so the modulo operation above, called on any .insert() or .contains() operation then crashed the node. The test uses the approach of just sending an arbitrary `filteradd` message after, which calls `CBloomFilter::insert()` (and in turn `CBloomFilter::Hash()`) on the node. The vulnerability was fixed by commit 37c6389c5a (an intentional covert fix, [according to gmaxwell](https://github.com/bitcoin/bitcoin/issues/18483#issuecomment-608224095)), which introduced flags `isEmpty`/`isFull` that wouldn't call the `Hash()` member function if `isFull` is true (set to true by default constructor).

  To validate that the test fails if the implementation is vulnerable, one can simply set the flags to false in the member function `UpdateEmptyFull()` (that is called after a filter received via `filterload` is constructed), which activates the vulnerable code path calling `Hash` in any case on adding or testing for data in the filter:
  ```diff
  diff --git a/src/bloom.cpp b/src/bloom.cpp
  index bd6069b..ef294a3 100644
  --- a/src/bloom.cpp
  +++ b/src/bloom.cpp
  @@ -199,8 +199,8 @@ void CBloomFilter::UpdateEmptyFull()
           full &= vData[i] == 0xff;
           empty &= vData[i] == 0;
       }
  -    isFull = full;
  -    isEmpty = empty;
  +    isFull = false;
  +    isEmpty = false;
   }
  ```
  Resulting in:
  ```
  $ ./p2p_filter.py
  [...]
  2020-04-03T14:38:59.593000Z TestFramework (INFO): Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed
  2020-04-03T14:38:59.695000Z TestFramework (ERROR): Assertion failed
  [...]
  [... some exceptions following ...]
  ```

ACKs for top commit:
  naumenkogs:
    utACK 0ed2d8e07d3806d78d03a77d2153f22f9d733a07

Tree-SHA512: 02d0253d13eab70c4bd007b0750c56a5a92d05d419d53033523eeb3ed80318bc95196ab90f7745ea3ac9ebae7caee3adbf2a055a40a4124e0915226e49018fe8
2023-05-31 12:01:04 -05:00
..
__init__.py
address.py Merge #17984: test: Add p2p test for forcerelay permission 2022-10-20 11:48:12 -04:00
authproxy.py
blocktools.py Merge #19082: test: Moved the CScriptNum asserts into the unit test in script.py 2023-02-27 23:12:41 -06:00
coverage.py
descriptors.py Merge #18032: rpc: Output a descriptor in createmultisig and addmultisigaddress 2023-04-06 20:15:47 +03:00
key.py merge bitcoin#19105: Add Muhash3072 implementation in Python 2022-04-27 20:05:13 +05:30
messages.py Merge #18515: test: add BIP37 remote crash bug [CVE-2013-5700] test to p2p_filter.py 2023-05-31 12:01:04 -05:00
mininode.py Merge #18515: test: add BIP37 remote crash bug [CVE-2013-5700] test to p2p_filter.py 2023-05-31 12:01:04 -05:00
muhash.py partial bitcoin#19055: Add MuHash3072 implementation 2022-04-27 20:05:13 +05:30
netutil.py Merge bitcoin/bitcoin#24342: test: remove import socket in test_ipv6_local 2022-04-11 09:46:40 -07:00
ripemd160.py docs/build: Kubuntu 22.04 build fix (#4843) 2022-05-28 23:27:04 -05:00
script_util.py Merge #18732: test: Remove unused, undocumented and misleading CScript.__add__ 2023-03-03 23:07:15 +05:30
script.py Merge #18732: test: Remove unused, undocumented and misleading CScript.__add__ 2023-03-03 23:07:15 +05:30
siphash.py
socks5.py
test_framework.py test: Various test improvements (#5382) 2023-05-24 12:38:33 -05:00
test_node.py test: Various test improvements (#5382) 2023-05-24 12:38:33 -05:00
test_shell.py Merge #17378: TestShell: Fix typos & implement cleanups 2023-01-23 12:22:29 -06:00
util.py test: Various test improvements (#5382) 2023-05-24 12:38:33 -05:00
wallet_util.py Merge #17891: scripted-diff: Replace CCriticalSection with RecursiveMutex 2023-05-24 12:43:57 -05:00