-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-142665: fix UAF when accessing a memoryview concurrently mutates the underlying buffer
#143324
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix use-after-free crashes when slicing a :class:`memoryview` or | ||
| accessing the elements of a sliced view concurrently mutates the | ||
| underlying buffer. Patch by Bénédikt Tran. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2623,7 +2623,10 @@ memory_subscript(PyObject *_self, PyObject *key) | |
| if (sliced == NULL) | ||
| return NULL; | ||
|
|
||
| if (init_slice(&sliced->view, key, 0) < 0) { | ||
| self->exports++; | ||
| int rc = init_slice(&sliced->view, key, 0); | ||
| self->exports--; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go this way, should not we call Also, we can have a similar issue with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For /* rvalue must be an exporter */
if (PyObject_GetBuffer(value, &src, PyBUF_FULL_RO) < 0)
return ret;so it's already protected I think
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I wasn't aware of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Strictly speaking no because those functions don't call any Python code, unless there are some invariants I'm not aware of |
||
| if (rc < 0) { | ||
| Py_DECREF(sliced); | ||
| return NULL; | ||
| } | ||
|
|
||
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.
Can you add a comment explaining the purpose of the
exports++? Add a reference to the GitHub issue (gh-142665:).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.
Ah, I think I wasn't consistent in my reviews or in my commits. I thought the commit history would have been enough for that. But sure I can a comment