Skip to contentSkip to conversation

Fix various overly aggressive protections in 2.45.1 and friends

PATCH Superseded Junio C Hamano 6 participants 36 messages May 21, 2024 – May 28, 2024 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix various overly aggressive protections in 2.45.1 and friends

As people have seen, the latest "security fix" release turned out to be a mixed bag of good vulnerability fixes with a bit over-eager "layered defence" that broke real uses cases like git-lfs. Let's quickly get them in working order back first, with the vision that we will then rebuild layered defence more carefully in the open on top as necessary.

What we have here are the first "revert" part.

These patches are designed to apply to 2.39.4; the series may have to grow as we discover more things to revert, but for now here are the patches to

- revert the over-eager "refusal to work" went into 2.39.4

- adjust 2.39.4 codebase to cleanly build and test (at CI and locally) by backported fixes

It would have been better if we did not have to have the latter class, but such is life.

I'll figure out a way to convey conflict resolutions as this topic gets merged up to newer maintenance tracks on the list so that people can assist with ensuring correctness of the result by reviewing, and follow up. ("git show --remerge-diff" might turn out to be such a way, but I do not know yet).

Jeff King (5):
send-email: drop FakeTerm hack
send-email: avoid creating more than one Term::ReadLine object
ci: drop mention of BREW_INSTALL_PACKAGES variable
ci: avoid bare "gcc" for osx-gcc job
ci: stop installing "gcc-13" for osx-gcc

Johannes Schindelin (6):
hook: plug a new memory leak
init: use the correct path of the templates directory again Revert "core.hooksPath: add some protection while cloning"
tests: verify that clone -c core.hooksPath=/dev/null works again
clone: drop the protections where hooks aren't run Revert "Add a helper function to compare file contents"

Junio C Hamano (1):
Revert "fetch/clone: detect dubious ownership of local repositories"

 .github/workflows/main.yml    |  3 +-
 Makefile                      |  2 +-
 builtin/clone.c               | 12 +-------
 cache.h                       | 14 ---------
 ci/install-dependencies.sh    |  2 --
 config.c                      | 13 +-------
 copy.c                        | 58 -----------------------------------
 git-send-email.perl           | 32 +++++++------------
 hook.c                        | 32 -------------------
 path.c                        |  2 --
 t/helper/test-path-utils.c    | 10 ------
 t/t0060-path-utils.sh         | 41 -------------------------
 t/t0411-clone-from-partial.sh |  6 ++--
 t/t1350-config-hooks-path.sh  |  7 +++++
 t/t1800-hook.sh               | 15 ---------
 t/t5601-clone.sh              | 51 ------------------------------
 t/t9001-send-email.sh         |  5 +--
 17 files changed, 28 insertions(+), 277 deletions(-)
Signature · 1 line
2.45.1-216-g4365c6fcf9
#3 lore raw

PATCH 2/12 send-email: avoid creating more than one Term::ReadLine object

From: Jeff King <[email protected]>

Every time git-send-email calls its ask() function to prompt the user, we call term(), which instantiates a new Term::ReadLine object. But in v1.46 of Term::ReadLine::Gnu (which provides the Term::ReadLine interface on some platforms), its constructor refuses to create a second instance[1]. So on systems with that version of the module, most git-send-email instances will fail (as we usually prompt for both "to" and "in-reply-to" unless the user provided them on the command line).

We can fix this by keeping a single instance variable and returning it for each call to term(). In perl 5.10 and up, we could do that with a "state" variable. But since we only require 5.008, we'll do it the old-fashioned way, with a lexical "my" in its own scope.

Note that the tests in t9001 detect this problem as-is, since the failure mode is for the program to die. But let's also beef up the "Prompting works" test to check that it correctly handles multiple inputs (if we had chosen to keep our FakeTerm hack in the previous commit, then the failure mode would be incorrectly ignoring prompts after the first).

[1] For discussion of why multiple instances are forbidden, see:
https://github.com/hirooih/perl-trg/issues/16

[jc: cherry-picked from v2.42.0-rc2~6^2]

---
 git-send-email.perl   | 18 +++++++++++++-----
 t/t9001-send-email.sh |  5 +++--
 2 files changed, 16 insertions(+), 7 deletions(-)
git-send-email.perl +13 -5
index 72d876f0a0..ad51508790 100755
@@ -917,11 +917,19 @@ sub get_patch_subject {
 	do_edit(@files);
 }
 
