Skip to contentSkip to conversation

setsebool problems

PATCH Daniel J Walsh 2 participants 3 messages Mar 24, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

We have a problem in the way we are handling booleans in FC3/RHEL4. Basically we are allowing the user to edit the booleans
file either by hand or by using setsebool -P. One problem is that if we want to override the default boolean value in policy with the booleans file.
We can not because selinux-policy-* has booleans marked as config(noreplace). Otherwise the user would loose his settings. Second problem is that setsebool allows users to customize booleans and as an option make them permanent. The way it makes them pemanant is it takes the values that are currently running in the kernel and rewrites the boolean file. This brings up the following bug

Quoted 2 lines

setsebool allow_ypbind=0
setsebool -P squid_disable_trans=1

Ends up with a booleans file containing
allow_ypbind=0
squid_disable_trans=1

Which is probably not what the user wanted.

So this patch changes the selinux handling of booleans. First it introduces a new file booleans.local which will contain the users custom boolean settings. booleans will be changes to a config file so that it will be overwritten by rpm on upgrade. security_load_booleans now reads booleans and booleans.local to setup boolean values. setsebool now only writes the changed values to booleans.local.

Ideas?

Dan

include/selinux/selinux.h +3 -0
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/selinux.h libselinux-1.23.2/include/selinux/selinux.h
@@ -136,6 +136,9 @@
 /* Load a policy configuration. */
 extern int security_load_policy(void *data, size_t len);
 
+/* Translate boolean strict to name value pair. */
+extern int security_process_boolean(char *buffer, char *name, int namelen, int *value);
+
 /* Load policy boolean settings.
    Path may be NULL, in which case the booleans are loaded from
    the active policy boolean configuration file. */
src/booleans.c +51 -28

102 lines not on this page · raw message

utils/setsebool.c +77 -41

158 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Daniel J Walsh

So this patch changes the selinux handling of booleans. First it introduces a new file booleans.local which will contain the users custom boolean settings. booleans will be changes to a config file so that it will be overwritten by rpm on upgrade. security_load_booleans now reads booleans and booleans.local to setup boolean values. setsebool now only writes the changed values to booleans.local.

Don't you need to modify libsepol (sepol_genbools) as well in order to get booleans.local consulted by load_policy and /sbin/init?

Signature · 8 lines
Stephen Smalley <[email protected]>
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 12 lines · Stephen Smalley
Quoted 3 lines · Daniel J Walsh

So this patch changes the selinux handling of booleans. First it introduces a new file booleans.local which will contain the users custom boolean settings. booleans will be changes to a config file so that it will be overwritten by rpm on upgrade. security_load_booleans now reads booleans and booleans.local to setup boolean values. setsebool now only writes the changed values to booleans.local.

Don't you need to modify libsepol (sepol_genbools) as well in order to get booleans.local consulted by load_policy and /sbin/init?

Ok here is the diff for sepol

src/genbools.c +52 -23
diff --exclude-from=exclude -N -u -r nsalibsepol/src/genbools.c libsepol-1.5.2/src/genbools.c
@@ -24,11 +24,39 @@
 	return dest;
 }
 
+static int process_boolean(char *buffer, char *name, int namesize, int *val) {
+	char name1[BUFSIZ];
+	char *ptr;
+	char *tok=strtok_r(buffer,"=",&ptr);
+	if (tok) {
+		strncpy(name1,tok, BUFSIZ-1);
+		strtrim(name,name1,namesize-1);
+		if ( name[0]=='#' ) return 0;
+		tok=strtok_r(NULL,"\0",&ptr);
+		if (tok) {
+			while (isspace(*tok)) tok++;
+			*val = -1;
+			if (isdigit(tok[0]))
+				*val=atoi(tok);
+			else if (!strncmp(tok, "true", sizeof("true")-1))
+				*val = 1;
+			else if (!strncmp(tok, "false", sizeof("false")-1))
+				*val = 0;
+			if (*val != 0 && *val != 1) {
+				fprintf(stderr,"illegal value for boolean %s=%s\n", name, tok);
+				return -1;
+			}
+			
+		}
+	}
+	return 1;
+}
+
 static int load_booleans(struct policydb *policydb, char *path) {
 	FILE *boolf;
 	char buffer[BUFSIZ];
+	char localbools[BUFSIZ];
 	char name[BUFSIZ];
-	char name1[BUFSIZ];
 	int val;
 	int errors=0;
 	struct cond_bool_datum *datum;
@@ -38,27 +66,28 @@
 		return -1;
 
         while (fgets(buffer, sizeof(buffer), boolf)) {
-		char *tok=strtok(buffer,"=");
-		if (tok) {
-			strncpy(name1,tok, BUFSIZ-1);
-			strtrim(name,name1,BUFSIZ-1);
-			if ( name[0]=='#' ) continue;
-			tok=strtok(NULL,"\0");
-			if (tok) {
-				while (isspace(*tok)) tok++;
-				val = -1;
-				if (isdigit(tok[0]))
-					val=atoi(tok);
-				else if (!strncasecmp(tok, "true", sizeof("true")-1))
-					val = 1;
-				else if (!strncasecmp(tok, "false", sizeof("false")-1))
-					val = 0;
-				if (val != 0 && val != 1) {
-					fprintf(stderr,"illegal value for boolean %s=%s\n", name, tok);
-					errors++;
-					continue;
-				}
-
+		int ret=process_boolean(buffer, name, sizeof(name), &val);
+		if (ret==-1) 
+			errors++;
+		if (ret==1) {
+			datum = hashtab_search(policydb->p_bools.table, name);
+			if (!datum) {
+				fprintf(stderr,"unknown boolean %s\n", name);
+				errors++;
+				continue;
+			}
+			datum->state = val;
+		}
+	}
+	fclose(boolf);
+	snprintf(localbools,sizeof(localbools), "%s.local", path);
+	boolf = fopen(localbools,"r");
+	if (boolf != NULL) {
+		while (fgets(buffer, sizeof(buffer), boolf)) {
+			int ret=process_boolean(buffer, name, sizeof(name), &val);
+			if (ret==-1) 
+				errors++;
+			if (ret==1) {
 				datum = hashtab_search(policydb->p_bools.table, name);
 				if (!datum) {
 					fprintf(stderr,"unknown boolean %s\n", name);
@@ -68,8 +97,8 @@
 				datum->state = val;
 			}
 		}
+		fclose(boolf);
 	}
-	fclose(boolf);
 
 	if (errors)
 		errno = EINVAL;