GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.9] gh-95778: CVE-2020-10735: Prevent DoS by very large int() by gpshead · Pull Request #96502 · python/cpython

Conversation

@gpshead

@gpshead gpshead commented Sep 2, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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).

  • Issue: CVE-2020-10735: Prevent DoS by large int<->str conversions #95778

I wrote up a one pager for the release managers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gpshead and others added 9 commits August 19, 2022 01:27
@gpshead
Backport to 3.9 of psrt/CVE-2020-10735-3.10backport.
576d772
@gpshead
Fix versionadded/versionchanged.
e5cd3fc
@gpshead
headers += Include/internal/pycore_long.h
9a3cd05
@gpshead @tiran
Update attribution in Misc/NEWS.d
c190dc9
Co-authored-by: Christian Heimes <[email protected]>
@tiran
Manually add new field to abi file
a7213dd
@gpshead
Move the whatsnew text per review.
2384ef4
Ned pointed this out on the 3.7 review, it matches other patch
changes and stands out better.
@gpshead
Merge branch 'CVE-2020-10735-3.9backport' of github.com:python/psrt i…
fcb123b
…nto CVE-2020-10735-3.9backport
@gpshead
Make the doctest actually run & fix it.
1378bde
@gpshead
Fix the docs build.
e51a8e2
@gpshead gpshead assigned ambv and gpshead Sep 2, 2022
@bedevere-bot bedevere-bot added the awaiting core review label Sep 2, 2022
@gpshead
Rename the news file to appease the Bedevere bot.
3e7eb9c
@gpshead gpshead added the release-blocker label Sep 2, 2022
@tiran tiran added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 2, 2022
@bedevere-bot

bedevere-bot commented Sep 2, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @tiran for commit 3e7eb9c 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 2, 2022
@gpshead
hexadecimal spelling =)
5c64ec6
@gpshead
gpshead marked this pull request as ready for review September 2, 2022 16:52
@gpshead
gpshead requested review from lysnikolaou, pablogsal and rhettinger as code owners September 2, 2022 16:52
@gpshead

gpshead commented Sep 2, 2022

Copy link
Copy Markdown
Member Author

I've been using the opening message text for the PR as the commit message when merging. The automatic one is gross.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead gpshead removed their assignment Sep 2, 2022
@gpshead

gpshead commented Sep 4, 2022

Copy link
Copy Markdown
Member Author

wait for #96537 to be integrated into this PR before merging, i'll remove the do-not-merge label then.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead gpshead added the DO-NOT-MERGE label Sep 4, 2022
gpshead and others added 4 commits September 3, 2022 23:17
@gpshead
doc typo: limitation
a37041f
python#96542
@gpshead
Misc: Fix a typo in the header comment.
b4957d8
@gpshead
remove unneeded doc note on float.as_integer_ratio
0515141
Per mdickinson@'s comment on the main branch PR.
@mdickinson @gpshead
pythongh-95778: Correctly pre-check for int-to-str conversion (python…
a1247fd
…#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]>
@gpshead gpshead added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed DO-NOT-MERGE labels Sep 4, 2022
@bedevere-bot

bedevere-bot commented Sep 4, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @gpshead for commit a1247fd 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 4, 2022
@ambv

ambv commented Sep 5, 2022

Copy link
Copy Markdown
Contributor

@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 FileNotFoundError: [Errno 2] No such file or directory: b'../../Tools/wasm/wasi-env', configure: error: cross build not supported for wasm32-unknown-emscripten, and emconfigure: error: (...) failed (returned 1).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv

ambv commented Sep 5, 2022

Copy link
Copy Markdown
Contributor

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:

ValueError: invalid or unsupported protocol version

In GH-95312 we did backport test changes that were supposed to fix this but apparently not. This is to be followed up separately.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv
ambv merged commit cec1e9d into python:3.9 Sep 5, 2022
@bedevere-bot bedevere-bot removed the awaiting core review label Sep 5, 2022
@bedevere-bot

bedevere-bot commented Sep 5, 2022

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD Shared 3.9 has failed when building commit cec1e9d.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/151/builds/591) and take a look at the build logs.
  4. Check if the failure is related to this commit (cec1e9d) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/151/builds/591

Failed tests:

  • test_ssl

Failed subtests:

  • test__create_stdlib_context - test.test_ssl.ContextTests
  • test_session_stats - test.test_ssl.ContextTests
  • test_protocol - test.test_ssl.ContextTests

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

406 tests OK.

10 slowest tests:

  • test_tokenize: 8 min 37 sec
  • test_multiprocessing_spawn: 7 min 23 sec
  • test_lib2to3: 6 min 28 sec
  • test_gdb: 5 min 21 sec
  • test_multiprocessing_forkserver: 4 min 50 sec
  • test_concurrent_futures: 4 min 30 sec
  • test_unparse: 4 min 10 sec
  • test_asyncio: 3 min 49 sec
  • test_capi: 3 min 12 sec
  • test_pickle: 3 min 7 sec

1 test failed:
test_ssl

18 tests skipped:
test_dbm_gnu test_devpoll test_epoll test_idle test_ioctl
test_msilib test_spwd test_startfile test_tcl test_tix test_tk
test_ttk_guionly test_ttk_textonly test_turtle test_winconsoleio
test_winreg test_winsound test_zipfile64

1 re-run test:
test_ssl

Total duration: 33 min 15 sec

Click to see traceback logs
Traceback (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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rhettinger rhettinger Awaiting requested review from rhettinger rhettinger is a code owner
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ambv ambv

Labels

release-blocker

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@gpshead @bedevere-bot @ambv @tiran @mdickinson
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.