René's URL Explorer Experiment


Title: gh-149816: Fix UAF in Modules/_pickle.c by alexkats · Pull Request #150024 · python/cpython · GitHub

Open Graph Title: gh-149816: Fix UAF in Modules/_pickle.c by alexkats · Pull Request #150024 · python/cpython

X Title: gh-149816: Fix UAF in Modules/_pickle.c by alexkats · Pull Request #150024 · python/cpython

Description: Get a strong reference atomically for list item instead of 2 operations. Original description of the problem from 91.md: Vulnerability #91 Title: Racy list item borrow causes UAF Category: Memory Safety Violations Tags: write,race,env,dos CWEs: CWE-416, CWE-367 CVSS: CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:N/VC:L/VI:L/VA:H/SC:N/SI:N/SA:N Severity: Medium (5.8) Location: cpython/Modules/_pickle.c:3213:3214 in function batch_list_exact Description batch_list_exact reads list elements using PyList_GET_ITEM and only then increments the reference count (Py_INCREF) without holding the list lock or using a safe strong-ref getter (cpython/Modules/_pickle.c:3213-3214, also cpython/Modules/_pickle.c:3197-3198). In free-threaded mode, _pickle runs without the GIL (cpython/Modules/_pickle.c:8242), so concurrent list mutation is possible while pickling. A mutator thread can remove/replace the same element and decref it to zero (cpython/Objects/listobject.c:1145-1156) between size check/access in batch_list_exact (cpython/Modules/_pickle.c:3212-3214), leading to Py_INCREF on freed memory (use-after-free write). Trigger Conditions Pre-conditions: CPython is built/run in free-threaded mode (no global interpreter lock). The C accelerator _pickle is used (it declares no-GIL operation at cpython/Modules/_pickle.c:8242). Target object is an exact list and protocol is greater than 0, so save_list uses batch_list_exact (cpython/Modules/_pickle.c:3266-3269). The same list object is shared across threads. Data flow: Thread A calls pickle.dumps(shared_list, protocol=5); save_list dispatches to batch_list_exact (cpython/Modules/_pickle.c:3266-3269). In batch_list_exact, Thread A evaluates loop/size and then fetches a borrowed element via PyList_GET_ITEM (cpython/Modules/_pickle.c:3212-3213). Concurrently, Thread B mutates that list index (e.g., del shared_list[i] or shared_list[i] = other), and list code decrefs the old element (cpython/Objects/listobject.c:1145-1156), potentially freeing it. Thread A performs Py_INCREF(item) on the stale pointer (cpython/Modules/_pickle.c:3214), triggering UAF memory corruption/crash. Impact This can cause native memory corruption in the interpreter (use-after-free with refcount write), typically leading to process crash (denial of service) and potentially enabling arbitrary code execution in worst case under favorable heap/layout conditions. Exploitability is constrained by requiring a free-threaded build and a concurrent mutation race on the same list object, but the code path is reachable from normal Python APIs (pickle.dumps) and does not enforce safety against such concurrent access. Remediation In batch_list_exact() (cpython/Modules/_pickle.c), replace both unsafe borrowed-ref reads (PyList_GET_ITEM + Py_INCREF) with a strong-reference API (PyList_GetItemRef / internal equivalent) so element lifetime is acquired atomically for free-threaded builds. Remove dependence on repeatedly reading live list size inside the loop; instead iterate against a stable expected length captured in save_list() and passed into batch_list_exact(). Add explicit mutation detection/error handling in the exact-list fast path (similar to dict/set batching): if size/index validity changes during traversal, raise a deterministic RuntimeError (e.g., “list changed size during iteration”) instead of continuing. Add/extend free-threaded regression tests for concurrent pickle.dumps() + list mutation to ensure no UAF/crash, and verify behavior is clean exception-only under race. Reproduction Build a free-threaded CPython (the no-GIL configuration) with debug aids enabled if possible (ASAN/UBSAN build, or at least --with-pydebug). In that interpreter, create a test scenario with a shared exact list used by two concurrent threads: one thread repeatedly pickles the same list with protocol > 0 (so _pickle takes the fast exact-list path), the other thread continuously mutates that same list (delete/replace items, especially around low indexes). Make the list elements objects with short lifetimes (frequent replacement with fresh temporary objects) and run both threads in tight loops for many iterations to maximize race frequency. Repeat the run a few times if it does not trigger immediately; race timing is non-deterministic. Increasing core count, reducing sleeps, and extending runtime should increase hit rate. Confirm the issue by observing any of the following: interpreter crash/segfault during pickling, debug build fatal error related to refcount/object validity, sanitizer report showing a use-after-free or invalid memory access with frames near _pickle list batching / Py_INCREF on a list item. Code Context item = PyList_GET_ITEM(obj, total); Py_INCREF(item); Issue: gh-149816

Open Graph Description: Get a strong reference atomically for list item instead of 2 operations. Original description of the problem from 91.md: Vulnerability #91 Title: Racy list item borrow causes UAF Category: Memory S...

X Description: Get a strong reference atomically for list item instead of 2 operations. Original description of the problem from 91.md: Vulnerability #91 Title: Racy list item borrow causes UAF Category: Memory S...

