From 03b400b3c4759014f8fb413297eead640156daeb Mon Sep 17 00:00:00 2001 From: Christopher Larson Date: Tue, 21 Apr 2015 17:39:00 -0700 Subject: [PATCH 1/3] external-toolchain: correct ownership of our files Since we're running cp -p to preserve other aspects, we need to manually correct the ownership to what we expect (root:root) rather than the current ownership. JIRA: SB-4185 Signed-off-by: Christopher Larson --- classes/external-toolchain.bbclass | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/external-toolchain.bbclass b/classes/external-toolchain.bbclass index 78eeb3a..251096e 100644 --- a/classes/external-toolchain.bbclass +++ b/classes/external-toolchain.bbclass @@ -105,10 +105,12 @@ python do_install () { } python external_toolchain_do_install () { + import subprocess installdest = d.getVar('D', True) sysroots, mirrors = get_file_search_metadata(d) files = gather_pkg_files(d) copy_from_sysroots(files, sysroots, mirrors, installdest) + subprocess.check_call(['chown', '-R', 'root:root', installdest]) } external_toolchain_do_install[vardeps] += "${@' '.join('FILES_%s' % pkg for pkg in '${PACKAGES}'.split())}" From 51c7d1240274eb7980b1dfd700819a2efd430903 Mon Sep 17 00:00:00 2001 From: Christopher Larson Date: Fri, 24 Apr 2015 16:09:10 -0700 Subject: [PATCH 2/3] ncurses: work around ownership problem Due to a previous workaround, the external gcc/g++ is run outside of pseudo context. The ncurses install target re-links the libraries directly into ${D}, so we need to make sure the ownership on those files is correct. JIRA: SB-4185 Signed-off-by: Christopher Larson --- core/recipes-core/ncurses/ncurses_%.bbappend | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 core/recipes-core/ncurses/ncurses_%.bbappend diff --git a/core/recipes-core/ncurses/ncurses_%.bbappend b/core/recipes-core/ncurses/ncurses_%.bbappend new file mode 100644 index 0000000..3802316 --- /dev/null +++ b/core/recipes-core/ncurses/ncurses_%.bbappend @@ -0,0 +1,6 @@ +# Work around the fact that gcc/g++ is not run under pseudo at the moment to +# bypass a different bug. Ncurses links the libs directly into place in the +# destination, so we need to correct the ownership here. +do_install_append () { + chown root:root ${D}${base_libdir}/lib*.so.* ${D}${libdir}/lib*.so.* +} From ac653d0390097f89b33c8bee6b5b180a782094cd Mon Sep 17 00:00:00 2001 From: Christopher Larson Date: Fri, 24 Apr 2015 16:10:22 -0700 Subject: [PATCH 3/3] package_qa_sourcery: add host user ownership test Check for files outside of /home which are owned by the user running bitbake. Add `package_qa_sourcery` to `PACKAGE_CLASSES`, and `${SOURCERY_QA}` to your `WARN_QA` or `ERROR_QA` to use. This will be submitted to oe-core's package_qa. JIRA: SB-4185 Signed-off-by: Christopher Larson --- classes/package_qa_sourcery.bbclass | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 classes/package_qa_sourcery.bbclass diff --git a/classes/package_qa_sourcery.bbclass b/classes/package_qa_sourcery.bbclass new file mode 100644 index 0000000..93499dc --- /dev/null +++ b/classes/package_qa_sourcery.bbclass @@ -0,0 +1,36 @@ +inherit package + +SOURCERY_QA = "host-user-contaminated" + +# We need to test in fakeroot context to check file ownership +do_package_qa[fakeroot] = "1" + +HOST_USER_UID := "${@os.getuid()}" +HOST_USER_UID[type] = "integer" +HOST_USER_GID := "${@os.getgid()}" +HOST_USER_GID[type] = "integer" + +QAPATHTEST[host-user-contaminated] = "package_qa_check_host_user" +def package_qa_check_host_user(path, name, d, elf, messages): + """Check for files outside of /home which are owned by the user running bitbake.""" + + if not os.path.lexists(path): + return + + check_uid = oe.data.typed_value('HOST_USER_UID', d) + check_gid = oe.data.typed_value('HOST_USER_GID', d) + + dest = d.getVar('PKGDEST', True) + home = os.path.join(dest, 'home') + if path == home or path.startswith(home + os.sep): + return + + stat = os.lstat(path) + 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 + + 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