Skip to content

Commit 7397ca3

Browse files
committed
Git 2.25.4
This merges up the security fix from v2.17.5. Signed-off-by: Jonathan Nieder <[email protected]>
2 parents 67b0a24 + b86a4be commit 7397ca3

17 files changed

+499
-42
lines changed

Documentation/RelNotes/2.17.5.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Git v2.17.5 Release Notes
2+
=========================
3+
4+
This release is to address a security issue: CVE-2020-11008
5+
6+
Fixes since v2.17.4
7+
-------------------
8+
9+
* With a crafted URL that contains a newline or empty host, or lacks
10+
a scheme, the credential helper machinery can be fooled into
11+
providing credential information that is not appropriate for the
12+
protocol in use and host being contacted.
13+
14+
Unlike the vulnerability CVE-2020-5260 fixed in v2.17.4, the
15+
credentials are not for a host of the attacker's choosing; instead,
16+
they are for some unspecified host (based on how the configured
17+
credential helper handles an absent "host" parameter).
18+
19+
The attack has been made impossible by refusing to work with
20+
under-specified credential patterns.
21+
22+
Credit for finding the vulnerability goes to Carlo Arenas.

Documentation/RelNotes/2.18.4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.18.4 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.19.5.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.19.5 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.20.4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.20.4 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.21.3.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.21.3 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.22.4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.22.4 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.23.3.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.23.3 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.24.3.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.24.3 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

Documentation/RelNotes/2.25.4.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Git v2.25.4 Release Notes
2+
=========================
3+
4+
This release merges the security fix that appears in v2.17.5; see
5+
the release notes for that version for details.

GIT-VERSION-GEN

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
GVF=GIT-VERSION-FILE
4-
DEF_VER=v2.25.3
4+
DEF_VER=v2.25.4
55

66
LF='
77
'

RelNotes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Documentation/RelNotes/2.25.3.txt
1+
Documentation/RelNotes/2.25.4.txt

credential.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ static int proto_is_http(const char *s)
8989

9090
static void credential_apply_config(struct credential *c)
9191
{
92+
if (!c->host)
93+
die(_("refusing to work with credential missing host field"));
94+
if (!c->protocol)
95+
die(_("refusing to work with credential missing protocol field"));
96+
9297
if (c->configured)
9398
return;
9499
git_config(credential_config_callback, c);
@@ -191,8 +196,11 @@ int credential_read(struct credential *c, FILE *fp)
191196
return 0;
192197
}
193198

194-
static void credential_write_item(FILE *fp, const char *key, const char *value)
199+
static void credential_write_item(FILE *fp, const char *key, const char *value,
200+
int required)
195201
{
202+
if (!value && required)
203+
BUG("credential value for %s is missing", key);
196204
if (!value)
197205
return;
198206
if (strchr(value, '\n'))
@@ -202,11 +210,11 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
202210

203211
void credential_write(const struct credential *c, FILE *fp)
204212
{
205-
credential_write_item(fp, "protocol", c->protocol);
206-
credential_write_item(fp, "host", c->host);
207-
credential_write_item(fp, "path", c->path);
208-
credential_write_item(fp, "username", c->username);
209-
credential_write_item(fp, "password", c->password);
213+
credential_write_item(fp, "protocol", c->protocol, 1);
214+
credential_write_item(fp, "host", c->host, 1);
215+
credential_write_item(fp, "path", c->path, 0);
216+
credential_write_item(fp, "username", c->username, 0);
217+
credential_write_item(fp, "password", c->password, 0);
210218
}
211219

212220
static int run_credential_helper(struct credential *c,
@@ -352,8 +360,11 @@ int credential_from_url_gently(struct credential *c, const char *url,
352360
* (3) proto://<user>:<pass>@<host>/...
353361
*/
354362
proto_end = strstr(url, "://");
355-
if (!proto_end)
356-
return 0;
363+
if (!proto_end || proto_end == url) {
364+
if (!quiet)
365+
warning(_("url has no scheme: %s"), url);
366+
return -1;
367+
}
357368
cp = proto_end + 3;
358369
at = strchr(cp, '@');
359370
colon = strchr(cp, ':');
@@ -374,10 +385,8 @@ int credential_from_url_gently(struct credential *c, const char *url,
374385
host = at + 1;
375386
}
376387

377-
if (proto_end - url > 0)
378-
c->protocol = xmemdupz(url, proto_end - url);
379-
if (slash - host > 0)
380-
c->host = url_decode_mem(host, slash - host);
388+
c->protocol = xmemdupz(url, proto_end - url);
389+
c->host = url_decode_mem(host, slash - host);
381390
/* Trim leading and trailing slashes from path */
382391
while (*slash == '/')
383392
slash++;
@@ -401,8 +410,6 @@ int credential_from_url_gently(struct credential *c, const char *url,
401410

402411
void credential_from_url(struct credential *c, const char *url)
403412
{
404-
if (credential_from_url_gently(c, url, 0) < 0) {
405-
warning(_("skipping credential lookup for url: %s"), url);
406-
credential_clear(c);
407-
}
413+
if (credential_from_url_gently(c, url, 0) < 0)
414+
die(_("credential url cannot be parsed: %s"), url);
408415
}

fsck.c

Lines changed: 136 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "tag.h"
1010
#include "fsck.h"
1111
#include "refs.h"
12+
#include "url.h"
1213
#include "utf8.h"
1314
#include "decorate.h"
1415
#include "oidset.h"
@@ -911,17 +912,147 @@ static int fsck_tag(const struct object_id *oid, const char *buffer,
911912
return ret;
912913
}
913914

915+
/*
916+
* Like builtin/submodule--helper.c's starts_with_dot_slash, but without
917+
* relying on the platform-dependent is_dir_sep helper.
918+
*
919+
* This is for use in checking whether a submodule URL is interpreted as
920+
* relative to the current directory on any platform, since \ is a
921+
* directory separator on Windows but not on other platforms.
922+
*/
923+
static int starts_with_dot_slash(const char *str)
924+
{
925+
return str[0] == '.' && (str[1] == '/' || str[1] == '\\');
926+
}
927+
928+
/*
929+
* Like starts_with_dot_slash, this is a variant of submodule--helper's
930+
* helper of the same name with the twist that it accepts backslash as a
931+
* directory separator even on non-Windows platforms.
932+
*/
933+
static int starts_with_dot_dot_slash(const char *str)
934+
{
935+
return str[0] == '.' && starts_with_dot_slash(str + 1);
936+
}
937+
938+
static int submodule_url_is_relative(const char *url)
939+
{
940+
return starts_with_dot_slash(url) || starts_with_dot_dot_slash(url);
941+
}
942+
943+
/*
944+
* Count directory components that a relative submodule URL should chop
945+
* from the remote_url it is to be resolved against.
946+
*
947+
* In other words, this counts "../" components at the start of a
948+
* submodule URL.
949+
*
950+
* Returns the number of directory components to chop and writes a
951+
* pointer to the next character of url after all leading "./" and
952+
* "../" components to out.
953+
*/
954+
static int count_leading_dotdots(const char *url, const char **out)
955+
{
956+
int result = 0;
957+
while (1) {
958+
if (starts_with_dot_dot_slash(url)) {
959+
result++;
960+
url += strlen("../");
961+
continue;
962+
}
963+
if (starts_with_dot_slash(url)) {
964+
url += strlen("./");
965+
continue;
966+
}
967+
*out = url;
968+
return result;
969+
}
970+
}
971+
/*
972+
* Check whether a transport is implemented by git-remote-curl.
973+
*
974+
* If it is, returns 1 and writes the URL that would be passed to
975+
* git-remote-curl to the "out" parameter.
976+
*
977+
* Otherwise, returns 0 and leaves "out" untouched.
978+
*
979+
* Examples:
980+
* http::https://example.com/repo.git -> 1, https://example.com/repo.git
981+
* https://example.com/repo.git -> 1, https://example.com/repo.git
982+
* git://example.com/repo.git -> 0
983+
*
984+
* This is for use in checking for previously exploitable bugs that
985+
* required a submodule URL to be passed to git-remote-curl.
986+
*/
987+
static int url_to_curl_url(const char *url, const char **out)
988+
{
989+
/*
990+
* We don't need to check for case-aliases, "http.exe", and so
991+
* on because in the default configuration, is_transport_allowed
992+
* prevents URLs with those schemes from being cloned
993+
* automatically.
994+
*/
995+
if (skip_prefix(url, "http::", out) ||
996+
skip_prefix(url, "https::", out) ||
997+
skip_prefix(url, "ftp::", out) ||
998+
skip_prefix(url, "ftps::", out))
999+
return 1;
1000+
if (starts_with(url, "http://") ||
1001+
starts_with(url, "https://") ||
1002+
starts_with(url, "ftp://") ||
1003+
starts_with(url, "ftps://")) {
1004+
*out = url;
1005+
return 1;
1006+
}
1007+
return 0;
1008+
}
1009+
9141010
static int check_submodule_url(const char *url)
9151011
{
916-
struct credential c = CREDENTIAL_INIT;
917-
int ret;
1012+
const char *curl_url;
9181013

9191014
if (looks_like_command_line_option(url))
9201015
return -1;
9211016

922-
ret = credential_from_url_gently(&c, url, 1);
923-
credential_clear(&c);
924-
return ret;
1017+
if (submodule_url_is_relative(url)) {
1018+
char *decoded;
1019+
const char *next;
1020+
int has_nl;
1021+
1022+
/*
1023+
* This could be appended to an http URL and url-decoded;
1024+
* check for malicious characters.
1025+
*/
1026+
decoded = url_decode(url);
1027+
has_nl = !!strchr(decoded, '\n');
1028+
1029+
free(decoded);
1030+
if (has_nl)
1031+
return -1;
1032+
1033+
/*
1034+
* URLs which escape their root via "../" can overwrite
1035+
* the host field and previous components, resolving to
1036+
* URLs like https::example.com/submodule.git and
1037+
* https:///example.com/submodule.git that were
1038+
* susceptible to CVE-2020-11008.
1039+
*/
1040+
if (count_leading_dotdots(url, &next) > 0 &&
1041+
(*next == ':' || *next == '/'))
1042+
return -1;
1043+
}
1044+
1045+
else if (url_to_curl_url(url, &curl_url)) {
1046+
struct credential c = CREDENTIAL_INIT;
1047+
int ret = 0;
1048+
if (credential_from_url_gently(&c, curl_url, 1) ||
1049+
!*c.host)
1050+
ret = -1;
1051+
credential_clear(&c);
1052+
return ret;
1053+
}
1054+
1055+
return 0;
9251056
}
9261057

9271058
struct fsck_gitmodules_data {

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ static int has_cert_password(void)
558558
return 0;
559559
if (!cert_auth.password) {
560560
cert_auth.protocol = xstrdup("cert");
561+
cert_auth.host = xstrdup("");
561562
cert_auth.username = xstrdup("");
562563
cert_auth.path = xstrdup(ssl_cert);
563564
credential_fill(&cert_auth);

0 commit comments

Comments
 (0)