-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* maint-2.33: Git 2.33.4 Git 2.32.3 Git 2.31.4 Git 2.30.5 setup: tighten ownership checks post CVE-2022-24765 git-compat-util: allow root to access both SUDO_UID and root owned t0034: add negative tests and allow git init to mostly work under sudo git-compat-util: avoid failing dir ownership checks if running privileged t: regression git needs safe.directory when using sudo
- Loading branch information
Showing
9 changed files
with
269 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Git v2.30.5 Release Notes | ||
========================= | ||
|
||
This release contains minor fix-ups for the changes that went into | ||
Git 2.30.3 and 2.30.4, addressing CVE-2022-29187. | ||
|
||
* The safety check that verifies a safe ownership of the Git | ||
worktree is now extended to also cover the ownership of the Git | ||
directory (and the `.git` file, if there is any). | ||
|
||
Carlo Marcelo Arenas Belón (1): | ||
setup: tighten ownership checks post CVE-2022-24765 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Git v2.31.4 Release Notes | ||
========================= | ||
|
||
This release merges up the fixes that appear in v2.30.5 to address | ||
the security issue CVE-2022-29187; see the release notes for that | ||
version for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Git v2.32.3 Release Notes | ||
========================= | ||
|
||
This release merges up the fixes that appear in v2.30.5 and | ||
v2.31.4 to address the security issue CVE-2022-29187; see the | ||
release notes for these versions for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Git v2.33.4 Release Notes | ||
========================= | ||
|
||
This release merges up the fixes that appear in v2.30.5, v2.31.4 | ||
and v2.32.3 to address the security issue CVE-2022-29187; see | ||
the release notes for these versions for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,12 +401,68 @@ static inline int git_offset_1st_component(const char *path) | |
#endif | ||
|
||
#ifndef is_path_owned_by_current_user | ||
|
||
#ifdef __TANDEM | ||
#define ROOT_UID 65535 | ||
#else | ||
#define ROOT_UID 0 | ||
#endif | ||
|
||
/* | ||
* Do not use this function when | ||
* (1) geteuid() did not say we are running as 'root', or | ||
* (2) using this function will compromise the system. | ||
* | ||
* PORTABILITY WARNING: | ||
* This code assumes uid_t is unsigned because that is what sudo does. | ||
* If your uid_t type is signed and all your ids are positive then it | ||
* should all work fine. | ||
* If your version of sudo uses negative values for uid_t or it is | ||
* buggy and return an overflowed value in SUDO_UID, then git might | ||
* fail to grant access to your repository properly or even mistakenly | ||
* grant access to someone else. | ||
* In the unlikely scenario this happened to you, and that is how you | ||
* got to this message, we would like to know about it; so sent us an | ||
* email to [email protected] indicating which platform you are | ||
* using and which version of sudo, so we can improve this logic and | ||
* maybe provide you with a patch that would prevent this issue again | ||
* in the future. | ||
*/ | ||
static inline void extract_id_from_env(const char *env, uid_t *id) | ||
{ | ||
const char *real_uid = getenv(env); | ||
|
||
/* discard anything empty to avoid a more complex check below */ | ||
if (real_uid && *real_uid) { | ||
char *endptr = NULL; | ||
unsigned long env_id; | ||
|
||
errno = 0; | ||
/* silent overflow errors could trigger a bug here */ | ||
env_id = strtoul(real_uid, &endptr, 10); | ||
if (!*endptr && !errno) | ||
*id = env_id; | ||
} | ||
} | ||
|
||
static inline int is_path_owned_by_current_uid(const char *path) | ||
{ | ||
struct stat st; | ||
uid_t euid; | ||
|
||
if (lstat(path, &st)) | ||
return 0; | ||
return st.st_uid == geteuid(); | ||
|
||
euid = geteuid(); | ||
if (euid == ROOT_UID) | ||
{ | ||
if (st.st_uid == ROOT_UID) | ||
return 1; | ||
else | ||
extract_id_from_env("SUDO_UID", &euid); | ||
} | ||
|
||
return st.st_uid == euid; | ||
} | ||
|
||
#define is_path_owned_by_current_user is_path_owned_by_current_uid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Helpers for running git commands under sudo. | ||
|
||
# Runs a scriplet passed through stdin under sudo. | ||
run_with_sudo () { | ||
local ret | ||
local RUN="$TEST_DIRECTORY/$$.sh" | ||
write_script "$RUN" "$TEST_SHELL_PATH" | ||
# avoid calling "$RUN" directly so sudo doesn't get a chance to | ||
# override the shell, add aditional restrictions or even reject | ||
# running the script because its security policy deem it unsafe | ||
sudo "$TEST_SHELL_PATH" -c "\"$RUN\"" | ||
ret=$? | ||
rm -f "$RUN" | ||
return $ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/sh | ||
|
||
test_description='verify safe.directory checks while running as root' | ||
|
||
. ./test-lib.sh | ||
. "$TEST_DIRECTORY"/lib-sudo.sh | ||
|
||
if [ "$GIT_TEST_ALLOW_SUDO" != "YES" ] | ||
then | ||
skip_all="You must set env var GIT_TEST_ALLOW_SUDO=YES in order to run this test" | ||
test_done | ||
fi | ||
|
||
if ! test_have_prereq NOT_ROOT | ||
then | ||
skip_all="These tests do not support running as root" | ||
test_done | ||
fi | ||
|
||
test_lazy_prereq SUDO ' | ||
sudo -n id -u >u && | ||
id -u root >r && | ||
test_cmp u r && | ||
command -v git >u && | ||
sudo command -v git >r && | ||
test_cmp u r | ||
' | ||
|
||
if ! test_have_prereq SUDO | ||
then | ||
skip_all="Your sudo/system configuration is either too strict or unsupported" | ||
test_done | ||
fi | ||
|
||
test_expect_success SUDO 'setup' ' | ||
sudo rm -rf root && | ||
mkdir -p root/r && | ||
( | ||
cd root/r && | ||
git init | ||
) | ||
' | ||
|
||
test_expect_success SUDO 'sudo git status as original owner' ' | ||
( | ||
cd root/r && | ||
git status && | ||
sudo git status | ||
) | ||
' | ||
|
||
test_expect_success SUDO 'setup root owned repository' ' | ||
sudo mkdir -p root/p && | ||
sudo git init root/p | ||
' | ||
|
||
test_expect_success 'cannot access if owned by root' ' | ||
( | ||
cd root/p && | ||
test_must_fail git status | ||
) | ||
' | ||
|
||
test_expect_success 'can access if addressed explicitly' ' | ||
( | ||
cd root/p && | ||
GIT_DIR=.git GIT_WORK_TREE=. git status | ||
) | ||
' | ||
|
||
test_expect_success SUDO 'can access with sudo if root' ' | ||
( | ||
cd root/p && | ||
sudo git status | ||
) | ||
' | ||
|
||
test_expect_success SUDO 'can access with sudo if root by removing SUDO_UID' ' | ||
( | ||
cd root/p && | ||
run_with_sudo <<-END | ||
unset SUDO_UID && | ||
git status | ||
END | ||
) | ||
' | ||
|
||
# this MUST be always the last test | ||
test_expect_success SUDO 'cleanup' ' | ||
sudo rm -rf root | ||
' | ||
|
||
test_done |