-sub term {
-	require Term::ReadLine;
-	return $ENV{"GIT_SEND_EMAIL_NOTTY"}
-			? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
-			: Term::ReadLine->new('git-send-email');
+{
+	# Only instantiate one $term per program run, since some
+	# Term::ReadLine providers refuse to create a second instance.
+	my $term;
+	sub term {
+		require Term::ReadLine;
+		if (!defined $term) {
+			$term = $ENV{"GIT_SEND_EMAIL_NOTTY"}
+				? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
+				: Term::ReadLine->new('git-send-email');
+		}
+		return $term;
+	}
 }
 
 sub ask {
t/t9001-send-email.sh +3 -2
index 1130ef21b3..0f08a9542b 100755
@@ -337,13 +337,14 @@ test_expect_success $PREREQ 'Show all headers' '
 test_expect_success $PREREQ 'Prompting works' '
 	clean_fake_sendmail &&
 	(echo "[email protected]" &&
-	 echo ""
+	 echo "[email protected]"
 	) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$patches \
 		2>errors &&
 		grep "^From: A U Thor <[email protected]>\$" msgtxt1 &&
-		grep "^To: [email protected]\$" msgtxt1
+		grep "^To: [email protected]\$" msgtxt1 &&
+		grep "^In-Reply-To: <[email protected]>" msgtxt1
 '
 
 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
Signature · 1 line
2.45.1-216-g4365c6fcf9
#5 lore raw

PATCH 3/12 ci: drop mention of BREW_INSTALL_PACKAGES variable

In reply to Junio C Hamano

From: Jeff King <[email protected]>

The last user of this variable went away in 4a6e4b9602 (CI: remove Travis CI support, 2021-11-23), so it's doing nothing except making it more confusing to find out which packages _are_ installed.

[jc: cherry-picked from v2.45.0-1-g9d4453e8d6]

---
 ci/install-dependencies.sh | 2 --
 1 file changed, 2 deletions(-)
ci/install-dependencies.sh +0 -2
index 4f407530d3..33039d516b 100755
@@ -34,8 +34,6 @@ macos-*)
 	export HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1
 	# Uncomment this if you want to run perf tests:
 	# brew install gnu-time
-	test -z "$BREW_INSTALL_PACKAGES" ||
-	brew install $BREW_INSTALL_PACKAGES
 	brew link --force gettext
 	mkdir -p $HOME/bin
 	(
Signature · 1 line
2.45.1-216-g4365c6fcf9
#1 lore raw

PATCH 1/12 send-email: drop FakeTerm hack

In reply to Junio C Hamano

From: Jeff King <[email protected]>

Back in 280242d1cc (send-email: do not barf when Term::ReadLine does not like your terminal, 2006-07-02), we added a fallback for when Term::ReadLine's constructor failed: we'd have a FakeTerm object instead, which would then die if anybody actually tried to call readline() on it. Since we instantiated the $term variable at program startup, we needed this workaround to let the program run in modes when we did not prompt the user.

But later, in f4dc9432fd (send-email: lazily load modules for a big speedup, 2021-05-28), we started loading Term::ReadLine lazily only when ask() is called. So at that point we know we're trying to prompt the user, and we can just die if ReadLine instantiation fails, rather than making this fake object to lazily delay showing the error.

This should be OK even if there is no tty (e.g., we're in a cron job), because Term::ReadLine will return a stub object in that case whose "IN" and "OUT" functions return undef. And since 5906f54e47 (send-email:
don't attempt to prompt if tty is closed, 2009-03-31), we check for that case and skip prompting.

And we can be sure that FakeTerm was not kicking in for such a situation, because it has actually been broken since that commit! It does not define "IN" or "OUT" methods, so perl would barf with an error. If FakeTerm was in use, we were neither honoring what 5906f54e47 tried to do, nor producing the readable message that 280242d1cc intended.

So we're better off just dropping FakeTerm entirely, and letting the error reported by constructing Term::ReadLine through.

[jc: cherry-picked from v2.42.0-rc2~6^2~1]

---
 git-send-email.perl | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
git-send-email.perl +2 -20
index 5861e99a6e..72d876f0a0 100755
@@ -26,18 +26,6 @@
 
 Getopt::Long::Configure qw/ pass_through /;
 
-package FakeTerm;
-sub new {
-	my ($class, $reason) = @_;
-	return bless \$reason, shift;
-}
-sub readline {
-	my $self = shift;
-	die "Cannot use readline on FakeTerm: $$self";
-}
-package main;
-
-
 sub usage {
 	print <<EOT;
 git send-email' [<options>] <file|directory>
@@ -930,16 +918,10 @@ sub get_patch_subject {
 }
 
 sub term {
-	my $term = eval {
-		require Term::ReadLine;
-		$ENV{"GIT_SEND_EMAIL_NOTTY"}
+	require Term::ReadLine;
+	return $ENV{"GIT_SEND_EMAIL_NOTTY"}
 			? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
 			: Term::ReadLine->new('git-send-email');
-	};
-	if ($@) {
-		$term = FakeTerm->new("$@: going non-interactive");
-	}
-	return $term;
 }
 
 sub ask {
Signature · 1 line
2.45.1-216-g4365c6fcf9
#6 lore raw

PATCH 4/12 ci: avoid bare "gcc" for osx-gcc job

In reply to Junio C Hamano

From: Jeff King <[email protected]>

On macOS, a bare "gcc" (without a version) will invoke a wrapper for clang, not actual gcc. Even when gcc is installed via homebrew, that only provides version-specific links in /usr/local/bin (like "gcc-13"), and never a version-agnostic "gcc" wrapper.

As far as I can tell, this has been the case for a long time, and this osx-gcc job has largely been doing nothing. We can point it at "gcc-13", which will pick up the homebrew-installed version.

The fix here is specific to the github workflow file, as the gitlab one does not have a matching job.

It's a little unfortunate that we cannot just ask for the latest version of gcc which homebrew provides, but as far as I can tell there is no easy alias (you'd have to find the highest number gcc-* in /usr/local/bin yourself).

[jc: cherry-picked from v2.45.0-2-g11c7001e3d]

---
 .github/workflows/main.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.github/workflows/main.yml +1 -1
index 2dc0221f7f..583e7cd5f0 100644
@@ -264,7 +264,7 @@ jobs:
             cc: clang
             pool: macos-13
           - jobname: osx-gcc
-            cc: gcc
+            cc: gcc-13
             cc_package: gcc-13
             pool: macos-13
           - jobname: linux-gcc-default
Signature · 1 line
2.45.1-216-g4365c6fcf9
#7 lore raw

PATCH 5/12 ci: stop installing "gcc-13" for osx-gcc

In reply to Junio C Hamano

From: Jeff King <[email protected]>

Our osx-gcc job explicitly asks to install gcc-13. But since the GitHub runner image already comes with gcc-13 installed, this is mostly doing nothing (or in some cases it may install an incremental update over the runner image). But worse, it recently started causing errors like:

==> Fetching gcc@13
==> Downloading https://ghcr.io/v2/homebrew/core/gcc/13/blobs/sha256:fb2403d97e2ce67eb441b54557cfb61980830f3ba26d4c5a1fe5ecd0c9730d1a
==> Pouring [email protected]
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/c++-13
Target /usr/local/bin/c++-13
is a symlink belonging to gcc. You can unlink it:
brew unlink gcc

which cause the whole CI job to bail.

I didn't track down the root cause, but I suspect it may be related to homebrew recently switching the "gcc" default to gcc-14. And it may even be fixed when a new runner image is released. But if we don't need to run brew at all, it's one less thing for us to worry about.

[jc: cherry-picked from v2.45.0-3-g7df2405b38]

---
 .github/workflows/main.yml | 1 -
 1 file changed, 1 deletion(-)
.github/workflows/main.yml +0 -1
index 583e7cd5f0..76e3f1e768 100644
@@ -265,7 +265,6 @@ jobs:
             pool: macos-13
           - jobname: osx-gcc
             cc: gcc-13
-            cc_package: gcc-13
             pool: macos-13
           - jobname: linux-gcc-default
             cc: gcc
Signature · 1 line
2.45.1-216-g4365c6fcf9
#8 lore raw

PATCH 6/12 hook: plug a new memory leak

In reply to Junio C Hamano

From: Johannes Schindelin <[email protected]>

In 8db1e8743c0 (clone: prevent hooks from running during a clone, 2024-03-28), I introduced an inadvertent memory leak that was unfortunately not caught before v2.45.1 was released. Here is a fix.

---
 hook.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hook.c +3 -1
index 632b537b99..fc974cee1d 100644
@@ -18,8 +18,10 @@ static int identical_to_template_hook(const char *name, const char *path)
 		found_template_hook = access(template_path.buf, X_OK) >= 0;
 	}
 #endif
-	if (!found_template_hook)
+	if (!found_template_hook) {
+		strbuf_release(&template_path);
 		return 0;
+	}
 
 	ret = do_files_match(template_path.buf, path);
 
Signature · 1 line
2.45.1-216-g4365c6fcf9
#9 lore raw

PATCH 7/12 init: use the correct path of the templates directory again

In reply to Junio C Hamano

From: Johannes Schindelin <[email protected]>

In df93e407f06 (init: refactor the template directory discovery into its own function, 2024-03-29), I refactored the way the templates directory is discovered.

The refactoring was faithful, but missed a reference in the Makefile where the DEFAULT_GIT_TEMPLATE_DIR constant is defined. As a consequence, Git v2.45.1 and friends will always use the hard-coded path /usr/share/git-core/templates.

Let's fix that by defining the DEFAULT_GIT_TEMPLATE_DIR when building setup.o, where that constant is actually used.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 093829ae28..4b1502ba2c 100644
@@ -2751,7 +2751,7 @@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \
 	'-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"'
 
 builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX
-builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \
+setup.sp setup.s setup.o: EXTRA_CPPFLAGS = \
 	-DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"'
 
 config.sp config.s config.o: GIT-PREFIX
Signature · 1 line
2.45.1-216-g4365c6fcf9
#10 lore raw

PATCH 8/12 Revert "core.hooksPath: add some protection while cloning"

In reply to Junio C Hamano

From: Johannes Schindelin <[email protected]>

This defense-in-depth was intended to protect the clone operation against future escalations where bugs in git clone would allow attackers to write arbitrary files in the .git/ directory would allow for Remote Code Execution attacks via maliciously-placed hooks.

However, it turns out that the core.hooksPath protection has unintentional side effects so severe that they do not justify the benefit of the protections. For example, it has been reported in
https://lore.kernel.org/git/[email protected]/
that the following invocation, which is intended to make git clone safer, is itself broken by that protective measure:

	git clone --config core.hooksPath=/dev/null <url>

Since it turns out that the benefit does not justify the cost, let's revert 20f3588efc6 (core.hooksPath: add some protection while cloning, 2024-03-30).

---
 config.c        | 13 +------------
 t/t1800-hook.sh | 15 ---------------
 2 files changed, 1 insertion(+), 27 deletions(-)
config.c +1 -12
index 85b37f2ee0..8c1c4071f0 100644
@@ -1525,19 +1525,8 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
 	if (!strcmp(var, "core.attributesfile"))
 		return git_config_pathname(&git_attributes_file, var, value);
 
-	if (!strcmp(var, "core.hookspath")) {
-		if (current_config_scope() == CONFIG_SCOPE_LOCAL &&
-		    git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0))
-			die(_("active `core.hooksPath` found in the local "
-			      "repository config:\n\t%s\nFor security "
-			      "reasons, this is disallowed by default.\nIf "
-			      "this is intentional and the hook should "
-			      "actually be run, please\nrun the command "
-			      "again with "
-			      "`GIT_CLONE_PROTECTION_ACTIVE=false`"),
-			    value);
+	if (!strcmp(var, "core.hookspath"))
 		return git_config_pathname(&git_hooks_path, var, value);
-	}
 
 	if (!strcmp(var, "core.bare")) {
 		is_bare_repository_cfg = git_config_bool(var, value);
t/t1800-hook.sh +0 -15
index 7ee12e6f48..2ef3579fa7 100755
@@ -177,19 +177,4 @@ test_expect_success 'git hook run a hook with a bad shebang' '
 	test_cmp expect actual
 '
 
-test_expect_success 'clone protections' '
-	test_config core.hooksPath "$(pwd)/my-hooks" &&
-	mkdir -p my-hooks &&
-	write_script my-hooks/test-hook <<-\EOF &&
-	echo Hook ran $1
-	EOF
-
-	git hook run test-hook 2>err &&
-	grep "Hook ran" err &&
-	test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \
-		git hook run test-hook 2>err &&
-	grep "active .core.hooksPath" err &&
-	! grep "Hook ran" err
-'
-
 test_done
Signature · 1 line
2.45.1-216-g4365c6fcf9
#11 lore raw

PATCH 9/12 tests: verify that `clone -c core.hooksPath=/dev/null` works again

In reply to Junio C Hamano

From: Johannes Schindelin <[email protected]>

As part of the protections added in Git v2.45.1 and friends, repository-local core.hooksPath settings are no longer allowed, as a defense-in-depth mechanism to prevent future Git vulnerabilities to raise to critical level if those vulnerabilities inadvertently allow the repository-local config to be written.

What the added protection did not anticipate is that such a repository-local core.hooksPath can not only be used to point to maliciously-placed scripts in the current worktree, but also to _prevent_ hooks from being called altogether.

We just reverted the core.hooksPath protections, based on the Git maintainer's recommendation in
https://lore.kernel.org/git/[email protected]/ to address this concern as well as related ones. Let's make sure that we won't regress while trying to protect the clone operation further.

---
 t/t1350-config-hooks-path.sh | 7 +++++++
 1 file changed, 7 insertions(+)
t/t1350-config-hooks-path.sh +7 -0
index f6dc83e2aa..45a0492917 100755
@@ -41,4 +41,11 @@ test_expect_success 'git rev-parse --git-path hooks' '
 	test .git/custom-hooks/abc = "$(cat actual)"
 '
 
+test_expect_success 'core.hooksPath=/dev/null' '
+	git clone -c core.hooksPath=/dev/null . no-templates &&
+	value="$(git -C no-templates config --local core.hooksPath)" &&
+	# The Bash used by Git for Windows rewrites `/dev/null` to `nul`
+	{ test /dev/null = "$value" || test nul = "$value"; }
+'
+
 test_done
Signature · 1 line
2.45.1-216-g4365c6fcf9
#13 lore raw

PATCH 10/12 clone: drop the protections where hooks aren't run

In reply to Junio C Hamano

From: Johannes Schindelin <[email protected]>

As part of the security bug-fix releases v2.39.4, ..., v2.45.1, I introduced logic to safeguard git clone from running hooks that were installed _during_ the clone operation.

The rationale was that Git's CVE-2024-32002, CVE-2021-21300, CVE-2019-1354, CVE-2019-1353, CVE-2019-1352, and CVE-2019-1349 should have been low-severity vulnerabilities but were elevated to critical/high severity by the attack vector that allows a weakness where files inside .git/ can be inadvertently written during a git clone to escalate to a Remote Code Execution attack by virtue of installing a malicious post-checkout hook that Git will then run at the end of the operation without giving the user a chance to see what code is executed.

Unfortunately, Git LFS uses a similar strategy to install its own post-checkout hook during a git clone; In fact, Git LFS is installing four separate hooks while running the smudge filter.

While this pattern is probably in want of being improved by introducing better support in Git for Git LFS and other tools wishing to register hooks to be run at various stages of Git's commands, let's undo the clone protections to unbreak Git LFS-enabled clones.

This reverts commit 8db1e8743c0 (clone: prevent hooks from running during a clone, 2024-03-28).

---
 builtin/clone.c  | 12 +-----------
 hook.c           | 34 --------------------------------
 t/t5601-clone.sh | 51 ------------------------------------------------
 3 files changed, 1 insertion(+), 96 deletions(-)
builtin/clone.c +1 -11
index e7721f5c22..9ec500d427 100644
@@ -937,8 +937,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	int err = 0, complete_refs_before_fetch = 1;
 	int submodule_progress;
 	int filter_submodules = 0;
-	const char *template_dir;
-	char *template_dir_dup = NULL;
 
 	struct transport_ls_refs_options transport_ls_refs_options =
 		TRANSPORT_LS_REFS_OPTIONS_INIT;
@@ -958,13 +956,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		usage_msg_opt(_("You must specify a repository to clone."),
 			builtin_clone_usage, builtin_clone_options);
 
-	xsetenv("GIT_CLONE_PROTECTION_ACTIVE", "true", 0 /* allow user override */);
-	template_dir = get_template_dir(option_template);
-	if (*template_dir && !is_absolute_path(template_dir))
-		template_dir = template_dir_dup =
-			absolute_pathdup(template_dir);
-	xsetenv("GIT_CLONE_TEMPLATE_DIR", template_dir, 1);
-
 	if (option_depth || option_since || option_not.nr)
 		deepen = 1;
 	if (option_single_branch == -1)
@@ -1112,7 +1103,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	init_db(git_dir, real_git_dir, template_dir, GIT_HASH_UNKNOWN, NULL,
+	init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
 		INIT_DB_QUIET);
 
 	if (real_git_dir) {
@@ -1430,7 +1421,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	free(unborn_head);
 	free(dir);
 	free(path);
-	free(template_dir_dup);
 	UNLEAK(repo);
 	junk_mode = JUNK_LEAVE_ALL;
 
hook.c +0 -34
index fc974cee1d..22b274b60b 100644
@@ -3,32 +3,6 @@
 #include "run-command.h"
 #include "config.h"
 
-static int identical_to_template_hook(const char *name, const char *path)
-{
-	const char *env = getenv("GIT_CLONE_TEMPLATE_DIR");
-	const char *template_dir = get_template_dir(env && *env ? env : NULL);
-	struct strbuf template_path = STRBUF_INIT;
-	int found_template_hook, ret;
-
-	strbuf_addf(&template_path, "%s/hooks/%s", template_dir, name);
-	found_template_hook = access(template_path.buf, X_OK) >= 0;
-#ifdef STRIP_EXTENSION
-	if (!found_template_hook) {
-		strbuf_addstr(&template_path, STRIP_EXTENSION);
-		found_template_hook = access(template_path.buf, X_OK) >= 0;
-	}
-#endif
-	if (!found_template_hook) {
-		strbuf_release(&template_path);
-		return 0;
-	}
-
-	ret = do_files_match(template_path.buf, path);
-
-	strbuf_release(&template_path);
-	return ret;
-}
-
 const char *find_hook(const char *name)
 {
 	static struct strbuf path = STRBUF_INIT;
@@ -64,14 +38,6 @@ const char *find_hook(const char *name)
 		}
 		return NULL;
 	}
-	if (!git_hooks_path && git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0) &&
-	    !identical_to_template_hook(name, path.buf))
-		die(_("active `%s` hook found during `git clone`:\n\t%s\n"
-		      "For security reasons, this is disallowed by default.\n"
-		      "If this is intentional and the hook should actually "
-		      "be run, please\nrun the command again with "
-		      "`GIT_CLONE_PROTECTION_ACTIVE=false`"),
-		    name, path.buf);
 	return path.buf;
 }
 
t/t5601-clone.sh +0 -51

57 lines not on this page · raw message

Signature · 1 line
2.45.1-216-g4365c6fcf9
#14 lore raw

PATCH 11/12 Revert "Add a helper function to compare file contents"

In reply to Junio C Hamano

From: Johannes Schindelin <[email protected]>

Now that during a git clone, the hooks' contents are no longer compared to the templates' files', the caller for which the do_files_match() function was introduced is gone, and therefore this function can be retired, too.

This reverts commit 584de0b4c23 (Add a helper function to compare file contents, 2024-03-30).

---
 cache.h                    | 14 ---------
 copy.c                     | 58 --------------------------------------
 t/helper/test-path-utils.c | 10 -------
 t/t0060-path-utils.sh      | 41 ---------------------------
 4 files changed, 123 deletions(-)
cache.h +0 -14
index 16b34799bf..8c5fb1e1ba 100644
@@ -1785,20 +1785,6 @@ int copy_fd(int ifd, int ofd);
 int copy_file(const char *dst, const char *src, int mode);
 int copy_file_with_time(const char *dst, const char *src, int mode);
 
-/*
- * Compare the file mode and contents of two given files.
- *
- * If both files are actually symbolic links, the function returns 1 if the link
- * targets are identical or 0 if they are not.
- *
- * If any of the two files cannot be accessed or in case of read failures, this
- * function returns 0.
- *
- * If the file modes and contents are identical, the function returns 1,
- * otherwise it returns 0.
- */
-int do_files_match(const char *path1, const char *path2);
-
 void write_or_die(int fd, const void *buf, size_t count);
 void fsync_or_die(int fd, const char *);
 int fsync_component(enum fsync_component component, int fd);
copy.c +0 -58

61 lines not on this page · raw message

t/helper/test-path-utils.c +0 -10
index 0e0de21807..f69709d674 100644
@@ -495,16 +495,6 @@ int cmd__path_utils(int argc, const char **argv)
 		return !!res;
 	}
 
-	if (argc == 4 && !strcmp(argv[1], "do_files_match")) {
-		int ret = do_files_match(argv[2], argv[3]);
-
-		if (ret)
-			printf("equal\n");
-		else
-			printf("different\n");
-		return !ret;
-	}
-
 	fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
 		argv[1] ? argv[1] : "(there was none)");
 	return 1;
t/t0060-path-utils.sh +0 -41

45 lines not on this page · raw message

Signature · 1 line
2.45.1-216-g4365c6fcf9
#15 lore raw

PATCH 12/12 Revert "fetch/clone: detect dubious ownership of local repositories"

In reply to Junio C Hamano

This partially reverts f4aa8c8b (fetch/clone: detect dubious ownership of local repositories, 2024-04-10) that broke typical read-only use cases (e.g. by git-daemon serving fetches and clones) where "nobody" who has no write permission serves repositories owned by others. The function to die upon seeing dubious ownership is still kept, as there are other users of it, but calls to it from the generic repository discovery code path, which triggered in cases far wider than originally intended (i.e. to stop local clones), have been removed.

---
 path.c                        | 2 --
 t/t0411-clone-from-partial.sh | 6 +++---
 2 files changed, 3 insertions(+), 5 deletions(-)
path.c +0 -2
index d61f70e87d..492e17ad12 100644
@@ -840,7 +840,6 @@ const char *enter_repo(const char *path, int strict)
 		if (!suffix[i])
 			return NULL;
 		gitfile = read_gitfile(used_path.buf);
-		die_upon_dubious_ownership(gitfile, NULL, used_path.buf);
 		if (gitfile) {
 			strbuf_reset(&used_path);
 			strbuf_addstr(&used_path, gitfile);
@@ -851,7 +850,6 @@ const char *enter_repo(const char *path, int strict)
 	}
 	else {
 		const char *gitfile = read_gitfile(path);
-		die_upon_dubious_ownership(gitfile, NULL, path);
 		if (gitfile)
 			path = gitfile;
 		if (chdir(path))
t/t0411-clone-from-partial.sh +3 -3
index b3d6ddc4bc..a481ed97b7 100755
@@ -23,7 +23,7 @@ test_expect_success 'create evil repo' '
 	>evil/.git/shallow
 '
 
-test_expect_success 'local clone must not fetch from promisor remote and execute script' '
+test_expect_failure 'local clone must not fetch from promisor remote and execute script' '
 	rm -f script-executed &&
 	test_must_fail git clone \
 		--upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
@@ -33,7 +33,7 @@ test_expect_success 'local clone must not fetch from promisor remote and execute
 	test_path_is_missing script-executed
 '
 
-test_expect_success 'clone from file://... must not fetch from promisor remote and execute script' '
+test_expect_failure 'clone from file://... must not fetch from promisor remote and execute script' '
 	rm -f script-executed &&
 	test_must_fail git clone \
 		--upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
@@ -43,7 +43,7 @@ test_expect_success 'clone from file://... must not fetch from promisor remote a
 	test_path_is_missing script-executed
 '
 
-test_expect_success 'fetch from file://... must not fetch from promisor remote and execute script' '
+test_expect_failure 'fetch from file://... must not fetch from promisor remote and execute script' '
 	rm -f script-executed &&
 	test_must_fail git fetch \
 		--upload-pack="GIT_TEST_ASSUME_DIFFERENT_OWNER=true git-upload-pack" \
Signature · 1 line
2.45.1-216-g4365c6fcf9
#16 lore raw

Re: [PATCH 12/12] Revert "fetch/clone: detect dubious ownership of local repositories"

Quoted 10 lines · Junio C Hamano

This partially reverts f4aa8c8b (fetch/clone: detect dubious ownership of local repositories, 2024-04-10) that broke typical read-only use cases (e.g. by git-daemon serving fetches and clones) where "nobody" who has no write permission serves repositories owned by others. The function to die upon seeing dubious ownership is still kept, as there are other users of it, but calls to it from the generic repository discovery code path, which triggered in cases far wider than originally intended (i.e. to stop local clones), have been removed.

Quoted 2 lines

---

I am inclined to propose dropping this step, actually.

cf. https://lore.kernel.org/git/[email protected]/

#19 lore raw

[rPATCH 13/12] Merge branch 'jc/fix-aggressive-protection-2.39'

In reply to Junio C Hamano

This is "git show --remerge-diff" of the result of adjusting the jc/fix-aggressive-protection-2.39 topic (which you just saw) into maint-2.40 track.
The result is called jc/fix-aggressive-protection-2.40.

It is not for direct consumption by "git am".

If this format looks reasonable to folks as a way to review the result of merging up fixes, I'll follow up with "patches" for more recent maintenance tracks.

builtin/clone.c +0 -0

remerge CONFLICT (content): Merge conflict in builtin/clone.c index 17d34efebd..399b2d3f42 100644

builtin/clone.c +0 -7
@@ -1447,15 +1447,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	free(unborn_head);
 	free(dir);
 	free(path);
-<<<<<<< b9b439e0e3 (Git 2.40.2)
 	free(repo_to_free);
-	free(template_dir_dup);
-||||||| 47b6d90e91
-	free(template_dir_dup);
 	UNLEAK(repo);
-=======
-	UNLEAK(repo);
->>>>>>> 9074ec92e7 (Revert "fetch/clone: detect dubious ownership of local repositories")
 	junk_mode = JUNK_LEAVE_ALL;
 
 	transport_ls_refs_options_release(&transport_ls_refs_options);
t/t1800-hook.sh +0 -0

remerge CONFLICT (content): Merge conflict in t/t1800-hook.sh index edf0fa1334..3506f627b6 100755

t/t1800-hook.sh +0 -34
@@ -177,7 +177,6 @@ test_expect_success 'git hook run a hook with a bad shebang' '
 	test_cmp expect actual
 '
 
-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< b9b439e0e3 (Git 2.40.2)
 test_expect_success 'stdin to hooks' '
 	write_script .git/hooks/test-hook <<-\EOF &&
 	echo BEGIN stdin
@@ -196,37 +195,4 @@ test_expect_success 'stdin to hooks' '
 	test_cmp expect actual
 '
 
-test_expect_success 'clone protections' '
-	test_config core.hooksPath "$(pwd)/my-hooks" &&
-	mkdir -p my-hooks &&
-	write_script my-hooks/test-hook <<-\EOF &&
-	echo Hook ran $1
-	EOF
-
-	git hook run test-hook 2>err &&
-	grep "Hook ran" err &&
-	test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \
-		git hook run test-hook 2>err &&
-	grep "active .core.hooksPath" err &&
-	! grep "Hook ran" err
-'
-
-|||||||||||||||||||||||||||||||| 47b6d90e91
-test_expect_success 'clone protections' '
-	test_config core.hooksPath "$(pwd)/my-hooks" &&
-	mkdir -p my-hooks &&
-	write_script my-hooks/test-hook <<-\EOF &&
-	echo Hook ran $1
-	EOF
-
-	git hook run test-hook 2>err &&
-	grep "Hook ran" err &&
-	test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \
-		git hook run test-hook 2>err &&
-	grep "active .core.hooksPath" err &&
-	! grep "Hook ran" err
-'
-
-================================
->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 9074ec92e7 (Revert "fetch/clone: detect dubious ownership of local repositories")
 test_done
#22 lore raw

[rPATCH 14/12] Merge branch 'jc/fix-aggressive-protection-2.40'

In reply to Junio C Hamano

With patches 01/12 - 12/12 applied on top of maint-2.39 (the result of which is called jc/fix-aggressive-protection-2.39), and then the result merged to maint-2.40 with conflict resolutions shown in 13/12, I've prepared jc/fix-aggressive-protection-2.40.

This is "git show --remerge-diff" of the result of adjusting the jc/fix-aggressive-protection-2.40 topic to maint-2.41 track. The result is called jc/fix-aggressive-protection-2.41.

It is not for direct consumption by "git am".

The only tricky part is an evil merge to copy.h that was made necessarily due to recent header file shuffling.

builtin/clone.c +0 -0

remerge CONFLICT (content): Merge conflict in builtin/clone.c index 85ecda8e6f..b7db074b7e 100644

builtin/clone.c +0 -8
@@ -958,15 +958,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	int err = 0, complete_refs_before_fetch = 1;
 	int submodule_progress;
 	int filter_submodules = 0;
-<<<<<<< 0f15832059 (Git 2.41.1)
 	int hash_algo;
-	const char *template_dir;
-	char *template_dir_dup = NULL;
-||||||| b9b439e0e3
-	const char *template_dir;
-	char *template_dir_dup = NULL;
-=======
->>>>>>> 1b2b92753e (Merge branch 'jc/fix-aggressive-protection-2.39' into HEAD)
 
 	struct transport_ls_refs_options transport_ls_refs_options =
 		TRANSPORT_LS_REFS_OPTIONS_INIT;
cache.h +0 -0

remerge CONFLICT (content): Merge conflict in cache.h index 534e983b90..bdedb87e83 100644

cache.h +0 -1294

1,301 lines not on this page · raw message

copy.h +0 -14
index 057259a3a7..2af77cba86 100644
@@ -7,18 +7,4 @@ int copy_fd(int ifd, int ofd);
 int copy_file(const char *dst, const char *src, int mode);
 int copy_file_with_time(const char *dst, const char *src, int mode);
 
-/*
- * Compare the file mode and contents of two given files.
- *
- * If both files are actually symbolic links, the function returns 1 if the link
- * targets are identical or 0 if they are not.
- *
- * If any of the two files cannot be accessed or in case of read failures, this
- * function returns 0.
- *
- * If the file modes and contents are identical, the function returns 1,
- * otherwise it returns 0.
- */
-int do_files_match(const char *path1, const char *path2);
-
 #endif /* COPY_H */
#24 lore raw
In reply to Junio C Hamano

Hi Junio,

Quoted 5 lines · Junio C Hamano

I'll figure out a way to convey conflict resolutions as this topic gets merged up to newer maintenance tracks on the list so that people can assist with ensuring correctness of the result by reviewing, and follow up. ("git show --remerge-diff" might turn out to be such a way, but I do not know yet).

I pushed 12/12 to https://github.com/dscho/git's
various-fixes-for-v2.45.1-and-friends branch, and updated the tentative/maint-* branches accordingly:

+ b9a96c4e5dc...c6da96aa5f0 maint-2.39 -> tentative/maint-2.39 (forced update)
+ 4bf5d57da62...fff57b200d1 maint-2.40 -> tentative/maint-2.40 (forced update)
+ 5215e4e3687...616450032a0 maint-2.41 -> tentative/maint-2.41 (forced update)
+ 33efa2ad1a6...b1ea89bc2d6 maint-2.42 -> tentative/maint-2.42 (forced update)
+ 0aeca2f80b1...093c42a6c6b maint-2.43 -> tentative/maint-2.43 (forced update)
+ 9953011fcdd...3c7a7b923b3 maint-2.44 -> tentative/maint-2.44 (forced update)

Ciao,
Johannes

#23 lore raw

Re: [rPATCH 14/12] Merge branch 'jc/fix-aggressive-protection-2.40'

In reply to Junio C Hamano
Quoted 2 lines · Junio C Hamano

The only tricky part is an evil merge to copy.h that was made necessarily due to recent header file shuffling.

Up to this step it seems there is no cascading impact if we dropped the [12/12] from the series. I forgot that hook.c needs to lose "#include <copy.h>" during this merge, which also was made necessarily due to recent header file shuffling.

#25 lore raw
In reply to Johannes Schindelin
Quoted 11 lines · Johannes Schindelin
Quoted 5 lines · Junio C Hamano

I'll figure out a way to convey conflict resolutions as this topic gets merged up to newer maintenance tracks on the list so that people can assist with ensuring correctness of the result by reviewing, and follow up. ("git show --remerge-diff" might turn out to be such a way, but I do not know yet).

I pushed 12/12 to https://github.com/dscho/git's
various-fixes-for-v2.45.1-and-friends branch, and updated the tentative/maint-* branches accordingly:

Thanks, but I suspect it is not productive use of your time to merge these up until we know we are happy with what we are merging up.

Even though I did the 12/12 that reverts the "iffy ownership check during repository discovery", it is far from clear without discussion if that is a reasonable thing to do or use of safe.directory by narrow non-target audience (like k.org that may use gitolite and/or bare git for hosting) that lets nobody access trusted user repositories. Every time we find new issues or different solutions, somebody has to merge it up, eventually to maint-2.45, but I am afraid it may be a bit too early to commit.

Quoted 9 lines

+ b9a96c4e5dc...c6da96aa5f0 maint-2.39 -> tentative/maint-2.39 (forced update)
+ 4bf5d57da62...fff57b200d1 maint-2.40 -> tentative/maint-2.40 (forced update)
+ 5215e4e3687...616450032a0 maint-2.41 -> tentative/maint-2.41 (forced update)
+ 33efa2ad1a6...b1ea89bc2d6 maint-2.42 -> tentative/maint-2.42 (forced update)
+ 0aeca2f80b1...093c42a6c6b maint-2.43 -> tentative/maint-2.43 (forced update)
+ 9953011fcdd...3c7a7b923b3 maint-2.44 -> tentative/maint-2.44 (forced update)

Ciao,
Johannes

#26 lore raw
Quoted 17 lines · Junio C Hamano
Quoted 11 lines · Johannes Schindelin
Quoted 5 lines · Junio C Hamano

I'll figure out a way to convey conflict resolutions as this topic gets merged up to newer maintenance tracks on the list so that people can assist with ensuring correctness of the result by reviewing, and follow up. ("git show --remerge-diff" might turn out to be such a way, but I do not know yet).

I pushed 12/12 to https://github.com/dscho/git's
various-fixes-for-v2.45.1-and-friends branch, and updated the tentative/maint-* branches accordingly:

Thanks, but I suspect it is not productive use of your time to merge these up until we know we are happy with what we are merging up.

Quoted 8 lines

Even though I did the 12/12 that reverts the "iffy ownership check during repository discovery", it is far from clear without discussion if that is a reasonable thing to do or use of safe.directory by narrow non-target audience (like k.org that may use gitolite and/or bare git for hosting) that lets nobody access trusted user repositories. Every time we find new issues or different solutions, somebody has to merge it up, eventually to maint-2.45, but I am afraid it may be a bit too early to commit.

Another thing is that, now this is not an embargoed set of secret releases, I'd want to have them go through 'next' down to 'master' in the usual way, with the usual "develop in the open" fashion, before we convince ourselves that the whole cascade is ready. We may find necessary updates while these fixes are in 'next' due to $WORK folks feeding 'next' based updates to $CORP users and helping us find issues, in which case we would need to add more patches on top of the topic based on maint-2.39 (and merge it up all the way). After that is all done, we would finally become ready to write release notes for the tracks, which will be merged up the same way as the "oops, we found we need another patch while the series was in 'next'" case. Preparing tentative/maint-* set of branches your way, with release notes and GIT-VERSION-GEN updates together ready to be tagged, would not help prepare something that I can feed other developers in 'seen' and then 'next'.

Thanks.

#12 lore raw

Re: [PATCH 09/12] tests: verify that `clone -c core.hooksPath=/dev/null` works again

In reply to Junio C Hamano

Thanks, Junio and Johannes. Looking forward to making use of this again!

Quoted 47 lines · Junio C Hamano

From: Johannes Schindelin <[email protected]>

As part of the protections added in Git v2.45.1 and friends, repository-local core.hooksPath settings are no longer allowed, as a defense-in-depth mechanism to prevent future Git vulnerabilities to raise to critical level if those vulnerabilities inadvertently allow the repository-local config to be written.

What the added protection did not anticipate is that such a repository-local core.hooksPath can not only be used to point to maliciously-placed scripts in the current worktree, but also to _prevent_ hooks from being called altogether.

We just reverted the core.hooksPath protections, based on the Git maintainer's recommendation in
https://lore.kernel.org/git/[email protected]/ to address this concern as well as related ones. Let's make sure that we won't regress while trying to protect the clone operation further.

---
t/t1350-config-hooks-path.sh | 7 +++++++

1 file changed, 7 insertions(+)
t/t1350-config-hooks-path.sh +0 -0
index f6dc83e2aa..45a0492917 100755
@@ -41,4 +41,11 @@ test_expect_success 'git rev-parse --git-path hooks' '
 	test .git/custom-hooks/abc = "$(cat actual)"

'

t/t1350-config-hooks-path.sh +7 -0
+test_expect_success 'core.hooksPath=/dev/null' '
+	git clone -c core.hooksPath=/dev/null . no-templates &&
+	value="$(git -C no-templates config --local core.hooksPath)" &&
+	# The Bash used by Git for Windows rewrites `/dev/null` to `nul`
+	{ test /dev/null = "$value" || test nul = "$value"; }
+'
+

test_done

Signature · 1 line
2.45.1-216-g4365c6fcf9
#17 lore raw

Re: [PATCH 12/12] Revert "fetch/clone: detect dubious ownership of local repositories"

In reply to Junio C Hamano

Hi Junio,

Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Junio C Hamano

This partially reverts f4aa8c8b (fetch/clone: detect dubious ownership of local repositories, 2024-04-10) that broke typical read-only use cases (e.g. by git-daemon serving fetches and clones) where "nobody" who has no write permission serves repositories owned by others. The function to die upon seeing dubious ownership is still kept, as there are other users of it, but calls to it from the generic repository discovery code path, which triggered in cases far wider than originally intended (i.e. to stop local clones), have been removed.

Quoted 6 lines
Quoted 2 lines

---

I am inclined to propose dropping this step, actually.

cf. https://lore.kernel.org/git/[email protected]/

To https://github.com/dscho/git
+ c6da96aa5f0...f71d7009814 maint-2.39 -> tentative/maint-2.39 (forced update)
+ fff57b200d1...21dc6c4d521 maint-2.40 -> tentative/maint-2.40 (forced update)
+ 616450032a0...0d21b3451cd maint-2.41 -> tentative/maint-2.41 (forced update)
+ b1ea89bc2d6...e9bd0c8f8c4 maint-2.42 -> tentative/maint-2.42 (forced update)
+ 093c42a6c6b...9926037ce8c maint-2.43 -> tentative/maint-2.43 (forced update)
+ 3c7a7b923b3...aec5a9bf52c maint-2.44 -> tentative/maint-2.44 (forced update)
+ aeddcb02756...d3c56966d13 maint-2.45 -> tentative/maint-2.45 (forced update)

This command-line comes up with no differences (meaning: you resolved the merge conflicts, even the ones without conflict markers, in the same way as I did, which is good):

  for i in $(seq 39 45)
  do
    case $i in
    39) gitster=jc/fix-2.45.1-and-friends-for-2.39;;
    45) gitster=jc/fix-2.45.1-and-friends-for-maint;;
    *)  gitster=fixes/2.45.1/2.$i;;
    esac &&
    git diff gitster/$gitster..dscho/tentative/maint-2.$i -- \
      ':(exclude)Documentation/RelNotes/' \
      ':(exclude)GIT-VERSION-GEN' \
      ':(exclude)RelNotes'
  done

