René's URL Explorer Experiment


Title: `_hashlib`: Use-After-Free + Double Free in `_hashopenssl.c` `py_hashentry_table_new()` · Issue #145301 · python/cpython · GitHub

Open Graph Title: `_hashlib`: Use-After-Free + Double Free in `_hashopenssl.c` `py_hashentry_table_new()` · Issue #145301 · python/cpython

X Title: `_hashlib`: Use-After-Free + Double Free in `_hashopenssl.c` `py_hashentry_table_new()` · Issue #145301 · python/cpython

Description: Crash report What happened? In py_hashentry_table_new(), when _Py_hashtable_set() fails for an alias key (line 270), entry is explicitly freed via PyMem_Free(entry) at line 271. However, this same entry was already successfully inserted ...

Open Graph Description: Crash report What happened? In py_hashentry_table_new(), when _Py_hashtable_set() fails for an alias key (line 270), entry is explicitly freed via PyMem_Free(entry) at line 271. However, this same ...

X Description: Crash report What happened? In py_hashentry_table_new(), when _Py_hashtable_set() fails for an alias key (line 270), entry is explicitly freed via PyMem_Free(entry) at line 271. However, this same ...

Opengraph URL: https://github.com/python/cpython/issues/145301

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_hashlib`: Use-After-Free + Double Free in `_hashopenssl.c` `py_hashentry_table_new()`","articleBody":"# Crash report\n\n### What happened?\n\nIn `py_hashentry_table_new()`, when `_Py_hashtable_set()` fails for an alias key (line 270), `entry` is explicitly freed via `PyMem_Free(entry)` at line 271. However, this same `entry` was already successfully inserted into the hashtable under `py_name` at line 263. The `goto error` path then calls `_Py_hashtable_destroy(ht)` (line 280), which invokes the destroy callback `py_hashentry_t_destroy_value()` on the already-freed entry.\n\n\n```c\n// Modules/_hashopenssl.c - py_hashentry_table_new()\n\nfor (const py_hashentry_t *h = py_hashes; h->py_name != NULL; h++) {\n    py_hashentry_t *entry = (py_hashentry_t *)PyMem_Malloc(sizeof(py_hashentry_t));\n    if (entry == NULL) {\n        goto error;\n    }\n    memcpy(entry, h, sizeof(py_hashentry_t));\n\n    // [line 263] entry inserted into hashtable under py_name - hashtable now owns it\n    if (_Py_hashtable_set(ht, (const void*)entry->py_name, (void*)entry) \u003c 0) {\n        PyMem_Free(entry);\n        goto error;\n    }\n    entry->refcnt = 1;\n\n    if (h->py_alias != NULL) {\n        // [line 270] second insert fails (e.g. OOM)\n        if (_Py_hashtable_set(ht, (const void*)entry->py_alias, (void*)entry) \u003c 0) {\n            PyMem_Free(entry);   // [line 271] BUG: entry freed, but still in hashtable under py_name\n            goto error;          // [line 272] jumps to error path\n        }\n        entry->refcnt++;\n    }\n}\n\nreturn ht;\nerror:\n    _Py_hashtable_destroy(ht);  // [line 280] destroy callback called on already-freed entry\n    return NULL;\n```\n\n### Build\n\n```bash\nmkdir build-asan && cd build-asan\n../configure --with-pydebug --with-address-sanitizer --without-pymalloc\nmake -j$(nproc)\n```\n\n```python\nimport subprocess\nimport sys\n\ncode = (\n    \"import sys, _testcapi\\n\"\n    \"if '_hashlib' in sys.modules:\\n\"\n    \"    del sys.modules['_hashlib']\\n\"\n    \"_testcapi.set_nomemory(40, 41)\\n\"\n    \"try:\\n\"\n    \"    import _hashlib\\n\"\n    \"except (MemoryError, ImportError):\\n\"\n    \"    pass\\n\"\n    \"finally:\\n\"\n    \"    _testcapi.remove_mem_hooks()\\n\"\n)\n\nresult = subprocess.run(\n    [sys.executable, '-c', code],\n    capture_output=True, text=True, timeout=10\n)\n\nif result.returncode != 0:\n    print(f\"[*] CRASH confirmed (rc={result.returncode})\")\n    print(f\"[*] {result.stderr.strip().split(chr(10))[-1]}\")\nelse:\n    print(\"[*] No crash (try different start values)\")\n```\n\n```bash\n$ ./build-asan/python uaf_asan.py\n[*] CRASH confirmed (rc=-6)\n[*] python: ../Include/internal/pycore_stackref.h:554: PyStackRef_FromPyObjectSteal: Assertion `obj != NULL' failed.\n```\n\n### GDB backtrace\n\n```bash\n$ gdb -batch -ex run -ex bt --args ./build-asan/python -c \"\nimport sys, _testcapi\nif '_hashlib' in sys.modules:\n    del sys.modules['_hashlib']\n_testcapi.set_nomemory(40, 41)\ntry:\n    import _hashlib\nexcept (MemoryError, ImportError):\n    pass\nfinally:\n    _testcapi.remove_mem_hooks()\n\"\n```\n\n```\npython: ../Include/internal/pycore_stackref.h:554: PyStackRef_FromPyObjectSteal: Assertion `obj != NULL' failed.\n\nProgram received signal SIGABRT, Aborted.\n\n#0  __pthread_kill_implementation at ./nptl/pthread_kill.c:44\n#1  __pthread_kill_internal at ./nptl/pthread_kill.c:78\n#2  __GI___pthread_kill at ./nptl/pthread_kill.c:89\n#3  __GI_raise at ../sysdeps/posix/raise.c:26\n#4  __GI_abort at ./stdlib/abort.c:79\n#5  __assert_fail_base — Assertion `obj != NULL' failed.\n#6  __assert_fail at ./assert/assert.c:105\n#7  PyStackRef_FromPyObjectSteal at ../Include/internal/pycore_stackref.h:554\n#8  _PyEval_EvalFrameDefault at ../Python/generated_cases.c.h:292\n...\n#15 import_find_and_load — importing _hashlib\n...\n#19 _PyEval_EvalFrameDefault at ../Python/generated_cases.c.h:6424\n```\n\n\nThe assertion fires because memory corruption during `_hashlib` module init (caused by the UAF/double-free) propagates a NULL into the eval loop.\n\n\n## Suggested Fix\n\nRemove `PyMem_Free(entry)` at line 271. The `entry` is already owned by the hashtable (under `py_name` with `refcnt=1`), so `_Py_hashtable_destroy()` in the error path will correctly clean it up via the destroy callback.\n\n```diff\n     if (h->py_alias != NULL) {\n         if (_Py_hashtable_set(ht, (const void*)entry->py_alias, (void*)entry) \u003c 0) {\n-            PyMem_Free(entry);\n             goto error;\n         }\n         entry->refcnt++;\n     }\n```\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.15.0a6+\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-145321\n* gh-145523\n* gh-145532\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/raminfp","@type":"Person","name":"raminfp"},"datePublished":"2026-02-27T05:48:19Z","url":"https://github.com/python/cpython/issues/145301"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:da608e94-9887-5040-f566-6e0bf518e32e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD17A:AFBD9:1AB929C:233029E:6B021B62
html-safe-nonce6212c3cdf72ab4c4283f40c7a022cb417f6539fc65b6ff250698781328faf322
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTdBOkFGQkQ5OjFBQjkyOUM6MjMzMDI5RTo2QjAyMUI2MiIsInZpc2l0b3JfaWQiOiI0MjYzODY1NjIyODMzNzk3OTg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac2c3cfc632474c4cc899613a518749a6e618c92fc685865d4aa98a011c8cbc1bc
hovercard-subject-tagissue:3999236952
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/145301/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f6e4f259bb785d1535dba373fec0e36b4263aa8529762623dab25aa0b5ee6e85/python/cpython/issues/145301
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f6e4f259bb785d1535dba373fec0e36b4263aa8529762623dab25aa0b5ee6e85/python/cpython/issues/145301
og:image:altCrash report What happened? In py_hashentry_table_new(), when _Py_hashtable_set() fails for an alias key (line 270), entry is explicitly freed via PyMem_Free(entry) at line 271. However, this same ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameraminfp
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/145301#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F145301
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F145301
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/145301
Reloadhttps://github.com/python/cpython/issues/145301
Reloadhttps://github.com/python/cpython/issues/145301
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/145301
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/145301
_hashlib: Use-After-Free + Double Free in _hashopenssl.c py_hashentry_table_new()https://github.com/python/cpython/issues/145301#top
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
easyhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22easy%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/raminfp
raminfphttps://github.com/raminfp
on Feb 27, 2026https://github.com/python/cpython/issues/145301#issue-3999236952
gh-145301: Fix double-free in hashlib and hmac module initialization #145321https://github.com/python/cpython/pull/145321
[3.14] gh-145301: Fix double-free in hashlib and hmac module initialization (GH-145321) #145523https://github.com/python/cpython/pull/145523
[3.13] gh-145301: Fix double-free in hashlib initialization (GH-145321) #145532https://github.com/python/cpython/pull/145532
raminfphttps://github.com/raminfp
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
on Feb 27, 2026https://github.com/python/cpython/issues/145301#event-23125886701
raminfphttps://github.com/raminfp
on Feb 27, 2026https://github.com/python/cpython/issues/145301#event-23125901911
sergey-miryanovhttps://github.com/sergey-miryanov
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
on Feb 27, 2026https://github.com/python/cpython/issues/145301#event-23132755681
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Feb 27, 2026https://github.com/python/cpython/issues/145301#issuecomment-3972224247
https://github.com/raminfp
raminfphttps://github.com/raminfp
on Feb 27, 2026https://github.com/python/cpython/issues/145301#issuecomment-3972246644
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Feb 27, 2026https://github.com/python/cpython/issues/145301#issuecomment-3972282249
sergey-miryanovhttps://github.com/sergey-miryanov
easyhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22easy%22
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
on Feb 27, 2026https://github.com/python/cpython/issues/145301#event-23132973322
gpsheadhttps://github.com/gpshead
on Mar 5, 2026https://github.com/python/cpython/issues/145301#event-23281930191
gh-145301: Fix double-free in hashlib and hmac module initialization (G…https://github.com/python/cpython/commit/6acaf659ef0fdee131bc02f0b58685da039b5855
gh-145301https://github.com/python/cpython/issues/145301
G…https://github.com/python/cpython/pull/145321
6acaf65https://github.com/python/cpython/commit/6acaf659ef0fdee131bc02f0b58685da039b5855
miss-islingtonhttps://github.com/miss-islington
on Mar 5, 2026https://github.com/python/cpython/issues/145301#event-23281937376
pythongh-145301: Fix double-free in hashlib and hmac module initializ…https://github.com/miss-islington/cpython/commit/a7e690b9c9df7c216ad8c713a54acf9a819dbed2
pythongh-145301https://github.com/python/cpython/issues/145301
a7e690bhttps://github.com/miss-islington/cpython/commit/a7e690b9c9df7c216ad8c713a54acf9a819dbed2
gpsheadhttps://github.com/gpshead
on Mar 5, 2026https://github.com/python/cpython/issues/145301#event-23282388031
[3.14] gh-145301: Fix double-free in hashlib and hmac module initiali…https://github.com/python/cpython/commit/f42692838c49c97844124b4fbb68c44d5424bbe0
gh-145301https://github.com/python/cpython/issues/145301
f426928https://github.com/python/cpython/commit/f42692838c49c97844124b4fbb68c44d5424bbe0
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Mar 5, 2026https://github.com/python/cpython/issues/145301#issuecomment-4002769446
@raminfphttps://github.com/raminfp
@krylosov-aahttps://github.com/krylosov-aa
sergey-miryanovhttps://github.com/sergey-miryanov
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Mar 5, 2026https://github.com/python/cpython/issues/145301#event-23286172089
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Mar 5, 2026https://github.com/python/cpython/issues/145301#issuecomment-4002772167
sergey-miryanovhttps://github.com/sergey-miryanov
on Mar 5, 2026https://github.com/python/cpython/issues/145301#event-23286186745
encukouhttps://github.com/encukou
on Mar 10, 2026https://github.com/python/cpython/issues/145301#event-23433544619
[3.13] gh-145301: Fix double-free in hashlib initialization (GH-145321)…https://github.com/python/cpython/commit/ba0d1b7deecf221597b2858c46fe6c4ff6f8417e
gh-145301https://github.com/python/cpython/issues/145301
GH-145321https://github.com/python/cpython/pull/145321
ba0d1b7https://github.com/python/cpython/commit/ba0d1b7deecf221597b2858c46fe6c4ff6f8417e
https://github.com/sergey-miryanov
sergey-miryanovhttps://github.com/sergey-miryanov
on Mar 10, 2026https://github.com/python/cpython/issues/145301#issuecomment-4034135906
sergey-miryanovhttps://github.com/sergey-miryanov
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Mar 10, 2026https://github.com/python/cpython/issues/145301#event-23445616667
ljfphttps://github.com/ljfp
on Apr 25, 2026https://github.com/python/cpython/issues/145301#event-24868322957
pythongh-145301: Fix double-free in hashlib and hmac module initializ…https://github.com/ljfp/cpython/commit/83fd6e171f33bbd1621af9c00310aa64177e408a
pythongh-145301https://github.com/python/cpython/issues/145301
83fd6e1https://github.com/ljfp/cpython/commit/83fd6e171f33bbd1621af9c00310aa64177e408a
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/145301
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/145301
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
easyhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22easy%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.