Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-06-18 03:12:31 +0300
committerJunio C Hamano <gitster@pobox.com>2022-06-18 03:12:31 +0300
commit694c0cc0fb531b17750ac6e81920054f193f8eb8 (patch)
treefad0a4206959b893d567b876d64efa39ba032861
parentb4eda05d58ca3e4808d3d86ab5826c77995a06f7 (diff)
parent6b11e3d52e919cce91011f4f9025e6f4b61375f2 (diff)
Merge branch 'cb/path-owner-check-with-sudo-plus'
"sudo git foo" used to consider a repository owned by the original user a safe one to access; it now also considers a repository owned by root a safe one, too (after all, if an attacker can craft a malicious repository owned by root, the box is 0wned already). * cb/path-owner-check-with-sudo-plus: git-compat-util: allow root to access both SUDO_UID and root owned
-rw-r--r--Documentation/config/safe.txt7
-rw-r--r--git-compat-util.h7
-rwxr-xr-xt/t0034-root-safe-directory.sh15
3 files changed, 11 insertions, 18 deletions
diff --git a/Documentation/config/safe.txt b/Documentation/config/safe.txt
index 1ee10fae14..fa02f3ccc5 100644
--- a/Documentation/config/safe.txt
+++ b/Documentation/config/safe.txt
@@ -30,12 +30,13 @@ that you deem safe.
As explained, Git only allows you to access repositories owned by
yourself, i.e. the user who is running Git, by default. When Git
is running as 'root' in a non Windows platform that provides sudo,
- however, git checks the SUDO_UID environment variable that sudo creates
-and will allow access to the uid recorded as its value instead.
+however, git checks the SUDO_UID environment variable that sudo creates
+and will allow access to the uid recorded as its value in addition to
+the id from 'root'.
This is to make it easy to perform a common sequence during installation
"make && sudo make install". A git process running under 'sudo' runs as
'root' but the 'sudo' command exports the environment variable to record
which id the original user has.
If that is not what you would prefer and want git to only trust
-repositories that are owned by root instead, then you must remove
+repositories that are owned by root instead, then you can remove
the `SUDO_UID` variable from root's environment before invoking git.
diff --git a/git-compat-util.h b/git-compat-util.h
index fd36d3bfdc..58d7708296 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -497,7 +497,12 @@ static inline int is_path_owned_by_current_uid(const char *path)
euid = geteuid();
if (euid == ROOT_UID)
- extract_id_from_env("SUDO_UID", &euid);
+ {
+ if (st.st_uid == ROOT_UID)
+ return 1;
+ else
+ extract_id_from_env("SUDO_UID", &euid);
+ }
return st.st_uid == euid;
}
diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh
index a621f1ea5e..ff31176128 100755
--- a/t/t0034-root-safe-directory.sh
+++ b/t/t0034-root-safe-directory.sh
@@ -68,7 +68,7 @@ test_expect_success 'can access if addressed explicitly' '
)
'
-test_expect_failure SUDO 'can access with sudo if root' '
+test_expect_success SUDO 'can access with sudo if root' '
(
cd root/p &&
sudo git status
@@ -85,19 +85,6 @@ test_expect_success SUDO 'can access with sudo if root by removing SUDO_UID' '
)
'
-test_lazy_prereq SUDO_SUDO '
- sudo sudo id -u >u &&
- id -u root >r &&
- test_cmp u r
-'
-
-test_expect_success SUDO_SUDO 'can access with sudo abusing SUDO_UID' '
- (
- cd root/p &&
- sudo sudo git status
- )
-'
-
# this MUST be always the last test
test_expect_success SUDO 'cleanup' '
sudo rm -rf root