Skip to contentSkip to conversation

python: Harden tools against "rogue" modules

PATCH In review Vit Mojzis 2 participants 3 messages Oct 18, 2022 – Nov 9, 2022 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 python: Harden tools against "rogue" modules

Python scripts present in "/usr/sbin" override regular modules. Make sure /usr/sbin is not present in PYTHONPATH.

Fixes:
#cat > /usr/sbin/audit.py <<EOF
import sys
print("BAD GUY!", file=sys.stderr)
sys.exit(1)
EOF
#semanage boolean -l
BAD GUY!

---
 python/audit2allow/audit2allow    | 2 +-
 python/audit2allow/sepolgen-ifgen | 2 +-
 python/chcat/chcat                | 2 +-
 python/semanage/semanage          | 2 +-
 python/sepolicy/sepolicy.py       | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
python/audit2allow/audit2allow +1 -1
index 09b06f66..eafeea88 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Authors: Karl MacMillan <[email protected]>
 # Authors: Dan Walsh <[email protected]>
 #
python/audit2allow/sepolgen-ifgen +1 -1
index b7a04c71..f2cc0c32 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # Authors: Karl MacMillan <[email protected]>
 #
python/chcat/chcat +1 -1
index 952cb818..68718ec5 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2005 Red Hat
 # see file 'COPYING' for use and warranty information
 #
python/semanage/semanage +1 -1
index 10ab3fa6..b21d1484 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2012-2013 Red Hat
 # AUTHOR: Miroslav Grepl <[email protected]>
 # AUTHOR: David Quigley <[email protected]>
python/sepolicy/sepolicy.py +1 -1
index c7a70e09..733d4048 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2012 Red Hat
 # AUTHOR: Dan Walsh <[email protected]>
 # see file 'COPYING' for use and warranty information
Signature · 1 line
2.37.3
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Vit Mojzis

Python scripts present in "/usr/sbin" override regular modules. Make sure /usr/sbin is not present in PYTHONPATH.

Fixes:
#cat > /usr/sbin/audit.py <<EOF
import sys
print("BAD GUY!", file=sys.stderr)
sys.exit(1)
EOF
#semanage boolean -l
BAD GUY!

Quoted 1 line
Quoted 61 lines
---
 python/audit2allow/audit2allow    | 2 +-
 python/audit2allow/sepolgen-ifgen | 2 +-
 python/chcat/chcat                | 2 +-
 python/semanage/semanage          | 2 +-
 python/sepolicy/sepolicy.py       | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
python/audit2allow/audit2allow +1 -1
index 09b06f66..eafeea88 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Authors: Karl MacMillan <[email protected]>
 # Authors: Dan Walsh <[email protected]>
 #
python/audit2allow/sepolgen-ifgen +1 -1
index b7a04c71..f2cc0c32 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # Authors: Karl MacMillan <[email protected]>
 #
python/chcat/chcat +1 -1
index 952cb818..68718ec5 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2005 Red Hat
 # see file 'COPYING' for use and warranty information
 #
python/semanage/semanage +1 -1
index 10ab3fa6..b21d1484 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2012-2013 Red Hat
 # AUTHOR: Miroslav Grepl <[email protected]>
 # AUTHOR: David Quigley <[email protected]>
python/sepolicy/sepolicy.py +1 -2
index c7a70e09..733d4048 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2012 Red Hat
 # AUTHOR: Dan Walsh <[email protected]>
 # see file 'COPYING' for use and warranty information
--

2.37.3

#2 lore raw
Quoted 15 lines · James Carter
Quoted 13 lines · Vit Mojzis

Python scripts present in "/usr/sbin" override regular modules. Make sure /usr/sbin is not present in PYTHONPATH.

Fixes:
#cat > /usr/sbin/audit.py <<EOF
import sys
print("BAD GUY!", file=sys.stderr)
sys.exit(1)
EOF
#semanage boolean -l
BAD GUY!

Quoted 4 lines
Quoted 1 line

Merged.
Thanks,
Jim

Quoted 61 lines
Quoted 61 lines
---
 python/audit2allow/audit2allow    | 2 +-
 python/audit2allow/sepolgen-ifgen | 2 +-
 python/chcat/chcat                | 2 +-
 python/semanage/semanage          | 2 +-
 python/sepolicy/sepolicy.py       | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
python/audit2allow/audit2allow +1 -1
index 09b06f66..eafeea88 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Authors: Karl MacMillan <[email protected]>
 # Authors: Dan Walsh <[email protected]>
 #
python/audit2allow/sepolgen-ifgen +1 -1
index b7a04c71..f2cc0c32 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # Authors: Karl MacMillan <[email protected]>
 #
python/chcat/chcat +1 -1
index 952cb818..68718ec5 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2005 Red Hat
 # see file 'COPYING' for use and warranty information
 #
python/semanage/semanage +1 -1
index 10ab3fa6..b21d1484 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2012-2013 Red Hat
 # AUTHOR: Miroslav Grepl <[email protected]>
 # AUTHOR: David Quigley <[email protected]>
python/sepolicy/sepolicy.py +1 -2
index c7a70e09..733d4048 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Copyright (C) 2012 Red Hat
 # AUTHOR: Dan Walsh <[email protected]>
 # see file 'COPYING' for use and warranty information
--

2.37.3