Skip to contentSkip to conversation

python: Harden more tools agains "rogue" modules

PATCH In review Vit Mojzis 2 participants 3 messages Dec 6, 2023 – Dec 12, 2023 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 python: Harden more tools agains "rogue" modules

Python scripts present in the same directory as the tool override regular modules.

Fixes:

      #cat > /usr/bin/signal.py <<EOF
      import sys
      print("BAD GUY!", file=sys.stderr)
      sys.exit(1)
      EOF
      #sandbox date
      BAD GUY!
---
 dbus/selinux_server.py       | 2 +-
 gui/polgengui.py             | 2 +-
 gui/system-config-selinux.py | 6 +++---
 sandbox/sandbox              | 2 +-
 sandbox/start                | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
dbus/selinux_server.py +1 -1
index a969f226..469c526f 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -EsI
 
 import dbus
 import dbus.service
gui/polgengui.py +1 -1
index 16116ba6..9c151a11 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # polgengui.py - GUI for SELinux Config tool in system-config-selinux
 #
gui/system-config-selinux.py +3 -3
index 9f53b7fe..0b6ba4b5 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # system-config-selinux.py - GUI for SELinux Config tool in system-config-selinux
 #
@@ -32,6 +32,8 @@ except RuntimeError as e:
     print("This is a graphical application and requires DISPLAY to be set.")
     sys.exit(1)
 
+sys.path.append('/usr/share/system-config-selinux')
+
 from gi.repository import GObject
 import statusPage
 import booleansPage
@@ -66,8 +68,6 @@ except:
 
 version = "1.0"
 
-sys.path.append('/usr/share/system-config-selinux')
-
 
 ##
 ## Pull in the Glade file
sandbox/sandbox +1 -1
index a2762a7d..fe631a92 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Authors: Dan Walsh <[email protected]>
 # Authors: Thomas Liu <[email protected]>
 # Authors: Josh Cogliati
sandbox/start +1 -1
index 4ed3cb5c..3c1a1783 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 try:
     from subprocess import getstatusoutput
 except ImportError:
Signature · 1 line
2.41.0
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Vit Mojzis

Python scripts present in the same directory as the tool override regular modules.

Fixes:

      #cat > /usr/bin/signal.py <<EOF
      import sys
      print("BAD GUY!", file=sys.stderr)
      sys.exit(1)
      EOF
      #sandbox date
      BAD GUY!
Quoted 1 line
Quoted 80 lines
---
 dbus/selinux_server.py       | 2 +-
 gui/polgengui.py             | 2 +-
 gui/system-config-selinux.py | 6 +++---
 sandbox/sandbox              | 2 +-
 sandbox/start                | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
dbus/selinux_server.py +1 -1
index a969f226..469c526f 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -EsI
 
 import dbus
 import dbus.service
gui/polgengui.py +1 -1
index 16116ba6..9c151a11 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # polgengui.py - GUI for SELinux Config tool in system-config-selinux
 #
gui/system-config-selinux.py +3 -3
index 9f53b7fe..0b6ba4b5 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # system-config-selinux.py - GUI for SELinux Config tool in system-config-selinux
 #
@@ -32,6 +32,8 @@ except RuntimeError as e:
     print("This is a graphical application and requires DISPLAY to be set.")
     sys.exit(1)
 
+sys.path.append('/usr/share/system-config-selinux')
+
 from gi.repository import GObject
 import statusPage
 import booleansPage
@@ -66,8 +68,6 @@ except:
 
 version = "1.0"
 
-sys.path.append('/usr/share/system-config-selinux')
-
 
 ##
 ## Pull in the Glade file
sandbox/sandbox +1 -1
index a2762a7d..fe631a92 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Authors: Dan Walsh <[email protected]>
 # Authors: Thomas Liu <[email protected]>
 # Authors: Josh Cogliati
sandbox/start +1 -2
index 4ed3cb5c..3c1a1783 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 try:
     from subprocess import getstatusoutput
 except ImportError:
--

2.41.0

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

Python scripts present in the same directory as the tool override regular modules.

Fixes:

      #cat > /usr/bin/signal.py <<EOF
      import sys
      print("BAD GUY!", file=sys.stderr)
      sys.exit(1)
      EOF
      #sandbox date
      BAD GUY!
Quoted 4 lines
Quoted 1 line

Merged.
Thanks,
Jim

Quoted 80 lines
Quoted 80 lines
---
 dbus/selinux_server.py       | 2 +-
 gui/polgengui.py             | 2 +-
 gui/system-config-selinux.py | 6 +++---
 sandbox/sandbox              | 2 +-
 sandbox/start                | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
dbus/selinux_server.py +1 -1
index a969f226..469c526f 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python3 -EsI
 
 import dbus
 import dbus.service
gui/polgengui.py +1 -1
index 16116ba6..9c151a11 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # polgengui.py - GUI for SELinux Config tool in system-config-selinux
 #
gui/system-config-selinux.py +3 -3
index 9f53b7fe..0b6ba4b5 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 #
 # system-config-selinux.py - GUI for SELinux Config tool in system-config-selinux
 #
@@ -32,6 +32,8 @@ except RuntimeError as e:
     print("This is a graphical application and requires DISPLAY to be set.")
     sys.exit(1)
 
+sys.path.append('/usr/share/system-config-selinux')
+
 from gi.repository import GObject
 import statusPage
 import booleansPage
@@ -66,8 +68,6 @@ except:
 
 version = "1.0"
 
-sys.path.append('/usr/share/system-config-selinux')
-
 
 ##
 ## Pull in the Glade file
sandbox/sandbox +1 -1
index a2762a7d..fe631a92 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 # Authors: Dan Walsh <[email protected]>
 # Authors: Thomas Liu <[email protected]>
 # Authors: Josh Cogliati
sandbox/start +1 -2
index 4ed3cb5c..3c1a1783 100644
@@ -1,4 +1,4 @@
-#!/usr/bin/python3 -Es
+#!/usr/bin/python3 -EsI
 try:
     from subprocess import getstatusoutput
 except ImportError:
--

2.41.0