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.13] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234)#139367
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
hartwork commented Sep 26, 2025 • edited by github-actions bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by github-actions bot
Uh oh!
There was an error while loading. Please reload this page.
…2025-59375) (python#139234) Expose the XML Expat 2.7.2 mitigation APIs to disallow use of disproportional amounts of dynamic memory from within an Expat parser (see CVE-2025-59375 for instance). The exposed APIs are available on Expat parsers, that is, parsers created by `xml.parsers.expat.ParserCreate()`, as: - `parser.SetAllocTrackerActivationThreshold(threshold)`, and - `parser.SetAllocTrackerMaximumAmplification(max_factor)`. (cherry picked from commit f04bea4)
picnixz commented Sep 26, 2025
Ah I think we cross-posted but I actually want to simplify the future backports and next PR by using another generic handler (it will ease the diff). See #139366 |
hartwork commented Sep 26, 2025
@picnixz I saw your message #139234 (comment) but did not expect impact on my wip 3.13 backport and not more than that fix. What should best be done with this pull request? Closing is alright with me if automation replaces my work after merge of #139366 — can it? Else I'm happy to adjust in here. |
picnixz commented Sep 26, 2025
I'll try to make an automated backport. If it succeeds, then good. Otherwise we'll need something else :( However, I'm surprised by the segfaults? |
picnixz commented Sep 26, 2025
(Segfaults could be because you didn't |
hartwork commented Sep 26, 2025
picnixz commented Sep 26, 2025
The address sanitizer says that there is a heap-UAF. |
…on API (python#139366) Fix some typos left in f04bea4, and simplify some internal functions to ease maintenance of future mitigation APIs. (cherry picked from commit 68a1778)
hartwork commented Sep 28, 2025
@picnixz I have used the same technique as #139359 (review) here now to find any potential issues in the diff backported. The key thing that stands out is the difference in I'm attaching my three diffs if you would like to see my cross-diff comparison with your own eyes:
Looking from a different angle next… |
hartwork commented Sep 28, 2025
@picnixz I found that… Two (or arguably four) tests are failing:
A parser instance is being freed twice. The minimal reproducer for Python 3.13 (but not 3.14) is this: classUseAfterFreeCrashDemoTest(unittest.TestCase): deftest_use_after_free__crash(self): parser=expat.ParserCreate() subparser=parser.ExternalEntityParserCreate(None)While interestingly adding classNoUseAfterFreeHereTest(unittest.TestCase): deftest_use_after_free__no_crash(self): parser=expat.ParserCreate() subparser=parser.ExternalEntityParserCreate(None) delsubparserSimilarly, appending… delsetterdelsubparserdelparser…to both original tests in here works around the issue. My understanding is that there is an unrelated object graph issue here that makes CPython free things in the wrong order. I'll add my workaround for a green CI for the moment, create a new separate issue about that, and hope for ideas from your side about how to proceed from there. |
picnixz commented Sep 28, 2025 • 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.
That's interesting. It could be the incremental GC which was deferred to Python 3.14 (https://docs.python.org/3.14/whatsnew/3.14.html#incremental-garbage-collection). |
picnixz commented Sep 28, 2025 • 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.
Anyway, we can correctly assume that we have a UAF. Let's create a separate issue (do you want to?) |
hartwork commented Sep 28, 2025
hartwork commented Sep 28, 2025 • 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.
picnixz commented Sep 28, 2025
I would prefer waiting for the UAF to be fixed if it's ok for you. We usually don't like having a branch with temporary workarounds. |
hartwork commented Sep 28, 2025 • 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.
@picnixz good with me, I can revert the workaround later 👍 |
picnixz commented Oct 7, 2025
To have a good synchronization, we'll also delay 3.10 to 3.13 backports for their next release cycle (see #139359 (comment)). |
ambv commented Oct 8, 2025
I set DO-NOT-MERGE to avoid confusion. Unset that when you think we should be releasing this. |
picnixz commented Nov 2, 2025
The commit message will be I'll rerun the CI |
picnixz commented Nov 2, 2025 • 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.
@hartwork can you merge 3.13 into this backport please to trigger a CI run? and do the same for the other backports? (just hit the "update branch" button; I can't because you didn't allow maintainers to directly push on your branch) |
hartwork commented Nov 2, 2025
@picnixz done for 3.{10..13} just now 👍 |
picnixz commented Nov 2, 2025
Thanks. I won't be able to merge 3.10, 3.11 and 3.12 as only the RMs can. I will review them myself because they weren't automated backports IIRC and we needed to tweak a bit things and there because of the lack of some functions (or maybe we did so in a smart way already). Anyway, I need to work on something else for today but hopefully I'll be able to review it by next week. Then, we can backport the other PRs. |
hartwork commented Nov 2, 2025
@picnixz understood, yes 👍
Do you want me to summarize the difference between these four backports?
Thank you! 👍 |
bc36bd1 into python:3.13Uh oh!
There was an error while loading. Please reload this page.
Expose the XML Expat 2.7.2 mitigation APIs to disallow use of disproportional amounts of dynamic memory from within an Expat parser (see CVE-2025-59375 for instance).
The exposed APIs are available on Expat parsers, that is, parsers created by
xml.parsers.expat.ParserCreate(), as:parser.SetAllocTrackerActivationThreshold(threshold), andparser.SetAllocTrackerMaximumAmplification(max_factor).(cherry picked from commit f04bea4)
CC @picnixz
📚 Documentation preview 📚: https://cpython-previews--139367.org.readthedocs.build/