mirror of
https://git.yoctoproject.org/poky
synced 2026-02-22 17:39:39 +01:00
CVE-2024-32002: Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, repositories with submodules can be crafted in a way that exploits a bug in Git whereby it can be fooled into writing files not into the submodule's worktree but into a `.git/` directory. This allows writing a hook that will be executed while the clone operation is still running, giving the user no opportunity to inspect the code that is being executed. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. If symbolic link support is disabled in Git (e.g. via `git config --global core.symlinks false`), the described attack won't work. As always, it is best to avoid cloning repositories from untrusted sources. CVE-2024-32004: Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, an attacker can prepare a local repository in such a way that, when cloned, will execute arbitrary code during the operation. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. As a workaround, avoid cloning repositories from untrusted sources. CVE-2024-32020: Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, local clones may end up hardlinking files into the target repository's object database when source and target repository reside on the same disk. If the source repository is owned by a different user, then those hardlinked files may be rewritten at any point in time by the untrusted user. Cloning local repositories will cause Git to either copy or hardlink files of the source repository into the target repository. This significantly speeds up such local clones compared to doing a "proper" clone and saves both disk space and compute time. When cloning a repository located on the same disk that is owned by a different user than the current user we also end up creating such hardlinks. These files will continue to be owned and controlled by the potentially-untrusted user and can be rewritten by them at will in the future. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. CVE-2024-32021: Git is a revision control system. Prior to versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4, when cloning a local source repository that contains symlinks via the filesystem, Git may create hardlinks to arbitrary user-readable files on the same filesystem as the target repository in the `objects/` directory. Cloning a local repository over the filesystem may creating hardlinks to arbitrary user-owned files on the same filesystem in the target Git repository's `objects/` directory. When cloning a repository over the filesystem (without explicitly specifying the `file://` protocol or `--no-local`), the optimizations for local cloning will be used, which include attempting to hard link the object files instead of copying them. While the code includes checks against symbolic links in the source repository, which were added during the fix for CVE-2022-39253, these checks can still be raced because the hard link operation ultimately follows symlinks. If the object on the filesystem appears as a file during the check, and then a symlink during the operation, this will allow the adversary to bypass the check and create hardlinks in the destination objects directory to arbitrary, user-readable files. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. CVE-2024-32465: Git is a revision control system. The Git project recommends to avoid working in untrusted repositories, and instead to clone it first with `git clone --no-local` to obtain a clean copy. Git has specific protections to make that a safe operation even with an untrusted source repository, but vulnerabilities allow those protections to be bypassed. In the context of cloning local repositories owned by other users, this vulnerability has been covered in CVE-2024-32004. But there are circumstances where the fixes for CVE-2024-32004 are not enough: For example, when obtaining a `.zip` file containing a full copy of a Git repository, it should not be trusted by default to be safe, as e.g. hooks could be configured to run within the context of that repository. The problem has been patched in versions 2.45.1, 2.44.1, 2.43.4, 2.42.2, 2.41.1, 2.40.2, and 2.39.4. As a workaround, avoid using Git in repositories that have been obtained via archives from untrusted sources. References: https://nvd.nist.gov/vuln/detail/CVE-2024-32002 https://nvd.nist.gov/vuln/detail/CVE-2024-32004 https://nvd.nist.gov/vuln/detail/CVE-2024-32020 https://nvd.nist.gov/vuln/detail/CVE-2024-32021 https://nvd.nist.gov/vuln/detail/CVE-2024-32465 (From OE-Core rev: 209c41377abf6853455b00af3923f1b244a3766b) Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
159 lines
5.9 KiB
Diff
159 lines
5.9 KiB
Diff
From f4aa8c8bb11dae6e769cd930565173808cbb69c8 Mon Sep 17 00:00:00 2001
|
|
From: Johannes Schindelin <johannes.schindelin@gmx.de>
|
|
Date: Wed, 10 Apr 2024 14:39:37 +0200
|
|
Subject: [PATCH] fetch/clone: detect dubious ownership of local repositories
|
|
|
|
When cloning from somebody else's repositories, it is possible that,
|
|
say, the `upload-pack` command is overridden in the repository that is
|
|
about to be cloned, which would then be run in the user's context who
|
|
started the clone.
|
|
|
|
To remind the user that this is a potentially unsafe operation, let's
|
|
extend the ownership checks we have already established for regular
|
|
gitdir discovery to extend also to local repositories that are about to
|
|
be cloned.
|
|
|
|
This protection extends also to file:// URLs.
|
|
|
|
The fixes in this commit address CVE-2024-32004.
|
|
|
|
Note: This commit does not touch the `fetch`/`clone` code directly, but
|
|
instead the function used implicitly by both: `enter_repo()`. This
|
|
function is also used by `git receive-pack` (i.e. pushes), by `git
|
|
upload-archive`, by `git daemon` and by `git http-backend`. In setups
|
|
that want to serve repositories owned by different users than the
|
|
account running the service, this will require `safe.*` settings to be
|
|
configured accordingly.
|
|
|
|
Also note: there are tiny time windows where a time-of-check-time-of-use
|
|
("TOCTOU") race is possible. The real solution to those would be to work
|
|
with `fstat()` and `openat()`. However, the latter function is not
|
|
available on Windows (and would have to be emulated with rather
|
|
expensive low-level `NtCreateFile()` calls), and the changes would be
|
|
quite extensive, for my taste too extensive for the little gain given
|
|
that embargoed releases need to pay extra attention to avoid introducing
|
|
inadvertent bugs.
|
|
|
|
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
|
|
|
|
CVE: CVE-2024-32004
|
|
|
|
Upstream-Status: Backport [https://github.com/git/git/commit/f4aa8c8bb11dae6e769cd930565173808cbb69c8]
|
|
|
|
Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com>
|
|
---
|
|
cache.h | 12 ++++++++++++
|
|
path.c | 2 ++
|
|
setup.c | 21 +++++++++++++++++++++
|
|
t/t0411-clone-from-partial.sh | 6 +++---
|
|
4 files changed, 38 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/cache.h b/cache.h
|
|
index 281f00a..a59bdbe 100644
|
|
--- a/cache.h
|
|
+++ b/cache.h
|
|
@@ -615,6 +615,18 @@ void set_git_work_tree(const char *tree);
|
|
|
|
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
|
|
|
+/*
|
|
+ * Check if a repository is safe and die if it is not, by verifying the
|
|
+ * ownership of the worktree (if any), the git directory, and the gitfile (if
|
|
+ * any).
|
|
+ *
|
|
+ * Exemptions for known-safe repositories can be added via `safe.directory`
|
|
+ * config settings; for non-bare repositories, their worktree needs to be
|
|
+ * added, for bare ones their git directory.
|
|
+ */
|
|
+void die_upon_dubious_ownership(const char *gitfile, const char *worktree,
|
|
+ const char *gitdir);
|
|
+
|
|
void setup_work_tree(void);
|
|
/*
|
|
* Find the commondir and gitdir of the repository that contains the current
|
|
diff --git a/path.c b/path.c
|
|
index d73146b..ae1fb01 100644
|
|
--- a/path.c
|
|
+++ b/path.c
|
|
@@ -840,6 +840,7 @@ 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);
|
|
@@ -850,6 +851,7 @@ 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))
|
|
diff --git a/setup.c b/setup.c
|
|
index 1ad7330..475c92e 100644
|
|
--- a/setup.c
|
|
+++ b/setup.c
|
|
@@ -1151,6 +1151,27 @@ static int ensure_valid_ownership(const char *gitfile,
|
|
return data.is_safe;
|
|
}
|
|
|
|
+void die_upon_dubious_ownership(const char *gitfile, const char *worktree,
|
|
+ const char *gitdir)
|
|
+{
|
|
+ struct strbuf report = STRBUF_INIT, quoted = STRBUF_INIT;
|
|
+ const char *path;
|
|
+
|
|
+ if (ensure_valid_ownership(gitfile, worktree, gitdir, &report))
|
|
+ return;
|
|
+
|
|
+ strbuf_complete(&report, '\n');
|
|
+ path = gitfile ? gitfile : gitdir;
|
|
+ sq_quote_buf_pretty("ed, path);
|
|
+
|
|
+ die(_("detected dubious ownership in repository at '%s'\n"
|
|
+ "%s"
|
|
+ "To add an exception for this directory, call:\n"
|
|
+ "\n"
|
|
+ "\tgit config --global --add safe.directory %s"),
|
|
+ path, report.buf, quoted.buf);
|
|
+}
|
|
+
|
|
enum discovery_result {
|
|
GIT_DIR_NONE = 0,
|
|
GIT_DIR_EXPLICIT,
|
|
diff --git a/t/t0411-clone-from-partial.sh b/t/t0411-clone-from-partial.sh
|
|
index fb72a0a..eb3360d 100755
|
|
--- a/t/t0411-clone-from-partial.sh
|
|
+++ b/t/t0411-clone-from-partial.sh
|
|
@@ -23,7 +23,7 @@ test_expect_success 'create evil repo' '
|
|
>evil/.git/shallow
|
|
'
|
|
|
|
-test_expect_failure 'local clone must not fetch from promisor remote and execute script' '
|
|
+test_expect_success '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" \
|
|
@@ -32,7 +32,7 @@ test_expect_failure 'local clone must not fetch from promisor remote and execute
|
|
test_path_is_missing script-executed
|
|
'
|
|
|
|
-test_expect_failure 'clone from file://... must not fetch from promisor remote and execute script' '
|
|
+test_expect_success '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" \
|
|
@@ -41,7 +41,7 @@ test_expect_failure 'clone from file://... must not fetch from promisor remote a
|
|
test_path_is_missing script-executed
|
|
'
|
|
|
|
-test_expect_failure 'fetch from file://... must not fetch from promisor remote and execute script' '
|
|
+test_expect_success '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" \
|
|
--
|
|
2.40.0
|