Sitelet https://github.com/python/cpython/issues/140120
Skip to content

Memory leak in hmac module with HACL* backend detected by AddressSanitizer #140120

Description

@ashm-dev

Bug report

Bug Description:

A memory leak has been detected in the hmac module when running test_hmac. The issue appears to be specific to the Hacl_Streaming_HMAC implementation, as indicated by the stack traces from the AddressSanitizer (ASan) report. The leaks occur within functions responsible for HMAC digest computation (_Py_LibHacl_Hacl_Streaming_HMAC_digest, hmac_digest_compute_locked), suggesting that memory allocated during these operations is not being properly deallocated.

Steps to Reproduce:

  1. Configure the build with the following flags to enable debugging and AddressSanitizer:

    CC=clang CXX=clang++ \
    ./configure \
    --disable-optimizations \
    --with-valgrind \
    --with-pydebug \
    --enable-pystats \
    --with-address-sanitizer
  2. Build CPython:

    make -j$(nproc)
  3. Run the hmac test suite:

    ./python -m test test_hmac

System Information:

  • OS: Ubuntu 25.04 (Plucky Puffin)
  • Kernel: Linux huawei 6.14.0-33-generic #33-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 17 23:22:02 UTC 2025 x86_64
  • Clang Version: Ubuntu clang version 20.1.2 (0ubuntu1)

ASan Leak Report:

test.log

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. gpshead commented on Oct 14, 2025

    @gpshead
    Member

    patch from upstream hacl* needed - #140124 (comment)

  2. protz commented on Oct 15, 2025

    @protz
    Contributor

    Thanks for the heads-up. Is there any more precise information as to where the issue occurs? Do we know which allocation is not freed?

    CC @R1kM

  3. protz commented on Oct 15, 2025

    @protz
    Contributor

    Oh I see the patch is in https://github.com/python/cpython/pull/140124/files -- let me look into this.

  4. protz commented on Oct 15, 2025

    @protz
    Contributor

    hacl-star/hacl-star#1064 has been merged so the next refresh of HACL* will have the fix. Thanks for reporting!

  5. self-assigned this
    on Oct 16, 2025
  6. added a commit that references this issue on Oct 16, 2025
  7. added a commit that references this issue on Oct 16, 2025
  8. ashm-dev commented on Oct 16, 2025

    @ashm-dev
    ContributorAuthor

    I checked, there are no more leaks, thank you!

  9. added a commit that references this issue on Oct 17, 2025
  10. gpshead commented on Oct 17, 2025

    @gpshead
    Member

    yay, thanks for finding this!

  11. added a commit that references this issue on Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixesextension-modulesC modules in the Modules dirperformancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions