Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
[3.9] gh-95778: CVE-2020-10735: Prevent DoS by very large int()#96502
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
gpshead commented Sep 2, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
bedevere-bot commented Sep 2, 2022
gpshead commented Sep 2, 2022
I've been using the opening message text for the PR as the commit message when merging. The automatic one is gross. |
gpshead commented Sep 4, 2022
wait for #96537 to be integrated into this PR before merging, i'll remove the do-not-merge label then. |
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>
bedevere-bot commented Sep 4, 2022
ambv commented Sep 5, 2022
@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 |
ambv commented Sep 5, 2022
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. |
bedevere-bot commented Sep 5, 2022
|
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.