gh-143236: fix _PyEval_LoadName has use-after-free issue#143283
Closed
fatelei wants to merge 6 commits intopython:mainfrom
Closed
gh-143236: fix _PyEval_LoadName has use-after-free issue#143283fatelei wants to merge 6 commits intopython:mainfrom
fatelei wants to merge 6 commits intopython:mainfrom
Conversation
Contributor
|
This change seems not fix the issue. diff --git a/Python/ceval.c b/Python/ceval.c
index 924afaa974..14c9ba9ad0 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4061,9 +4061,15 @@ _PyEval_LoadName(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *na
"no locals found");
return NULL;
}
- if (PyMapping_GetOptionalItem(frame->f_locals, name, &value) < 0) {
+ PyObject *locals = frame->f_locals;
+ Py_INCREF(locals);
+
+ if (PyMapping_GetOptionalItem(locals, name, &value) < 0) {
+ Py_DECREF(locals);
return NULL;
}
+
+ Py_DECREF(locals);
if (value != NULL) {
return value;
} |
Member
|
Closing since the fix is not straightforward. Please wait until we find a way to correctly fix it. We also need to consider the performance impact. So let's discuss more on the issue first. In the future, please don't jump at fixing stuff if (1) the reproducer still crashes (2) there is a possible performance penalty that needs to be assessed and no assessments were done. This wastes reviewer's time. |
sobolevn
reviewed
Dec 30, 2025
Member
sobolevn
left a comment
There was a problem hiding this comment.
I agree that the fix is not really obvious.
| } | ||
| if (PyMapping_GetOptionalItem(frame->f_locals, name, &value) < 0) { | ||
|
|
||
| PyObject *locals = frame->f_locals; |
Member
There was a problem hiding this comment.
can the same also happen to f_globals? f_builtins?
Contributor
Author
There was a problem hiding this comment.
can the same also happen to
f_globals?f_builtins?
yes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix _PyEval_LoadName has use-after-free issue
_PyEval_LoadNamevia re-entrant frame locals lookup #143236