fix(auth): Python 3.14 segfault in mTLS SSL_CTX pointer extraction - #1
Open
jay0lee wants to merge 1 commit into
Open
fix(auth): Python 3.14 segfault in mTLS SSL_CTX pointer extraction#1jay0lee wants to merge 1 commit into
jay0lee wants to merge 1 commit into
Conversation
….14) PR googleapis#16976 replaced pyOpenSSL with stdlib ssl but changed the SSL_CTX* pointer offset formula from the stable: ctypes.sizeof(ctypes.c_void_p) * 2 to the fragile: sys.getsizeof(object()) Python 3.14 changed the PyObject header layout, causing sys.getsizeof(object()) to return a different value. This makes _cast_ssl_ctx_to_void_p_stdlib() read garbage memory, which is passed to OpenSSL as an SSL_CTX* → segfault during mTLS handshake. The standalone google-auth-library-python repo already had the correct formula. This commit restores it. Fixes segfault on Ubuntu 26.04 (Python 3.14) when using ECP mTLS offload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
wif-bunkersegfaults on Ubuntu 26.04 (Python 3.14) during the mTLS TLS handshake when using ECP offload.Root Cause
PR googleapis/google-cloud-python#16976 (July 2, 2026) replaced pyOpenSSL with stdlib ssl but changed the SSL_CTX* pointer offset formula in
_custom_tls_signer.py:Before (standalone repo, stable):
After (PR googleapis#16976, broken on 3.14):
Python 3.14 changed the
PyObjectheader layout, sosys.getsizeof(object())returns a different value. The wrong offset reads garbage memory, which gets passed to OpenSSL as anSSL_CTX*pointer → segfault.Fix
Restore the stable offset formula:
ctypes.sizeof(ctypes.c_void_p) * 2. This equals theob_refcnt + ob_typeheader size and is consistent across CPython versions.The standalone
google-auth-library-pythonrepo already had this correct formula — it was lost during the monorepo refactor.Testing
--use-adcmTLS handshake