git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/9] hash algorithm leak fixes

From
Jeff King <peff@peff.net>
Date
Jul 2, 2026, 07:52 UTC
Message-ID
<20260702075234.GA1548258@coredump.intra.peff.net>
This series fixes some leaks you can find by running:
  make SANITIZE=leak \
       OPENSSL_SHA256=1 \
       GIT_TEST_DEFAULT_HASH=sha256 \
       test

The crux of the issue is that we depend on calling git_hash_final() to clean up any git_hash_ctx we've initialized. But we don't always call that function (we may return early due to an error, etc).

We don't see these in our regular leak-test builds because the default hash implementations we use treat the hash_ctx as a sequence of bytes. So there's no cleanup needed, and just letting the context go out of scope is fine. But other implementations do allocate on initialization, and need to have some kind of free/discard function. So building with OPENSSL_SHA256 above is what lets us see the leaks.

You can see the same thing with OPENSSL_SHA1, but of course we don't recommend that. Using OPENSSL_SHA1_UNSAFE likewise, but it sees only a subset of the leaks since it is only used in a few code paths. Those leaks would be found if we turned on leak-checking in the linux-TEST-vars job, but the rest of them would require leak-checking the linux-sha256 job.

And as a special bonus, patch 8 is a semi-related leak that only affects libgcrypt. I don't think we build against that in CI at all. :-/

  [1/9]: csum-file: drop discard_hashfile()
  [2/9]: hash: add discard primitive
  [3/9]: csum-file: always finalize or discard hash
  [4/9]: csum-file: provide a function to release checkpoints
  [5/9]: patch-id: discard hash when done
  [6/9]: check_stream_oid(): discard hash on read error
  [7/9]: http: discard hash in dumb-http http_object_request
  [8/9]: hash: fix memory leak copying sha256 gcrypt handles
  [9/9]: hash: add platform-specific discard functions
 builtin/fast-import.c |  1 +
 builtin/patch-id.c    |  1 +
 csum-file.c           | 30 +++++++++++++++++-------------
 csum-file.h           |  2 +-
 diff.c                |  1 +
 hash.c                | 29 +++++++++++++++++++++++++++++
 hash.h                | 22 ++++++++++++++++++++++
 http.c                |  4 ++++
 http.h                |  1 +
 object-file.c         |  4 ++++
 sha1/openssl.h        |  6 ++++++
 sha256/gcrypt.h       |  7 +++++++
 sha256/openssl.h      |  6 ++++++
 13 files changed, 100 insertions(+), 14 deletions(-)
-Peff
Next: Jeff King
Message 1 of 20 in “hash algorithm leak fixes”
  1. 0/9 hash algorithm leak fixesJeff King, Jul 2, 2026
  2. 1/9 csum-file: drop discard_hashfile()Jeff King, Jul 2, 2026
  3. Junio C HamanoJul 2, 2026
  4. Jeff KingJul 2, 2026
  5. Patrick SteinhardtJul 3, 2026
  6. 2/9 hash: add discard primitiveJeff King, Jul 2, 2026
  7. Patrick SteinhardtJul 3, 2026
  8. 3/9 csum-file: always finalize or discard hashJeff King, Jul 2, 2026
  9. 4/9 csum-file: provide a function to release checkpointsJeff King, Jul 2, 2026
  10. Patrick SteinhardtJul 3, 2026
  11. 5/9 patch-id: discard hash when doneJeff King, Jul 2, 2026
  12. 6/9 check_stream_oid(): discard hash on read errorJeff King, Jul 2, 2026
  13. 7/9 http: discard hash in dumb-http http_object_requestJeff King, Jul 2, 2026
  14. Patrick SteinhardtJul 3, 2026
  15. brian m. carlsonJul 3, 2026
  16. Jeff KingJul 6, 2026
  17. Jeff KingJul 6, 2026
  18. Patrick SteinhardtJul 6, 2026
  19. 8/9 hash: fix memory leak copying sha256 gcrypt handlesJeff King, Jul 2, 2026
  20. 9/9 hash: add platform-specific discard functionsJeff King, Jul 2, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.