Skip to content

gh-134100: Fix UAF in PyImport_ImportModuleLevelObject #134117

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

Merged
merged 6 commits into from
May 18, 2025

Conversation

Nico-Posada
Copy link
Contributor

@Nico-Posada Nico-Posada commented May 16, 2025

Decref after using to_return instead of before.

@Nico-Posada
Copy link
Contributor Author

Not really sure how to add tests for this

@ZeroIntensity
Copy link
Member

Use the repro from the issue for a test.

@picnixz picnixz added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels May 16, 2025
Comment on lines 234 to 235
with self.assertRaisesRegex(KeyError, r"'a\.b+' not in sys\.modules as expected"):
__import__(f"{loooong}.c", {"__package__": "a"}, level=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with self.assertRaisesRegex(KeyError, r"'a\.b+' not in sys\.modules as expected"):
__import__(f"{loooong}.c", {"__package__": "a"}, level=1)
with self.assertRaisesRegex(
KeyError,
r"'a\.b+' not in sys\.modules as expected",
):
__import__(f"{loooong}.c", {"__package__": "a"},
level=1)

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with two little technicalities.

@kumaraditya303 kumaraditya303 merged commit 4e9005d into python:main May 18, 2025
39 checks passed
@miss-islington-app
Copy link

Thanks @Nico-Posada for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 18, 2025
…ect` (pythonGH-134117)

(cherry picked from commit 4e9005d)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented May 18, 2025

GH-134171 is a backport of this pull request to the 3.14 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 18, 2025
…ect` (pythonGH-134117)

(cherry picked from commit 4e9005d)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 18, 2025
@bedevere-app
Copy link

bedevere-app bot commented May 18, 2025

GH-134172 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 18, 2025
kumaraditya303 pushed a commit that referenced this pull request May 18, 2025
…ject` (GH-134117) (#134172)

gh-134100: Fix use-after-free in `PyImport_ImportModuleLevelObject` (GH-134117)
(cherry picked from commit 4e9005d)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
kumaraditya303 pushed a commit that referenced this pull request May 18, 2025
…ject` (GH-134117) (#134171)

gh-134100: Fix use-after-free in `PyImport_ImportModuleLevelObject` (GH-134117)
(cherry picked from commit 4e9005d)

Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants