python3: sanitize userbase in _sysconfig_vars JSON to avoid host path leak
PATCH v2 1/2 python3: sanitize userbase in _sysconfig_vars JSON to avoid host path leak
The _sysconfig_vars__linux_x86_64-linux-gnu.json file contains a "userbase" field that is populated from the build host user's $HOME at build time. This leaks the build host user's home directory path into the target rootfs.
The existing py_package_preprocess() cleanup for this JSON file only strips known OE build path prefixes (STAGING_DIR_TARGET, RECIPE_SYSROOT, etc.), but the userbase value comes from the build user's $HOME environment variable which doesn't match any of those patterns.
Set userbase to an empty string in the packaged JSON. This is safe because at runtime, sysconfig.get_config_vars() always recomputes userbase by calling _getuserbase(), which resolves the actual target user's ~/.local path dynamically. The static value in the JSON is never used for runtime path resolution.
--- meta/recipes-devtools/python/python3_3.14.5.bb | 1 + 1 file changed, 1 insertion(+)
meta/recipes-devtools/python/python3_3.14.5.bb +1 -0
@@ -390,6 +390,7 @@ py_package_preprocess () { -e 's:${RECIPE_SYSROOT_NATIVE}::g' \ -e 's:${RECIPE_SYSROOT}::g' \ -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \ + -e 's|"userbase": ".*"|"userbase": ""|g' \ ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfig_vars*.json }
Signature · 1 line
2.43.0
PATCH v2 2/2 insane.bbclass: check for build host HOME directory in packaged files
Extend package_qa_check_buildpaths to also detect the build host's HOME directory path in target packages. This catches cases where \$HOME-derived paths (such as userbase in Python's sysconfig) leak into the rootfs.
--- meta/classes-global/insane.bbclass | 4 ++++ 1 file changed, 4 insertions(+)
meta/classes-global/insane.bbclass +4 -0
@@ -439,11 +439,15 @@ def package_qa_check_buildpaths(path, name, d, elf): return tmpdir = bytes(d.getVar('TMPDIR'), encoding="utf-8") + homedir = bytes(os.environ.get('HOME', ''), encoding="utf-8") with open(path, 'rb') as f: file_content = f.read() if tmpdir in file_content: path = package_qa_clean_path(path, d, name) oe.qa.handle_error("buildpaths", "File %s in package %s contains reference to TMPDIR" % (path, name), d) + if homedir and homedir in file_content: + path = package_qa_clean_path(path, d, name) + oe.qa.handle_error("buildpaths", "File %s in package %s contains reference to the build host HOME directory" % (path, name), d) QAPATHTEST[xorg-driver-abi] = "package_qa_check_xorg_driver_abi"
Signature · 1 line
2.43.0
Re: [OE-core] [PATCH v2 2/2] insane.bbclass: check for build host HOME directory in packaged files
Thanks, much appreciated!
Alex
Quoted 43 lines · Bin Cao via lists.openembedded.org
Extend
package_qa_check_buildpathsto also detect the build host's HOME directory path in target packages. This catches cases where \$HOME-derived paths (such as userbase in Python's sysconfig) leak into the rootfs.Signed-off-by Bin Cao <[email protected]>--- meta/classes-global/insane.bbclass | 4 ++++ 1 file changed, 4 insertions(+)meta/classes-global/insane.bbclass +4
-1@@ -439,11 +439,15 @@ def package_qa_check_buildpaths(path, name, d, elf): return tmpdir = bytes(d.getVar('TMPDIR'), encoding="utf-8") + homedir = bytes(os.environ.get('HOME', ''), encoding="utf-8") with open(path, 'rb') as f: file_content = f.read() if tmpdir in file_content: path = package_qa_clean_path(path, d, name) oe.qa.handle_error("buildpaths", "File %s in package %s contains reference to TMPDIR" % (path, name), d) + if homedir and homedir in file_content: + path = package_qa_clean_path(path, d, name) + oe.qa.handle_error("buildpaths", "File %s in package %s contains reference to the build host HOME directory" % (path, name), d) QAPATHTEST[xorg-driver-abi] = "package_qa_check_xorg_driver_abi" --2.43.0
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#238120): https://lists.openembedded.org/g/openembedded-core/message/238120
Mute This Topic: https://lists.openembedded.org/mt/119643013/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-