Skip to contentSkip to conversation

Optional rebuild

SEMANAGE Ivan Gyurdiev 2 participants 3 messages Dec 23, 2005 – Jan 2, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

This patch uses the modified flags to skip a rebuild whenever possible.
It also adds the active boolean header to semanage.h (which I missed because of diff excludes). It will now commit changes to the active booleans, so if no policy changes are done (modified = 0), or changes are done, but preservebools is enabled (which it is, by default), then changes to active booleans in the transaction will work as expected, and will not be overwritten by policy booleans.

This is also an optimization - allows running commit without rebuilding the policy, which could be beneficial for read-only operations using a transaction - it also seems more correct, because a read-only operation should not alter the state of the system - commit should not apply any changes that weren't explicit.

Note that semodule -B with no arguments will break, because now the build will be skipped. I haven't fixed it yet, but I've added an interface for that purpose - semanage_do_rebuild, to parallel semanage_do_reload (but the default in this new function is 0 - no rebuilds if no changes).

libsemanage/include/semanage/handle.h +5 -0
diff -Naurp --exclude-from excludes old/libsemanage/include/semanage/handle.h new/libsemanage/include/semanage/handle.h
@@ -59,6 +59,11 @@ int semanage_reload_policy(semanage_hand
  * 1 for yes (default), 0 for no */
 void semanage_set_reload(semanage_handle_t *handle, int do_reload);
 
+/* set whether to rebuild the policy on commit, even if no
+ * changes were performed.
+ * 1 for yes, 0 for no (default) */
+void semanage_set_rebuild(semanage_handle_t *handle, int do_rebuild);
+
 /* Check whether policy is managed via libsemanage on this system.
  * Must be called prior to trying to connect.
  * Return 1 if policy is managed via libsemanage on this system,
libsemanage/include/semanage/semanage.h +1 -0
diff -Naurp --exclude-from excludes old/libsemanage/include/semanage/semanage.h new/libsemanage/include/semanage/semanage.h
@@ -39,6 +39,7 @@
 /* Dbase */
 #include <semanage/booleans_local.h>
 #include <semanage/booleans_policy.h>
+#include <semanage/booleans_active.h>
 #include <semanage/users_local.h>
 #include <semanage/users_policy.h>
 #include <semanage/seusers.h>
libsemanage/src/direct_api.c +46 -27

83 lines not on this page · raw message

libsemanage/src/handle.c +12 -0
diff -Naurp --exclude-from excludes old/libsemanage/src/handle.c new/libsemanage/src/handle.c
@@ -57,6 +57,10 @@ semanage_handle_t *semanage_handle_creat
 		goto err;
 	sepol_msg_set_callback(sh->sepolh, semanage_msg_relay_handler, sh);
 
+	/* By default do not rebuild the policy on commit
+	 * If any changes are made, this flag is ignored */
+	sh->do_rebuild = 0;
+
 	/* By default always reload policy after commit if SELinux is enabled. */
 	sh->do_reload = (is_selinux_enabled() > 0);
 
@@ -74,6 +78,14 @@ semanage_handle_t *semanage_handle_creat
 	return NULL;
 }
 
+void semanage_set_rebuild(semanage_handle_t *sh, int do_rebuild) {
+
+	assert(sh != NULL);
+
+	sh->do_rebuild = do_rebuild;
+	return;
+}
+
 void semanage_set_reload(semanage_handle_t *sh, int do_reload) {
 	
 	assert(sh != NULL);
libsemanage/src/handle.h +1 -0
diff -Naurp --exclude-from excludes old/libsemanage/src/handle.h new/libsemanage/src/handle.h
@@ -62,6 +62,7 @@ struct semanage_handle {
 	int is_connected;
 	int is_in_transaction;
 	int do_reload;		/* whether to reload policy after commit */
+	int do_rebuild;		/* whether to rebuild policy if there were no changes */
 	int modules_modified;
 
 	/* This timeout is used for transactions and waiting for lock
libsemanage/src/libsemanage.map +1 -1
diff -Naurp --exclude-from excludes old/libsemanage/src/libsemanage.map new/libsemanage/src/libsemanage.map
@@ -8,7 +8,7 @@ LIBSEMANAGE_1.0 {
 	  semanage_module_list; semanage_module_info_datum_destroy;
 	  semanage_module_list_nth; semanage_module_get_name;
 	  semanage_module_get_version; semanage_select_store;
-	  semanage_reload_policy; semanage_set_reload;
+	  semanage_reload_policy; semanage_set_reload; semanage_set_rebuild;
 	  semanage_user_*; semanage_bool_*; semanage_seuser_*;
 	  semanage_iface_*; semanage_context_*;
   local: *;
libsemanage/src/policy_components.c +3 -2
diff -Naurp --exclude-from excludes old/libsemanage/src/policy_components.c new/libsemanage/src/policy_components.c
@@ -188,7 +188,8 @@ int semanage_commit_components(
 		semanage_bool_dbase_local(handle),
 		semanage_user_dbase_local(handle),
 		/* semanage_port_dbase_local(handle), */
-		semanage_seuser_dbase(handle)
+		semanage_seuser_dbase(handle),
+		semanage_bool_dbase_active(handle),
 	};
 	const int CCOUNT = sizeof(components)/sizeof(components[0]);
 
@@ -207,7 +208,7 @@ int semanage_commit_components(
 	return STATUS_SUCCESS;
 
 	err:
-	ERR(handle, "could not commit local modifications");
+	ERR(handle, "could not commit local/active modifications");
 
 	for (i=0; i < CCOUNT; i++) 
 		components[i]->dtable->drop_cache(components[i]->dbase);
#1 lore raw
Quoted 5 lines · Ivan Gyurdiev

This patch uses the modified flags to skip a rebuild whenever possible.
It also adds the active boolean header to semanage.h (which I missed because of diff excludes). It will now commit changes to the active booleans, so if no policy changes are done (modified = 0), or changes are done, but preservebools is enabled (which it is, by default), then changes to active booleans in the transaction will work as expected, and will not be overwritten by policy booleans.

I'm not sure I understand this. If preservebools is enabled the policy must be rebuilt. Looking at the patch it looks like you do rebuild when persistent booleans are changed though.

Quoted 2 lines

This is also an optimization - allows running commit without rebuilding the policy, which could be beneficial for read-only operations using a transaction - it also seems more correct, because a read-only operation should not alter the state of the system - commit should not apply any changes that weren't explicit.

A commit is by definition a write operation. The user is responsible for
not committing if there aren't any changes.

Quoted 3 lines

Note that semodule -B with no arguments will break, because now the build will be skipped. I haven't fixed it yet, but I've added an interface for that purpose - semanage_do_rebuild, to parallel semanage_do_reload (but the default in this new function is 0 - no rebuilds if no changes).

I see that you already sent this patch but it's better not to break things with the intention of fixing them later.

--
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 8 lines
Quoted 6 lines

This patch uses the modified flags to skip a rebuild whenever possible.
It also adds the active boolean header to semanage.h (which I missed because of diff excludes). It will now commit changes to the active booleans, so if no policy changes are done (modified = 0), or changes are done, but preservebools is enabled (which it is, by default), then changes to active booleans in the transaction will work as expected, and will not be overwritten by policy booleans.

I'm not sure I understand this. If preservebools is enabled the policy must be rebuilt. Looking at the patch it looks like you do rebuild when persistent booleans are changed though.

I'm confused. Here's what the patch does - normally if you commit, you will always rebuild policy, and in certain cases, depending on preservebools that will cause any changes to active booleans to be overwritten (by the booleans in policy). So, if you want to change active booleans in a transaction, they might get overwritten for no reason. After the patch, if you commit you will only rebuild if necessary (if something affectng policy was changed). This means that you can have a transaction that changes a bunch of (active) booleans, then does a commit, and everything works as expected.

I guess that if you decide to add a bunch of users, and preservebools = 0, and then add some active booleans, and then commit that still wouldn't work, because a rebuild would be forced, and policy booleans would take precedence to active boolean changes.

Quoted 4 lines
Quoted 2 lines

This is also an optimization - allows running commit without rebuilding the policy, which could be beneficial for read-only operations using a transaction - it also seems more correct, because a read-only operation should not alter the state of the system - commit should not apply any changes that weren't explicit.

A commit is by definition a write operation. The user is responsible for not committing if there aren't any changes.

I disagree - I think it's the other way around. If there aren't any changes, then commit should have no effect. If you do writes on commit that the user didn't request, that seems broken to me - all changes should be initiated by the user. A commit flushes those changes, and should have as few side effects as possible. Anyway, I don't see why we shouldn't make things a bit faster if we can.

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