sandbox: do not try setup directories without -X or -M
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'
Signed-off-by Petr Lautrbach <[email protected]>
--- policycoreutils/sandbox/sandbox | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
policycoreutils/sandbox/sandbox +2 -1
@@ -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
PATCH 2/2 sandbox: create a new session for sandboxed processes
It helps to prevent sandboxed processes to inject arbitrary commands into the parent.
Signed-off-by Petr Lautrbach <[email protected]>
--- policycoreutils/sandbox/sandbox | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
policycoreutils/sandbox/sandbox +9 -4
@@ -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
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.
Signed-off-by Petr Lautrbach <[email protected]>
Thanks, both patches applied.
Quoted 29 lines
--- policycoreutils/sandbox/sandbox | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)policycoreutils/sandbox/sandbox +9
-4@@ -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: