Skip to contentSkip to conversation

sandbox: do not try setup directories without -X or -M

PATCH In review Petr Lautrbach 2 participants 3 messages Sep 23, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sandbox: do not try setup directories without -X or -M

sandbox tried to copy all affected files to the new home or tmp even though -M or -X was not specified and there was no new directory.

Fixes:

$ sandbox ls ~
/usr/bin/sandbox: [Errno 17] File exists: '/root'
---
 policycoreutils/sandbox/sandbox | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
policycoreutils/sandbox/sandbox +2 -1
index 4ed57c1..9cc13c2 100644
@@ -503,7 +503,8 @@ sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-
         try:
             self.__parse_options()
             self.__gen_context()
-            self.__setup_dir()
+            if self.__mount:
+                self.__setup_dir()
             return self.__execute()
         except KeyboardInterrupt:
             sys.exit(0)
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/2 sandbox: create a new session for sandboxed processes

It helps to prevent sandboxed processes to inject arbitrary commands into the parent.

---
 policycoreutils/sandbox/sandbox | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
policycoreutils/sandbox/sandbox +9 -4
index 9cc13c2..07c340c 100644
@@ -471,10 +471,15 @@ sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-
                     cmds += ["--"] + self.__paths
                 return subprocess.Popen(cmds).wait()
 
-            selinux.setexeccon(self.__execcon)
-            rc = subprocess.Popen(self.__cmds).wait()
-            selinux.setexeccon(None)
-            return rc
+            pid = os.fork()
+            if pid == 0:
+                rc = os.setsid()
+                if rc:
+                    return rc
+                selinux.setexeccon(self.__execcon)
+                os.execv(self.__cmds[0], self.__cmds)
+            rc = os.waitpid(pid, 0)
+            return os.WEXITSTATUS(rc[1])
 
         finally:
             for i in self.__paths:
Signature · 1 line
2.9.3
#2 lore raw

Re: [PATCH 2/2] sandbox: create a new session for sandboxed processes

Quoted 4 lines · Petr Lautrbach

It helps to prevent sandboxed processes to inject arbitrary commands into the parent.

Thanks, both patches applied.

Quoted 29 lines
---
 policycoreutils/sandbox/sandbox | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
policycoreutils/sandbox/sandbox +9 -4
index 9cc13c2..07c340c 100644
@@ -471,10 +471,15 @@ sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-
                     cmds += ["--"] + self.__paths
                 return subprocess.Popen(cmds).wait()
 
-            selinux.setexeccon(self.__execcon)
-            rc = subprocess.Popen(self.__cmds).wait()
-            selinux.setexeccon(None)
-            return rc
+            pid = os.fork()
+            if pid == 0:
+                rc = os.setsid()
+                if rc:
+                    return rc
+                selinux.setexeccon(self.__execcon)
+                os.execv(self.__cmds[0], self.__cmds)
+            rc = os.waitpid(pid, 0)
+            return os.WEXITSTATUS(rc[1])
 
         finally:
             for i in self.__paths: