Skip to contentSkip to conversation

file_type_auto_trans is not sufficient

DISCUSSION Ivan Gyurdiev 6 participants 27 messages May 28, 2005 – Jun 1, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

As part of my current project, I am running into a large number of cases where file_type_auto_trans is not an acceptable solution for changing the context for a newly created file/directory. This always happens in a conflicting-transition scenario (very common):

For example:

1)
libgnome needs to create .gnome2 and .gnome2_private with a context that differs from the parent directory. Applications that link to libgnome may already have a transition defined for (ROLE_home_dir_t: dir)

2)
libfontconfig needs to create .font.cache-# with a context that differs from the parent directory. Same problem for (ROLE_hime_dir_t: file)

3)
Mail apps need to be able to save mail to $HOME under some context (likely ROLE_untrusted_content_t:file/dir). Same goes for web content saved by mozilla. This conflicts with the usual transition.

4)
libORBit2 needs to create /tmp/orbit-$USER... with a specific context while the app may have its own tmp_domain. Same for libICE.

===============

To address those problems, I think I need to add selinux support to a number of applications, and perform the transition in the code. I'm not sure what's the best way to do that. Does adding the following functions to libselinux (or elsewhere) make sense?

int mkdir_restorecon(const char *pathname, mode_t mode); int creat_restorecon(const char *pathname, mode_t mode); int mknod_restorecon(const char *pathname, mode_t mode, dev_t dev);

Those would perform getfscreate/matchpathcon/setfscreate cycle, and would ignore errors in permissive mode.

Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 6 lines

To address those problems, I think I need to add selinux support to a number of applications, and perform the transition in the code. I'm not sure what's the best way to do that. Does adding the following functions to libselinux (or elsewhere) make sense?

Quoted 6 lines

int mkdir_restorecon(const char *pathname, mode_t mode); int creat_restorecon(const char *pathname, mode_t mode); int mknod_restorecon(const char *pathname, mode_t mode, dev_t dev);

Those would perform getfscreate/matchpathcon/setfscreate cycle, and would ignore errors in permissive mode.

Actually, what exactly happens when you call setfscreate() and at the same time you have a matching file_type_auto_trans rule?

In my case for /tmp/gconfd-$USER vs /tmp/orbit-$USER, (process is gconf, executing libORBit code that creates orbit-$USER) the orbit getfscreate() rule took precedence over
the matching file_type_auto_trans in gconfd... does
this always happen, or do I have to make a choice
between either file_type_auto_trans, or setfscreate() ?

Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
Quoted 12 lines · Ivan Gyurdiev
Quoted 11 lines

To address those problems, I think I need to add selinux support
to a number of applications, and perform the transition in the code. I'm not sure what's the best way to do that. Does adding the following functions to libselinux (or elsewhere) make sense?

int mkdir_restorecon(const char *pathname, mode_t mode); int creat_restorecon(const char *pathname, mode_t mode); int mknod_restorecon(const char *pathname, mode_t mode, dev_t dev);

Those would perform getfscreate/matchpathcon/setfscreate cycle, and would ignore errors in permissive mode.

Quoted 11 lines

Actually, what exactly happens when you call setfscreate() and at the same time you have a matching file_type_auto_trans rule?

In my case for /tmp/gconfd-$USER vs /tmp/orbit-$USER,
(process is gconf, executing libORBit code that creates orbit-$USER)
the orbit getfscreate() rule took precedence over
the matching file_type_auto_trans in gconfd... does
this always happen, or do I have to make a choice between either file_type_auto_trans, or setfscreate() ?

setfscreatecon takes precedence.

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 2 lines

setfscreatecon takes precedence.

...on second thought this interface doesn't work at all - apps call higher level functions for portability - the C standard functions (fopen...), glib (g_mkdir).

Maybe just add:

/* Performs a context match, and changes the file creation context.
* On success, returns the old context. On failure, returns NULL.
* The context returned must be freed with freecon() */

security_context_t switch_context(const char* pathname, mode_t mode) {
        security_context_t prev_ctx = NULL;
        security_context_t tmp_ctx = NULL;

        /* Attempt to get the current context. */
        if (getfscreatecon(&prev_ctx) < 0)
                return NULL;

        /* Attempt a match. */
        if (matchpathcon(pathname, mode, &tmp_ctx) >= 0) {
                if (setfscreatecon(tmp_ctx) < 0) {
                        freecon(tmp_ctx);
                        freecon(prev_ctx);
                        return NULL;
                }
                freecon(tmp_ctx);
        }

        return prev_ctx;
}

...and then do this in every app that needs it, replacing mkdir with the appropriate function. This is annoying.... but I can't think how else to write a better interface.

/* Performs a mkdir call, and sets the context of the directory
* being created, according to matchpathcon. On SElinux failure
* returns -1. Otherwise, returns the usual mkdir status. */

int mkdir_restorecon(const char *pathname, mode_t mode) {
        security_context_t prev_ctx = NULL;
        int status;

        if (is_selinux_enabled()) {
                prev_ctx = switch_context(pathname, mode);

                if ((prev_ctx != NULL) && security_getenforce())
                        return -1;
        }

        status = mkdir(pathname, mode);

        if (prev_ctx != NULL) {
                setfscreatecon(prev_ctx);
                freecon(prev_ctx);
        }

        return status;
}
Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw
Quoted 54 lines · Ivan Gyurdiev
Quoted 3 lines

setfscreatecon takes precedence.

...on second thought this interface doesn't work at all - apps call higher level functions for portability - the C standard functions (fopen...), glib (g_mkdir).

Maybe just add:

/* Performs a context match, and changes the file creation context.
* On success, returns the old context. On failure, returns NULL.
* The context returned must be freed with freecon() */

security_context_t switch_context(const char* pathname, mode_t mode) {
       security_context_t prev_ctx = NULL;
       security_context_t tmp_ctx = NULL;

       /* Attempt to get the current context. */
       if (getfscreatecon(&prev_ctx) < 0)
               return NULL;

       /* Attempt a match. */
       if (matchpathcon(pathname, mode, &tmp_ctx) >= 0) {
               if (setfscreatecon(tmp_ctx) < 0) {
                       freecon(tmp_ctx);
                       freecon(prev_ctx);
                       return NULL;
               }
               freecon(tmp_ctx);
       }

       return prev_ctx;
}

...and then do this in every app that needs it, replacing
mkdir with the appropriate function. This is annoying.... but I can't think how else to write a better interface.

/* Performs a mkdir call, and sets the context of the directory
* being created, according to matchpathcon. On SElinux failure
* returns -1. Otherwise, returns the usual mkdir status. */

int mkdir_restorecon(const char *pathname, mode_t mode) {
       security_context_t prev_ctx = NULL;
       int status;

       if (is_selinux_enabled()) {
               prev_ctx = switch_context(pathname, mode);

               if ((prev_ctx != NULL) && security_getenforce())
                       return -1;
       }

       status = mkdir(pathname, mode);
Quoted 10 lines
       if (prev_ctx != NULL) {
               setfscreatecon(prev_ctx);
               freecon(prev_ctx);
       }

       return status;
}

You do not necessarily want to return an error or matchpathcon failure. matchpathcon can return ENOENT to indicate that it matched <<none>>

In this case the setfscreatecon should not be called but the code should continue. IE the file should get created with the default context.

Signature · 4 lines
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw
Quoted 57 lines
Quoted 47 lines

/* Performs a context match, and changes the file creation context.
* On success, returns the old context. On failure, returns NULL.
* The context returned must be freed with freecon() */

security_context_t switch_context(const char* pathname, mode_t mode) {
       security_context_t prev_ctx = NULL;
       security_context_t tmp_ctx = NULL;

       /* Attempt to get the current context. */
       if (getfscreatecon(&prev_ctx) < 0)
               return NULL;

       /* Attempt a match. */
       if (matchpathcon(pathname, mode, &tmp_ctx) >= 0) {
               if (setfscreatecon(tmp_ctx) < 0) {
                       freecon(tmp_ctx);
                       freecon(prev_ctx);
                       return NULL;
               }
               freecon(tmp_ctx);
       }

       return prev_ctx;
}

...and then do this in every app that needs it, replacing mkdir with the appropriate function. This is annoying.... but I can't think how else to write a better interface.

/* Performs a mkdir call, and sets the context of the directory
* being created, according to matchpathcon. On SElinux failure
* returns -1. Otherwise, returns the usual mkdir status. */

int mkdir_restorecon(const char *pathname, mode_t mode) {
       security_context_t prev_ctx = NULL;
       int status;

       if (is_selinux_enabled()) {
               prev_ctx = switch_context(pathname, mode);

               if ((prev_ctx != NULL) && security_getenforce())
                       return -1;
       }

       status = mkdir(pathname, mode);
Quoted 10 lines
       if (prev_ctx != NULL) {
               setfscreatecon(prev_ctx);
               freecon(prev_ctx);
       }

       return status;
}
Quoted 4 lines

You do not necessarily want to return an error or matchpathcon failure. matchpathcon can return ENOENT to indicate that it matched <<none>>

               if ((prev_ctx != NULL) && security_getenforce())

This should be if ((prev_ctx == NULL) ... Given that, there is no error on matchpathcon failure.

Quoted 3 lines

In this case the setfscreatecon should not be called but the code should continue. IE the
file should get created with the default context.

That's what it does... it also tries to setfscreatecon back to restore the old context on no change, but I thought that was acceptable.

The issue is - this interface is rather ugly - can anyone come up with a better one, or should I go ahead and patch various programs like this.

Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#6 lore raw
Quoted 4 lines

The issue is - this interface is rather ugly - can anyone come up with a better one, or should I go ahead and patch various programs like this.

Sample patches attached. I also have to patch libICE. Fonts patch works fine, but I can't get gnome/ORBit to compile because of docbook problems. Any domain calling orbit_connect, ice_connect, read_fonts, or gnome_application (see my other mail - PATCH)
executes the following macro:

################################################################
#
# can_restore_context(domain)
#
# Permissions for restoring the context

# of a file via setfscreatecon/getfscreatecon/matchpathcon
#

define(can_restore_context',

# Protect against double inclusion
ifdef(can_restore_context_$1', ', `
define(`can_restore_context_$1')

can_setfscreate($1)
can_getsecurity($1)
r_dir_file($1, selinux_config_t)
r_dir_file($1, file_context_t)
allow $1 default_context_t:dir search;

') dnl ifdef can_restore_context_args
') dnl can_restore_context

It also makes virtually everything depend on libselinux.

I'm really starting to think that this is too ugly, and not an acceptable solution, but I don't have another suggestion at this time.

Signature · 2 lines
Ivan Gyurdiev <[email protected]>
Cornell University
configure.in +11 -0
diff -aur fontconfig-2.2.3.orig/configure.in fontconfig-2.2.3/configure.in
@@ -132,6 +132,17 @@
 CFLAGS="$fontconfig_save_cflags"
 LIBS="$fontconfig_save_libs"
 
+dnl Checks for SELinux
+AC_CHECK_LIB(selinux, security_switch_context, have_switch_context=yes)
+AC_CHECK_HEADER(selinux/selinux.h, have_selinux_h=yes)
+if test "x$have_switch_context" = "xyes" && test "x$have_selinux_h" = "xyes"; then
+  AC_DEFINE([WITH_SELINUX], 1, [define to enable SELinux support])
+  SELINUX_CFLAGS="-I/usr/include/selinux"
+  SELINUX_LDFLAGS="-lselinux"
+fi
+AC_SUBST(SELINUX_LDFLAGS)
+AC_SUBST(SELINUX_CFLAGS)
+
 #
 # Check expat configuration
 #
src/fccache.c +25 -1
diff -aur fontconfig-2.2.3.orig/src/fccache.c fontconfig-2.2.3/src/fccache.c
@@ -23,6 +23,9 @@
  */
 
 #include "fcint.h"
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+#endif
 
 /*
  * POSIX has broken stdio so that getc must do thread-safe locking,
@@ -855,6 +858,10 @@
     FcGlobalCacheFile	*file;
     FcAtomic		*atomic;
 
+#ifdef WITH_SELINUX
+    security_context_t prev_ctx = NULL;
+#endif
+
     if (!cache->updated && cache->referenced == cache->entries)
 	return FcTrue;
     
@@ -866,16 +873,33 @@
     if (getuid () != geteuid ())
 	return FcFalse;
 #endif
-    
+
+#ifdef WITH_SELINUX
+    if (is_selinux_enabled()) {
+        prev_ctx = security_switch_context((char*) cache_file, 0200);
+
+            if ((prev_ctx == NULL) && security_getenforce()) 
+                 goto bail0;
+    }
+#endif
+
     atomic = FcAtomicCreate (cache_file);
     if (!atomic)
 	goto bail0;
     if (!FcAtomicLock (atomic))
 	goto bail1;
+
     f = fopen ((char *) FcAtomicNewFile(atomic), "w");
     if (!f)
 	goto bail2;
 
+#ifdef WITH_SELINUX
+    if (prev_ctx != NULL) {
+        setfscreatecon(prev_ctx);
+        freecon(prev_ctx);
+    }
+#endif
+
     for (dir_hash = 0; dir_hash < FC_GLOBAL_CACHE_DIR_HASH_SIZE; dir_hash++)
     {
 	for (dir = cache->ents[dir_hash]; dir; dir = dir->next)
src/Makefile.am +2 -0
diff -aur fontconfig-2.2.3.orig/src/Makefile.am fontconfig-2.2.3/src/Makefile.am
@@ -44,6 +44,7 @@
 INCLUDES = 						\
 	$(FREETYPE_CFLAGS)				\
 	$(EXPAT_CFLAGS)					\
+	$(SELINUX_CFLAGS)				\	
 	-DFONTCONFIG_PATH='"$(CONFDIR)"'		\
 	-I$(top_srcdir)					\
 	-I$(top_srcdir)/src
@@ -76,6 +77,7 @@
 lib_LTLIBRARIES = libfontconfig.la
 
 libfontconfig_la_LDFLAGS =			\
+	$(SELINUX_LDFLAGS)			\
 	-version-info @LT_VERSION_INFO@ $(no_undefined) $(export_symbols)
 
 libfontconfig_la_LIBADD = $(FREETYPE_LIBS) $(EXPAT_LIBS)
fontconfig.spec renamed from fontconfig.spec.orig +8 -4
@@ -41,10 +41,13 @@
 # https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=148748
 Patch30: fontconfig-2.2.3-add-sazanami.patch
 
+# Restore SELinux context of the global font cache
+Patch31: fontconfig-2.2.3-selinux_restore.patch
+
 BuildRequires: freetype-devel >= %{freetype_version}
 BuildRequires: expat-devel
 BuildRequires: perl
-# For nodocs patch
+BuildRequires: /usr/bin/autoconf
 BuildRequires: /usr/bin/automake-1.7
 
 PreReq: freetype >= %{freetype_version}
@@ -86,15 +89,16 @@
 
 %patch30 -p1 -b .sazanami
 
+%patch31 -p1 -b .selinux_restore
+
 %if %{disable_docs}
 %patch14 -p1 -b .nodocs
 %endif
 
 %build
-
-%if %{disable_docs}
+autoconf
 automake-1.7
-%endif
+autoheader
 
 %configure --with-add-fonts=/usr/X11R6/lib/X11/fonts/Type1,/usr/X11R6/lib/X11/fonts/OTF
 make
configure.in +11 -0
diff -aur libgnome-2.10.0.orig/configure.in libgnome-2.10.0/configure.in
@@ -94,6 +94,17 @@
 
 GNOME_COMPILE_WARNINGS
 
+dnl Checks for SELinux
+AC_CHECK_LIB(selinux, security_switch_context, have_switch_context=yes)
+AC_CHECK_HEADER(selinux/selinux.h, have_selinux_h=yes)
+if test "x$have_switch_context" = "xyes" && test "x$have_selinux_h" = "xyes"; then
+  AC_DEFINE([WITH_SELINUX], 1, [define to enable SELinux support])
+  SELINUX_CFLAGS="-I/usr/include/selinux"
+  SELINUX_LDFLAGS="-lselinux"
+fi
+AC_SUBST(SELINUX_LDFLAGS)
+AC_SUBST(SELINUX_CFLAGS)
+
 dnl Define GNOME_ENABLE_DEBUG if the --enable-debug switch was given.
 GNOME_DEBUG_CHECK
 
libgnome/gnome-init.c +24 -0
diff -aur libgnome-2.10.0.orig/libgnome/gnome-init.c libgnome-2.10.0/libgnome/gnome-init.c
@@ -53,6 +53,10 @@
 
 #include <libgnomevfs/gnome-vfs-init.h>
 
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+#endif
+
 /*****************************************************************************
  * bonobo
  *****************************************************************************/
@@ -266,6 +270,9 @@
 {
 	char *safe_pathname;
 	int len, ret;
+#ifdef WITH_SELINUX
+	security_context_t prev_ctx = NULL;
+#endif
 	
 	safe_pathname = g_strdup (pathname);
 	len = strlen (safe_pathname);
@@ -273,8 +280,25 @@
 	if (len > 1 && safe_pathname[len - 1] == '/')
 		safe_pathname[len - 1] = '\0';
 
+#ifdef WITH_SELINUX
+	if (is_selinux_enabled()) {
+		prev_ctx = security_switch_context(pathname, mode);
+
+		if ((prev_ctx == NULL) && security_getenforce()) {
+			ret = -1;	
+			goto exit;
+		}
+        }
+#endif
 	ret = mkdir (safe_pathname, mode);
 
+	exit:
+#ifdef WITH_SELINUX
+	if (prev_ctx != NULL) {
+		setfscreatecon(prev_ctx);
+		freecon(prev_ctx);
+	}
+#endif
 	g_free (safe_pathname);
 
 	return ret;
libgnome/Makefile.am +2 -0
diff -aur libgnome-2.10.0.orig/libgnome/Makefile.am libgnome-2.10.0/libgnome/Makefile.am
@@ -17,6 +17,7 @@
 	-I$(srcdir)/..						\
 	$(WARN_CFLAGS)						\
 	$(LIBGNOME_CFLAGS)					\
+	$(SELINUX_CFLAGS)					\
 	-DG_DISABLE_DEPRECATED					\
 	-DLIBGNOME_PREFIX=\""$(prefix)"\"			\
 	-DLIBGNOME_LIBDIR=\""$(libdir)"\"			\
@@ -129,6 +130,7 @@
 	parse-path.cP
 
 libgnome_2_la_LDFLAGS = \
+	$(SELINUX_LDFLAGS)	\
 	-version-info $(LIBGNOME_CURRENT):$(LIBGNOME_REVISION):$(LIBGNOME_AGE) \
 	-no-undefined \
 	-export-symbols-regex "^[^_].*"
libgnome.spec renamed from libgnome.spec.orig +8 -0
@@ -6,6 +6,7 @@
 %define gnome_vfs2_version 2.5.3
 %define orbit2_version 2.5.1
 %define esound_version 0.2.27
+%define automake17_version 1.7.9
 
 %define po_package libgnome-2.0
 
@@ -41,6 +42,8 @@
 BuildRequires:  libxslt-devel >= %{libxslt_version}
 BuildRequires:  intltool
 BuildRequires: gtk-doc
+BuildRequires: autoconf
+BuildRequires: automake17 >= %{automake17_version}
 
 Patch0: libgnome-2.7.2-default-gtk-theme.patch
 Patch1: libgnome-2.7.2-default-background.patch
@@ -50,6 +53,7 @@
 Patch5: libgnome-2.8.0-default-browser.patch
 Patch6: libgnome-2.8.0-stat-homedir.patch
 Patch7: libgnome-2.9.1-popt.patch
+Patch8: libgnome-2.10.0-selinux_restore.patch
 
 # Added to avoid the warning messages about utmp group, bug #24171
 # fixme, just libzvt?
@@ -103,8 +107,12 @@
 %patch5 -p1 -b .default-browser
 %patch6 -p1 -b .stat-homedir
 %patch7 -p1 -b .popt
+%patch8 -p1 -b .selinux_restore
 
 %build
+autoconf
+automake-1.7
+autoheader
 intltoolize -f
 %configure --enable-gtk-doc
 # Having strange problems adding it to CFLAGS. Oh well.
include/selinux/selinux.h +7 -0
diff -Naur libselinux-1.23.10.orig/include/selinux/selinux.h libselinux-1.23.10/include/selinux/selinux.h
@@ -307,6 +307,13 @@
    be relabeled . */
 extern int is_context_customizable (security_context_t scontext);
 
+
+/* Performs a context match (matchpathcon), and changes the file creation  
+ * context. On success, returns the old context. On failure, returns NULL.
+ * The context returned must be freed with freecon() */
+
+extern security_context_t security_switch_context(const char *pathname, mode_t mode);
+
 #ifdef __cplusplus
 }
 #endif
src/switch_context.c +27 -0
diff -Naur libselinux-1.23.10.orig/src/switch_context.c libselinux-1.23.10/src/switch_context.c
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include <sys/types.h>
+#include <selinux/selinux.h>
+
+security_context_t security_switch_context(const char* pathname, mode_t mode) {
+	security_context_t prev_ctx = NULL;
+	security_context_t tmp_ctx = NULL;
+
+	/* Attempt to get the current context. */
+	if (getfscreatecon(&prev_ctx) < 0)
+		return NULL;
+
+	/* Attempt a match. */
+	if (matchpathcon(pathname, mode, &tmp_ctx) >= 0) {
+
+		/* Successful match - switch context */
+		if (setfscreatecon(tmp_ctx) < 0) {
+			freecon(tmp_ctx);
+			freecon(prev_ctx);
+			return NULL;
+		}
+		freecon(tmp_ctx);
+	}
+
+	/* Return old context */
+	return prev_ctx;
+}
libselinux.spec renamed from libselinux.spec.orig +2 -0
@@ -6,6 +6,7 @@
 Group: System Environment/Libraries
 Source: http://www.nsa.gov/selinux/archives/%{name}-%{version}.tgz
 Patch: libselinux-rhat.patch
+Patch1: libselinux-context_restore.patch
 
 BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
 
@@ -36,6 +37,7 @@
 %prep
 %setup -q
 %patch -p1 -b .rhat
+%patch1 -p1 -b .context_restore
 
 %build
 make CFLAGS="-g %{optflags}"
configure.in +11 -0
diff -aur ORBit2-2.12.1.orig/configure.in ORBit2-2.12.1/configure.in
@@ -128,6 +128,17 @@
 AC_SUBST(LOCAL_LINC_LIBS)
 AC_SUBST(LOCAL_LINC_CFLAGS)
 
+dnl Checks for SELinux
+AC_CHECK_LIB(selinux, security_switch_context, have_switch_context=yes)
+AC_CHECK_HEADER(selinux/selinux.h, have_selinux_h=yes)
+if test "x$have_switch_context" = "xyes" && test "x$have_selinux_h" = "xyes"; then
+  AC_DEFINE([WITH_SELINUX], 1, [define to enable SELinux support])
+  SELINUX_CFLAGS="-I/usr/include/selinux"
+  SELINUX_LDFLAGS="-lselinux"
+fi
+AC_SUBST(SELINUX_LDFLAGS)
+AC_SUBST(SELINUX_CFLAGS)
+
 dnl Checks for libraries.
 PKG_CHECK_MODULES(ORBIT, \
 	glib-2.0 >= $GLIB_REQUIRED \
src/orb/GIOP/giop.c +36 -1
diff -aur ORBit2-2.12.1.orig/src/orb/GIOP/giop.c ORBit2-2.12.1/src/orb/GIOP/giop.c
@@ -26,6 +26,10 @@
 #define mkdir(path, mode) _mkdir (path)
 #endif
 
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+#endif
+
 /* FIXME: need to clean this up at shutdown */
 static int      corba_wakeup_fds[2];
 #define WAKEUP_POLL  corba_wakeup_fds [0]
@@ -120,6 +124,37 @@
 	return cur_dir;
 }
 
+/* Performs a standard mkdir call, but restores
+ * the context of the directory being created from
+ * via matchpathcon */
+
+static int
+mkdir_restorecon(const char* pathname, mode_t mode) {
+	int status;
+
+#ifdef WITH_SELINUX
+	security_context_t prev_ctx = NULL;
+
+	if (is_selinux_enabled()) {
+		prev_ctx = security_switch_context(pathname, mode);
+
+		if ((prev_ctx == NULL) && security_getenforce()) 
+			return -1;
+	}
+#endif
+
+	status = mkdir(pathname, mode);
+
+#ifdef WITH_SELINUX
+	if (prev_ctx != NULL) {
+		setfscreatecon(prev_ctx);
+		freecon(prev_ctx);
+	}
+#endif
+	return status;
+}
+
+
 static void
 giop_tmpdir_init (void)
 {
@@ -161,7 +196,7 @@
 				"%s/%s-%4x", tmp_root, dirname, id.b);
 		}
 
-		if (mkdir (newname, 0700) < 0) {
+		if (mkdir_restorecon(newname, 0700) < 0) {
 			switch (errno) {
 			case EACCES:
 				g_error ("I can't write to '%s', ORB init failed",
src/orb/GIOP/Makefile.am +2 -1
diff -aur ORBit2-2.12.1.orig/src/orb/GIOP/Makefile.am ORBit2-2.12.1/src/orb/GIOP/Makefile.am
@@ -6,7 +6,8 @@
 	$(ORBIT_DEBUG_CFLAGS)		\
 	$(DISABLE_DEPRECATED_CFLAGS)	\
 	$(LOCAL_LINC_CFLAGS)		\
-	$(ORBIT_CFLAGS)
+	$(ORBIT_CFLAGS)			\
+	$(SELINUX_CFLAGS)
 
 noinst_LTLIBRARIES=libGIOP.la
 
src/orb/Makefile.am +1 -0
diff -aur ORBit2-2.12.1.orig/src/orb/Makefile.am ORBit2-2.12.1/src/orb/Makefile.am
@@ -20,6 +20,7 @@
 	-version-info $(LT_VERSION)   \
 	-no-undefined		      \
 	$(ORBIT_LIBS)                 \
+	$(SELINUX_LDFLAGS)            \
 	-lpopt
 
 libORBit_2_la_LIBADD= \
ORBit2.spec renamed from ORBit2.spec.orig +7 -0
@@ -14,8 +14,11 @@
 BuildRequires: glib2-devel >= %{glib2_version}
 BuildRequires: pkgconfig >= 0.14
 BuildRequires: gtk-doc >= 1.1
+BuildRequires: autoconf
+BuildRequires: automake17 >= 1.7.9
 
 Patch0: ORBit2-2.12.1-reduce-size-of-io-thread-stack.patch
+Patch1: ORBit2-2.12.1-selinux_restore.patch
 
 %description
 ORBit is a high-performance CORBA (Common Object Request Broker 
@@ -52,8 +55,12 @@
 %setup -q
 
 %patch0 -p1 -b .reduce-size-of-io-thread-stack
+%patch1 -p1 -b .selinux_restore
 
 %build
+autoconf
+automake-1.7
+autoheader
 %configure --enable-gtk-doc
 make
 
#7 lore raw
Quoted 3 lines

I'm really starting to think that this is too ugly, and not an acceptable solution, but I don't have another suggestion at this time.

The fontconfig patch is wrong - does not always restore context...

More significantly, however, how does this scheme work in multithreaded context? It seems like it won't work - the switch-create-restore sequence should not be interruptible if multiple threads share the same creation context...

Signature · 8 lines
Ivan Gyurdiev <[email protected]>
Cornell University


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#8 lore raw
Quoted 4 lines · Ivan Gyurdiev

More significantly, however, how does this scheme work in multithreaded context? It seems like it won't work - the switch-create-restore sequence should not be interruptible if multiple threads share the same creation context...

The issue of multi-threaded apps came up when the SELinux API was overhauled for 2.6 and the original extended operations like mkdir_secure() and execve_secure() were replaced by setfscreatecon() and setexeccon() prior to the normal operation. At that time, it was possible to use them in multi-threaded apps because the fscreate and exec contexts are stored per-kernel-thread, NPTL used a 1:1 user:kernel threading model, and /proc/self referenced the per-thread state. Then, circa 2.6.0-test6, /proc was suddenly changed such that top-level /proc only contains the thread group leaders and /proc/self refers to the thread group leader rather than the per-thread state, and you have to use /proc/self/task/<tid> to access the per-thread state. Thus, at present, any multi-threaded app will encounter a denial upon attempting to use setfscreatecon(3) or setexeccon(3) from a thread other than the thread group leader. In short, the API doesn't presently allow for use by multiple threads, although the implementation could support it (for any threading library that uses a 1:1 user-to-kernel threading model).

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#9 lore raw
Quoted 15 lines

At that time, it was
possible to use them in multi-threaded apps because the fscreate and exec contexts are stored per-kernel-thread, NPTL used a 1:1 user:kernel threading model, and /proc/self referenced the per-thread state. Then, circa 2.6.0-test6, /proc was suddenly changed such that top-level /proc only contains the thread group leaders and /proc/self refers to the thread group leader rather than the per-thread state, and you have to use /proc/self/task/<tid> to access the per-thread state. Thus, at present, any multi-threaded app will encounter a denial upon attempting to use setfscreatecon(3) or setexeccon(3) from a thread other than the thread group leader. In short, the API doesn't presently allow for use by multiple threads, although the implementation could support it (for any threading library that uses a 1:1 user-to-kernel threading model).

So other threads will fail to create the desired file in enforcing mode. This certainly seems like a bad thing...

Would you recommend I go ahead with this setfscreatecon scheme, though?

I don't see any other way to create things in the proper context when you have two (or more) conflicting file_type_auto_trans rules.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#10 lore raw
In reply to Ivan Gyurdiev
Quoted 11 lines · Ivan Gyurdiev

To address those problems, I think I need to add selinux support to a number of applications, and perform the transition in the code. I'm not sure what's the best way to do that. Does adding the following functions to libselinux (or elsewhere) make sense?

int mkdir_restorecon(const char *pathname, mode_t mode); int creat_restorecon(const char *pathname, mode_t mode); int mknod_restorecon(const char *pathname, mode_t mode, dev_t dev);

Those would perform getfscreate/matchpathcon/setfscreate cycle, and would ignore errors in permissive mode.

I'd advise against creating a composite interface like this, as it runs into the same problems that we had with the original SELinux API (which had extended forms of mkdir/creat/mknod/exec), i.e. use of glibc functions that internally use these functions, as you note in a later message. Instead, keep the setting and resetting of the fscreate context as a separate operation, and then let the application continue to use ordinary mkdir/create/mknod or glibc functions for the actual creation.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#11 lore raw
Quoted 6 lines

I'd advise against creating a composite interface like this, as it runs into the same problems that we had with the original SELinux API (which had extended forms of mkdir/creat/mknod/exec), i.e. use of glibc functions that internally use these functions, as you note in a later message.

I agree, that was a bad idea.

Quoted 4 lines

Instead, keep the setting and resetting of the fscreate
context as a separate operation, and then let the application continue to use ordinary mkdir/create/mknod or glibc functions for the actual creation.

Yes, but there's problems with that - in particular:

- is this thread-safe - see my later message

- is this a good idea - it pushes dynamic type changes into various programs, while otherwise it's all in the policy, and easier to analyze

- makes virtually everything depend on libselinux

- I'm replicating the same code pattern in lots of places...

- it puts linux-specific code into otherwise portable apps. I've surrounded it all by WITH_SELINUX, but it's still rather ugly - don't think upstream will like it.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#12 lore raw
Quoted 3 lines · Ivan Gyurdiev

Yes, but there's problems with that - in particular:

- is this thread-safe - see my later message

Answer: Thread-safe, yes. Allowed by current libselinux, no.

Quoted 2 lines

- is this a good idea - it pushes dynamic type changes into various programs, while otherwise it's all in the policy, and easier to analyze

Everything still has to be allowed by the policy, so analysis is still feasible. setfscreatecon() just selects one of the types allowed by the policy for that domain to create. Further, as you are using matchpathcon(3), you can still see the filesystem mapping via file_contexts. Possibly the real question is whether the fine-grained typing is truly justified and/or whether it might be feasible to achieve via relocation so that the parent directory can be the distinguisher.

Quoted 1 line

- makes virtually everything depend on libselinux

Already true, e.g. /sbin/init, coreutils, ...
If it is a real concern, then others have suggested dlopen() and friends. But given that distros have been willing to date to accept fundamental dependency for init and coreutils, it seems unlikely to be needed.

Quoted 1 line

- I'm replicating the same code pattern in lots of places...

True.

Quoted 3 lines

- it puts linux-specific code into otherwise portable apps. I've surrounded it all by WITH_SELINUX, but it's still rather ugly - don't think upstream will like it.

True.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#13 lore raw
In reply to Ivan Gyurdiev
Quoted 29 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ivan Gyurdiev
Sent: Tuesday, May 31, 2005 9:36 AM
To: Stephen Smalley
Cc: [email protected]; [email protected]
Subject: Re: file_type_auto_trans is not sufficient

Quoted 5 lines

I'd advise against creating a composite interface like this, as it runs into the same problems that we had with the original SELinux API (which had extended forms of mkdir/creat/mknod/exec), i.e. use of glibc functions that internally use these functions, as you note in a later message.

I agree, that was a bad idea.

Quoted 4 lines

Instead, keep the setting and resetting of the fscreate
context as a separate operation, and then let the application continue to use ordinary mkdir/create/mknod or glibc functions for the actual creation.

Yes, but there's problems with that - in particular:

- is this thread-safe - see my later message

- is this a good idea - it pushes dynamic type changes into various programs, while otherwise it's all in the policy, and easier to analyze

Quoted 8 lines

- makes virtually everything depend on libselinux

- I'm replicating the same code pattern in lots of places...

- it puts linux-specific code into otherwise portable apps. I've surrounded it all by WITH_SELINUX, but it's still rather ugly - don't think upstream will like it.

The other option, of course, is to change the applications to use/create many more directories, each with a separate type to allow the file_type_auto_trans rules to work. Your orbit example might mean that there is a /tmp/orbit directory where all orbit files are created. This may not be any more feasible, but I think it should at least be considered.

Karl

---
Karl MacMillan
Tresys Technology
http://www.tresys.com
(410) 290-1411 ext 134

Quoted 6 lines

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#14 lore raw
Quoted 5 lines

The other option, of course, is to change the applications to use/create many more directories, each with a separate type to allow the file_type_auto_trans rules to work. Your orbit example might mean that there is a /tmp/orbit directory where all orbit files are created.

The problem is not multiple source domains - that can be addressed through macros. The problem is that those domains use the same directory (Usually /tmp, or /home), for their own purposes, and they need the same transition (same directory and target class (dir/file)).

Because you can have only one transition, this creates a problem.

For example, look at mozilla, using the patches I posted earlier:

Needs transition on :

(ROLE_home_dir_t, file) -> ROLE_untrusted_content_t
when saving web pages
(ROLE_home_dir_t, file) -> ROLE_fonts_cache_t
when updating the font cache (read_fonts macro, libfontconfig)
(ROLE_home_dir_t, dir) -> ROLE_mozilla_home_t
when creating its home directory
(ROLE_home_dir_t, dir) -> ROLE_untrusted_content_t
when saving web pages image data

(tmp_t, file) -> ROLE_untrusted_content_t
when saving temporary files from the internet
(tmp_t, dir) -> ROLE_untrusted_content_t
same problem
(tmp_t, dir) -> ROLE_orbit_tmp_t
when creating the ORBit temp folder, libORBit2 (through bonobo)

Evolution has most of the same problems.

This is most problematic when the creation code is in a shared library, because that gets called from lots of domains, which may use the same container directory/mode pair for their own data.

Earlier we discussed how keeping settings away from content would be a good idea. Still, that wouldn't solve the problem, since then you would have to distinguish between different types of settings, which would all need a transition (and an app may need to use all of them via shared libraries)

You're also suggesting that the problem is with the application, while to me this seems like a SELinux problem. I'm not sure restructuring directories so that they only store homogenous data (labeled the same way) is feasable (or desirable).

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#15 lore raw
Quoted 11 lines

-----Original Message-----
From: Ivan Gyurdiev [mailto:[email protected]]
Sent: Tuesday, May 31, 2005 10:57 AM
To: Karl MacMillan
Cc: 'Stephen Smalley'; [email protected]; [email protected]
Subject: RE: file_type_auto_trans is not sufficient

Quoted 1 line

The other option, of course, is to change the applications to use/create

many

Quoted 1 line

more directories, each with a separate type to allow the

Quoted 9 lines

file_type_auto_trans

Quoted 2 lines

rules to work. Your orbit example might mean that there is a /tmp/orbit directory where all orbit files are created.

The problem is not multiple source domains - that can be addressed through macros. The problem is that those domains use the same directory (Usually /tmp, or /home), for their own purposes, and they need the same transition (same directory and target class (dir/file)).

I know - that is why I am suggesting that each application could use multiple directories. That means that orbit might put files into multiple directories that were previously created, e.g. both /tmp and /tmp/orbit. The net result is the same as making them selinux aware, but without the problem of selinux specific code. It also works fine for multiple threads.

Again, this might mean creating many directory types and forcing directory layouts that upstream / users might not like so it may not be an real option, but technically it would work.

Karl

---
Karl MacMillan
Tresys Technology
http://www.tresys.com
(410) 290-1411 ext 134

Quoted 34 lines

Because you can have only one transition, this creates a problem.

For example, look at mozilla, using the patches I posted earlier:

Needs transition on :

(ROLE_home_dir_t, file) -> ROLE_untrusted_content_t
when saving web pages
(ROLE_home_dir_t, file) -> ROLE_fonts_cache_t
when updating the font cache (read_fonts macro, libfontconfig)
(ROLE_home_dir_t, dir) -> ROLE_mozilla_home_t
when creating its home directory
(ROLE_home_dir_t, dir) -> ROLE_untrusted_content_t
when saving web pages image data

(tmp_t, file) -> ROLE_untrusted_content_t
when saving temporary files from the internet
(tmp_t, dir) -> ROLE_untrusted_content_t
same problem
(tmp_t, dir) -> ROLE_orbit_tmp_t
when creating the ORBit temp folder, libORBit2 (through bonobo)

Evolution has most of the same problems.

This is most problematic when the creation code is in a shared library, because that gets called from lots of domains, which may use the same container directory/mode pair for their own data.

Earlier we discussed how keeping settings away from content would be a good idea. Still, that wouldn't solve the problem, since then you would have to distinguish between different types of settings, which would all need a transition (and an app may need to use all of them via shared libraries)

Quoted 4 lines

You're also suggesting that the problem is with the application, while to me this seems like a SELinux problem. I'm not sure restructuring directories so that they only store homogenous data (labeled the same way) is feasable (or desirable).

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#16 lore raw
Quoted 4 lines

I know - that is why I am suggesting that each application could use multiple directories. That means that orbit might put files into multiple directories that were previously created, e.g. both /tmp and /tmp/orbit.

I am not following this - can you give an example.

Say you have an application such as gconf, which stores its data in /tmp/gconfd-$USER (so it needs to be able to create that). GConf is linked to libORBit2, hence it needs to be able to create /tmp/orbit-$USER.

Running gconfd in an individual domain is possible (and that's exactly what I've done). Running orbit in its domain does not work (at least not without a dynamic transition), because it's library code.

Are you saying that either gconfd or orbit need to move their files outside their designated directory and into /tmp?

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#17 lore raw
Quoted 7 lines · Ivan Gyurdiev

I am not following this - can you give an example.

Say you have an application such as gconf, which stores its data in /tmp/gconfd-$USER (so it needs to be able to create that). GConf is linked to libORBit2, hence it needs to be able to create /tmp/orbit-$USER.

Quoted 6 lines

Running gconfd in an individual domain is possible (and that's exactly what I've done). Running orbit in its domain does not work (at least not without a dynamic transition), because it's library code.

Are you saying that either gconfd or orbit need to move their files outside their designated directory and into /tmp?

Problem is that they both want to create directly in /tmp. It would be preferable if they had a dedicated subtree, e.g. /tmp/gconfd and /tmp/orbit, with all per-user subdirectories underneath, so that the top-level directory could be typed separately and set up a priori (at boot if truly under /tmp, as they might otherwise have been deleted). BTW, what will per-user /tmp directories due to these conventions anyway, even aside from any possible SELinux-related change?

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#18 lore raw
Quoted 6 lines

Problem is that they both want to create directly in /tmp. It would be preferable if they had a dedicated subtree, e.g. /tmp/gconfd and /tmp/orbit, with all per-user subdirectories underneath, so that the top-level directory could be typed separately and set up a priori (at boot if truly under /tmp, as they might otherwise have been deleted).

So you're saying that the directories should be created ahead of time by a startup script, and restorecon executed on them... something like tmpskel? Maybe that can be used for libICE, which I want to label /tmp/.ICE-unix as ice_tmp_t.

What about /home, which has the same problem, but directories can't be created ahead of time (adding to /skel doesn't work - if an application is installed, the users created prior to installation have no folder).

What about file conflicts - then you can't create directories ahead of time...

Quoted 2 lines

BTW, what will per-user /tmp directories due to these conventions anyway, even aside from any possible SELinux-related change?

What's the question again?

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#19 lore raw
Quoted 4 lines · Ivan Gyurdiev
Quoted 2 lines

BTW, what will per-user /tmp directories due to these conventions anyway, even aside from any possible SELinux-related change?

What's the question again?

If Fedora implements private tmp directories (regardless of approach, whether using namespaces and bind mounts ala polyinstantiated directories or using the simple profile script suggested on fedora- devel-list), then creating $TMPDIR/gconfd-$USER becomes rather silly, as $TMPDIR becomes per-user anyway.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#20 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 4 lines · Ivan Gyurdiev
Quoted 2 lines

BTW, what will per-user /tmp directories due to these conventions anyway, even aside from any possible SELinux-related change?

What's the question again?

If Fedora implements private tmp directories (regardless of approach, whether using namespaces and bind mounts ala polyinstantiated directories or using the simple profile script suggested on fedora- devel-list), then creating $TMPDIR/gconfd-$USER becomes rather silly, as $TMPDIR becomes per-user anyway.

That's true... but something still needs to create those directories (with our without the USER in it). If they're not created ahead of time then you run into transition ambiguity.

I suppose they could be created ahead of time:

- on-boot script for creating those "common-root" directories in /tmp, based on what applications are currently installed (...need apps to put folders in this "tmpskel")

- applications could add /home/.* folders for users that already exist when installed, and at the same time install their folder in /skel to deal with future users. All of this seems rather fragile though.

- files: move into directories to eliminate the problem.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#21 lore raw
In reply to Ivan Gyurdiev
Quoted 11 lines · Ivan Gyurdiev
Quoted 6 lines

Problem is that they both want to create directly in /tmp. It would be preferable if they had a dedicated subtree, e.g. /tmp/gconfd and /tmp/orbit, with all per-user subdirectories underneath, so that the top-level directory could be typed separately and set up a priori (at boot if truly under /tmp, as they might otherwise have been deleted).

So you're saying that the directories should be created ahead of time by a startup script, and restorecon executed on them... something like tmpskel? Maybe that can be used for libICE, which I want to label /tmp/.ICE-unix as ice_tmp_t.

there is a whole slew of legacy applications that assume access to /tmp/.ICE-unix, /tmp/.X11-unix etc.

it's a known problem for which the solution - creating tmp subdirectories - has been "scheduled" / "shelved".

l.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#22 lore raw
In reply to Ivan Gyurdiev
Quoted 12 lines · Ivan Gyurdiev
Quoted 4 lines

I know - that is why I am suggesting that each application could use multiple directories. That means that orbit might put files into multiple directories that were previously created, e.g. both /tmp and /tmp/orbit.

I am not following this - can you give an example.

Say you have an application such as gconf, which stores its data in /tmp/gconfd-$USER (so it needs to be able to create that). GConf is linked to libORBit2, hence it needs to be able to create /tmp/orbit-$USER.

Quoted 6 lines

Running gconfd in an individual domain is possible (and that's exactly what I've done). Running orbit in its domain does not work (at least not without a dynamic transition), because it's library code.

Are you saying that either gconfd or orbit need to move their files outside their designated directory and into /tmp?

into /tmp/gconfd/something-$USER.

yep.

maybe the way forward is to create a [tiny] library with two functions in it: one that creates /tmp/socket and another that opens it, convert all programs to use that library, then convert the library to create /tmp/dir/socket.

l.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#23 lore raw
In reply to Ivan Gyurdiev
Quoted 6 lines · Ivan Gyurdiev
Quoted 5 lines

The other option, of course, is to change the applications to use/create many more directories, each with a separate type to allow the file_type_auto_trans rules to work. Your orbit example might mean that there is a /tmp/orbit directory where all orbit files are created.

Quoted 6 lines

The problem is not multiple source domains - that can be addressed through macros. The problem is that those domains use the same directory (Usually /tmp, or /home), for their own purposes, and they need the same transition (same directory and target class (dir/file)).

Because you can have only one transition, this creates a problem.

...

thinking "sideways" again - as i am wont to do.

how about... a "sideways" solution to this - at the kernel level?

a "silent" redirection / remount, on a per-application basis?

no, i'm not joking.

an option to "mount" which allows a specific APPLICATION (or group of applications) to have any files/directories it creates/accesses in a subdirectory ACTUALLY occur ELSEWHERE.

e.g.:

mount -o redirectexe=/usr/bin/mozilla-firefox /tmp /tmp/mozilla mount -o redirectexe=/usr/bin/gnomeshite,/usr/bin/gnomemoreshite /tmp /tmp/gconf

hm, that could get out-of-hand - the number of programs involved that would need redirection..

*thinks* ... some other mechanism for "grouping" executables...

you could even hang it off of an selinux context (!) or selinux domain (!) such that a set of executables, possibly those executed by certain users, would result in filesystem redirection - but not others.

at your own discretion.

then, you _could_ specify /tmp/gconf equals "a different file context".

l.

#24 lore raw
Quoted 53 lines · Luke Kenneth Casson Leighton
Quoted 10 lines · Ivan Gyurdiev
Quoted 9 lines

The other option, of course, is to change the applications to use/create many more directories, each with a separate type to allow the file_type_auto_trans rules to work. Your orbit example might mean that there is a /tmp/orbit directory where all orbit files are created.

Quoted 8 lines

The problem is not multiple source domains - that can be addressed through macros. The problem is that those domains use the same directory (Usually /tmp, or /home), for their own purposes, and they need the same transition (same directory and target class (dir/file)).

Because you can have only one transition, this creates a problem.

...

thinking "sideways" again - as i am wont to do.

how about... a "sideways" solution to this - at the kernel level?

a "silent" redirection / remount, on a per-application basis?

no, i'm not joking.

an option to "mount" which allows a specific APPLICATION (or group of applications) to have any files/directories it creates/accesses in a subdirectory ACTUALLY occur ELSEWHERE.

e.g.:

mount -o redirectexe=/usr/bin/mozilla-firefox /tmp /tmp/mozilla mount -o redirectexe=/usr/bin/gnomeshite,/usr/bin/gnomemoreshite /
tmp /tmp/gconf

hm, that could get out-of-hand - the number of programs involved that would need redirection..

*thinks* ... some other mechanism for "grouping" executables...

you could even hang it off of an selinux context (!) or selinux
domain
(!) such that a set of executables, possibly those executed by certain users, would result in filesystem redirection - but not
others.

Quoted 6 lines

at your own discretion.

then, you _could_ specify /tmp/gconf equals "a different file
context".

Something like this already exists in userspace, though it's not entirely transparent. The polyinsantiation library I posted a couple of weeks ago allows applications to bind mount (in a private namespace) member directories according to policy (type member rules). This is mostly thought of as useful for user separation, but it can separate any types. So, add a short wrapper program to call security_setupns() (from my patch) around mozilla and appropriate policy, and mozilla can have a private /tmp. (note: the wrapper would need to link any important files out of the original /tmp, such as X11 sockfiles).

That said, this doesn't solve Ivan's problem. You still have a single application (gconfd in his example) creating /tmp/gconfd and /tmp/orbit, with only one type transition rule allowed. You can't mount /tmp/gconfd over /tmp for portions of execution, and then /tmp/orbit over /tmp for other parts of execution.

Chad

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#25 lore raw
Quoted 5 lines · Chad Sellers

That said, this doesn't solve Ivan's problem. You still have a single application (gconfd in his example) creating /tmp/gconfd and / tmp/orbit, with only one type transition rule allowed. You can't mount /tmp/gconfd over /tmp for portions of execution, and then /tmp/ orbit over /tmp for other parts of execution.

drat - duh, course you can't.

"transitional" library it is, then.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#26 lore raw
In reply to Luke Kenneth Casson Leighton
Quoted 11 lines · Luke Kenneth Casson Leighton

thinking "sideways" again - as i am wont to do.

how about... a "sideways" solution to this - at the kernel level?

a "silent" redirection / remount, on a per-application basis?

no, i'm not joking.

an option to "mount" which allows a specific APPLICATION (or group of applications) to have any files/directories it creates/accesses in a subdirectory ACTUALLY occur ELSEWHERE.

That's polyinstantiated directories. See Chad Seller's postings. However, it uses the kernel's existing support for per-process namespaces and bind mounts rather than anything new in the kernel.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.