[3.9] gh-95778: CVE-2020-10735: Prevent DoS by very large int()#96502
Conversation
Co-authored-by: Christian Heimes <christian@python.org>
Ned pointed this out on the 3.7 review, it matches other patch changes and stands out better.
|
I've been using the opening message text for the PR as the commit message when merging. The automatic one is gross. |
Sorry, something went wrong.
|
wait for #96537 to be integrated into this PR before merging, i'll remove the do-not-merge label then. |
Sorry, something went wrong.
Per mdickinson@'s comment on the main branch PR.
…#96537) Converting a large enough `int` to a decimal string raises `ValueError` as expected. However, the raise comes _after_ the quadratic-time base-conversion algorithm has run to completion. For effective DOS prevention, we need some kind of check before entering the quadratic-time loop. Oops! =) The quick fix: essentially we catch _most_ values that exceed the threshold up front. Those that slip through will still be on the small side (read: sufficiently fast), and will get caught by the existing check so that the limit remains exact. The justification for the current check. The C code check is: ```c max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10 ``` In GitHub markdown math-speak, writing $M$ for `max_str_digits`, $L$ for `PyLong_SHIFT` and $s$ for `size_a`, that check is: $$\left\lfloor\frac{M}{3L}\right\rfloor \le \left\lfloor\frac{s - 11}{10}\right\rfloor$$ From this it follows that $$\frac{M}{3L} < \frac{s-1}{10}$$ hence that $$\frac{L(s-1)}{M} > \frac{10}{3} > \log_2(10).$$ So $$2^{L(s-1)} > 10^M.$$ But our input integer $a$ satisfies $|a| \ge 2^{L(s-1)}$, so $|a|$ is larger than $10^M$. This shows that we don't accidentally capture anything _below_ the intended limit in the check. <!-- gh-issue-number: pythongh-95778 --> * Issue: pythongh-95778 <!-- /gh-issue-number --> Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
|
@tiran can wasm32 failures be ignored here? This is a 3.9 backport and that version is not supported on WASM? Those fail to build with errors like |
Sorry, something went wrong.
|
The FeeBSD Shared PR failure is unrelated. It's an openssl test failure due to trying to use a protocol that is not supported on the machine: In GH-95312 we did backport test changes that were supposed to fix this but apparently not. This is to be followed up separately. |
Sorry, something went wrong.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️Hi! The buildbot AMD64 FreeBSD Shared 3.9 has failed when building commit cec1e9d. What do you need to do:
You can take a look at the buildbot page here: https://buildbot.python.org/all/#builders/151/builds/591 Failed tests:
Failed subtests:
Summary of the results of the build (if available): == Tests result: FAILURE then FAILURE == 406 tests OK. 10 slowest tests:
1 test failed: 18 tests skipped: 1 re-run test: Total duration: 33 min 15 sec Click to see traceback logsTraceback (most recent call last):
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/test/test_ssl.py", line 1718, in test__create_stdlib_context
ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1,
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/ssl.py", line 776, in _create_unverified_context
context = SSLContext(protocol)
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/ssl.py", line 484, in __new__
self = _SSLContext.__new__(cls, protocol)
ValueError: invalid or unsupported protocol version
Traceback (most recent call last):
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/test/test_ssl.py", line 1144, in test_protocol
ctx = ssl.SSLContext(proto)
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/ssl.py", line 484, in __new__
self = _SSLContext.__new__(cls, protocol)
ValueError: invalid or unsupported protocol version
Traceback (most recent call last):
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/test/test_ssl.py", line 1527, in test_session_stats
ctx = ssl.SSLContext(proto)
File "/usr/home/buildbot/python/3.9.koobs-freebsd-564d/build/Lib/ssl.py", line 484, in __new__
self = _SSLContext.__new__(cls, protocol)
ValueError: invalid or unsupported protocol version
|
Sorry, something went wrong.
Integer to and from text conversions via CPython's bignum
inttype is not safe against denial of service attacks due to malicious input. Very large input strings with hundred thousands of digits can consume several CPU seconds.This PR comes fresh from a pile of work done in our private PSRT security response team repo.
This backports #96499 aka 511ca94
Signed-off-by: Christian Heimes [Red Hat] christian@python.org
Tons-of-polishing-up-by: Gregory P. Smith [Google] greg@krypto.org
Reviews via the private PSRT repo via many others (see the NEWS entry in the PR).
I wrote up a one pager for the release managers.