Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade libgit2 to 1.3.0 #3962

Merged
merged 9 commits into from
Feb 8, 2022
Merged

Upgrade libgit2 to 1.3.0 #3962

merged 9 commits into from
Feb 8, 2022

Conversation

nalimilan
Copy link
Member

@nalimilan nalimilan commented Nov 28, 2021

Comment on lines -5 to -44
@@ -111,6 +111,14 @@ typedef struct {
* have the SHA-256 hash of the hostkey.
*/
unsigned char hash_sha256[32];
+
+ /**
+ * Hostkey itself.
+ */
+ int hostkey_type;
+ size_t hostkey_len;
+ unsigned char hostkey[1024];
+
} git_cert_hostkey;

/**
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index f4ed05bb1..ec6366a5f 100644
index 471c3273ed..32189d0979 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -523,6 +523,7 @@ static int _git_ssh_setup_conn(
@@ -525,6 +525,7 @@ static int _git_ssh_setup_conn(
git_credential *cred = NULL;
LIBSSH2_SESSION* session=NULL;
LIBSSH2_CHANNEL* channel=NULL;
LIBSSH2_SESSION *session=NULL;
LIBSSH2_CHANNEL *channel=NULL;
+ char *host_and_port;

t->current_stream = NULL;

@@ -566,6 +567,12 @@ post_extract:

cert.parent.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;

+ key = libssh2_session_hostkey(session, &cert.hostkey_len, &cert.hostkey_type);
+ bzero(&cert.hostkey, sizeof(cert.hostkey));
+ if (cert.hostkey_len > sizeof(cert.hostkey))
+ cert.hostkey_len = sizeof(cert.hostkey);
+ memcpy(&cert.hostkey, key, cert.hostkey_len);
+
#ifdef LIBSSH2_HOSTKEY_HASH_SHA256
key = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256);
if (key != NULL) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefanKarpinski This part of the patch seems to have been replaced by libgit2/libgit2@29fe5f6. I'm not sure whether it's perfectly equivalent though. x-ref #2419.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun. I guess we need to make sure that the certificate_callback and ssh_knownhost_check stuff in LibGit2 still works with the new libgit2 version. The patch was required, IIRC, because the old version of libgit2 was doing several broken things:

  1. It was failing to pass the port number with the host, which is necessary when connecting over SSH using different ports and using the known hosts file.
  2. It didn't pass the actual hostkey info from the connection to the callback, which made it impossible to do hostkey verification.

It's unclear how (or if) anyone was actually using SSH hostkey checking previously.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the first thing is still broken but the second thing got fixed but in an incompatible way because they stuck that raw_type field in there instead of just appending the hostkey data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. So AFAIK I kept the patch for the first thing so it should be OK. For the second one, tests added by JuliaLang/julia#39324 cover it, right? At least they pass with libgit2 1.3 and this branch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that tests the port part but it looks like it tests the hostkey part. I was testing by actually connecting to a host that I was proxying through to github.

Copy link
Member Author

@nalimilan nalimilan Dec 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I've just done this, and it seems to work!

For the record, here's what I did to forward port 22 on my machine to github.com:

sudo iptables -t nat -A PREROUTING -i wlo1 -p tcp --dport 32800  -j DNAT --to 38.140.156.5:22
sudo iptables -A FORWARD -i wlo1 -p tcp --dport 22 -d 38.140.156.5 -j ACCEPT

Then I had to go through my router as trying to connect from the same machine avoids the forwarding.

Then I installed a package via (after manually adding A.B.C.D to ~/.ssh/known_hosts with the signature for github.com):

]add ssh://git@A.B.C.D:32800/nalimilan/FreqTables.jl.git

One weird fact is that if I call git clone ssh://git@A.B.C.D:32800/nalimilan/FreqTables.jl.git, an entry for [A.B.C.D]:32800 is added to ~/.ssh/known_hosts, but that entry isn't used by ]add ... to work. I need to add the signature without the port. I guess that's expected since the same happens on Julia 1.6.

Anything I missed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump.

@giordano giordano added the julia 💜 ❤️ 💚 Builders and issues related to Julia and its dependencies label Nov 29, 2021
@mkitti
Copy link
Contributor

mkitti commented Jan 7, 2022

Would it make sense to pin this to MbedTLS 2.28.0?

@mkitti
Copy link
Contributor

mkitti commented Jan 7, 2022

JuliaLang/julia#42311 will not be able to succeed until we move the pin for LibGit2 to 2.28

LoadError("sysimg.jl", 19, LoadError("/buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.8/LibGit2/src/LibGit2.jl", 3, LoadError("/buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.8/LibGit2/src/utils.jl", 44, ErrorException("could not load library \"libgit2\"\nlibmbedtls.so.13: cannot open shared object file: No such file or directory"))))

@ViralBShah
Copy link
Member

What do we need to get this merged?

@giordano
Copy link
Member

Besides the fact it isn't clear to me whether the discussion above finished, we should decide whether to ship MbedTLS 2.28 in julia v1.8: if so, we must link libgit2 to that version (mbedtls breaks the ABI every time....)

@ViralBShah
Copy link
Member

I do believe we want to ship MbedTLS 2.28 in julia v1.8, and because of the security vulnerabilities, we may even need to backport to 1.7 and 1.6

@giordano
Copy link
Member

we may even need to backport to 1.7 and 1.6

That's not going to work: since mbedtls breaks the ABI, it'll break any package depending on it, like libcurl, libgit2.

@nalimilan
Copy link
Member Author

I think everything is ready, we just need a confirmation by @StefanKarpinski. JuliaLang/julia#43250 bumps libgit2 in Julia and should be merged soon after this one.

@ViralBShah
Copy link
Member

we may even need to backport to 1.7 and 1.6

That's not going to work: since mbedtls breaks the ABI, it'll break any package depending on it, like libcurl, libgit2.

Right - but if we don't that would mean that we have an LTS with know security vulnerabilities. It appears to me that we will probably need to update that whole bunch.

@ViralBShah
Copy link
Member

@nalimilan If things are good and passing tests, I suggest merging.

@ViralBShah
Copy link
Member

I think we still need to pin to MbedTLS 2.28 before merging.

@giordano
Copy link
Member

Note that you'll first need to update mbedtls 2.28 in julia, and perhaps update all dependent packages together at the same time, otherwise nothing will work at all.

@ViralBShah
Copy link
Member

ViralBShah commented Jan 30, 2022

I assume that all Ygg PRs need to be merged first, and then Julia 1.8-dev does a single PR to bump them all. We still need an upstream release of libssh2. Going step by step - can we merge this PR now?

@nalimilan
Copy link
Member Author

@giordano Could you confirm what steps we should take?

@mkitti
Copy link
Contributor

mkitti commented Feb 7, 2022

The issue to watch is #4208 for libssh2. It would be preferable to have a version bump upstream, although we need to consider if we should just create a libssh2 1.10.1 ourselves.

@giordano
Copy link
Member

giordano commented Feb 7, 2022

Yes, libgit2 and libssh2 linking to the new mbedtls must all go together.

@nalimilan
Copy link
Member Author

OK. TBH I don't really understand the situation with libssh2: is there anything preventing us from upgrading to 1.10.0 and handling the security fix after the feature freeze?

@ViralBShah
Copy link
Member

We can certainly after the freeze. It is just a crucial CVE in mbedtls, so sooner the better.

@ViralBShah
Copy link
Member

ViralBShah commented Feb 7, 2022

@nalimilan We now have libssh2 1.10.1 merged in #4208. Updating this PR to use that version.

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
Copy link
Member

@giordano giordano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok with me. Feel free to merge if there are no more concerns with compatibility on the julia side

@ViralBShah
Copy link
Member

Only one way to find out.

@ViralBShah ViralBShah merged commit 4ebbdc2 into master Feb 8, 2022
@ViralBShah ViralBShah deleted the nl/libgit2-1.3.0 branch February 8, 2022 14:24
simeonschaub pushed a commit to simeonschaub/Yggdrasil that referenced this pull request Feb 23, 2022
* Upgrade libgit2 to 1.3.0

* Delete libgit2-continue-zlib.patch

* Update libgit2-hostkey.patch

* Update libgit2-hostkey.patch

* Pin MbedTLS to 2.28

* Update L/LibGit2/build_tarballs.jl

* Update build_tarballs.jl

* Update build_tarballs.jl

* Update L/LibGit2/build_tarballs.jl

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>

Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
julia 💜 ❤️ 💚 Builders and issues related to Julia and its dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants