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

Re: [PATCH 02/10] builtin/fast-import: fix segfault with unsafe SHA1

From
Taylor Blau <me@ttaylorr.com>
Date
Jan 8, 2025, 19:21 UTC
Message-ID
<Z37QS/MnGUZ7zcrR@nand.local>
In-Reply-To
<Z30YvHKjA_b6_xwt@pks.im>
On Tue, Jan 07, 2025 at 01:06:20PM +0100, Patrick Steinhardt wrote:
Show 34 quoted lines
> > > > I think we should perhaps combine forces here. My ideal end-state is to
> > > > have the unsafe_hash_algo() stuff land from my earlier series, then have
> > > > these two fixes (adjusted to the new world order as above), and finally
> > > > the Meson fixes after that.
> > > >
> > > > Does that seem like a plan to you? If so, I can put everything together
> > > > and send it out (if you're OK with me forging your s-o-b).
> > >
> > > I think the ideal state would be if the hashing function used was stored
> > > as part of `struct git_hash_ctx`. So the flow basically becomes for
> > > example:
> > >
> > >     ```
> > >     struct git_hash_ctx ctx;
> > >     struct object_id oid;
> > >
> > >     git_hash_sha1_init(&ctx);
> > >     git_hash_update(&ctx, data);
> > >     git_hash_final_oid(&oid, &ctx);
> > >     ```
> > >
> > > Note how the intermediate calls don't need to know which hash function
> > > you used to initialize the `struct git_hash_ctx` -- the structure itself
> > > should remember what it has been initilized with and do the right thing.
> >
> > I'm not sure I'm following you here. In the stream_blob() function
> > within fast-import, the problem isn't that we're switching hash
> > functions mid-stream, but that we're initializing the hashfile_context
> > structure with the wrong hash function to begin with.
>
> True, but it would have been a non-issue if the hash context itself knew
> which hash function to use for updates. Sure, we would've used the slow
> variant of SHA1 instead of the fast-but-unsafe one. But that feels like
> the lesser evil compared to crashing.

For posterity, Patrick and I used some of our monthly meeting this morning to spend some time together pairing on this idea.

It ended up being a dead-end, since this approach only protects you against changing the hash function mid-stream, and not using the incorrect context type from the union.

That was along the lines of what I was originally thinking, and so I resurrected my series to introduce 'unsafe_hash_algo()' here:

    https://lore.kernel.org/git/cover.1736363652.git.me@ttaylorr.com/

I got the impression that Patrick and I are on the same page there as that being a good path forward, but I'll let him chime in in case I misunderstood anything.

Thanks, Taylor

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 8 of 19 in “Fix segfaults when using the unsafe SHA1 backend”
  1. 00/10 Fix segfaults when using the unsafe SHA1 backendPatrick Steinhardt, Dec 30, 2024
  2. 02/10 builtin/fast-import: fix segfault with unsafe SHA1 backendPatrick Steinhardt, Dec 30, 2024
  3. Taylor BlauDec 30, 2024
  4. Patrick SteinhardtJan 3, 2025
  5. Junio C HamanoJan 3, 2025
  6. Taylor BlauJan 6, 2025
  7. Patrick SteinhardtJan 7, 2025
  8. Taylor BlauJan 8, 2025
  9. Patrick SteinhardtJan 9, 2025
  10. 01/10 bulk-checkin: fix segfault with unsafe SHA1 backendPatrick Steinhardt, Dec 30, 2024
  11. 03/10 ci: exercise unsafe OpenSSL backendPatrick Steinhardt, Dec 30, 2024
  12. Taylor BlauDec 30, 2024
  13. 04/10 meson: consistenlty spell 'CommonCrypto'Patrick Steinhardt, Dec 30, 2024
  14. 05/10 meson: deduplicate access to SHA1/SHA256 backend optionsPatrick Steinhardt, Dec 30, 2024
  15. 06/10 meson: require SecurityFramework when it's used as SHA1 backendPatrick Steinhardt, Dec 30, 2024
  16. 07/10 meson: simplify conditions for HTTPS and SHA1 dependenciesPatrick Steinhardt, Dec 30, 2024
  17. 08/10 meson: add missing dots for build optionsPatrick Steinhardt, Dec 30, 2024
  18. 09/10 meson: wire up unsafe SHA1 backendPatrick Steinhardt, Dec 30, 2024
  19. 10/10 meson: provide a summary of configured backendsPatrick Steinhardt, Dec 30, 2024

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.