Skip to content

Commit fc346cb

Browse files
committed
Sync with 2.20.2
* maint-2.20: (36 commits) Git 2.20.2 t7415: adjust test for dubiously-nested submodule gitdirs for v2.20.x Git 2.19.3 Git 2.18.2 Git 2.17.3 Git 2.16.6 test-drop-caches: use `has_dos_drive_prefix()` Git 2.15.4 Git 2.14.6 mingw: handle `subst`-ed "DOS drives" mingw: refuse to access paths with trailing spaces or periods mingw: refuse to access paths with illegal characters unpack-trees: let merged_entry() pass through do_add_entry()'s errors quote-stress-test: offer to test quoting arguments for MSYS2 sh t6130/t9350: prepare for stringent Win32 path validation quote-stress-test: allow skipping some trials quote-stress-test: accept arguments to test via the command-line tests: add a helper to stress test argument quoting mingw: fix quoting of arguments Disallow dubiously-nested submodule git directories ...
2 parents 8104ec9 + 4cd1cf3 commit fc346cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+935
-82
lines changed

Documentation/RelNotes/2.14.6.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Git v2.14.6 Release Notes
2+
=========================
3+
4+
This release addresses the security issues CVE-2019-1348,
5+
CVE-2019-1349, CVE-2019-1350, CVE-2019-1351, CVE-2019-1352,
6+
CVE-2019-1353, CVE-2019-1354, and CVE-2019-1387.
7+
8+
Fixes since v2.14.5
9+
-------------------
10+
11+
* CVE-2019-1348:
12+
The --export-marks option of git fast-import is exposed also via
13+
the in-stream command feature export-marks=... and it allows
14+
overwriting arbitrary paths.
15+
16+
* CVE-2019-1349:
17+
When submodules are cloned recursively, under certain circumstances
18+
Git could be fooled into using the same Git directory twice. We now
19+
require the directory to be empty.
20+
21+
* CVE-2019-1350:
22+
Incorrect quoting of command-line arguments allowed remote code
23+
execution during a recursive clone in conjunction with SSH URLs.
24+
25+
* CVE-2019-1351:
26+
While the only permitted drive letters for physical drives on
27+
Windows are letters of the US-English alphabet, this restriction
28+
does not apply to virtual drives assigned via subst <letter>:
29+
<path>. Git mistook such paths for relative paths, allowing writing
30+
outside of the worktree while cloning.
31+
32+
* CVE-2019-1352:
33+
Git was unaware of NTFS Alternate Data Streams, allowing files
34+
inside the .git/ directory to be overwritten during a clone.
35+
36+
* CVE-2019-1353:
37+
When running Git in the Windows Subsystem for Linux (also known as
38+
"WSL") while accessing a working directory on a regular Windows
39+
drive, none of the NTFS protections were active.
40+
41+
* CVE-2019-1354:
42+
Filenames on Linux/Unix can contain backslashes. On Windows,
43+
backslashes are directory separators. Git did not use to refuse to
44+
write out tracked files with such filenames.
45+
46+
* CVE-2019-1387:
47+
Recursive clones are currently affected by a vulnerability that is
48+
caused by too-lax validation of submodule names, allowing very
49+
targeted attacks via remote code execution in recursive clones.
50+
51+
Credit for finding these vulnerabilities goes to Microsoft Security
52+
Response Center, in particular to Nicolas Joly. The `fast-import`
53+
fixes were provided by Jeff King, the other fixes by Johannes
54+
Schindelin with help from Garima Singh.

Documentation/RelNotes/2.15.4.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Git v2.15.4 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.14.6 to address
5+
the security issues CVE-2019-1348, CVE-2019-1349, CVE-2019-1350,
6+
CVE-2019-1351, CVE-2019-1352, CVE-2019-1353, CVE-2019-1354, and
7+
CVE-2019-1387; see the release notes for that version for details.
8+
9+
In conjunction with a vulnerability that was fixed in v2.20.2,
10+
`.gitmodules` is no longer allowed to contain entries of the form
11+
`submodule.<name>.update=!command`.

Documentation/RelNotes/2.16.6.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Git v2.16.6 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.14.6 and in
5+
v2.15.4 addressing the security issues CVE-2019-1348, CVE-2019-1349,
6+
CVE-2019-1350, CVE-2019-1351, CVE-2019-1352, CVE-2019-1353,
7+
CVE-2019-1354, and CVE-2019-1387; see the release notes for those
8+
versions for details.

