Title: CI: UBSan runs GIL-only and never against the JIT; two configurations already shipped by distros are unsanitized · Issue #154927 · python/cpython · GitHub
Open Graph Title: CI: UBSan runs GIL-only and never against the JIT; two configurations already shipped by distros are unsanitized · Issue #154927 · python/cpython
X Title: CI: UBSan runs GIL-only and never against the JIT; two configurations already shipped by distros are unsanitized · Issue #154927 · python/cpython
Description: Feature or enhancement Proposal The UBSan job in .github/workflows/build.yml runs against exactly one configuration: GIL-enabled, no JIT. Two configurations that CI already builds — and that distributions already ship — are never sanitiz...
Open Graph Description: Feature or enhancement Proposal The UBSan job in .github/workflows/build.yml runs against exactly one configuration: GIL-enabled, no JIT. Two configurations that CI already builds — and that distri...
X Description: Feature or enhancement Proposal The UBSan job in .github/workflows/build.yml runs against exactly one configuration: GIL-enabled, no JIT. Two configurations that CI already builds — and that distri...
Opengraph URL: https://github.com/python/cpython/issues/154927
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CI: UBSan runs GIL-only and never against the JIT; two configurations already shipped by distros are unsanitized","articleBody":"# Feature or enhancement\n\n## Proposal\n\nThe UBSan job in `.github/workflows/build.yml` runs against exactly one configuration: GIL-enabled, no JIT. Two configurations that CI already builds — and that distributions already ship — are never sanitized. Both are cheap to add, and I have measured what each would have caught.\n\n### 1. UBSan × `free-threading: true`\n\nThe sanitizer matrix pairs TSan with `free-threading: {false, true}` but UBSan only with `false`:\n\n```yaml\n free-threading:\n - false\n - true\n sanitizer:\n - TSan\n include:\n - check-name: Undefined behavior\n sanitizer: UBSan\n free-threading: false\n```\n\nSo files that only compile under `Py_GIL_DISABLED` are never built under UBSan. That is not a hypothetical gap: `Python/uniqueid.c:185` shifted a negative per-thread refcount delta left, which is UB, and it fired from interpreter startup and from every GC cycle. Over the full suite with all suppressions disabled:\n\n| | UB reports | test failures | failing files |\n|----------|-----------:|--------------:|--------------:|\n| before | 1762 | 529 | 61 |\n| after #154915 | 0 | 0 | 0 |\n\nOnce #154915 lands, this configuration is green, so adding it is a regression guard rather than a source of new work.\n\n### 2. UBSan × `--enable-experimental-jit`\n\n`jit.yml` builds the JIT in several configurations and `tail-call.yml` builds `--with-tail-call-interp`, but neither is ever combined with a sanitizer. The JIT's own C code — the stencil patcher in `Python/jit.c`, and the tier-2 optimiser in `Python/optimizer*.c` which only compiles under `-D_Py_TIER2=1` — is therefore never sanitized in CI.\n\nThis one has already proven productive when done by hand: gh-139269 (an unaligned `uint64_t` store in `Python/jit.c`'s `patch_*` functions, which segfaulted release builds) was found by building `--enable-experimental-jit` with `-fsanitize=address,undefined`, and gh-142476 was an ASan-found leak in `allocate_executor`.\n\nI ran the full test suite against a machine-code JIT build under UBSan, with every entry in `Tools/ubsan/suppressions.txt` disabled: **clean, zero reports**, 51,459 tests across 493 files, 4m50s. Verified non-vacuous — `_testinternalcapi.get_jit_backend()` returns `jit` and a hot loop produces real machine-code ranges, so this was the copy-and-patch JIT rather than a silent fallback to the uop interpreter.\n\nSince it is already green, this is also a pure regression guard.\n\n## Two smaller findings from the same sweep\n\n- **`local-bounds` is enabled nowhere.** `--with-undefined-behavior-sanitizer` injects plain `-fsanitize=undefined`, and `local-bounds` is not in that group even though it detects genuine UB. I built with it on and ran the full suite: **zero findings**, including no false positives from the trailing variable-length array idiom, which was the obvious risk. It looks free to add.\n- **`float-divide-by-zero`** (also not in the group) yields exactly one hit, `Modules/expat/xmlparse.c:869`, in vendored libexpat, which deliberately relies on IEEE-754 `+inf` and documents that in a comment. Not worth enabling without excluding expat.\n\n## On cost\n\nThe usual objection to widening the matrix is build time. For reference, a full PGO + ThinLTO + UBSan build — the heaviest combination I tried, including the instrumented build, the profile run, the rebuild and the ThinLTO link — took **9 min 43 s** at `--jobs=8`. A plain UBSan build is far cheaper, and the JIT suite run above took under five minutes.\n\n(That PGO/LTO configuration found nothing new, incidentally. It is worth noting only because `--enable-optimizations` and `--with-lto` appear in no workflow at all, while Arch, Debian and python-build-standalone all ship them. UBSan's checks are source-level, so PGO/LTO mostly changes which UB is *reached*; miscompilation from UB would show up as test failures rather than sanitizer reports, which is a different exercise.)\n\n## Linked PRs\n\n- #154915 — fixes the free-threaded UB, prerequisite for adding that matrix entry\n\n# Has this already been discussed elsewhere?\n\nThis is a follow-up to gh-148286.\n\n# Links to previous discussion of this feature:\n\n- gh-148286\n- gh-139269\n- gh-142476\n","author":{"url":"https://github.com/matthiasgoergens","@type":"Person","name":"matthiasgoergens"},"datePublished":"2026-07-30T13:22:46Z","url":"https://github.com/python/cpython/issues/154927"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:13b66216-617c-c3b4-cdfa-24ff5c466b54 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A234:21BD98:3FC7835:50AD7D3:6B024F23 |
| html-safe-nonce | 54450738d9111c2f2986a0516dbc7f987ee669d31d2a56572d7ee0b8fac68771 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjM0OjIxQkQ5ODozRkM3ODM1OjUwQUQ3RDM6NkIwMjRGMjMiLCJ2aXNpdG9yX2lkIjoiODc4NDc3NjU3NDQzMDI4NzcxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8d34b495b2b65070c095bd1bd3fa5f8d7bf90db630885560691d4912caf8d790 |
| hovercard-subject-tag | issue:5020175548 |
| 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/154927/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bf49303fdb15ee25e80a5e73b7bcabc840c0b92308e4ff22057a155af689128c/python/cpython/issues/154927 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bf49303fdb15ee25e80a5e73b7bcabc840c0b92308e4ff22057a155af689128c/python/cpython/issues/154927 |
| og:image:alt | Feature or enhancement Proposal The UBSan job in .github/workflows/build.yml runs against exactly one configuration: GIL-enabled, no JIT. Two configurations that CI already builds — and that distri... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | matthiasgoergens |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width