-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
[3.8] gh-95778: CVE-2020-10735: Prevent DoS by very large int() #96503
Conversation
Co-authored-by: Gregory P. Smith <[email protected]>
Fixes test_ast and test_compile.
Ned pointed this out on the 3.7 branch, it matches other patch changes and stands out better.
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] <[email protected]>
@tiran can wasm32 failures be ignored here? This is a 3.8 backport and that version is not supported on WASM? Those fail to build with errors like |
Unfortunately, there are legitimate failures here. Arch ASAN Debug https://buildbot.python.org/all/#/builders/586/builds/778:
Arch ASAN https://buildbot.python.org/all/#/builders/581/builds/779:
Arch USAN https://buildbot.python.org/all/#/builders/720/builds/676:
FreeBSD Shared https://buildbot.python.org/all/#/builders/203/builds/821:
s390x https://buildbot.python.org/all/#/builders/111/builds/784:
Gentoo with X https://buildbot.python.org/all/#/builders/344/builds/803:
At least the ASAN and USAN failures are definitely related to this change, the others might be related indirectly. |
what makes you think those are related to this change? Arch ASAN 3.8 both: https://buildbot.python.org/all/#/builders/590 and https://buildbot.python.org/all/#/builders/580 show red for six months on 3.8. and Arch USAN has not 3.8 bot and history at all. |
If you want a baseline for those bots on 3.8 with no changes, I ran them via #96586. |
We looked into this. 3.7 and 3.8 are typically not running address and undefined behavior sanitizers on buildbots. The label-driven trigger on PRs is overly broad and runs configurations that aren't used by us for the oldest branches in regular testing. At least 3.8 fails ASAN and UBSAN without #96503 applied as well. I'm landing this. |
|
|
|
|
FYI, we're skipping |
Integer to and from text conversions via CPython's bignum
int
type 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] [email protected]
Tons-of-polishing-up-by: Gregory P. Smith [Google] [email protected]
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.