Documentation/RelNotes/2.17.3.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Git v2.17.3 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.14.6 and in
5+
v2.15.4 addressing the security issues CVE-2019-1348, CVE-2019-1349,
6+
CVE-2019-1350, CVE-2019-1351, CVE-2019-1352, CVE-2019-1353,
7+
CVE-2019-1354, and CVE-2019-1387; see the release notes for those
8+
versions for details.
9+
10+
In addition, `git fsck` was taught to identify `.gitmodules` entries
11+
of the form `submodule.<name>.update=!command`, which have been
12+
disallowed in v2.15.4.

Documentation/RelNotes/2.18.2.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Git v2.18.2 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.14.6, v2.15.4
5+
and in v2.17.3, addressing the security issues CVE-2019-1348,
6+
CVE-2019-1349, CVE-2019-1350, CVE-2019-1351, CVE-2019-1352,
7+
CVE-2019-1353, CVE-2019-1354, and CVE-2019-1387; see the release notes
8+
for those versions for details.

Documentation/RelNotes/2.19.3.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Git v2.19.3 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.14.6, v2.15.4
5+
and in v2.17.3, addressing the security issues CVE-2019-1348,
6+
CVE-2019-1349, CVE-2019-1350, CVE-2019-1351, CVE-2019-1352,
7+
CVE-2019-1353, CVE-2019-1354, and CVE-2019-1387; see the release notes
8+
for those versions for details.

Documentation/RelNotes/2.20.2.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Git v2.20.2 Release Notes
2+
=========================
3+
4+
This release merges up the fixes that appear in v2.14.6, v2.15.4
5+
and in v2.17.3, addressing the security issues CVE-2019-1348,
6+
CVE-2019-1349, CVE-2019-1350, CVE-2019-1351, CVE-2019-1352,
7+
CVE-2019-1353, CVE-2019-1354, and CVE-2019-1387; see the release notes
8+
for those versions for details.
9+
10+
The change to disallow `submodule.<name>.update=!command` entries in
11+
`.gitmodules` which was introduced v2.15.4 (and for which v2.17.3
12+
added explicit fsck checks) fixes the vulnerability in v2.20.x where a
13+
recursive clone followed by a submodule update could execute code
14+
contained within the repository without the user explicitly having
15+
asked for that (CVE-2019-19604).
16+
17+
Credit for finding this vulnerability goes to Joern Schneeweisz,
18+
credit for the fixes goes to Jonathan Nieder.

Documentation/git-fast-import.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ OPTIONS
5151
memory used by fast-import during this run. Showing this output
5252
is currently the default, but can be disabled with --quiet.
5353

54+
--allow-unsafe-features::
55+
Many command-line options can be provided as part of the
56+
fast-import stream itself by using the `feature` or `option`
57+
commands. However, some of these options are unsafe (e.g.,
58+
allowing fast-import to access the filesystem outside of the
59+
repository). These options are disabled by default, but can be
60+
allowed by providing this option on the command line. This
61+
currently impacts only the `export-marks`, `import-marks`, and
62+
`import-marks-if-exists` feature commands.
63+
+
64+
Only enable this option if you trust the program generating the
65+
fast-import stream! This option is enabled automatically for
66+
remote-helpers that use the `import` capability, as they are
67+
already trusted to run their own code.
68+
5469
Options for Frontends
5570
~~~~~~~~~~~~~~~~~~~~~
5671

