Add checks for "host user contamination"
v2 cover Add checks for "host user contamination"
From: Christopher Larson <[email protected]>
This adds a QA test, as well as a rootfs_ function for use in ROOTFS_POSTPROCESS_COMMAND, to warn/error when paths are owned by the same user/group as the user running bitbake. This is useful to catch stuff which is written outside of pseudo's control, for example.
v2 changes: handle missing files in the host-user-contamined test by catching ENOENT OSErrors from os.lstat.
The following changes since commit bdeb32b4cdbe316f17c2fd854d59e05e8f2e8ffc:
rt-tests: drop unnecessary added-missing-dependencies.patch (2015-09-01 11:43:38 +0100)
are available in the git repository at:
git://github.com/kergoth/openembedded-core host-user-contaminated
https://github.com/kergoth/openembedded-core/tree/host-user-contaminated
Christopher Larson (3):
insane.bbclass: handle tests which need fakeroot insane.bbclass: add host-user-contaminated test image.bbclass: add rootfs_check_host_user_contaminated
meta/classes/image.bbclass | 14 ++++++++++++++ meta/classes/insane.bbclass | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-)
Signature · 1 line
2.2.1
PATCH v2 1/3 insane.bbclass: handle tests which need fakeroot
From: Christopher Larson <[email protected]>
If any tests listed in FAKEROOT_QA are enabled (listed in ALL_QA), then run do_package_qa under fakeroot.
--- meta/classes/insane.bbclass | 8 ++++++++ 1 file changed, 8 insertions(+)
meta/classes/insane.bbclass +8 -0
@@ -38,6 +38,9 @@ ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \ split-strip packages-list pkgv-undefined var-undefined \ version-going-backwards expanded-d \ " +FAKEROOT_QA = "" +FAKEROOT_QA[doc] = "QA tests which need to run under fakeroot. If any \ +enabled tests are listed here, the do_package_qa task will run under fakeroot." ALL_QA = "${WARN_QA} ${ERROR_QA}"
@@ -1210,6 +1213,11 @@ python () { for var in 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RCONFLICTS', 'RPROVIDES', 'RREPLACES', 'FILES', 'pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm', 'ALLOW_EMPTY': if d.getVar(var, False): issues.append(var) + + fakeroot_tests = d.getVar('FAKEROOT_QA', True).split() + if set(tests) & set(fakeroot_tests): + d.setVarFlag('do_package_qa', 'fakeroot', '1') + d.appendVarFlag('do_package_qa', 'depends', ' virtual/fakeroot-native:do_populate_sysroot') else: d.setVarFlag('do_package_qa', 'rdeptask', '') for i in issues:
Signature · 1 line
2.2.1
PATCH v2 2/3 insane.bbclass: add host-user-contaminated test
From: Christopher Larson <[email protected]>
- Add a test which checks for any paths outside of /home which are owned by the user running bitbake.
- Add the test to WARN_QA by default.
This test has been in meta-mentor for some time, and in our ERROR_QA for our builds, and has caught a number of issues for us.
--- meta/classes/insane.bbclass | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)
meta/classes/insane.bbclass +35 -2
@@ -31,14 +31,14 @@ WARN_QA ?= "ldflags useless-rpaths rpaths staticdev libdir xorg-driver-abi \ installed-vs-shipped compile-host-path install-host-path \ pn-overrides infodir build-deps file-rdeps \ unknown-configure-option symlink-to-sysroot multilib \ - invalid-pkgconfig \ + invalid-pkgconfig host-user-contaminated \ " ERROR_QA ?= "dev-so debug-deps dev-deps debug-files arch pkgconfig la \ perms dep-cmp pkgvarcheck perm-config perm-line perm-link \ split-strip packages-list pkgv-undefined var-undefined \ version-going-backwards expanded-d \ " -FAKEROOT_QA = "" +FAKEROOT_QA = "host-user-contaminated" FAKEROOT_QA[doc] = "QA tests which need to run under fakeroot. If any \ enabled tests are listed here, the do_package_qa task will run under fakeroot."
@@ -950,6 +950,39 @@ def package_qa_check_expanded_d(path,name,d,elf,messages): sane = False return sane +HOST_USER_UID := "${@os.getuid()}" +HOST_USER_GID := "${@os.getgid()}" + +QAPATHTEST[host-user-contaminated] = "package_qa_check_host_user" +def package_qa_check_host_user(path, name, d, elf, messages): + """Check for paths outside of /home which are owned by the user running bitbake.""" + + if not os.path.lexists(path): + return + + dest = d.getVar('PKGDEST', True) + home = os.path.join(dest, 'home') + if path == home or path.startswith(home + os.sep): + return + + try: + stat = os.lstat(path) + except OSError as exc: + import errno + if exc.errno != errno.ENOENT: + raise + else: + check_uid = int(d.getVar('HOST_USER_UID', True)) + if stat.st_uid == check_uid: + messages["host-user-contaminated"] = "%s is owned by uid %d, which is the same as the user running bitbake. This may be due to host contamination" % (path, check_uid) + return False + + check_gid = int(d.getVar('HOST_USER_GID', True)) + if stat.st_gid == check_gid: + messages["host-user-contaminated"] = "%s is owned by gid %d, which is the same as the user running bitbake. This may be due to host contamination" % (path, check_gid) + return False + return True + # The PACKAGE FUNC to scan each package python do_package_qa () { import subprocess
Signature · 1 line
2.2.1
PATCH v2 3/3 image.bbclass: add rootfs_check_host_user_contaminated
In reply to Christopher LarsonFrom: Christopher Larson <[email protected]>
This function is intended to be used in ROOTFS_POSTPROCESS_COMMAND, and checks for any paths outside of /home which are owned by the user running bitbake.
--- meta/classes/image.bbclass | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
meta/classes/image.bbclass +14 -0
@@ -460,6 +460,20 @@ rootfs_trim_schemas () { done } +rootfs_check_host_user_contaminated () { + contaminated="${WORKDIR}/host-user-contaminated.txt" + HOST_USER_UID="$(PSEUDO_UNLOAD=1 id -u)" + HOST_USER_GID="$(PSEUDO_UNLOAD=1 id -g)" + + find "${IMAGE_ROOTFS}" -wholename "${IMAGE_ROOTFS}/home" -prune \ + -user "$HOST_USER_UID" -o -group "$HOST_USER_GID" >"$contaminated" + + if [ -s "$contaminated" ]; then + echo "WARNING: Paths in the rootfs are owned by the same user or group as the user running bitbake. See the logfile for the specific paths." + cat "$contaminated" | sed "s,^, ," + fi +} + # Make any absolute links in a sysroot relative rootfs_sysroot_relativelinks () { sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
Signature · 1 line
2.2.1