Blame SOURCES/git-cve-2018-17456.patch

647f52
From d819a25360ba38dfec31e37413963adf5688db80 Mon Sep 17 00:00:00 2001
647f52
From: Jeff King <peff@peff.net>
647f52
Date: Mon, 24 Sep 2018 04:32:15 -0400
647f52
Subject: [PATCH 1/2] submodule--helper: use "--" to signal end of clone
647f52
 options
647f52
647f52
commit 98afac7a7cefdca0d2c4917dd8066a59f7088265 upstream.
647f52
647f52
When we clone a submodule, we call "git clone $url $path".
647f52
But there's nothing to say that those components can't begin
647f52
with a dash themselves, confusing git-clone into thinking
647f52
they're options. Let's pass "--" to make it clear what we
647f52
expect.
647f52
647f52
There's no test here, because it's actually quite hard to
647f52
make these names work, even with "git clone" parsing them
647f52
correctly. And we're going to restrict these cases even
647f52
further in future commits. So we'll leave off testing until
647f52
then; this is just the minimal fix to prevent us from doing
647f52
something stupid with a badly formed entry.
647f52
647f52
[jn: backported to 2.1.y by applying to git-submodule.sh
647f52
 instead of submodule--helper]
647f52
647f52
Reported-by: joernchen <joernchen@phenoelit.de>
647f52
Signed-off-by: Jeff King <peff@peff.net>
647f52
Signed-off-by: Junio C Hamano <gitster@pobox.com>
647f52
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
647f52
647f52
submodule-config: ban submodule urls that start with dash
647f52
647f52
commit f6adec4e329ef0e25e14c63b735a5956dc67b8bc upstream.
647f52
647f52
The previous commit taught the submodule code to invoke our
647f52
"git clone $url $path" with a "--" separator so that we
647f52
aren't confused by urls or paths that start with dashes.
647f52
647f52
However, that's just one code path. It's not clear if there
647f52
are others, and it would be an easy mistake to add one in
647f52
the future. Moreover, even with the fix in the previous
647f52
commit, it's quite hard to actually do anything useful with
647f52
such an entry. Any url starting with a dash must fall into
647f52
one of three categories:
647f52
647f52
 - it's meant as a file url, like "-path". But then any
647f52
   clone is not going to have the matching path, since it's
647f52
   by definition relative inside the newly created clone. If
647f52
   you spell it as "./-path", the submodule code sees the
647f52
   "/" and translates this to an absolute path, so it at
647f52
   least works (assuming the receiver has the same
647f52
   filesystem layout as you). But that trick does not apply
647f52
   for a bare "-path".
647f52
647f52
 - it's meant as an ssh url, like "-host:path". But this
647f52
   already doesn't work, as we explicitly disallow ssh
647f52
   hostnames that begin with a dash (to avoid option
647f52
   injection against ssh).
647f52
647f52
 - it's a remote-helper scheme, like "-scheme::data". This
647f52
   _could_ work if the receiver bends over backwards and
647f52
   creates a funny-named helper like "git-remote--scheme".
647f52
   But normally there would not be any helper that matches.
647f52
647f52
Since such a url does not work today and is not likely to do
647f52
anything useful in the future, let's simply disallow them
647f52
entirely. That protects the existing "git clone" path (in a
647f52
belt-and-suspenders way), along with any others that might
647f52
exist.
647f52
647f52
[jn: backported to 2.1.y by porting to shell]
647f52
[pc: backported to 1.8.3.1 by using $sm_path instead of $displayname
647f52
 and split tests into a separate commit]
647f52
647f52
Signed-off-by: Jeff King <peff@peff.net>
647f52
Signed-off-by: Junio C Hamano <gitster@pobox.com>
647f52
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
647f52
647f52
submodule-config: ban submodule paths that start with a dash
647f52
647f52
commit 273c61496f88c6495b886acb1041fe57965151da upstream.
647f52
647f52
We recently banned submodule urls that look like
647f52
command-line options. This is the matching change to ban
647f52
leading-dash paths.
647f52
647f52
As with the urls, this should not break any use cases that
647f52
currently work. Even with our "--" separator passed to
647f52
git-clone, git-submodule.sh gets confused. Without the code
647f52
portion of this patch, the clone of "-sub" added in t7417
647f52
would yield results like:
647f52
647f52
    /path/to/git-submodule: 410: cd: Illegal option -s
647f52
    /path/to/git-submodule: 417: cd: Illegal option -s
647f52
    /path/to/git-submodule: 410: cd: Illegal option -s
647f52
    /path/to/git-submodule: 417: cd: Illegal option -s
647f52
    Fetched in submodule path '-sub', but it did not contain b56243f8f4eb91b2f1f8109452e659f14dd3fbe4. D
647f52
irect fetching of that commit failed.
647f52
647f52
Moreover, naively adding such a submodule doesn't work:
647f52
647f52
  $ git submodule add $url -sub
647f52
  The following path is ignored by one of your .gitignore files:
647f52
  -sub
647f52
647f52
even though there is no such ignore pattern (the test script
647f52
hacks around this with a well-placed "git mv").
647f52
647f52
Unlike leading-dash urls, though, it's possible that such a
647f52
path _could_ be useful if we eventually made it work. So
647f52
this commit should be seen not as recommending a particular
647f52
policy, but rather temporarily closing off a broken and
647f52
possibly dangerous code-path. We may revisit this decision
647f52
later.
647f52
647f52
[jn: ported to git-submodule.sh
647f52
 pc: split the test into a separate commit ]