Ciao,
Johannes

Reviewed-by on v1 2/12
#4 lore raw

Re: [PATCH 02/12] send-email: avoid creating more than one Term::ReadLine object

In reply to Junio C Hamano
Quoted 22 lines · Junio C Hamano

From: Jeff King <[email protected]>

Every time git-send-email calls its ask() function to prompt the user, we call term(), which instantiates a new Term::ReadLine object. But in v1.46 of Term::ReadLine::Gnu (which provides the Term::ReadLine interface on some platforms), its constructor refuses to create a second instance[1]. So on systems with that version of the module, most git-send-email instances will fail (as we usually prompt for both "to" and "in-reply-to" unless the user provided them on the command line).

We can fix this by keeping a single instance variable and returning it for each call to term(). In perl 5.10 and up, we could do that with a "state" variable. But since we only require 5.008, we'll do it the old-fashioned way, with a lexical "my" in its own scope.

Note that the tests in t9001 detect this problem as-is, since the failure mode is for the program to die. But let's also beef up the "Prompting works" test to check that it correctly handles multiple inputs (if we had chosen to keep our FakeTerm hack in the previous commit, then the failure mode would be incorrectly ignoring prompts after the first).

Quoted 8 lines

[1] For discussion of why multiple instances are forbidden, see:
https://github.com/hirooih/perl-trg/issues/16

[jc: cherry-picked from v2.42.0-rc2~6^2]

Looking good to me. Thanks for taking care of this issue.

Quoted 55 lines
---
 git-send-email.perl   | 18 +++++++++++++-----
 t/t9001-send-email.sh |  5 +++--
 2 files changed, 16 insertions(+), 7 deletions(-)
git-send-email.perl +13 -5
index 72d876f0a0..ad51508790 100755
@@ -917,11 +917,19 @@ sub get_patch_subject {
 	do_edit(@files);
 }
 
