Bug 2128976
| Summary: | Tools must be hardened to not load "rogue" python modules | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 8 | Reporter: | Renaud Métrich <rmetrich> |
| Component: | policycoreutils | Assignee: | Vit Mojzis <vmojzis> |
| Status: | CLOSED ERRATA | QA Contact: | Amith <apeetham> |
| Severity: | high | Docs Contact: | |
| Priority: | high | ||
| Version: | 8.6 | CC: | dwalsh, lvrabec, mmalik, plautrba, qguo, vmojzis |
| Target Milestone: | rc | Keywords: | Triaged |
| Target Release: | --- | Flags: | pm-rhel:
mirror+
|
| Hardware: | All | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | policycoreutils-2.9-21.1.el8 | Doc Type: | No Doc Update |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2023-05-16 09:11:23 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (policycoreutils bug fix and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2023:3034 |
Description of problem: When a python script is present in "/usr/sbin", it takes precedence over regular modules. This breaks "semanage", for example when a "/usr/sbin/audit.py" script is present, e.g.: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # cat /usr/sbin/audit.py import sys print("BAD GUY!", file=sys.stderr) sys.exit(1) # semanage boolean -l BAD GUY! -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- This is very problematic because it's difficult to troubleshoot: python applications usually read a lot of modules from many places. Finding the culprit requires in-depth analysis using strace or similar tools. The root cause for this seems to having PYTHONPATH specify "/usr/sbin" when executing "semanage": -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # tail /usr/sbin/semanage [...] if __name__ == '__main__': print(sys.path) do_parser() # semanage boolean -l ['/usr/sbin', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages'] BAD GUY! -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- The root cause for this is only using "-Es" options in the shebang: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # head -1 /usr/sbin/semanage #! /usr/libexec/platform-python -Es -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- The tools needs to add "-I" as well: -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- # head -1 /usr/sbin/semanage #! /usr/libexec/platform-python -EsI # semanage boolean -l ['/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages'] SELinux boolean State Default Description ... -------- 8< ---------------- 8< ---------------- 8< ---------------- 8< -------- Version-Release number of selected component (if applicable): policycoreutils-python-utils-2.9-19.el8.noarch How reproducible: Always Steps to Reproduce: see above