Skip to content

fix(auth): Python 3.14 segfault in mTLS SSL_CTX pointer extraction - #1

Open
jay0lee wants to merge 1 commit into
mainfrom
fix/python314-ssl-ctx-offset
Open

fix(auth): Python 3.14 segfault in mTLS SSL_CTX pointer extraction#1
jay0lee wants to merge 1 commit into
mainfrom
fix/python314-ssl-ctx-offset

Conversation

@jay0lee

@jay0lee jay0lee commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Problem

wif-bunker segfaults 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):

offset = ctypes.sizeof(ctypes.c_void_p) * 2  # ob_refcnt + ob_type

After (PR googleapis#16976, broken on 3.14):

offset = sys.getsizeof(object())  # Changed in Python 3.14!

Python 3.14 changed the PyObject header layout, so sys.getsizeof(object()) returns a different value. The wrong offset reads garbage memory, which gets passed to OpenSSL as an SSL_CTX* pointer → segfault.

Fix

Restore the stable offset formula: ctypes.sizeof(ctypes.c_void_p) * 2. This equals the ob_refcnt + ob_type header size and is consistent across CPython versions.

The standalone google-auth-library-python repo already had this correct formula — it was lost during the monorepo refactor.

Testing

  • Ubuntu 24.04 (Python 3.12): ✅ passes (unchanged behavior)
  • Ubuntu 26.04 (Python 3.14): 🔧 fixes segfault during --use-adc mTLS handshake

….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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant