Skip to content

Commit b86a4be

Browse files
committed
Git 2.24.3
This merges up the security fix from v2.17.5. Signed-off-by: Jonathan Nieder <[email protected]>
2 parents 506223f + f2771ef commit b86a4be

16 files changed

+494
-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.

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.24.2
4+
DEF_VER=v2.24.3
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.24.2.txt
1+
Documentation/RelNotes/2.24.3.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"
@@ -948,17 +949,147 @@ static int fsck_tag(struct tag *tag, const char *data,
948949
return fsck_tag_buffer(tag, data, size, options);
949950
}
950951

952+
/*
953+
* Like builtin/submodule--helper.c's starts_with_dot_slash, but without
954+
* relying on the platform-dependent is_dir_sep helper.
955+
*
956+
* This is for use in checking whether a submodule URL is interpreted as
957+
* relative to the current directory on any platform, since \ is a
958+
* directory separator on Windows but not on other platforms.
959+
*/
960+
static int starts_with_dot_slash(const char *str)
961+
{
962+
return str[0] == '.' && (str[1] == '/' || str[1] == '\\');
963+
}
964+
965+
/*
966+
* Like starts_with_dot_slash, this is a variant of submodule--helper's
967+
* helper of the same name with the twist that it accepts backslash as a
968+
* directory separator even on non-Windows platforms.
969+
*/
970+
static int starts_with_dot_dot_slash(const char *str)
971+
{
972+
return str[0] == '.' && starts_with_dot_slash(str + 1);
973+
}
974+
975+
static int submodule_url_is_relative(const char *url)
976+
{
977+
return starts_with_dot_slash(url) || starts_with_dot_dot_slash(url);
978+
}
979+
980+
/*
981+
* Count directory components that a relative submodule URL should chop
982+
* from the remote_url it is to be resolved against.
983+
*
984+
* In other words, this counts "../" components at the start of a
985+
* submodule URL.
986+
*
987+
* Returns the number of directory components to chop and writes a
988+
* pointer to the next character of url after all leading "./" and
989+
* "../" components to out.
990+
*/
991+
static int count_leading_dotdots(const char *url, const char **out)
992+
{
993+
int result = 0;
994+
while (1) {
995+
if (starts_with_dot_dot_slash(url)) {
996+
result++;
997+
url += strlen("../");
998+
continue;
999+
}
1000+
if (starts_with_dot_slash(url)) {
1001+
url += strlen("./");
1002+
continue;
1003+
}
1004+
*out = url;
1005+
return result;
1006+
}
1007+
}
1008+
/*
1009+
* Check whether a transport is implemented by git-remote-curl.
1010+
*
1011+
* If it is, returns 1 and writes the URL that would be passed to
1012+
* git-remote-curl to the "out" parameter.
1013+
*
1014+
* Otherwise, returns 0 and leaves "out" untouched.
1015+
*
1016+
* Examples:
1017+
* http::https://example.com/repo.git -> 1, https://example.com/repo.git
1018+
* https://example.com/repo.git -> 1, https://example.com/repo.git
1019+
* git://example.com/repo.git -> 0
1020+
*
1021+
* This is for use in checking for previously exploitable bugs that
1022+
* required a submodule URL to be passed to git-remote-curl.
1023+
*/
1024+
static int url_to_curl_url(const char *url, const char **out)
1025+
{
1026+
/*
1027+
* We don't need to check for case-aliases, "http.exe", and so
1028+
* on because in the default configuration, is_transport_allowed
1029+
* prevents URLs with those schemes from being cloned
1030+
* automatically.
1031+
*/
1032+
if (skip_prefix(url, "http::", out) ||
1033+
skip_prefix(url, "https::", out) ||
1034+
skip_prefix(url, "ftp::", out) ||
1035+
skip_prefix(url, "ftps::", out))
1036+
return 1;
1037+
if (starts_with(url, "http://") ||
1038+
starts_with(url, "https://") ||
1039+
starts_with(url, "ftp://") ||
1040+
starts_with(url, "ftps://")) {
1041+
*out = url;
1042+
return 1;
1043+
}
1044+
return 0;
1045+
}
1046+
9511047
static int check_submodule_url(const char *url)
9521048
{
953-
struct credential c = CREDENTIAL_INIT;
954-
int ret;
1049+
const char *curl_url;
9551050

9561051
if (looks_like_command_line_option(url))
9571052
return -1;
9581053

959-
ret = credential_from_url_gently(&c, url, 1);
960-
credential_clear(&c);
961-
return ret;
1054+
if (submodule_url_is_relative(url)) {
1055+
char *decoded;
1056+
const char *next;
1057+
int has_nl;
1058+
1059+
/*
1060+
* This could be appended to an http URL and url-decoded;
1061+
* check for malicious characters.
1062+
*/
1063+
decoded = url_decode(url);
1064+
has_nl = !!strchr(decoded, '\n');
1065+
1066+
free(decoded);
1067+
if (has_nl)
1068+
return -1;
1069+
1070+
/*
1071+
* URLs which escape their root via "../" can overwrite
1072+
* the host field and previous components, resolving to
1073+
* URLs like https::example.com/submodule.git and
1074+
* https:///example.com/submodule.git that were
1075+
* susceptible to CVE-2020-11008.
1076+
*/
1077+
if (count_leading_dotdots(url, &next) > 0 &&
1078+
(*next == ':' || *next == '/'))
1079+
return -1;
1080+
}
1081+
1082+
else if (url_to_curl_url(url, &curl_url)) {
1083+
struct credential c = CREDENTIAL_INIT;
1084+
int ret = 0;
1085+
if (credential_from_url_gently(&c, curl_url, 1) ||
1086+
!*c.host)
1087+
ret = -1;
1088+
credential_clear(&c);
1089+
return ret;
1090+
}
1091+
1092+
return 0;
9621093
}
9631094

9641095
struct fsck_gitmodules_data {

http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ static int has_cert_password(void)
560560
return 0;
561561
if (!cert_auth.password) {
562562
cert_auth.protocol = xstrdup("cert");
563+
cert_auth.host = xstrdup("");
563564
cert_auth.username = xstrdup("");
564565
cert_auth.path = xstrdup(ssl_cert);
565566
credential_fill(&cert_auth);

0 commit comments

Comments
 (0)