Skip to content

gh-153570: Fix use-after-free in bytearray.take_bytes() with a reentrant __index__#153572

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:take-bytes-reentrant-uaf
Open

gh-153570: Fix use-after-free in bytearray.take_bytes() with a reentrant __index__#153572
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:take-bytes-reentrant-uaf

Conversation

@tonghuaroot

Copy link
Copy Markdown
Contributor

bytearray.take_bytes() used the size cached before the argument's __index__ call for its bounds check and
buffer reads, so an __index__ that resizes the bytearray left it reading freed memory. Re-read the size after
__index__, like bytearray.__setitem__ (GH-91153).

…reentrant __index__

bytearray.take_bytes() cached the size before the argument's __index__ call and
used it for the bounds check and the buffer reads, so an __index__ that resizes
the bytearray left it reading freed memory. Re-read the size after __index__,
matching bytearray.__setitem__ (pythonGH-91153).

@cmaloney cmaloney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like that during take_bytes() the byterray is resizable... but critical section doesn't prevent same thread mutation of the object.

This looks like a good fix for the current state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants