Skip to content

Possible resource exhaustation of expandvars in Tools/freeze/checkextensions.py #136073

Open

Description

@kexinoh

Bug Description:
The code will re-scan the newly generated content after replacing the variable. If a variable is defined to contain itself (i.e., a recursive definition), this process will fall into infinite recursion.

This recursion can lead to two forms of attacks: one is to cause an infinite loop and deplete CPU resources, and the other is to cause the string to grow infinitely and deplete memory resources. The final result will all lead to the application crashing or being unresponsive.

Vulnerability Locations :
1.

def expandvars(str, vars):

Repair Status:
None

Common Information:

  • CPython Version: main branch
  • Operating System: Linux
  • Credits: Finder is kexinoh (Xiangfan Wu) from QI-ANXIN Technology Research Institute.

Linked PRs

Activity

  1. changed the title [-]Potential Quadratic Complexity Vulnerabilities in Tools Modules[/-] [+]Unbounded Resource Exhaustion Vulnerability in the Tool Module via Recursive Expansion[/+] on Jun 28, 2025
  2. changed the title [-]Unbounded Resource Exhaustion Vulnerability in the Tool Module via Recursive Expansion[/-] [+]Unbounded Resource Exhaustion Vulnerability in `Tools/freeze/checkextensions.py`[/+] on Jun 28, 2025
  3. added
    triagedThe issue has been accepted as valid by a triager.
    type-bugAn unexpected behavior, bug, or error
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Jun 28, 2025
  4. picnixz commented on Jun 28, 2025

    @picnixz
    Member

    Ok, it actually affects freeze.py so I think we can backport it until 3.9. However, I haven't checked if this is a realistic attack

  5. StanFromIreland commented on Jun 28, 2025

    @StanFromIreland
    Member

    Out of curiosity, is freeze.py still maintained? The last update was 2 years ago and for this specific file 16.

  6. sobolevn commented on Jun 28, 2025

    @sobolevn
    Member

    Is it really a security issue? Tools/freeze is an internal tool, which is used when CPython is built. If someone can affect the building process - you have much bigger problems.

    I still think that this should be fixed, just doubting that this is a security issue.

  7. picnixz commented on Jun 28, 2025

    @picnixz
    Member

    Although it's internal, it's still somehow documented: https://docs.python.org/3/faq/programming.html#how-can-i-create-a-stand-alone-binary-from-a-python-script. But I agree that it can be hard to exploit. I'm more worried about "mistakes" that can lead to issues.

  8. brianschubert commented on Jun 28, 2025

    @brianschubert
    Contributor

    Hmm, is triggering this even possible in practice? From what I understand this would require having a cyclic variable definition in a Setup file, but Make already detects variable cycles, so wouldn't building the module fail before this could be a problem? E.g. adding CC=$(CC) will cause Make to exit with *** Recursive variable 'CC' references itself (eventually). Stop..

  9. kexinoh commented on Jun 29, 2025

    @kexinoh
    Author

    I'm not quite clear about the specific construction process of make, but what I want to explain is that for

    a=$aa

    This situation can also cause problems, but there is no actual variable loop.

  10. added a commit that references this issue on Jun 29, 2025
  11. serhiy-storchaka commented on Jun 29, 2025

    @serhiy-storchaka
    Member

    Thank you for opening an issue @kexinoh. I wrote the patch yesterday, but needed an issue number for reference.

    I agree that this is a minor bug, and perhaps not exploitable. But it is worth to fix it. Unfortunately, there are no unit tests for all this code, so I cannot add new tests for this function. I tested it manually.

  12. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    and removed on Jun 29, 2025
  13. changed the title [-]Unbounded Resource Exhaustion Vulnerability in `Tools/freeze/checkextensions.py`[/-] [+]Possible resource exhaustation of `expandvars` in `Tools/freeze/checkextensions.py`[/+] on Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixestriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions