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

Re: [PATCH v2 0/8] hash: introduce unsafe_hash_algo(), drop unsafe_ variants

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 10, 2025, 21:29 UTC
Message-ID
<Z4GRQvAIsSIeQuYd@nand.local>
In-Reply-To
<20250110104106.GB1014709@coredump.intra.peff.net>
On Fri, Jan 10, 2025 at 05:41:06AM -0500, Jeff King wrote:
Show 24 quoted lines
> On Wed, Jan 08, 2025 at 02:14:29PM -0500, Taylor Blau wrote:
>
> > (This series is rebased on 'master', which is 14650065b7
> > (RelNotes/2.48.0: fix typos etc., 2025-01-07) at the time of writing).
> >
> > The bulk of this series is unchanged since last time, but a new seventh
> > patch that further hardens the hashfile_checkpoint callers on top of
> > Patrick's recent series[1].
>
> I think that new patch is a definite improvement, though I left some
> comments there.
>
> The changes in patch 1 look fine to me (I still think a generic
> "test-tool hash" would make more sense, but I'm OK punting on that for
> now).
>
> I didn't see any response to the review in round 1 about the pointer
> dangers in patch 3. What do you think of using a separate
> git_hash_algo_fns struct, with the one-time conversion I showed in the
> subthread of:
>
>   https://lore.kernel.org/git/20241121093731.GD602681@coredump.intra.peff.net/
>
> ?

Oops. I must have missed those messages; and sure enough when focusing my inbox on this thread they are indeed unread :-).

That said, I am not sure that that direction is one that I'd want to go in. Part of the goal of this series is to make it possible to mix safe and unsafe function calls on the same hash function. So doing something like:

    struct git_hash_algo *algop;
    algop->init_fn(&ctx);
in one part of the code, and then (using the same algop) calling:
    algop->unsafe_final_fn(...);

should be impossible to do to. The benefit of having only a single set of functions implemented on the git_hash_algo type is that it is impossible to mix the two: you'd have to use a different git_hash_algo altogether!

So porting the above example to your and brian's git_hash_algo_fns struct, you'd still be able to do:

    algop->fn.init(&ctx);

in one part of the code and algop->unsafe_fn.final(...) in another part, which doesn't appear to me to be safer than the current situation that this series aims to solve.

But if I am misunderstanding something about your/brian's discussion earlier in this thread, please feel free to correct me.

Thanks, Taylor

Previous: Jeff KingNext: Jeff King
Message 34 of 60 in “hash: introduce unsafe_hash_algo(), drop unsafe_ variants”
  1. 0/6 hash: introduce unsafe_hash_algo(), drop unsafe_ variantsTaylor Blau, Nov 20, 2024
  2. 1/6 csum-file: store the hash algorithm as a struct fieldTaylor Blau, Nov 20, 2024
  3. Jeff KingNov 21, 2024
  4. 2/6 csum-file.c: extract algop from hashfile_checksum_valid()Taylor Blau, Nov 20, 2024
  5. 3/6 hash.h: introduce `unsafe_hash_algo()`Taylor Blau, Nov 20, 2024
  6. Jeff KingNov 21, 2024
  7. brian m. carlsonNov 22, 2024
  8. Jeff KingNov 22, 2024
  9. brian m. carlsonNov 22, 2024
  10. Taylor BlauJan 10, 2025
  11. Jeff KingJan 11, 2025
  12. 4/6 csum-file.c: use unsafe_hash_algo()Taylor Blau, Nov 20, 2024
  13. 5/6 t/helper/test-hash.c: use unsafe_hash_algo()Taylor Blau, Nov 20, 2024
  14. 6/6 hash.h: drop unsafe_ function variantsTaylor Blau, Nov 20, 2024
  15. Jeff KingNov 21, 2024
  16. 0/8 hash: introduce unsafe_hash_algo(), drop unsafe_ variantsTaylor Blau, Jan 8, 2025
  17. 1/8 t/helper/test-tool: implement sha1-unsafe helperTaylor Blau, Jan 8, 2025
  18. 2/8 csum-file: store the hash algorithm as a struct fieldTaylor Blau, Jan 8, 2025
  19. Patrick SteinhardtJan 16, 2025
  20. Taylor BlauJan 17, 2025
  21. 3/8 csum-file.c: extract algop from hashfile_checksum_valid()Taylor Blau, Jan 8, 2025
  22. 4/8 hash.h: introduce `unsafe_hash_algo()`Taylor Blau, Jan 8, 2025
  23. Patrick SteinhardtJan 16, 2025
  24. Taylor BlauJan 17, 2025
  25. 5/8 csum-file.c: use unsafe_hash_algo()Taylor Blau, Jan 8, 2025
  26. 6/8 t/helper/test-hash.c: use unsafe_hash_algo()Taylor Blau, Jan 8, 2025
  27. 7/8 csum-file: introduce hashfile_checkpoint_init()Taylor Blau, Jan 8, 2025
  28. Jeff KingJan 10, 2025
  29. Taylor BlauJan 10, 2025
  30. Taylor BlauJan 17, 2025
  31. Jeff KingJan 18, 2025
  32. 8/8 hash.h: drop unsafe_ function variantsTaylor Blau, Jan 8, 2025
  33. Jeff KingJan 10, 2025
  34. Taylor BlauJan 10, 2025
  35. Jeff KingJan 11, 2025
  36. Junio C HamanoJan 11, 2025
  37. Taylor BlauJan 11, 2025
  38. 0/8 hash: introduce unsafe_hash_algo(), drop unsafe_ variantsTaylor Blau, Jan 17, 2025
  39. 1/8 t/helper/test-tool: implement sha1-unsafe helperTaylor Blau, Jan 17, 2025
  40. 2/8 csum-file: store the hash algorithm as a struct fieldTaylor Blau, Jan 17, 2025
  41. 3/8 csum-file.c: extract algop from hashfile_checksum_valid()Taylor Blau, Jan 17, 2025
  42. 4/8 hash.h: introduce `unsafe_hash_algo()`Taylor Blau, Jan 17, 2025
  43. 5/8 csum-file.c: use unsafe_hash_algo()Taylor Blau, Jan 17, 2025
  44. 6/8 t/helper/test-hash.c: use unsafe_hash_algo()Taylor Blau, Jan 17, 2025
  45. 7/8 csum-file: introduce hashfile_checkpoint_init()Taylor Blau, Jan 17, 2025
  46. 8/8 hash.h: drop unsafe_ function variantsTaylor Blau, Jan 17, 2025
  47. Jeff KingJan 18, 2025
  48. Jeff KingJan 18, 2025
  49. Junio C HamanoJan 22, 2025
  50. 0/8 hash: introduce unsafe_hash_algo(), drop unsafe_ variantsTaylor Blau, Jan 23, 2025
  51. 1/8 t/helper/test-tool: implement sha1-unsafe helperTaylor Blau, Jan 23, 2025
  52. 2/8 csum-file: store the hash algorithm as a struct fieldTaylor Blau, Jan 23, 2025
  53. 3/8 csum-file.c: extract algop from hashfile_checksum_valid()Taylor Blau, Jan 23, 2025
  54. 4/8 hash.h: introduce `unsafe_hash_algo()`Taylor Blau, Jan 23, 2025
  55. 5/8 csum-file.c: use unsafe_hash_algo()Taylor Blau, Jan 23, 2025
  56. 6/8 t/helper/test-hash.c: use unsafe_hash_algo()Taylor Blau, Jan 23, 2025
  57. 7/8 csum-file: introduce hashfile_checkpoint_init()Taylor Blau, Jan 23, 2025
  58. 8/8 hash.h: drop unsafe_ function variantsTaylor Blau, Jan 23, 2025
  59. Junio C HamanoJan 23, 2025
  60. Jeff KingJan 23, 2025

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.