Skip to contentSkip to conversation

oeqa/selftest: add test for git working correctly inside pseudo

PATCH New Ross Burton 1 participant 5 messages May 6, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 oeqa/selftest: add test for git working correctly inside pseudo

The fix for CVE-2022-24765 in git[1] breaks any use of git inside pseudo. Add a simple test case to oe-selftest to verify that at least basic uses of git work fine under pseudo.

[1] https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9

---
 .../git-submodule-test/git-submodule-test.bb      | 15 +++++++++++++++
 meta/lib/oeqa/selftest/cases/git.py               | 15 +++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/git.py
meta-selftest/recipes-test/git-submodule-test/git-submodule-test.bb +15 -0
index cc5d7eae5a..fa3041b7d8 100644
@@ -7,3 +7,18 @@ INHIBIT_DEFAULT_DEPS = "1"
 
 SRC_URI = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master"
 SRCREV = "a2885dd7d25380d23627e7544b7bbb55014b16ee"
+
+S = "${WORKDIR}/git"
+
+do_test_git_as_user() {
+    cd ${S}
+    git status
+}
+addtask test_git_as_user after do_unpack
+
+fakeroot do_test_git_as_root() {
+    cd ${S}
+    git status
+}
+do_test_git_as_root[depends] += "virtual/fakeroot-native:do_populate_sysroot"
+addtask test_git_as_root after do_unpack
meta/lib/oeqa/selftest/cases/git.py new file +15 -0
new file mode 100644
index 0000000000..f12874dc7d
@@ -0,0 +1,15 @@
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake
+
+class GitCheck(OESelftestTestCase):
+    def test_git_intercept(self):
+        """
+        Git binaries with CVE-2022-24765 fixed will refuse to operate on a
+        repository which is owned by a different user. This breaks our
+        do_install task as that runs inside pseudo, so the git repository is
+        owned by the build user but git is running as (fake)root.
+
+        We have an intercept which disables pseudo, so verify that it works.
+        """
+        bitbake("git-submodule-test -c test_git_as_user")
+        bitbake("git-submodule-test -c test_git_as_root")
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/5 base: Avoid circular references to our own scripts

From: Richard Purdie <[email protected]>

We'd like to intercept git calls but we don't want circular references and HOSTTOOLS currently sets them up. Tweak to avoid them.

---
 meta/classes/base.bbclass | 3 +++
 1 file changed, 3 insertions(+)
meta/classes/base.bbclass +3 -0
index 3515720bf9..16b7c69995 100644
@@ -115,6 +115,9 @@ def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
     tools = d.getVar(toolsvar).split()
     origbbenv = d.getVar("BB_ORIGENV", False)
     path = origbbenv.getVar("PATH")
+    # Need to ignore our own scripts directory to avoid circular links
+    ourscripts = d.expand("${COREBASE}/scripts")
+    path = path.replace(ourscripts, "/ignoreme")
     bb.utils.mkdirhier(dest)
     notfound = []
     for tool in tools:
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/5 scripts: Make git intercept global

In reply to Ross Burton

From: Richard Purdie <[email protected]>

The previous minimially invasive git intercept simply isn't enough. For example, meson used in the igt-gpu-tools recipe hardcodes the path to git in the configure step so at install time, changing PATH has no effect.

There are lots of interesting things we could do to try and avoid problems but making the git intercept and dropping fakeroot privs for git global is probably the least worst solution at this point. It will add slight overhead to git calls but we don't make many so the overall impact is likely minimal.

---
 scripts/{git-intercept => }/git | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename scripts/{git-intercept => }/git (100%)
scripts/git renamed from scripts/git-intercept/git +0 -0
similarity index 100%
rename from scripts/git-intercept/git
rename to scripts/git
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/5 scripts/git: Ensure we don't have circular references

In reply to Ross Burton

From: Richard Purdie <[email protected]>

This is horrible but I'm running out of better ideas. We hit circular reference issues which we were trying to avoid in the core HOSTTOOLS code. When building the eSDK, there can be two copies of the script.

Therefore assume git will never be in a directory called scripts. This fixes eSDK build failures.

---
 scripts/git | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/git +8 -1
index 8adf5c9ecb..644055e540 100755
@@ -10,7 +10,14 @@ os.environ['PSEUDO_UNLOAD'] = '1'
 
 # calculate path to the real 'git'
 path = os.environ['PATH']
-path = path.replace(os.path.dirname(sys.argv[0]), '')
+# we need to remove our path but also any other copy of this script which
+# may be present, e.g. eSDK.
+replacements = [os.path.dirname(sys.argv[0])]
+for p in path.split(":"):
+    if p.endswith("/scripts"):
+        replacements.append(p)
+for r in replacements:
+    path = path.replace(r, '/ignoreme')
 real_git = shutil.which('git', path=path)
 
 if len(sys.argv) == 1:
Signature · 1 line
2.25.1
#4 lore raw

PATCH 5/5 Revert "bitbake.conf: mark all directories as safe for git to read"

In reply to Ross Burton

Turns out this doesn't actually work, as git doesn't respect the environment when reading the safe.directory configuration variable.

This reverts commit d4a5862ce8db97d26a3c32c4cffea3197c1defec.

---
 meta/conf/bitbake.conf | 8 --------
 1 file changed, 8 deletions(-)
meta/conf/bitbake.conf +0 -8
index 1deba8d910..0e939aca4f 100644
@@ -776,18 +776,10 @@ export PKG_CONFIG_DISABLE_UNINSTALLED = "yes"
 export PKG_CONFIG_SYSTEM_LIBRARY_PATH = "${base_libdir}:${libdir}"
 export PKG_CONFIG_SYSTEM_INCLUDE_PATH = "${includedir}"
 
-# Git configuration
-
 # Don't allow git to chdir up past WORKDIR so that it doesn't detect the OE
 # repository when building a recipe
 export GIT_CEILING_DIRECTORIES = "${WORKDIR}"
 
-# Treat all directories are safe, as during fakeroot tasks git will run as
-# root so recent git releases (eg 2.30.3) will refuse to work on repositories. See
-# https://github.com/git/git/commit/8959555cee7ec045958f9b6dd62e541affb7e7d9 for
-# further details.
-export GIT_CONFIG_PARAMETERS="'safe.directory=*'"
-
 ###
 ### Config file processing
 ###
Signature · 1 line
2.25.1