git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Bagas Sanjaya <bagasdotme@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>, Eric Wong <e@80x24.org>,
	Junio C Hamano <gitster@pobox.com>,
	Jonathan Tan <jonathantanmy@google.com>
Subject: Re: [REGRESSION] Can't clone GitHub repos (fetch-pack error) due to avoiding deprecated OpenSSL SHA-1 routines
Date: Thu, 31 Aug 2023 23:19:14 +0000	[thread overview]
Message-ID: <ZPEf8kbBUFqLO25W@tapette.crustytoothpaste.net> (raw)
In-Reply-To: <ZPCL11k38PXTkFga@debian.me>

[-- Attachment #1: Type: text/plain, Size: 2875 bytes --]

On 2023-08-31 at 12:47:19, Bagas Sanjaya wrote:
> Hi,
> 
> I built Git v2.42.0 on Debian testing, linked with OpenSSL (v3.0.10 from
> distribution) with Makefile knob `OPENSSL_SHA1=YesPlease 
> OPENSSL_SHA256=YesPlease`. I tried to shallow clone git.git repository:

I should point out that using OpenSSL's SHA-1 support is insecure
because it doesn't check for collisions.  As a practical matter, no
distro builds that way, and if you distributed that build, it would
probably qualify for a CVE.

However, OPENSSL_SHA256 being set is fine for a local build or a build
where you're not distributing OpenSSL itself.

> ```
> $ git clone https://github.com/git/git --depth=1 git-scm
> ```
> 
> All the necessary objects were fetched but the clone errored instead with:
> 
> ```
> fatal: fetch-pack: invalid index-pack output
> ```
> 
> This issue is a regression since v2.41.0 doesn't have it. Bisecting, the
> culprit is commit bda9c12073e7 (avoid SHA-1 functions deprecated in OpenSSL 3+,
> 2023-08-01). AFAIK, the culprit doesn't touch `fetch-pack.c` as I hoped.

I also see this with that configuration on Debian sid, and it appears to
affect SHA-256 as well.  The testsuite fails in a variety of spectacular
ways.  For example, t0410 is broken in exactly this way.

A simple git index-pack on Git's codebase shows a segfault in
`EVP_DigestUpdate` after calling `flush`.  It's not clear to me why this
would occur, but I did note that the context is a static variable.  I
wonder if there's something about this configuration that results in
breakage if a context is reused, although looking at the code, nothing
jumps out to me.

I did, however, apply this patch, which I think makes the problem really
clear:

----
diff --git a/sha1/openssl.h b/sha1/openssl.h
index 006c1f4ba5..0390ba9da6 100644
--- a/sha1/openssl.h
+++ b/sha1/openssl.h
@@ -32,6 +32,7 @@ static inline void openssl_SHA1_Final(unsigned char *digest,
 {
 	EVP_DigestFinal_ex(ctx->ectx, digest, NULL);
 	EVP_MD_CTX_free(ctx->ectx);
+	ctx->ectx = NULL;
 }
 
 static inline void openssl_SHA1_Clone(struct openssl_SHA1_CTX *dst,
----

Now we see that when the segfault happens, `input_ctx.sha1.ectx` is
NULL.  I'm not sure why that is, or what needs to be fixed, but I think
it's clear that _someone_ isn't calling the `init_fn` method before
re-using the context, and they definitely should be.

Hopefully this gives someone a good push in the right direction on
solving the problem.

If someone wants to pick up the above patch to help make this problem
more obvious in the future (don't forget to do the same for SHA-256),
please do so with my blessing.  I wouldn't say you need my sign-off
since it's so trivial, but feel free to forge it if it makes you feel
better.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

  reply	other threads:[~2023-08-31 23:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31 12:47 [REGRESSION] Can't clone GitHub repos (fetch-pack error) due to avoiding deprecated OpenSSL SHA-1 routines Bagas Sanjaya
2023-08-31 23:19 ` brian m. carlson [this message]
2023-09-01  0:57   ` Eric Wong
2023-09-01  2:09     ` [PATCH] treewide: fix various bugs w/ OpenSSL 3+ EVP API Eric Wong
2023-09-01  5:32       ` Junio C Hamano
2023-09-01  6:46       ` Oswald Buddenhagen
2023-09-01 11:02       ` Bagas Sanjaya
2023-09-01 11:09   ` [REGRESSION] Can't clone GitHub repos (fetch-pack error) due to avoiding deprecated OpenSSL SHA-1 routines Bagas Sanjaya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZPEf8kbBUFqLO25W@tapette.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=bagasdotme@gmail.com \
    --cc=e@80x24.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).