Opengraph URL: https://github.com/python/cpython/pull/150024

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:d6c6caea-e532-aac5-4922-82d09033aedb
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8C9A:19730C:1136897:1785C8C:6A520DA4
html-safe-nonce5fd4d6d2e6e2a9a27a7012d66bf0e662b022ebe5655c3a95941c3d33e0ff5985
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzlBOjE5NzMwQzoxMTM2ODk3OjE3ODVDOEM6NkE1MjBEQTQiLCJ2aXNpdG9yX2lkIjoiMjY4MjYzNzAyNTgzNjkyODQyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb67fe2a18ea33cec00f53f57210fb08be90893fffcd5c95dec0df12104cdd60a
hovercard-subject-tagpull_request:3704345519
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/150024/files
twitter:imagehttps://avatars.githubusercontent.com/u/7119810?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/7119810?s=400&v=4
og:image:altGet a strong reference atomically for list item instead of 2 operations. Original description of the problem from 91.md: Vulnerability #91 Title: Racy list item borrow causes UAF Category: Memory S...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/150024/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F150024%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F150024%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/150024/files
Reloadhttps://github.com/python/cpython/pull/150024/files
Reloadhttps://github.com/python/cpython/pull/150024/files
Please reload this pagehttps://github.com/python/cpython/pull/150024/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/150024/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.7k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
encukouhttps://github.com/encukou
python:mainhttps://github.com/python/cpython/tree/main
alexkats:fix-91https://github.com/alexkats/cpython/tree/fix-91
Conversation 12 https://github.com/python/cpython/pull/150024
Commits 3 https://github.com/python/cpython/pull/150024/commits
Checks 59 https://github.com/python/cpython/pull/150024/checks
Files changed https://github.com/python/cpython/pull/150024/files
Please reload this pagehttps://github.com/python/cpython/pull/150024/files
gh-149816: Fix UAF in Modules/_pickle.c https://github.com/python/cpython/pull/150024/files#top
Show all changes 3 commits https://github.com/python/cpython/pull/150024/files
6e4987c gh-149816: Fix UAF in Modules/_pickle.c alexkats May 18, 2026 https://github.com/python/cpython/pull/150024/commits/6e4987c4a28dbfad386cc04730e21a01cb22eaf7
9e2e0ba reword news gpshead May 18, 2026 https://github.com/python/cpython/pull/150024/commits/9e2e0ba481df8ca4b1a32ab09daafce254f29f2f
d1e3981 gh-149816: Check for changed list size in Modules/_pickle.c alexkats May 18, 2026 https://github.com/python/cpython/pull/150024/commits/d1e3981f5115bfaad27b604baa01a0ab94a3f4fa
Clear filters https://github.com/python/cpython/pull/150024/files
Please reload this pagehttps://github.com/python/cpython/pull/150024/files
Please reload this pagehttps://github.com/python/cpython/pull/150024/files
test_pickle.py https://github.com/python/cpython/pull/150024/files#diff-0ba3c585f5d7cb238340d9412562fff74cfd9d43910adb2d9ce74e0e333ddba5
2026-05-18-12-42-31.gh-issue-149816.F98iME.rst https://github.com/python/cpython/pull/150024/files#diff-38844e0a77bb6fe7b03563d10fabbf692ba14338af7c2f719f3226cf4d1fc0a1
_pickle.c https://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
Lib/test/test_free_threading/test_pickle.pyhttps://github.com/python/cpython/pull/150024/files#diff-0ba3c585f5d7cb238340d9412562fff74cfd9d43910adb2d9ce74e0e333ddba5
View file https://github.com/alexkats/cpython/blob/d1e3981f5115bfaad27b604baa01a0ab94a3f4fa/Lib/test/test_free_threading/test_pickle.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150024/{{ revealButtonHref }}
https://github.com/python/cpython/pull/150024/files#diff-0ba3c585f5d7cb238340d9412562fff74cfd9d43910adb2d9ce74e0e333ddba5
Misc/NEWS.d/next/Library/2026-05-18-12-42-31.gh-issue-149816.F98iME.rsthttps://github.com/python/cpython/pull/150024/files#diff-38844e0a77bb6fe7b03563d10fabbf692ba14338af7c2f719f3226cf4d1fc0a1
View file https://github.com/alexkats/cpython/blob/d1e3981f5115bfaad27b604baa01a0ab94a3f4fa/Misc/NEWS.d/next/Library/2026-05-18-12-42-31.gh-issue-149816.F98iME.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150024/{{ revealButtonHref }}
Modules/_pickle.chttps://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
View file https://github.com/alexkats/cpython/blob/d1e3981f5115bfaad27b604baa01a0ab94a3f4fa/Modules/_pickle.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150024/{{ revealButtonHref }}
https://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
https://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
https://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
https://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
https://github.com/python/cpython/pull/150024/files#diff-6a8bf1993db0eae81c2ee98e38eeb1ac4d9342b8b5c090f33417a064e6678562
Please reload this pagehttps://github.com/python/cpython/pull/150024/files
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.