-sub term {
-	require Term::ReadLine;
-	return $ENV{"GIT_SEND_EMAIL_NOTTY"}
-			? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
-			: Term::ReadLine->new('git-send-email');
+{
+	# Only instantiate one $term per program run, since some
+	# Term::ReadLine providers refuse to create a second instance.
+	my $term;
+	sub term {
+		require Term::ReadLine;
+		if (!defined $term) {
+			$term = $ENV{"GIT_SEND_EMAIL_NOTTY"}
+				? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
+				: Term::ReadLine->new('git-send-email');
+		}
+		return $term;
+	}
 }
 
 sub ask {
t/t9001-send-email.sh +3 -2
index 1130ef21b3..0f08a9542b 100755
@@ -337,13 +337,14 @@ test_expect_success $PREREQ 'Show all headers' '
 test_expect_success $PREREQ 'Prompting works' '
 	clean_fake_sendmail &&
 	(echo "[email protected]" &&
-	 echo ""
+	 echo "[email protected]"
 	) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
 		--smtp-server="$(pwd)/fake.sendmail" \
 		$patches \
 		2>errors &&
 		grep "^From: A U Thor <[email protected]>\$" msgtxt1 &&
-		grep "^To: [email protected]\$" msgtxt1
+		grep "^To: [email protected]\$" msgtxt1 &&
+		grep "^In-Reply-To: <[email protected]>" msgtxt1
 '
 
 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
Reviewed-by on v1 1/12
#2 lore raw

Re: [PATCH 01/12] send-email: drop FakeTerm hack

In reply to Junio C Hamano
Quoted 28 lines · Junio C Hamano

From: Jeff King <[email protected]>

Back in 280242d1cc (send-email: do not barf when Term::ReadLine does not like your terminal, 2006-07-02), we added a fallback for when Term::ReadLine's constructor failed: we'd have a FakeTerm object instead, which would then die if anybody actually tried to call readline() on it. Since we instantiated the $term variable at program startup, we needed this workaround to let the program run in modes when we did not prompt the user.

But later, in f4dc9432fd (send-email: lazily load modules for a big speedup, 2021-05-28), we started loading Term::ReadLine lazily only when ask() is called. So at that point we know we're trying to prompt the user, and we can just die if ReadLine instantiation fails, rather than making this fake object to lazily delay showing the error.

This should be OK even if there is no tty (e.g., we're in a cron job), because Term::ReadLine will return a stub object in that case whose "IN" and "OUT" functions return undef. And since 5906f54e47 (send-email:
don't attempt to prompt if tty is closed, 2009-03-31), we check for that case and skip prompting.

And we can be sure that FakeTerm was not kicking in for such a situation, because it has actually been broken since that commit! It does not define "IN" or "OUT" methods, so perl would barf with an error. If FakeTerm was in use, we were neither honoring what 5906f54e47 tried to do, nor producing the readable message that 280242d1cc intended.

Quoted 8 lines

So we're better off just dropping FakeTerm entirely, and letting the error reported by constructing Term::ReadLine through.

[jc: cherry-picked from v2.42.0-rc2~6^2~1]

Looking good to me. Thanks for taking care of this issue.

Quoted 46 lines
---
 git-send-email.perl | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
git-send-email.perl +2 -20
index 5861e99a6e..72d876f0a0 100755
@@ -26,18 +26,6 @@
 
 Getopt::Long::Configure qw/ pass_through /;
 
-package FakeTerm;
-sub new {
-	my ($class, $reason) = @_;
-	return bless \$reason, shift;
-}
-sub readline {
-	my $self = shift;
-	die "Cannot use readline on FakeTerm: $$self";
-}
-package main;
-
-
 sub usage {
 	print <<EOT;
 git send-email' [<options>] <file|directory>
@@ -930,16 +918,10 @@ sub get_patch_subject {
 }
 
 sub term {
-	my $term = eval {
-		require Term::ReadLine;
-		$ENV{"GIT_SEND_EMAIL_NOTTY"}
+	require Term::ReadLine;
+	return $ENV{"GIT_SEND_EMAIL_NOTTY"}
 			? Term::ReadLine->new('git-send-email', \*STDIN, \*STDOUT)
 			: Term::ReadLine->new('git-send-email');
-	};
-	if ($@) {
-		$term = FakeTerm->new("$@: going non-interactive");
-	}
-	return $term;
 }
 
 sub ask {
#27 lore raw
In reply to Junio C Hamano
Quoted 3 lines · Junio C Hamano

As people have seen, the latest "security fix" release turned out to be a mixed bag of good vulnerability fixes with a bit over-eager "layered defence" that broke real uses cases like git-lfs.

"fsck: warn about symlink pointing inside a gitdir" (a33fea0886cfa016d313d2bd66bdd08615bffbc9) also broke pushing git-annex repositories to eg Gitlab and has several other problems including dodgy PATH_MAX checks that cause new OS interoperability problems. (I posted details to an earlier thread but have now found this current one, oops.)

Please also revert it, or at least the portions for and symlinkPointsToGitDir and symlinkTargetLength. The checks for symlinkTargetBlob and symlinkTargetMissing seem worth keeping.

Quoted 3 lines

Let's quickly get them in working order back first, with the vision that we will then rebuild layered defence more carefully in the open on top as necessary.

Exellent plan.

Signature · 1 line
see shy jo
#18 lore raw

Re: [PATCH 12/12] Revert "fetch/clone: detect dubious ownership of local repositories"

In reply to Johannes Schindelin
Quoted 9 lines · Johannes Schindelin

To https://github.com/dscho/git
+ c6da96aa5f0...f71d7009814 maint-2.39 -> tentative/maint-2.39 (forced update)
+ fff57b200d1...21dc6c4d521 maint-2.40 -> tentative/maint-2.40 (forced update)
+ 616450032a0...0d21b3451cd maint-2.41 -> tentative/maint-2.41 (forced update)
+ b1ea89bc2d6...e9bd0c8f8c4 maint-2.42 -> tentative/maint-2.42 (forced update)
+ 093c42a6c6b...9926037ce8c maint-2.43 -> tentative/maint-2.43 (forced update)
+ 3c7a7b923b3...aec5a9bf52c maint-2.44 -> tentative/maint-2.44 (forced update)
+ aeddcb02756...d3c56966d13 maint-2.45 -> tentative/maint-2.45 (forced update)

Quoted 3 lines

This command-line comes up with no differences (meaning: you resolved the merge conflicts, even the ones without conflict markers, in the same way as I did, which is good):

Yeah, but I am afraid that it is a bit too premature to worry about the integration to merge them up. What's your take on the symlink stuff Joey raised recently?

Thanks.

#28 lore raw
In reply to Joey Hess
Quoted 11 lines · Joey Hess
Quoted 3 lines · Junio C Hamano

As people have seen, the latest "security fix" release turned out to be a mixed bag of good vulnerability fixes with a bit over-eager "layered defence" that broke real uses cases like git-lfs.

"fsck: warn about symlink pointing inside a gitdir" (a33fea0886cfa016d313d2bd66bdd08615bffbc9) also broke pushing git-annex repositories to eg Gitlab and has several other problems including dodgy PATH_MAX checks that cause new OS interoperability problems. (I posted details to an earlier thread but have now found this current one, oops.)

Quoted 4 lines

Please also revert it, or at least the portions for and symlinkPointsToGitDir and symlinkTargetLength. The checks for symlinkTargetBlob and symlinkTargetMissing seem worth keeping.

Looking at the change in question, in a33fea08 (fsck: warn about

Quoted 8 lines · you

fsck: warn about symlink pointing inside a gitdir

In the wake of fixing a vulnerability where git clone mistakenly followed a symbolic link that it had just written while checking out files, writing into a gitdir, let's add some defense-in-depth by teaching git fsck to report symbolic links stored in its trees that point inside .git/.

Quoted 8 lines

Even though the Git project never made any promises about the exact shape of the .git/ directory's contents, there are likely repositories out there containing symbolic links that point inside the gitdir. For that reason, let's only report these as warnings, not as errors. Security-conscious users are encouraged to configure fsck.symlinkPointsToGitDir = error.

I can make a few observations (in addition to what Joey already observed in the code around PATH_MAX, etc. [*]):

- Yes, if git-annex wants to keep its private data in a private directory .git/annex/objects it carved out for itself and want to point at them from the working tree with symbolic links, the extra check would trigger as fsck would see the symbolic link contents pointing into the .git/ directory, so certainly they would be affected.

- The extra check seems to have meant to target the symbolic links that point at objects, refs, config, and anything _we_ care about, as opposed to random garbage (from _our_ point of view) files third-parties throw into .git/ directory. Would it have made a better trade-off if we tried to make the check more precise, only complaining about the things we care about (in other words, what _we_ use), or will it become too brittle because what we care about will change over time?

- In any case, if it is merely warnings, not errors, these checks can be configured out. Wouldn't that be an escape-hatch enough?

So, I am ambivalent. I have prepared a revert queued on maint-2.39 and cascaded it up to the maintenance track, which I tentatively queued on top of 'seen', to see how much damage such a reversion involves (and it did not look too bad), but

(1) I am not sure if this is such a huge deal that requires a

     revert;

(2) I am not sure which one is more practical between ripping everything out and demoting these new fsck error types with FSCK_WARN to FSCK_IGNORE. If the structure of the code to perform these checks is more or less good and the actual check the code implements is bad, the latter might give us a better foundation to build on than rebuilding everything from scratch. On the other hand, if we are redoing things in the open, it may be better to forget about the code in 2.45.1/2.39.4 and to build from scratch for those reviewers and developers who will offer help.

(3) As I look at the change by a33fea08 again, it actually adds a few new fsck error types with FSCK_ERROR. Perhaps that is a good enough reason to do a straight revert for now?

Thanks. It is past my bedtime so I won't be pushing out the 'seen' with the revert I prepared as a practice, at least tonight.

[Reference]

* https://lore.kernel.org/git/[email protected]/

#20 lore raw

Reviewing merge commits, was Re: [rPATCH 13/12] Merge branch 'jc/fix-aggressive-protection-2.39'

In reply to Junio C Hamano

Hi Junio,

Quoted 3 lines · Junio C Hamano

If this format looks reasonable to folks as a way to review the result of merging up fixes, I'll follow up with "patches" for more recent maintenance tracks.

Personally, I find this format quite hard to parse, and I am concerned that the focus on the merge conflicts may distract too much from verifying the correctness of the result. Much of what is tricky about these merges happens outside conflict markers.

If it was up to me to verify such fixes, short of using Git and validating the correctness by performing the merge independently instead of trying to accomplish the validation by looking at a plain-text mail, I would compare the diff of maint-2.39 to the diff of maint-2.40. Something like this [*1*]:

  $ git range-diff \
    mbox:<(git diff v2.45.1...gitster/jc/fix-2.45.1-and-friends-for-2.39) \
    mbox:<(git diff v2.45.1...gitster/fixes/2.45.1/2.40)
  1:  00000000000 ! 1:  00000000000
      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
          if (real_git_dir) {
       @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
      -   free(unborn_head);
          free(dir);
          free(path);
      +   free(repo_to_free);
       -  free(template_dir_dup);
      -   UNLEAK(repo);
      ++  UNLEAK(repo);
          junk_mode = JUNK_LEAVE_ALL;

      +   transport_ls_refs_options_release(&transport_ls_refs_options);

        ## cache.h ##
       @@ cache.h: int copy_fd(int ifd, int ofd);
      @@ t/t1450-fsck.sh: test_expect_success 'fsck error on gitattributes with excessive
        test_done

        ## t/t1800-hook.sh ##
      -@@ t/t1800-hook.sh: test_expect_success 'git hook run a hook with a bad shebang' '
      +@@ t/t1800-hook.sh: test_expect_success 'stdin to hooks' '
          test_cmp expect actual
        '

It does get a bit more confusing with the diff between maint-2.40 and maint-2.41 because the declaration of do_files_match() moved from cache.h to copy.h, and the hunks removing that declaration are at different locations in the diffs:

  $ git range-diff \
    mbox:<(git diff v2.45.1...gitster/fixes/2.45.1/2.40) \
    mbox:<(git diff v2.45.1...gitster/fixes/2.45.1/2.41)
  1:  00000000000 ! 1:  00000000000
      @@ Makefile: exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \
        ## builtin/clone.c ##
       @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
      - 	int err = 0, complete_refs_before_fetch = 1;
        	int submodule_progress;
        	int filter_submodules = 0;
      + 	int hash_algo;
       -	const char *template_dir;
       -	char *template_dir_dup = NULL;

      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)

        	transport_ls_refs_options_release(&transport_ls_refs_options);

      - ## cache.h ##
      -@@ cache.h: int copy_fd(int ifd, int ofd);
      - int copy_file(const char *dst, const char *src, int mode);
      - int copy_file_with_time(const char *dst, const char *src, int mode);
      -
      --/*
      -- * Compare the file mode and contents of two given files.
      -- *
      -- * If both files are actually symbolic links, the function returns 1 if the link
      -- * targets are identical or 0 if they are not.
      -- *
      -- * If any of the two files cannot be accessed or in case of read failures, this
      -- * function returns 0.
      -- *
      -- * If the file modes and contents are identical, the function returns 1,
      -- * otherwise it returns 0.
      -- */
      --int do_files_match(const char *path1, const char *path2);
      --
      - void write_or_die(int fd, const void *buf, size_t count);
      - void fsync_or_die(int fd, const char *);
      - int fsync_component(enum fsync_component component, int fd);
      -
        ## ci/install-dependencies.sh ##
       @@ ci/install-dependencies.sh: macos-*)
        	export HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1
      @@ copy.c: int copy_file_with_time(const char *dst, const char *src, int mode)
       -	return ret;
       -}

      + ## copy.h ##
      +@@ copy.h: int copy_fd(int ifd, int ofd);
      + int copy_file(const char *dst, const char *src, int mode);
      + int copy_file_with_time(const char *dst, const char *src, int mode);
      +
      +-/*
      +- * Compare the file mode and contents of two given files.
      +- *
      +- * If both files are actually symbolic links, the function returns 1 if the link
      +- * targets are identical or 0 if they are not.
      +- *
      +- * If any of the two files cannot be accessed or in case of read failures, this
      +- * function returns 0.
      +- *
      +- * If the file modes and contents are identical, the function returns 1,
      +- * otherwise it returns 0.
      +- */
      +-int do_files_match(const char *path1, const char *path2);
      +-
      + #endif /* COPY_H */
      +
        ## fsck.c ##
       @@ fsck.c: static int fsck_tree(const struct object_id *tree_oid,
        				retval += report(options, tree_oid, OBJ_TREE,
      @@ git-send-email.perl: sub get_patch_subject {

        ## hook.c ##
       @@
      - #include "run-command.h"
      - #include "config.h"
      -
      + #include "strbuf.h"
      + #include "environment.h"
      + #include "setup.h"
      +-#include "copy.h"
      +-
       -static int identical_to_template_hook(const char *name, const char *path)
       -{
       -	const char *env = getenv("GIT_CLONE_TEMPLATE_DIR");
      @@ hook.c
       -	strbuf_release(&template_path);
       -	return ret;
       -}
      --
      +
        const char *find_hook(const char *name)
        {
      - 	static struct strbuf path = STRBUF_INIT;
       @@ hook.c: const char *find_hook(const char *name)
        		}
        		return NULL;
      @@ t/t1350-config-hooks-path.sh: test_expect_success 'git rev-parse --git-path hook
        test_done

        ## t/t1450-fsck.sh ##
      -@@ t/t1450-fsck.sh: test_expect_success 'fsck error on gitattributes with excessive size' '
      - 	test_cmp expected actual
      +@@ t/t1450-fsck.sh: test_expect_success 'fsck reports problems in main index without filename' '
      + 	test_cmp expect actual
        '

       -test_expect_success 'fsck warning on symlink target with excessive length' '

Another thing that makes the review of these diffs-of-diffs harder than necessary is the lack of color-coding in plain-text emails. When I look at the color-coded version, my eyes are immediately drawn away from the unimportant lines that start with a - or + but then continue in uncolored text that indicates context line changes only. Instead, my eyes shift immediately to the relevant parts, the blankets of red color.

Both the remerge-diff and the range-diff output do nothing, though, to help verifying that no-longer-needed #includes are removed (you can see that #include "copy.h" was removed from hook.c, but if that had been missed there would be no indicator thereof).

So while I find this output more useful than the remerge diffs, it is still far from ideal. I will therefore refrain from posting the range-diffs that correspond to the remaining maint-* merges.

Ciao,
Johannes

Footnote *1*: This mbox: construct requires
https://github.com/gitgitgadget/git/pull/1420 (or js/range-diff-mbox) to work as intended.

#21 lore raw

Re: Reviewing merge commits, was Re: [rPATCH 13/12] Merge branch 'jc/fix-aggressive-protection-2.39'

Quoted 2 lines · Johannes Schindelin

Much of what is tricky about these merges
happens outside conflict markers.

Yes. In other words, what you do not see in these outputs can be leaving semantic conflicts unresolved. If we made a change to a location where there wasn't a textual conflict (i.e., making an evil merge) in order to adjust for a semantic differences (e.g., they added a callsite to a function whose signature we updated), any of "git show --cc", "git range-diff", and "git show --remerge-diff" would show. If you failed to do so and introduced a bug (and worse yet, unlike "oh, we now require one more argument to the function" that compilers would catch for us, there are differences that compilers would not notice), none of the three will show.

Quoted 10 lines

If it was up to me to verify such fixes, short of using Git and validating the correctness by performing the merge independently instead of trying to accomplish the validation by looking at a plain-text mail, I would compare the diff of maint-2.39 to the diff of maint-2.40. Something like this [*1*]:
...
Both the remerge-diff and the range-diff output do nothing, though, to help verifying that no-longer-needed #includes are removed (you can see that #include "copy.h" was removed from hook.c, but if that had been missed there would be no indicator thereof).

In short, you are agreeing that between "remerge-diff" and "range-diff" there is no difference in power to let you notice what is *not* there, and I am agreeing to your "what is *not* there is often more problematic", so we are on the same page.

I do not think I am married to "remerge-diff" output, but it being the same form of the familiar "single-parent" patch, I personally find it far easier to read than "diff of diff". We may differ at that point, but it does not matter, as neither of our preferred format is adequate for the job.

;-)

#29 lore raw
In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano

- The extra check seems to have meant to target the symbolic links that point at objects, refs, config, and anything _we_ care about, as opposed to random garbage (from _our_ point of view) files third-parties throw into .git/ directory. Would it have made a better trade-off if we tried to make the check more precise, only complaining about the things we care about (in other words, what _we_ use)

I wondered about that possibility too. But it's not at all clear to me how a symlink to .git/objects/foo risks any more security problem to git than one to .git/annex/whatever, or indeed to /home/linus/.bashrc.

Git clearly has to get the security right of handling working tree files that are symlinks.

The security hole that triggered this defense in depth, CVE-2024-32021, involved an attacker with write access to .git/objects/ making a symlink in there while another repo was cloning it. So it involved symlinks inside a remote .git/objects/, which is very different than symlinks into .git/objects/.

While it's understandable that dealing with such a symlink related security hole may make one want to throw out the baby with the bathwater, this fsck check is more like you've kept the bathwater and only thrown out the baby. ;-)

Quoted 2 lines

- In any case, if it is merely warnings, not errors, these checks can be configured out. Wouldn't that be an escape-hatch enough?

The issue with that is, as we've experienced with Gitlab, git hosts that choose to set receive.fsckObjects will prevent pushes of git-annex repositories, and there's probably no way for a user to configure it out. So every major git host that does it has to be approached to configure it out, and some fraction probably won't. Which will be a major impact and ongoing concern for git-annex users[1], all for something that certainly adds no security to a bare repository on such a host.

Quoted 3 lines

I am not sure which one is more practical between ripping everything out and demoting these new fsck error types with FSCK_WARN to FSCK_IGNORE.

It could indeed be beneficial to have some kind of symlink check that is at FSCK_IGNORE by default. If someone is receiving a repository from an untrusted source, and doesn't want to deal with the security risks of symlinks in the working tree, they could configure it to be an error. Such a symlink check would probably need to catch more symlinks than only the ones into .git/ though. Having this available to git users seems like it could prevent a much larger class of security holes.

As for the symlink length check, I do think it makes sense for fsck to notice symlinks that are too long to make sense for any OS and so picking some appropriate value, rather than the local PATH_MAX, could keep that one.

Signature · 8 lines
see shy jo

[1] I'm particularly concerned about the class of large institutional
    users who are managing more data with git-annex than the total size of
    all of Github[2]. They have a good reason to be risk averse,
    and it could be a major disruption to cross-organizational workflows
    and need updates to DOIs etc for them to switch hosting providers.
[2] https://hachyderm.io/@joeyh/112486445240754919
#35 lore raw
In reply to Junio C Hamano
Quoted 29 lines · Junio C Hamano
Quoted 4 lines · Joey Hess

Please also revert it, or at least the portions for and symlinkPointsToGitDir and symlinkTargetLength. The checks for symlinkTargetBlob and symlinkTargetMissing seem worth keeping.

Looking at the change in question, in a33fea08 (fsck: warn about symlink pointing inside a gitdir, 2024-04-10), you said:
...
So, I am ambivalent. I have prepared a revert queued on maint-2.39 and cascaded it up to the maintenance track, which I tentatively queued on top of 'seen', to see how much damage such a reversion involves (and it did not look too bad), but

(1) I am not sure if this is such a huge deal that requires a

     revert;

(2) I am not sure which one is more practical between ripping everything out and demoting these new fsck error types with FSCK_WARN to FSCK_IGNORE. If the structure of the code to perform these checks is more or less good and the actual check the code implements is bad, the latter might give us a better foundation to build on than rebuilding everything from scratch. On the other hand, if we are redoing things in the open, it may be better to forget about the code in 2.45.1/2.39.4 and to build from scratch for those reviewers and developers who will offer help.

Quoted 6 lines

(3) As I look at the change by a33fea08 again, it actually adds a few new fsck error types with FSCK_ERROR. Perhaps that is a good enough reason to do a straight revert for now?

Thanks. It is past my bedtime so I won't be pushing out the 'seen' with the revert I prepared as a practice, at least tonight.

So at least for now, I've queued a full revert of the change in question in the "revert over-eager layering-on-top changes" pile, but as we haven't really seen anybody give good input to help me decide what to do with this step, the pile is still kept outside of the 'next' branch. At least it is visible on 'seen' as of tonight.

Thanks.

#30 lore raw
In reply to Joey Hess

Hi Joey,

Quoted 9 lines · Joey Hess
Quoted 7 lines · Junio C Hamano

- The extra check seems to have meant to target the symbolic links that point at objects, refs, config, and anything _we_ care about, as opposed to random garbage (from _our_ point of view) files third-parties throw into .git/ directory. Would it have made a better trade-off if we tried to make the check more precise, only complaining about the things we care about (in other words, what _we_ use)

Quoted 3 lines

I wondered about that possibility too. But it's not at all clear to me how a symlink to .git/objects/foo risks any more security problem to git than one to .git/annex/whatever, or indeed to /home/linus/.bashrc.

It risks more security problems because .git/objects/??/* is not re-hashed when it is being used by Git. That's a very easy way to slip in unwanted file contents.

And there is a good reason _not_ to write stuff inside the .git/ directory unless you happen to be, well, Git itself: Git makes no guarantees whatsoever that you can write into that directory whatever you want. A future Git version might even write a file .git/annex, breaking git-annex' assumptions, and that'd be totally within the guarantees Git makes.

Quoted 8 lines

Git clearly has to get the security right of handling working tree files that are symlinks.

The security hole that triggered this defense in depth, CVE-2024-32021, involved an attacker with write access to .git/objects/ making a symlink in there while another repo was cloning it. So it involved symlinks inside a remote .git/objects/, which is very different than symlinks into .git/objects/.

No, the vulnerability that triggered this defense-in-depth was not CVE-2024-32021, but instead CVE-2024-32002, a critical security issue.

Removing the defense-in-depth makes it more likely for otherwise relatively harmless bugs à la "oh whoops, we wrote something we shouldn't have" to escalate to full, critical Remote Code Execution vulnerabilities.

Ciao,
Johannes

#31 lore raw
Quoted 6 lines · Johannes Schindelin

And there is a good reason _not_ to write stuff inside the .git/ directory unless you happen to be, well, Git itself: Git makes no guarantees whatsoever that you can write into that directory whatever you want. A future Git version might even write a file .git/annex, breaking git-annex' assumptions, and that'd be totally within the guarantees Git makes.

Well git-annex is hardly the only program to decide to carve out part of .git/ for its own use. For example, git-lfs uses .git/lfs/ rather similarly.

Anyway, I hope I can ask nicely and not have tne git developers choose to use .git/annex/ for something. Since it would cause a large amount of pain to a large number of users, who would all have to rebase histories of (often massive) git repos to update symlinks pointing there.

Quoted 2 lines

No, the vulnerability that triggered this defense-in-depth was not CVE-2024-32021, but instead CVE-2024-32002, a critical security issue.

Ahh, thanks, I understand the concerns a little bit better now.

Signature · 1 line
see shy jo
#32 lore raw
In reply to Johannes Schindelin

Hi Johannes

Quoted 13 lines · Johannes Schindelin

Hi Joey,

Quoted 9 lines · Joey Hess
Quoted 7 lines · Junio C Hamano

- The extra check seems to have meant to target the symbolic links that point at objects, refs, config, and anything _we_ care about, as opposed to random garbage (from _our_ point of view) files third-parties throw into .git/ directory. Would it have made a better trade-off if we tried to make the check more precise, only complaining about the things we care about (in other words, what _we_ use)

Quoted 7 lines
Quoted 3 lines

I wondered about that possibility too. But it's not at all clear to me how a symlink to .git/objects/foo risks any more security problem to git than one to .git/annex/whatever, or indeed to /home/linus/.bashrc.

It risks more security problems because .git/objects/??/* is not re-hashed when it is being used by Git. That's a very easy way to slip in unwanted file contents.

What checks do we have in place to prevent git checking out blobs and gitlinks to paths under .git/? I'd have thought we should be applying the same restrictions to the target of symbolic links as we do to those.

Quoted 6 lines

And there is a good reason _not_ to write stuff inside the .git/ directory unless you happen to be, well, Git itself: Git makes no guarantees whatsoever that you can write into that directory whatever you want. A future Git version might even write a file .git/annex, breaking git-annex' assumptions, and that'd be totally within the guarantees Git makes.

This seems a bit harsh - many tools store their state under .git/ and I think it makes sense for them to do so as it avoids creating untracked files in the working copy. I would hope that we'd be considerate of widely used tools such as 'git annex' when adding new paths under .git/

Best Wishes

Phillip

#33 lore raw
Quoted 4 lines · Phillip Wood

What checks do we have in place to prevent git checking out blobs and gitlinks to paths under .git/? I'd have thought we should be applying the same restrictions to the target of symbolic links as we do to those.

We do not even allow ".git" slip into the index (most likely from a malicious tree object), so a direct "checkout" is not much of an issue. Of course you can introduce bugs to that regular mechanism in the future but that is not the target for 2.45.1's check we are going to revert. I think what Dscho worries about in his message is that we might by mistake write via a symbolic link in the working tree. If our procedure to update a checked out blob in the working tree were open/truncate/write/close an existing file, a checkout that switches from a version with a symbolic link at path F to a version with a regular file at path F may end up overwriting the target of F. I think the idea was (Dscho can correct me if I am misleading the log messge of a33fea08 (fsck: warn about symlink pointing inside a gitdir, 2024-04-10)) that such a bug from overwriting a file in our repository if we did not allow a symbolic link F to point into our repository.

#34 lore raw
In reply to Phillip Wood
Quoted 7 lines · Phillip Wood
Quoted 6 lines

And there is a good reason _not_ to write stuff inside the .git/ directory unless you happen to be, well, Git itself: Git makes no guarantees whatsoever that you can write into that directory whatever you want. A future Git version might even write a file .git/annex, breaking git-annex' assumptions, and that'd be totally within the guarantees Git makes.

Quoted 5 lines

This seems a bit harsh - many tools store their state under .git/ and I think it makes sense for them to do so as it avoids creating untracked files in the working copy. I would hope that we'd be considerate of widely used tools such as 'git annex' when adding new paths under .git/

Yes, a .git/annex file _can_ happen, but between civilized developer groups, such a thing would not happen without a good reason. If we have no good reason (apparently you and I did not think of any) to create such a file, "it can happen" is a poor straw-man, as we would be aiming to work well together.

Yes, when we have a symbolic link as a tracked content, updating the target of the link when we need to update it is simply a bug, and it does not matter if it points at a file inside our own repository, or a file inside a different and unrelated repository that is owned by the same user, or a file in the user's home directory. Our own repository is not all that special from that perspective, and a change to penalize symbolic links that point into our repository specifically probably did make a bad choice.

Thanks.