Skip to content

[3.15] gh-159786: Convert HACL* update() errors in _hmac after releasing the lock (GH-159805) - #159825

Merged
picnixz merged 1 commit into
python:3.15from
miss-islington:backport-0fba211-3.15
Oct 20, 2026
Merged

picnixz merged 1 commit into
python:3.15from
miss-islington:backport-0fba211-3.15

Conversation

@miss-islington

Copy link
Copy Markdown
Contributor

_hacl_hmac_state_update_once() converted the HACL* exit code into an
exception while the thread state was detached and, for HMAC.update(),
while the object's mutex was held. On debug builds, this re-attached the
thread state under the mutex and then called PyErr_Occurred() with the
thread state detached in the chunking loop of _hacl_hmac_state_update().

Return the raw HACL* exit code instead and convert it in _hmac.new() and
_hmac.HMAC.update() once the thread state is re-attached and the mutex
is released, as hmac_digest_compute_locked() already does. Release
builds keep ignoring the update() exit code.

Since _hacl_convert_errno() is now always called with an attached
thread state, remove the PyGILState_Ensure() added by gh-135561 and
assert that a thread state is attached instead.

  • simplify ifdefs: always check for the hacl error

(cherry picked from commit 0fba211)

Co-authored-by: Bénédikt Tran [email protected]
Co-authored-by: Gregory P. Smith [email protected]

…sing the lock (pythonGH-159805)

* pythongh-159786: Convert HACL* update() errors in `_hmac` after releasing the lock

`_hacl_hmac_state_update_once()` converted the HACL* exit code into an
exception while the thread state was detached and, for HMAC.update(),
while the object's mutex was held. On debug builds, this re-attached the
thread state under the mutex and then called PyErr_Occurred() with the
thread state detached in the chunking loop of `_hacl_hmac_state_update()`.

Return the raw HACL* exit code instead and convert it in `_hmac.new()` and
`_hmac.HMAC.update()` once the thread state is re-attached and the mutex
is released, as `hmac_digest_compute_locked()` already does. Release
builds keep ignoring the update() exit code.

Since `_hacl_convert_errno()` is now always called with an attached
thread state, remove the `PyGILState_Ensure()` added by pythongh-135561 and
assert that a thread state is attached instead.

* simplify ifdefs: always check for the hacl error

---------
(cherry picked from commit 0fba211)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Oct 20, 2026
@picnixz
picnixz enabled auto-merge (squash) October 20, 2026 19:49
@picnixz
picnixz merged commit 4250c67 into python:3.15 Oct 20, 2026
62 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sprint Oct 20, 2026
@miss-islington
miss-islington deleted the backport-0fba211-3.15 branch October 20, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants