Skip to contentSkip to conversation

Talking to Nalin today about the path substitution semanage problem, and he came up with a great idea.

PATCH Daniel J Walsh 2 participants 2 messages Mar 6, 2009 SELinux security module

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I was thinking of mangling the file_context file with substitutions, but he suggested that we do the substitution right in matchpathcon (selabel).

This would allow us to save hundreds of regular expressions and eliminate some heavy coding in semanage.

Here is a patch to libselinux that will read the

/etc/selinux/targeted/contexts/files/file_contexts.subs Looking for space separated names like

/myweb /var/www
/myspool /var/spool/mail

When matchpatchcon or selabel gets handed a path, like /myweb/index.html

the code looks through the list of subsitutions and switches out /myweb for /var/www

It hands the underlying code /var/www/index.html and gets the correct match.

With this type of functionality we can either get rid of genhomedircon or allow it to just generate subs files that look like

/export/home /home
/usr/local/home /home

This has a side benefit of decreasing the size of regexs we need to compile.

I think there is little to no costs. Other the strcmp on all paths handed in times the number of substitutions.

What do you think?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkmxijAACgkQrlYvE4MpobOJwwCglpslipw2U+wpy+vvryjgVpPX JK0AoNlBwM8SrgGyev7ZDZasuNpZU8d/
=R3fm
-----END PGP SIGNATURE-----

include/selinux/selinux.h +1 -0
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/selinux.h libselinux-2.0.78/include/selinux/selinux.h
@@ -457,6 +457,7 @@
 extern const char *selinux_file_context_path(void);
 extern const char *selinux_file_context_homedir_path(void);
 extern const char *selinux_file_context_local_path(void);
+extern const char *selinux_file_context_subs_path(void);
 extern const char *selinux_homedir_context_path(void);
 extern const char *selinux_media_context_path(void);
 extern const char *selinux_x_context_path(void);
src/file_path_suffixes.h +1 -0
diff --exclude-from=exclude -N -u -r nsalibselinux/src/file_path_suffixes.h libselinux-2.0.78/src/file_path_suffixes.h
@@ -20,3 +20,4 @@
     S_(FILE_CONTEXTS_LOCAL, "/contexts/files/file_contexts.local")
     S_(X_CONTEXTS, "/contexts/x_contexts")
     S_(COLORS, "/secolor.conf")
+    S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")
src/label.c +104 -1

139 lines not on this page · raw message

src/selinux_config.c +9 -1
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_config.c libselinux-2.0.78/src/selinux_config.c
@@ -40,7 +40,8 @@
 #define SECURETTY_TYPES   18
 #define X_CONTEXTS        19
 #define COLORS            20
-#define NEL               21
+#define FILE_CONTEXT_SUBS 21
+#define NEL               22
 
 /* New layout is relative to SELINUXDIR/policytype. */
 static char *file_paths[NEL];
@@ -391,3 +392,10 @@
 }
 
 hidden_def(selinux_x_context_path)
+
+const char * selinux_file_context_subs_path(void) {
+	return get_path(FILE_CONTEXT_SUBS);
+}
+
+hidden_def(selinux_file_context_subs_path)
+
src/selinux_internal.h +1 -0
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_internal.h libselinux-2.0.78/src/selinux_internal.h
@@ -59,6 +59,7 @@
     hidden_proto(selinux_file_context_path)
     hidden_proto(selinux_file_context_homedir_path)
     hidden_proto(selinux_file_context_local_path)
+    hidden_proto(selinux_file_context_subs_path)
     hidden_proto(selinux_netfilter_context_path)
     hidden_proto(selinux_homedir_context_path)
     hidden_proto(selinux_user_contexts_path)
#1 lore raw
Quoted 6 lines · Daniel J Walsh

With this type of functionality we can either get rid of genhomedircon or allow it to just generate subs files that look like

/export/home /home
/usr/local/home /home

Quoted 7 lines

This has a side benefit of decreasing the size of regexs we need to compile.

I think there is little to no costs.  Other the strcmp on all paths handed in times the number of substitutions.

What do you think?

Sounds OK apart from the fact that it doesn't set the identity.

What if you had an optional third field to store the identity for mapping individual users?

Also what are the plans regarding roles nowadays? Is there still a plan to use roles other than object_r in filesystem labels?

Signature · 9 lines
[email protected]
http://etbe.coker.com.au/          My Main Blog
http://doc.coker.com.au/           My Documents Blog


--
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.