Skip to contentSkip to conversation

Further users cleanup

SEPOL Ivan Gyurdiev 2 participants 9 messages Oct 21, 2005 – Oct 25, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

- remove select/kill/clear_unused things (will only be used in genusers)
- remove delete (all changes will be additive for now, through semanage)

- move delusers things into genusers.c
- move genusers/genbools prototypes from sepol.h into their respective headers

- map: remove sepol_clear_unused_users
- map: remove duplicate sepol_set_delusers (it's in there twice)

libsepol/include/sepol/booleans.h +22 -0
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policy_components.c --exclude '*_record.c' --exclude '*_record.h' --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/booleans.h new/libsepol/include/sepol/booleans.h
@@ -5,6 +5,28 @@
 #include <sepol/policydb.h>
 #include <sepol/boolean_record.h>
 
+/*--------------compatibility--------------*/
+
+/* Given an existing binary policy (starting at 'data', with length 'len')
+   and a boolean configuration file named by 'boolpath', rewrite the binary
+   policy for the boolean settings in the boolean configuration file.
+   The binary policy is rewritten in place in memory.
+   Returns 0 upon success, or -1 otherwise. */
+extern int sepol_genbools(
+	void *data, size_t len, 
+	char *boolpath);
+
+/* Given an existing binary policy (starting at 'data', with length 'len')
+   and boolean settings specified by the parallel arrays ('names', 'values')
+   with 'nel' elements, rewrite the binary policy for the boolean settings.
+   The binary policy is rewritten in place in memory.
+   Returns 0 upon success or -1 otherwise. */
+extern int sepol_genbools_array(
+	void *data, size_t len, 
+	char **names, int *values, 
+	int nel);
+/*---------------end compatbility------------*/
+
 /* Load a boolean into the policy */
 extern int sepol_bool_load (
 	sepol_policydb_t* policydb, 
libsepol/include/sepol/sepol.h +0 -27
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policy_components.c --exclude '*_record.c' --exclude '*_record.h' --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/sepol.h new/libsepol/include/sepol/sepol.h
@@ -19,33 +19,6 @@
 #include <sepol/policydb.h>
 #include <sepol/module.h>
 
-/* Given an existing binary policy (starting at 'data', with length 'len')
-   and a boolean configuration file named by 'boolpath', rewrite the binary
-   policy for the boolean settings in the boolean configuration file.
-   The binary policy is rewritten in place in memory.
-   Returns 0 upon success, or -1 otherwise. */
-extern int sepol_genbools(void *data, size_t len, char *boolpath);
-
-/* Given an existing binary policy (starting at 'data', with length 'len')
-   and boolean settings specified by the parallel arrays ('names', 'values')
-   with 'nel' elements, rewrite the binary policy for the boolean settings.  
-   The binary policy is rewritten in place in memory.
-   Returns 0 upon success or -1 otherwise. */
-extern int sepol_genbools_array(void *data, size_t len, char **names, int *values, int nel);
-
-/* Given an existing binary policy (starting at 'data with length 'len')
-   and user configurations living in 'usersdir', generate a new binary
-   policy for the new user configurations.  Sets '*newdata' and '*newlen'
-   to refer to the new binary policy image. */
-extern int sepol_genusers(void *data, size_t len,
-			  const char *usersdir,
-			  void **newdata, size_t *newlen);
-
-/* Enable or disable deletion of users by sepol_genusers(3) when
-   a user in original binary policy image is not defined by the
-   new user configurations.  Defaults to disabled. */
-extern void sepol_set_delusers(int on);
-
 /* Set internal policydb from a file for subsequent service calls. */
 extern int sepol_set_policydb_from_file(FILE *fp);
 
libsepol/include/sepol/users.h +16 -7
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policy_components.c --exclude '*_record.c' --exclude '*_record.h' --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/include/sepol/users.h new/libsepol/include/sepol/users.h
@@ -5,14 +5,23 @@
 #include <sepol/user_record.h>
 #include <stddef.h>
 
-/* Clear unused users */
-extern void sepol_clear_unused_users(
-	sepol_policydb_t* policydb);
+/*---------compatibility------------*/
 
-/* Delete the user */
-extern int sepol_user_del(
-	sepol_policydb_t* policydb, 
-	const char *username);
+/* Given an existing binary policy (starting at 'data with length 'len')
+   and user configurations living in 'usersdir', generate a new binary
+   policy for the new user configurations.  Sets '*newdata' and '*newlen'
+   to refer to the new binary policy image. */
+extern int sepol_genusers(
+	void *data, size_t len,
+	const char *usersdir,
+	void **newdata, size_t *newlen);
+
+/* Enable or disable deletion of users by sepol_genusers(3) when
+   a user in original binary policy image is not defined by the
+   new user configurations.  Defaults to disabled. */
+extern void sepol_set_delusers(int on);
+
+/*--------end compatibility----------*/
 
 /* Add the user if missing, or modify otherwise */
 extern int sepol_user_modify(
libsepol/src/genusers.c +5 -1
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policy_components.c --exclude '*_record.c' --exclude '*_record.h' --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/src/genusers.c new/libsepol/src/genusers.c
@@ -12,7 +12,11 @@
 #include "debug.h"
 #include "private.h"
 
-extern int selinux_delusers;
+int selinux_delusers = 0;
+
+void sepol_set_delusers(int on) {
+	selinux_delusers = on;
+}
 
 #undef BADLINE
 #define BADLINE() { \
libsepol/src/libsepol.map +2 -2
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude policy_components.c --exclude '*_record.c' --exclude '*_record.h' --exclude libsemanage.map --exclude 'module_record*' --exclude 'database_directory*' old/libsepol/src/libsepol.map new/libsepol/src/libsepol.map
@@ -1,6 +1,6 @@
 {
   global: 
-	sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers; sepol_debug; sepol_set_delusers;
+	sepol_genbools*; sepol_set_policydb_from_file; sepol_check_context; sepol_genusers; sepol_debug; 
 	sepol_policy_file_create; sepol_policy_file_free;
 	sepol_policy_file_set_mem; sepol_policy_file_set_fp;
 	sepol_policy_file_get_len; sepol_policy_file_set_handle;
@@ -19,7 +19,7 @@
 	sepol_module_package_write; 
 	sepol_link_modules; sepol_expand_module;
 	sepol_bool*; sepol_context*;
-	sepol_iface*; sepol_port*; sepol_user*; sepol_clear_unused_users;
+	sepol_iface*; sepol_port*; sepol_user*; 
 	sepol_set_delusers;
 	sepol_msg_*; sepol_handle_*;
   local: *;
libsepol/src/users.c +1 -108

119 lines not on this page · raw message

#1 lore raw
Quoted 9 lines · Ivan Gyurdiev

- remove select/kill/clear_unused things (will only be used in genusers)
- remove delete (all changes will be additive for now, through semanage)

- move delusers things into genusers.c
- move genusers/genbools prototypes from sepol.h into their respective headers

- map: remove sepol_clear_unused_users
- map: remove duplicate sepol_set_delusers (it's in there twice)

Ok. Note that we'll likely want to remove all wildcards from the map files (for both libsepol and libsemanage) and explicitly list all interfaces we want exported to avoid surprises, or at least check that we aren't exporting anything accidentally.
nm src/libsepol.so.1 | grep ' T ' shows some interfaces that shouldn't really be public at present.

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.
#2 lore raw
Quoted 7 lines

Ok. Note that we'll likely want to remove all wildcards from the map
files (for both libsepol and libsemanage) and explicitly list all
interfaces we want exported to avoid surprises, or at least check that
we aren't exporting anything accidentally. nm src/libsepol.so.1 | grep ' T ' shows some interfaces that shouldn't really be public at present.

Which ones? I tend to not prefix local things with sepol...

--
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 8 lines · Ivan Gyurdiev
Quoted 7 lines

Ok. Note that we'll likely want to remove all wildcards from the map files (for both libsepol and libsemanage) and explicitly list all interfaces we want exported to avoid surprises, or at least check that we aren't exporting anything accidentally.
nm src/libsepol.so.1 | grep ' T ' shows some interfaces that shouldn't really be public at present.

Which ones? I tend to not prefix local things with sepol...

The services.c functions also had sepol_ prefixes added when audit2why was created (it uses the static libsepol, but also uses libselinux, and libselinux has similar functions that interact with the kernel policy rather than a policy file/image). Hence, we get symbols like sepol_context_to_sid and sepol_port_sid exported by the wildcards. Also, one exported symbol that was pre-existing was sepol_genbools_policydb, which was likewise created for audit2why and accidentally exported by the wildcard there, but as there should be no other users and it was never put into the "public" header, it likely does no harm to correct it now to only export genbools and genbools_array.

Also need to fix this:

$ relinfo.pl src/libsepol.so.1
src/libsepol.so.1: 68 relocations, 61 relative (89%), 94 PLT entries, 60 for local syms (63%), 0 users

There shouldn't be any for local syms; need to bring over dso.h and hidden_def/hidden_proto stuff from libselinux.

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.
#4 lore raw
Quoted 6 lines · Stephen Smalley

Also need to fix this:

$ relinfo.pl src/libsepol.so.1
src/libsepol.so.1: 68 relocations, 61 relative (89%), 94 PLT entries, 60 for local syms (63%), 0 users

There shouldn't be any for local syms; need to bring over dso.h and hidden_def/hidden_proto stuff from libselinux.

Attached patch does this for the sepol_bool functions used internally by libsepol. Same kind of change needs to be made for all sepol functions that one sees in readelf -r libsepol.so.1

Signature · 2 lines
Stephen Smalley
National Security Agency
src/boolean_internal.h +11 -0
diff -X /home/sds/dontdiff -Nrup libsepol.old/src/boolean_internal.h libsepol/src/boolean_internal.h
@@ -0,0 +1,11 @@
+#include <sepol/boolean_record.h>
+#include "dso.h"
+
+hidden_proto(sepol_bool_key_create)
+hidden_proto(sepol_bool_key_unpack)
+hidden_proto(sepol_bool_get_name)
+hidden_proto(sepol_bool_set_name)
+hidden_proto(sepol_bool_get_value)
+hidden_proto(sepol_bool_set_value)
+hidden_proto(sepol_bool_create)
+hidden_proto(sepol_bool_free)
src/boolean_record.c +9 -1
diff -X /home/sds/dontdiff -Nrup libsepol.old/src/boolean_record.c libsepol/src/boolean_record.c
@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <sepol/boolean_record.h>
+#include "boolean_internal.h"
 #include "debug.h"
 
 struct sepol_bool {
@@ -36,6 +36,7 @@ int sepol_bool_key_create(
 	*key_ptr = tmp_key;
 	return STATUS_SUCCESS;
 }
+hidden_def(sepol_bool_key_create)
 
 void sepol_bool_key_unpack(
 	sepol_bool_key_t* key,
@@ -43,6 +44,7 @@ void sepol_bool_key_unpack(
 
 	*name = key->name;
 }
+hidden_def(sepol_bool_key_unpack)
 
 int sepol_bool_key_extract(sepol_bool_t* boolean, sepol_bool_key_t** key_ptr) {
 	if (sepol_bool_key_create(boolean->name, key_ptr) < 0) {
@@ -71,6 +73,7 @@ int sepol_bool_compare(
 const char* sepol_bool_get_name(sepol_bool_t* boolean) {
 	return boolean->name;
 }
+hidden_def(sepol_bool_get_name)
 
 int sepol_bool_set_name(sepol_bool_t* boolean, const char* name) {
 	boolean->name = strdup(name);
@@ -81,15 +84,18 @@ int sepol_bool_set_name(sepol_bool_t* bo
 	}
 	return STATUS_SUCCESS;
 }
+hidden_def(sepol_bool_set_name)
 
 /* Value */
 int sepol_bool_get_value(sepol_bool_t* boolean) {
 	return boolean->value;
 }
+hidden_def(sepol_bool_get_value)
 
 void sepol_bool_set_value(sepol_bool_t* boolean, int value) {
 	boolean->value = value;
 }
+hidden_def(sepol_bool_set_value)
 
 /* Create */
 int sepol_bool_create(sepol_bool_t** bool_ptr) {
@@ -107,6 +113,7 @@ int sepol_bool_create(sepol_bool_t** boo
 	*bool_ptr = boolean;
 	return STATUS_SUCCESS;
 }
+hidden_def(sepol_bool_create)
 
 /* Deep copy clone */
 int sepol_bool_clone(sepol_bool_t* boolean, sepol_bool_t** bool_ptr) {
@@ -137,3 +144,4 @@ void sepol_bool_free(sepol_bool_t* boole
 	free(boolean->name);
 	free(boolean);
 }
+hidden_def(sepol_bool_free)
src/booleans.c +1 -1
diff -X /home/sds/dontdiff -Nrup libsepol.old/src/booleans.c libsepol/src/booleans.c
@@ -10,7 +10,7 @@
 #include <sepol/policydb/hashtab.h>
 #include <sepol/policydb/policydb.h>
 #include <sepol/policydb/conditional.h>
-#include <sepol/boolean_record.h>
+#include "boolean_internal.h"
 
 static int bool_update (
 	policydb_t* policydb,
src/dso.h +23 -0
diff -X /home/sds/dontdiff -Nrup libsepol.old/src/dso.h libsepol/src/dso.h
@@ -0,0 +1,23 @@
+#ifndef _SEPOL_DSO_H
+#define _SEPOL_DSO_H	1
+
+#ifdef SHARED
+# define hidden __attribute__ ((visibility ("hidden")))
+# define hidden_proto(fct) __hidden_proto (fct, fct##_internal)
+# define __hidden_proto(fct, internal)	\
+     extern __typeof (fct) internal;	\
+     extern __typeof (fct) fct __asm (#internal) hidden;
+# if defined(__alpha__) || defined(__mips__)
+#  define hidden_def(fct) \
+     asm (".globl " #fct "\n" #fct " = " #fct "_internal");
+# else
+#  define hidden_def(fct) \
+     asm (".globl " #fct "\n.set " #fct ", " #fct "_internal");
+#endif
+#else
+# define hidden
+# define hidden_proto(fct)
+# define hidden_def(fct)
+#endif
+
+#endif
src/Makefile +1 -1
diff -X /home/sds/dontdiff -Nrup libsepol.old/src/Makefile libsepol/src/Makefile
@@ -27,7 +27,7 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) -c -o $@ $<
 
 %.lo:  %.c
-	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
+	$(CC) $(CFLAGS) -fpic -DSHARED -c -o $@ $<
 
 install: all
 	test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)
#5 lore raw
Quoted 6 lines · Stephen Smalley
Quoted 4 lines · Stephen Smalley

Also need to fix this:

$ relinfo.pl src/libsepol.so.1
src/libsepol.so.1: 68 relocations, 61 relative (89%), 94 PLT entries, 60 for local syms (63%), 0 users
Quoted 6 lines
Quoted 3 lines

There shouldn't be any for local syms; need to bring over dso.h and hidden_def/hidden_proto stuff from libselinux.

Attached patch does this for the sepol_bool functions used internally by libsepol.

I'm confused, the bool_record is supposed to be exported out of sepol... it's shared with semanage. That could change, based on the current discussion of sharing records... but I wasn't sure if that's what you intended.

--
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 11 lines · Ivan Gyurdiev
Quoted 10 lines · Stephen Smalley
Quoted 7 lines · Stephen Smalley

Also need to fix this:

$ relinfo.pl src/libsepol.so.1
src/libsepol.so.1: 68 relocations, 61 relative (89%), 94 PLT entries, 60 for local syms (63%), 0 users

There shouldn't be any for local syms; need to bring over dso.h and hidden_def/hidden_proto stuff from libselinux.

Quoted 6 lines
Quoted 2 lines

Attached patch does this for the sepol_bool functions used internally by libsepol.

I'm confused, the bool_record is supposed to be exported out of sepol... it's shared with semanage. That could change, based on the current discussion of sharing records... but I wasn't sure if that's what you intended.

hidden_def/hidden_proto isn't about hiding the symbol from users of the shared library (that would be done by marking it "hidden", or in the libsepol case, by omitting it from the map file). hidden_def/hidden_proto creates an internal reference to the symbol for use within the library so that intra-library use doesn't require a relocation.

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.
#7 lore raw
Quoted 11 lines
Quoted 3 lines

I'm confused, the bool_record is supposed to be exported out of sepol... it's shared with semanage. That could change, based on the current discussion of sharing records... but I wasn't sure if that's what you intended.

hidden_def/hidden_proto isn't about hiding the symbol from users of the shared library (that would be done by marking it "hidden", or in the libsepol case, by omitting it from the map file). hidden_def/hidden_proto creates an internal reference to the symbol for use within the library so that intra-library use doesn't require a relocation.

You only need this for booleans?

--
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 6 lines · Ivan Gyurdiev
Quoted 6 lines
Quoted 5 lines

I'm confused, the bool_record is supposed to be exported out of sepol... it's shared with semanage. That could change, based on the current discussion of sharing records... but I wasn't sure if that's what you intended.

Quoted 8 lines
Quoted 7 lines

hidden_def/hidden_proto isn't about hiding the symbol from users of the shared library (that would be done by marking it "hidden", or in the libsepol case, by omitting it from the map file). hidden_def/hidden_proto creates an internal reference to the symbol for use within the library so that intra-library use doesn't require a relocation.

You only need this for booleans?

No, I need it for all functions used within the library that are also exported to users of the shared library. The patch was just to get you started. Not a high priority, mind you, just something we want to do as a cleanup.

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.