647f52
647f52
fsck: detect submodule urls starting with dash
647f52
647f52
commit a124133e1e6ab5c7a9fef6d0e6bcb084e3455b46 upstream.
647f52
647f52
Urls with leading dashes can cause mischief on older
647f52
versions of Git. We should detect them so that they can be
647f52
rejected by receive.fsckObjects, preventing modern versions
647f52
of git from being a vector by which attacks can spread.
647f52
647f52
[jn: backported to 2.1.y: using error_func instead of report
647f52
 to report fsck errors]
647f52
647f52
[pc: split tests into a separate commit]
647f52
647f52
Signed-off-by: Jeff King <peff@peff.net>
647f52
Signed-off-by: Junio C Hamano <gitster@pobox.com>
647f52
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
647f52
647f52
fsck: detect submodule paths starting with dash
647f52
647f52
commit 1a7fd1fb2998002da6e9ff2ee46e1bdd25ee8404 upstream.
647f52
647f52
As with urls, submodule paths with dashes are ignored by
647f52
git, but may end up confusing older versions. Detecting them
647f52
via fsck lets us prevent modern versions of git from being a
647f52
vector to spread broken .gitmodules to older versions.
647f52
647f52
Compared to blocking leading-dash urls, though, this
647f52
detection may be less of a good idea:
647f52
647f52
  1. While such paths provide confusing and broken results,
647f52
     they don't seem to actually work as option injections
647f52
     against anything except "cd". In particular, the
647f52
     submodule code seems to canonicalize to an absolute
647f52
     path before running "git clone" (so it passes
647f52
     /your/clone/-sub).
647f52
647f52
  2. It's more likely that we may one day make such names
647f52
     actually work correctly. Even after we revert this fsck
647f52
     check, it will continue to be a hassle until hosting
647f52
     servers are all updated.
647f52
647f52
On the other hand, it's not entirely clear that the behavior
647f52
in older versions is safe. And if we do want to eventually
647f52
allow this, we may end up doing so with a special syntax
647f52
anyway (e.g., writing "./-sub" in the .gitmodules file, and
647f52
teaching the submodule code to canonicalize it when
647f52
comparing).
647f52
647f52
So on balance, this is probably a good protection.
647f52
647f52
[jn: backported to 2.1.y: using error_func instead of report
647f52
 to report fsck errors]
647f52
647f52
[pc: split test to a separate commit]
647f52
---
647f52
 fsck.c           | 10 ++++++++++
647f52
 git-submodule.sh | 20 +++++++++++++++-----
647f52
 2 files changed, 25 insertions(+), 5 deletions(-)
647f52
647f52
diff --git a/fsck.c b/fsck.c
647f52
index 811724125..90d641066 100644
647f52
--- a/fsck.c
647f52
+++ b/fsck.c
647f52
@@ -442,6 +442,16 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata)
647f52
 		data->ret += data->error_func(data->obj, FSCK_ERROR,
647f52
 					      "disallowed submodule name: %s",
647f52
 					      name);
647f52
+	if (!strcmp(key, "url") && value &&
647f52
+	    looks_like_command_line_option(value))
647f52
+		data->ret += data->error_func(data->obj, FSCK_ERROR,
647f52
+					      "disallowed submodule url: %s",
647f52
+					      value);
647f52
+	if (!strcmp(key, "path") && value &&
647f52
+	    looks_like_command_line_option(value))
647f52
+		data->ret += data->error_func(data->obj, FSCK_ERROR,
647f52
+					      "disallowed submodule path: %s",
647f52
+					      value);
647f52
 	free(name);
647f52
 
647f52
 	return 0;
647f52
diff --git a/git-submodule.sh b/git-submodule.sh
647f52
index e958ce840..b5176ecc3 100755
647f52
--- a/git-submodule.sh
647f52
+++ b/git-submodule.sh
647f52
@@ -205,6 +205,11 @@ module_name()
647f52
 	re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
647f52
 	name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
647f52
 		sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
647f52
+	case "$sm_path" in
647f52
+	-*)
647f52
+		die "$(eval_gettext "Submodule path '\$sm_path' may be interpreted as a command-line option")"
647f52
+		;;
647f52
+	esac
647f52
 	test -z "$name" &&
647f52
 	die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
647f52
 	check_module_name "$name"
647f52
@@ -248,7 +253,7 @@ module_clone()
647f52
 		(
647f52
 			clear_local_git_env
647f52
 			git clone $quiet -n ${reference:+"$reference"} \
647f52
-				--separate-git-dir "$gitdir" "$url" "$sm_path"
647f52
+				--separate-git-dir "$gitdir" -- "$url" "$sm_path"
647f52
 		) ||
647f52
 		die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
647f52
 	fi
647f52
@@ -547,11 +552,13 @@ cmd_init()
647f52
 		if test -z "$(git config "submodule.$name.url")"
647f52
 		then
647f52
 			url=$(git config -f .gitmodules submodule."$name".url)
647f52
-			test -z "$url" &&
647f52
-			die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
647f52
-
647f52
-			# Possibly a url relative to parent
647f52
 			case "$url" in
647f52
+			"")
647f52
+				die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
647f52
+				;;
647f52
+			-*)
647f52
+				die "$(eval_gettext "Submodule at path '\$sm_path' has url '\$url' which may be interpreted as a command-line option")"
647f52
+				;;
647f52
 			./*|../*)
647f52
 				url=$(resolve_relative_url "$url") || exit
647f52
 				;;
647f52
@@ -1213,6 +1220,9 @@ cmd_sync()
647f52
 
647f52
 		# Possibly a url relative to parent
647f52
 		case "$url" in
647f52
+		-*)
647f52
+			die "$(eval_gettext "Submodule at path '\$sm_path' has url '\$url' which may be interpreted as a command-line option")"
647f52
+			;;
647f52
 		./*|../*)
647f52
 			# rewrite foo/bar as ../.. to find path from
647f52
 			# submodule work tree to superproject work tree
647f52
-- 
647f52
2.14.4
647f52