Skip to contentSkip to conversation

Patches from Fedora on the sandbox package.

PATCH New Dan Walsh 2 participants 5 messages May 12, 2014 – May 13, 2014 SELinux security module

lore
Share & tools
lore

Dan Walsh

author
#0 lore raw

This patch set includes the setcurrent patch for setexec to handle a fix for of libcap-ng.

author
#1 lore raw

PATCH 2/4 Update XDG_RUNTIME_DIR directory

---
 policycoreutils/sandbox/seunshare.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
policycoreutils/sandbox/seunshare.c +11 -0
index 97f3920..596a43e 100644
@@ -964,6 +964,7 @@ int main(int argc, char **argv) {
 	if (child == 0) {
 		char *display = NULL;
 		char *LANG = NULL;
+		char *RUNTIME_DIR = NULL;
 		int rc = -1;
 		char *resolved_path = NULL;
 
@@ -1014,6 +1015,13 @@ int main(int argc, char **argv) {
 			}
 		}
 
+		if ((RUNTIME_DIR = getenv("XDG_RUNTIME_DIR")) != NULL) {
+			if ((RUNTIME_DIR = strdup(RUNTIME_DIR)) == NULL) {
+				perror(_("Out of memory"));
+				goto childerr;
+			}
+		}
+
 		if ((rc = clearenv()) != 0) {
 			perror(_("Failed to clear environment"));
 			goto childerr;
@@ -1022,6 +1030,8 @@ int main(int argc, char **argv) {
 			rc |= setenv("DISPLAY", display, 1);
 		if (LANG)
 			rc |= setenv("LANG", LANG, 1);
+		if (RUNTIME_DIR)
+			rc |= setenv("XDG_RUNTIME_DIR", RUNTIME_DIR, 1);
 		rc |= setenv("HOME", pwd->pw_dir, 1);
 		rc |= setenv("SHELL", pwd->pw_shell, 1);
 		rc |= setenv("USER", pwd->pw_name, 1);
@@ -1049,6 +1059,7 @@ childerr:
 		free(resolved_path);
 		free(display);
 		free(LANG);
+		free(RUNTIME_DIR);
 		exit(-1);
 	}
 
Signature · 1 line
1.9.0
author
#2 lore raw

PATCH 3/4 Remove handling of cgroups from sandbox

In reply to Dan Walsh

It never worked correctly and this should be handled with an API to systemd going forward.

---
 policycoreutils/sandbox/Makefile    |   2 +-
 policycoreutils/sandbox/sandbox     |  10 +-
 policycoreutils/sandbox/seunshare.8 |   5 +-
 policycoreutils/sandbox/seunshare.c | 218 +-----------------------------------
 4 files changed, 5 insertions(+), 230 deletions(-)
policycoreutils/sandbox/Makefile +1 -1
index 981c56c..5671170 100644
@@ -8,7 +8,7 @@ MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 SHAREDIR ?= $(PREFIX)/share/sandbox
 override CFLAGS += $(LDFLAGS) -I$(PREFIX)/include -DPACKAGE="\"policycoreutils\"" -Wall -Werror -Wextra -W
-LDLIBS += -lcgroup -lselinux -lcap-ng -L$(LIBDIR)
+LDLIBS += -lselinux -lcap-ng -L$(LIBDIR)
 SEUNSHARE_OBJS = seunshare.o
 
 all: sandbox seunshare sandboxX.sh start
policycoreutils/sandbox/sandbox +2 -8
index 3668abe..3678c5d 100644
@@ -280,9 +280,9 @@ Policy defines the following types for use with the -t:
                pass
 
         usage = _("""
-sandbox [-h] [-c] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-W windowmanager ] [ -w windowsize ] [[-i file ] ...] [ -t type ] command
+sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-W windowmanager ] [ -w windowsize ] [[-i file ] ...] [ -t type ] command
 
-sandbox [-h] [-c] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-W windowmanager ] [ -w windowsize ] [[-i file ] ...] [ -t type ] -S
+sandbox [-h] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile ] [-W windowmanager ] [ -w windowsize ] [[-i file ] ...] [ -t type ] -S
 %s
 """) % types
 
@@ -338,10 +338,6 @@ sandbox [-h] [-c] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile
         parser.add_option("-l", "--level", dest="level", 
                           help=_("MCS/MLS level for the sandbox"))
 
-        parser.add_option("-c", "--cgroups",
-                          action="store_true", dest="usecgroup", default=False,
-                          help=_("Use cgroups to limit this sandbox."))
-
         parser.add_option("-C", "--capabilities",
                          action="store_true", dest="usecaps", default=False,
                          help="Allow apps requiring capabilities to run within the sandbox.")
@@ -426,8 +422,6 @@ sandbox [-h] [-c] [-l level ] [-[X|M] [-H homedir] [-T tempdir]] [-I includefile
     def __execute(self):
            try:
                   cmds = [ SEUNSHARE,  "-Z", self.__execcon ]
-                  if self.__options.usecgroup:
-                         cmds.append('-c')
                   if self.__options.usecaps:
                          cmds.append('-C')
                   if self.__mount:
policycoreutils/sandbox/seunshare.8 +1 -4
index 06610c0..76b75c8 100644
@@ -3,7 +3,7 @@
 seunshare \- Run cmd with alternate homedir, tmpdir and/or SELinux context
 .SH SYNOPSIS
 .B seunshare
-[ -v ] [ -c ] [ -C ] [ -k ] [ -t tmpdir ] [ -h homedir ] [ -Z context ] -- executable [args]
+[ -v ] [ -C ] [ -k ] [ -t tmpdir ] [ -h homedir ] [ -Z context ] -- executable [args]
 .br
 .SH DESCRIPTION
 .PP
@@ -18,9 +18,6 @@ Alternate homedir to be used by the application.  Homedir must be owned by the u
 \fB\-t\ tmpdir
 Use alternate tempory directory to mount on /tmp.  tmpdir must be owned by the user.
 .TP
-\fB\-c --cgroups\fR
-Use cgroups to control this copy of seunshare.  Specify parameters in /etc/sysconfig/sandbox.  Max memory usage and cpu usage are to be specified in percent.  You can specify which CPUs to use by numbering them 0,1,2... etc.
-.TP
 \fB\-C --capabilities\fR
 Allow apps executed within the namespace to use capabilities.  Default is no capabilities.
 .TP
policycoreutils/sandbox/seunshare.c +1 -217

260 lines not on this page · raw message

Signature · 1 line
1.9.0
author
#3 lore raw

PATCH 4/4 seunshare: Try to use setcurrent before setexec

In reply to Dan Walsh

From: Andy Lutomirski <[email protected]>

If seunshare uses PR_SET_NO_NEW_PRIVS, which certain versions of libcap-ng set, setexeccon will cause execve to fail. This also makes setting selinux context the very last action taken by seunshare prior to exec, as it may otherwise cause things to fail.

Note that this won't work without adjusting the system policy to allow this use of setcurrent. This rule appears to work:

    allow unconfined_t sandbox_t:process dyntransition;

although a better rule would probably relax the unconfined_t restriction.

---
 policycoreutils/sandbox/seunshare.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
policycoreutils/sandbox/seunshare.c +14 -6
index a221920..c92e394 100644
@@ -826,17 +826,25 @@ int main(int argc, char **argv) {
 			goto childerr;
 		}
 
-		/* selinux context */
-		if (execcon && setexeccon(execcon) != 0) {
-			fprintf(stderr, _("Could not set exec context to %s. %s\n"), execcon, strerror(errno));
-			goto childerr;
-		}
-
 		if (chdir(pwd->pw_dir)) {
 			perror(_("Failed to change dir to homedir"));
 			goto childerr;
 		}
 		setsid();
+
+		/* selinux context */
+		if (execcon) {
+			/* try dyntransition, since no_new_privs can interfere
+			 * with setexeccon */
+			if (setcon(execcon) != 0) {
+				/* failed; fall back to setexeccon */
+				if (setexeccon(execcon) != 0) {
+					fprintf(stderr, _("Could not set exec context to %s. %s\n"), execcon, strerror(errno));
+					goto childerr;
+				}
+			}
+		}
+
 		execv(argv[optind], argv + optind);
 		fprintf(stderr, _("Failed to execute command %s: %s\n"), argv[optind], strerror(errno));
 childerr:
Signature · 1 line
1.9.0