-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-123083: Fix a potential use-after-free in STORE_ATTR_WITH_HINT
#123092
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
Conversation
@@ -1476,6 +1476,24 @@ def test_dict_items_result_gc_reversed(self): | |||
gc.collect() | |||
self.assertTrue(gc.is_tracked(next(it))) | |||
|
|||
def test_store_evilattr(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that this is the proper place.
Misc/NEWS.d/next/Core_and_Builtins/2024-08-17-17-26-25.gh-issue-123083.9xWLJ-.rst
Outdated
Show resolved
Hide resolved
STORE_ATTR_WITH_HINT
Python/bytecodes.c
Outdated
@@ -2234,12 +2234,12 @@ dummy_func( | |||
PyDict_WatchEvent event = old_value == NULL ? PyDict_EVENT_ADDED : PyDict_EVENT_MODIFIED; | |||
new_version = _PyDict_NotifyEvent(tstate->interp, event, dict, name, PyStackRef_AsPyObjectBorrow(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should structure this to match the ordering in dictobject.c
:
Lines 1693 to 1707 in b6d0a40
MAINTAIN_TRACKING(mp, key, value); | |
PyObject *old_value = mp->ma_values->values[ix]; | |
if (old_value == NULL) { | |
uint64_t new_version = _PyDict_NotifyEvent(interp, PyDict_EVENT_ADDED, mp, key, value); | |
STORE_SPLIT_VALUE(mp, ix, Py_NewRef(value)); | |
_PyDictValues_AddToInsertionOrder(mp->ma_values, ix); | |
STORE_USED(mp, mp->ma_used + 1); | |
mp->ma_version_tag = new_version; | |
} | |
else { | |
uint64_t new_version = _PyDict_NotifyEvent(interp, PyDict_EVENT_MODIFIED, mp, key, value); | |
STORE_SPLIT_VALUE(mp, ix, Py_NewRef(value)); | |
mp->ma_version_tag = new_version; | |
Py_DECREF(old_value); | |
} |
- Update GC tracking if necessary
- Notify event
- Store value and version tag
- Decref old value
Could you add a comment, specifically why this is the correct order? |
Thank you for the kind review! |
@colesbury @markshannon gentle ping :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me. But let @colesbury review it before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too
Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
Sorry, @corona10, I could not cleanly backport this to
|
Sorry, @corona10, I could not cleanly backport this to
|
…R_WITH_HINT`` (pythongh-123092) (cherry picked from commit 297f2e0) Co-authored-by: Donghee Na <donghee.na@python.org>
…R_WITH_HINT`` (pythongh-123092) (cherry picked from commit 297f2e0) Co-authored-by: Donghee Na <donghee.na@python.org>
GH-123235 is a backport of this pull request to the 3.13 branch. |
GH-123237 is a backport of this pull request to the 3.12 branch. |
STORE_ATTR_WITH_HINT
has potential use-after-free #123083