Skip to contentSkip to conversation

Patch to make libsemanage/selinux policy require less space.

PATCH Daniel J Walsh 1 participant 1 message Sep 26, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

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

Currently selinux-policy*rpm install the pp files in /usr/share/selinux/POLICYTYPE/*.pp

Then it calls semodule on them to load the policy. libsemanage copies the policy package files to /etc/selinux/targeted/modules/active, Then it recopies the files to /etc/selinux/targeted/modules/previous, where it finishes the assembly of the files.

So we end up requiring three times as much space as necessary if the modules are not changing.

Policy in Rawhide is 36 megabytes.

So on small devices or even usb sticks and cd's this is a large waste of space. This patch is an attempt to use hard links when we can.

I have not put it in production, since I wanted people who know the library better then me to tell me whether it is a cracked idea.

There is really two ideas in the patch. One is to add interfaces semanage_modules_*_file which take a file instead of a block of memory.
semodule would then be changed to use these interfaces.

The library then calls semanage_link, This function checks to make sure the file countext of the source matches the file context of the destination, if they match, the tool will attempt a link, if either fails the tool will fall back to copy them.

I changed the write_file to unlink the destination file which would remove the linked file if it exists.

semanage_store has been changed, so that the creation of the sandbox is via link, if possible.

Is this a good idea or bad?

Also want to reinvestigate using some form of compression. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkjdEWAACgkQrlYvE4MpobNvEQCgsedSuXz9Igagh3jJF5gja4/U 18sAn0wDWTMjtu5gLrIN/zD/Ox0dk49z
=gtQW
-----END PGP SIGNATURE-----

include/semanage/modules.h +6 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/include/semanage/modules.h libsemanage-2.0.28/include/semanage/modules.h
@@ -30,10 +30,16 @@
 
 int semanage_module_install(semanage_handle_t *,
 			    char *module_data, size_t data_len);
+int semanage_module_install_file(semanage_handle_t *,
+				 const char *module_name);
 int semanage_module_upgrade(semanage_handle_t *,
 			    char *module_data, size_t data_len);
+int semanage_module_upgrade_file(semanage_handle_t *,
+				 const char *module_name);
 int semanage_module_install_base(semanage_handle_t *,
 				 char *module_data, size_t data_len);
+int semanage_module_install_base_file(semanage_handle_t *,
+				      const char *module_name);
 int semanage_module_remove(semanage_handle_t *, char *module_name);
 
 /* semanage_module_info is for getting information on installed
src/direct_api.c +197 -0

245 lines not on this page · raw message

src/libsemanage.map +4 -2
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/libsemanage.map libsemanage-2.0.28/src/libsemanage.map
@@ -3,8 +3,10 @@
           semanage_is_managed; semanage_connect; semanage_disconnect; 
 	  semanage_msg_*;
           semanage_begin_transaction; semanage_commit;
-          semanage_module_install; semanage_module_upgrade;
-	  semanage_module_install_base; semanage_module_remove;
+	  semanage_module_install; semanage_module_install_file;
+	  semanage_module_upgrade; semanage_module_upgrade_file;
+	  semanage_module_install_base; semanage_module_install_base_file;
+	  semanage_module_remove;
 	  semanage_module_list; semanage_module_info_datum_destroy;
 	  semanage_module_list_nth; semanage_module_get_name;
 	  semanage_module_get_version; semanage_select_store;
src/modules.c +57 -0

75 lines not on this page · raw message

src/policy.h +9 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/policy.h libsemanage-2.0.28/src/policy.h
@@ -49,8 +49,14 @@
 	/* Install a policy module */
 	int (*install) (struct semanage_handle *, char *, size_t);
 
+	/* Install a policy module */
+	int (*install_file) (struct semanage_handle *, const char *);
+
 	/* Upgrade a policy module */
 	int (*upgrade) (struct semanage_handle *, char *, size_t);
+	
+	/* Upgrade a policy module */
+	int (*upgrade_file) (struct semanage_handle *, const char *);
 
 	/* Remove a policy module */
 	int (*remove) (struct semanage_handle *, char *);
@@ -61,6 +67,9 @@
 
 	/* Install base policy */
 	int (*install_base) (struct semanage_handle *, char *, size_t);
+
+	/* Install a base module */
+	int (*install_base_file) (struct semanage_handle *, const char *);
 };
 
 /* Should be backend independent */
src/semanage_store.c +2 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/semanage_store.c libsemanage-2.0.28/src/semanage_store.c
@@ -440,6 +440,8 @@
 	char tmp[PATH_MAX];
 	char buf[4192];
 
+	if (link(src,dst) == 0) return 0;
+
 	n = snprintf(tmp, PATH_MAX, "%s.tmp", dst);
 	if (n < 0 || n >= PATH_MAX)
 		return -1;