Documentation/gitmodules.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ submodule.<name>.update::
4444
submodule init` to initialize the configuration variable of
4545
the same name. Allowed values here are 'checkout', 'rebase',
4646
'merge' or 'none'. See description of 'update' command in
47-
linkgit:git-submodule[1] for their meaning. Note that the
48-
'!command' form is intentionally ignored here for security
49-
reasons.
47+
linkgit:git-submodule[1] for their meaning. For security
48+
reasons, the '!command' form is not accepted here.
5049

5150
submodule.<name>.branch::
5251
A remote branch name for tracking updates in the upstream submodule.

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ static int checkout(int submodule_progress)
775775

776776
if (!err && (option_recurse_submodules.nr > 0)) {
777777
struct argv_array args = ARGV_ARRAY_INIT;
778-
argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
778+
argv_array_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL);
779779

780780
if (option_shallow_submodules == 1)
781781
argv_array_push(&args, "--depth=1");

builtin/submodule--helper.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "diffcore.h"
2020
#include "diff.h"
2121
#include "object-store.h"
22+
#include "dir.h"
2223

2324
#define OPT_QUIET (1 << 0)
2425
#define OPT_CACHED (1 << 1)
@@ -1358,7 +1359,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
13581359
char *p, *path = NULL, *sm_gitdir;
13591360
struct strbuf sb = STRBUF_INIT;
13601361
struct string_list reference = STRING_LIST_INIT_NODUP;
1361-
int dissociate = 0;
1362+
int dissociate = 0, require_init = 0;
13621363
char *sm_alternate = NULL, *error_strategy = NULL;
13631364

13641365
struct option module_clone_options[] = {
@@ -1385,6 +1386,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
13851386
OPT__QUIET(&quiet, "Suppress output for cloning a submodule"),
13861387
OPT_BOOL(0, "progress", &progress,
13871388
N_("force cloning progress")),
1389+
OPT_BOOL(0, "require-init", &require_init,
1390+
N_("disallow cloning into non-empty directory")),
13881391
OPT_END()
13891392
};
13901393

@@ -1412,6 +1415,10 @@ static int module_clone(int argc, const char **argv, const char *prefix)
14121415
} else
14131416
path = xstrdup(path);
14141417

1418+
if (validate_submodule_git_dir(sm_gitdir, name) < 0)
1419+
die(_("refusing to create/use '%s' in another submodule's "
1420+
"git dir"), sm_gitdir);
1421+
14151422
if (!file_exists(sm_gitdir)) {
14161423
if (safe_create_leading_directories_const(sm_gitdir) < 0)
14171424
die(_("could not create directory '%s'"), sm_gitdir);
@@ -1423,6 +1430,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
14231430
die(_("clone of '%s' into submodule path '%s' failed"),
14241431
url, path);
14251432
} else {
1433+
if (require_init && !access(path, X_OK) && !is_empty_dir(path))
1434+
die(_("directory not empty: '%s'"), path);
14261435
if (safe_create_leading_directories_const(path) < 0)
14271436
die(_("could not create directory '%s'"), path);
14281437
strbuf_addf(&sb, "%s/index", sm_gitdir);
@@ -1477,6 +1486,8 @@ static void determine_submodule_update_strategy(struct repository *r,
14771486
die(_("Invalid update mode '%s' configured for submodule path '%s'"),
14781487
val, path);
14791488
} else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
1489+
if (sub->update_strategy.type == SM_UPDATE_COMMAND)
1490+
BUG("how did we read update = !command from .gitmodules?");
14801491
out->type = sub->update_strategy.type;
14811492
out->command = sub->update_strategy.command;
14821493
} else
@@ -1535,6 +1546,7 @@ struct submodule_update_clone {
15351546
int recommend_shallow;
15361547
struct string_list references;
15371548
int dissociate;
1549+
unsigned require_init;
15381550
const char *depth;
15391551
const char *recursive_prefix;
15401552
const char *prefix;
@@ -1553,7 +1565,7 @@ struct submodule_update_clone {
15531565
int max_jobs;
15541566
};
15551567
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1556-
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
1568+
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, 0, \
15571569
NULL, NULL, NULL, \
15581570
NULL, 0, 0, 0, NULL, 0, 0, 1}
15591571

@@ -1680,6 +1692,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
16801692
argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
16811693
if (suc->recommend_shallow && sub->recommend_shallow == 1)
16821694
argv_array_push(&child->args, "--depth=1");
1695+
if (suc->require_init)
1696+
argv_array_push(&child->args, "--require-init");
16831697
argv_array_pushl(&child->args, "--path", sub->path, NULL);
16841698
argv_array_pushl(&child->args, "--name", sub->name, NULL);
16851699
argv_array_pushl(&child->args, "--url", url, NULL);
@@ -1870,6 +1884,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
18701884
OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
18711885
OPT_BOOL(0, "progress", &suc.progress,
18721886
N_("force cloning progress")),
1887+
OPT_BOOL(0, "require-init", &suc.require_init,
1888+
N_("disallow cloning into non-empty directory")),
18731889
OPT_END()
18741890
};
18751891

compat/mingw.c

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ int mingw_mkdir(const char *path, int mode)
390390
{
391391
int ret;
392392
wchar_t wpath[MAX_PATH];
393+
394+
if (!is_valid_win32_path(path)) {
395+
errno = EINVAL;
396+
return -1;
397+
}
398+
393399
if (xutftowcs_path(wpath, path) < 0)
394400
return -1;
395401
ret = _wmkdir(wpath);
@@ -463,14 +469,19 @@ int mingw_open (const char *filename, int oflags, ...)
463469
typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
464470
va_list args;
465471
unsigned mode;
466-
int fd;
472+
int fd, create = (oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
467473
wchar_t wfilename[MAX_PATH];
468474
open_fn_t open_fn;
469475

470476
va_start(args, oflags);
471477
mode = va_arg(args, int);
472478
va_end(args);
473479

480+
if (!is_valid_win32_path(filename)) {
481+
errno = create ? EINVAL : ENOENT;
482+
return -1;
483+
}
484+
474485
if (filename && !strcmp(filename, "/dev/null"))
475486
filename = "nul";
476487

@@ -537,6 +548,11 @@ FILE *mingw_fopen (const char *filename, const char *otype)
537548
int hide = needs_hiding(filename);
538549
FILE *file;
539550
wchar_t wfilename[MAX_PATH], wotype[4];
551+
if (!is_valid_win32_path(filename)) {
552+
int create = otype && strchr(otype, 'w');
553+
errno = create ? EINVAL : ENOENT;
554+
return NULL;
555+
}
540556
if (filename && !strcmp(filename, "/dev/null"))
541557
filename = "nul";
542558
if (xutftowcs_path(wfilename, filename) < 0 ||
@@ -559,6 +575,11 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
559575
int hide = needs_hiding(filename);
560576
FILE *file;
561577
wchar_t wfilename[MAX_PATH], wotype[4];
578+
if (!is_valid_win32_path(filename)) {
579+
int create = otype && strchr(otype, 'w');
580+
errno = create ? EINVAL : ENOENT;
581+
return NULL;
582+
}
562583
if (filename && !strcmp(filename, "/dev/null"))
563584
filename = "nul";
564585
if (xutftowcs_path(wfilename, filename) < 0 ||
@@ -1052,7 +1073,7 @@ static const char *quote_arg_msvc(const char *arg)
10521073
p++;
10531074
len++;
10541075
}
1055-
if (*p == '"')
1076+
if (*p == '"' || !*p)
10561077
n += count*2 + 1;
10571078
continue;
10581079
}
@@ -1074,16 +1095,19 @@ static const char *quote_arg_msvc(const char *arg)
10741095
count++;
10751096
*d++ = *arg++;
10761097
}
1077-
if (*arg == '"') {
1098+
if (*arg == '"' || !*arg) {
10781099
while (count-- > 0)
10791100
*d++ = '\\';
1101+
/* don't escape the surrounding end quote */
1102+
if (!*arg)
1103+
break;
10801104
*d++ = '\\';
10811105
}
10821106
}
10831107
*d++ = *arg++;
10841108
}
10851109
*d++ = '"';
1086-
*d++ = 0;
1110+
*d++ = '\0';
10871111
return q;
10881112
}
10891113

@@ -2464,6 +2488,50 @@ static void setup_windows_environment(void)
24642488
setenv("TERM", "cygwin", 1);
24652489
}
24662490

2491+
int is_valid_win32_path(const char *path)
2492+
{
2493+
int preceding_space_or_period = 0, i = 0, periods = 0;
2494+
2495+
if (!protect_ntfs)
2496+
return 1;
2497+
2498+
skip_dos_drive_prefix((char **)&path);
2499+
2500+
for (;;) {
2501+
char c = *(path++);
2502+
switch (c) {
2503+
case '\0':
2504+
case '/': case '\\':
2505+
/* cannot end in ` ` or `.`, except for `.` and `..` */
2506+
if (preceding_space_or_period &&
2507+
(i != periods || periods > 2))
2508+
return 0;
2509+
if (!c)
2510+
return 1;
2511+
2512+
i = periods = preceding_space_or_period = 0;
2513+
continue;
2514+
case '.':
2515+
periods++;
2516+
/* fallthru */
2517+
case ' ':
2518+
preceding_space_or_period = 1;
2519+
i++;
2520+
continue;
2521+
case ':': /* DOS drive prefix was already skipped */
2522+
case '<': case '>': case '"': case '|': case '?': case '*':
2523+
/* illegal character */
2524+
return 0;
2525+
default:
2526+
if (c > '\0' && c < '\x20')
2527+
/* illegal character */
2528+
return 0;
2529+
}
2530+
preceding_space_or_period = 0;
2531+
i++;
2532+
}
2533+
}
2534+
24672535
/*
24682536
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
24692537
* mingw startup code, see init.c in mingw runtime).

0 commit comments

Comments
 (0)