All of lore.kernel.org
 help / color / mirror / Atom feed
From: Darrel Goeddel <dgoeddel@TrustedCS.com>
To: Stephen Smalley <sds@epoch.ncsc.mil>
Cc: "selinux@tycho.nsa.gov" <selinux@tycho.nsa.gov>
Subject: Re: [patch] typeattribute statements
Date: Mon, 13 Dec 2004 15:08:33 -0600	[thread overview]
Message-ID: <41BE04D1.1090903@trustedcs.com> (raw)
In-Reply-To: <1102969792.27895.66.camel@moss-spartans.epoch.ncsc.mil>

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

Stephen Smalley wrote:
> Thanks, looks good.  Only concern is the duplication of the MLS
> attribute handling code; we should use a common helper (although that
> code should be obsoleted in the future anyway).
> 

Yes, that code should be going away - which is probably why I took no real 
effort to mess with it now.  I have consolidated it for the time being with this 
new version of the patch.  How's this one look?

-- 

Darrel

[-- Attachment #2: typeattr-3.patch --]
[-- Type: text/plain, Size: 4891 bytes --]

Index: policy_parse.y
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/checkpolicy/policy_parse.y,v
retrieving revision 1.25
diff -u -r1.25 policy_parse.y
--- policy_parse.y	5 Nov 2004 19:14:42 -0000	1.25
+++ policy_parse.y	13 Dec 2004 20:58:06 -0000
@@ -68,6 +68,7 @@
 static int define_av_base(void);
 static int define_attrib(void);
 static int define_typealias(void);
+static int define_typeattribute(void);
 static int define_type(int alias);
 static int define_compute_type(int which);
 static int define_te_avtab(int which);
@@ -121,6 +122,7 @@
 %token ROLE
 %token ROLES
 %token TYPEALIAS
+%token TYPEATTRIBUTE
 %token TYPE
 %token TYPES
 %token ALIAS
@@ -287,6 +289,7 @@
 te_decl			: attribute_def
                         | type_def
                         | typealias_def
+                        | typeattribute_def
                         | bool_def
                         | transition_def
                         | te_avtab_def
@@ -303,6 +306,9 @@
 typealias_def           : TYPEALIAS identifier alias_def ';'
 			{if (define_typealias()) return -1;}
 			;
+typeattribute_def	: TYPEATTRIBUTE identifier id_comma_list ';'
+			{if (define_typeattribute()) return -1;}
+			;
 opt_attr_list           : ',' id_comma_list
 			| 
 			;
@@ -1633,10 +1639,9 @@
 static int define_typealias(void)
 {
 	char *id;
-	type_datum_t *t, *aliasdatum;;
+	type_datum_t *t, *aliasdatum;
 	int ret;
 
-
 	if (pass == 2) {
 		while ((id = queue_remove(id_queue))) 
 			free(id);
@@ -1686,6 +1691,86 @@
 	return 0;
 }
 
+#ifdef CONFIG_SECURITY_SELINUX_MLS
+static int handle_mls_attributes(char *id, unsigned int value)
+{
+	if (!strcmp(id, "mlstrustedreader")) {
+		if (ebitmap_set_bit(&policydbp->trustedreaders, value, TRUE)) {
+			return -1;
+		}
+	} else if (!strcmp(id, "mlstrustedwriter")) {
+		if (ebitmap_set_bit(&policydbp->trustedwriters, value, TRUE)) {
+			return -1;
+		}
+	} else if (!strcmp(id, "mlstrustedobject")) {
+		if (ebitmap_set_bit(&policydbp->trustedobjects, value, TRUE)) {
+			return -1;
+		}
+	}
+	return 0;
+}
+#else /* CONFIG_SECURITY_SELINUX_MLS */
+#define handle_mls_attributes(id, value) 0
+#endif /* CONFIG_SECURITY_SELINUX_MLS */
+
+static int define_typeattribute(void)
+{
+	char *id;
+	type_datum_t *t, *attr;
+
+	if (pass == 2) {
+		while ((id = queue_remove(id_queue)))
+			free(id);
+		return 0;
+	}
+
+	id = (char *)queue_remove(id_queue);
+	if (!id) {
+		yyerror("no type name for typeattribute definition?");
+		return -1;
+	}
+
+	t = hashtab_search(policydbp->p_types.table, id);
+	if (!t || t->isattr) {
+		sprintf(errormsg, "unknown type %s", id);
+		yyerror(errormsg);
+		free(id);
+		return -1;
+	}
+
+	while ((id = queue_remove(id_queue))) {
+		if (handle_mls_attributes(id, (t->value - 1))) {
+			yyerror("out of memory");
+			free(id);
+			return -1;
+		}
+		attr = hashtab_search(policydbp->p_types.table, id);
+		if (!attr) {
+			sprintf(errormsg, "attribute %s is not declared", id);
+			/* treat it as a fatal error */
+			yyerror(errormsg);
+			free(id);
+			return -1;
+		}
+
+		if (!attr->isattr) {
+			sprintf(errormsg, "%s is a type, not an attribute", id);
+			yyerror(errormsg);
+			free(id);
+			return -1;
+		}
+
+		free(id);
+
+		if (ebitmap_set_bit(&attr->types, (t->value - 1), TRUE)) {
+			yyerror("out of memory");
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 static int define_type(int alias)
 {
 	char *id;
@@ -1767,27 +1852,11 @@
 	}
 
 	while ((id = queue_remove(id_queue))) {
-#ifdef CONFIG_SECURITY_SELINUX_MLS
-		if (!strcmp(id, "mlstrustedreader")) {
-			if (ebitmap_set_bit(&policydbp->trustedreaders, datum->value - 1, TRUE)) {
-				yyerror("out of memory");
-				free(id);
-				return -1;
-			}
-		} else if (!strcmp(id, "mlstrustedwriter")) {
-			if (ebitmap_set_bit(&policydbp->trustedwriters, datum->value - 1, TRUE)) {
-				yyerror("out of memory");
-				free(id);
-				return -1;
-			}
-		} else if (!strcmp(id, "mlstrustedobject")) {
-			if (ebitmap_set_bit(&policydbp->trustedobjects, datum->value - 1, TRUE)) {
-				yyerror("out of memory");
-				free(id);
-				return -1;
-			}
+		if (handle_mls_attributes(id, (datum->value - 1))) {
+			yyerror("out of memory");
+			free(id);
+			return -1;
 		}
-#endif
 		attr = hashtab_search(policydbp->p_types.table, id);
 		if (!attr) {
 			sprintf(errormsg, "attribute %s is not declared", id);
Index: policy_scan.l
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux-usr/checkpolicy/policy_scan.l,v
retrieving revision 1.6
diff -u -r1.6 policy_scan.l
--- policy_scan.l	9 Aug 2004 18:12:29 -0000	1.6
+++ policy_scan.l	13 Dec 2004 20:58:06 -0000
@@ -64,6 +64,8 @@
 types				{ return(TYPES); }
 TYPEALIAS |
 typealias			{ return(TYPEALIAS); }
+TYPEATTRIBUTE |
+typeattribute			{ return(TYPEATTRIBUTE); }
 TYPE |
 type				{ return(TYPE); }
 BOOL |

  reply	other threads:[~2004-12-13 21:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-13 15:53 [patch] typeattribute statements Darrel Goeddel
2004-12-13 20:05 ` Darrel Goeddel
2004-12-13 20:29   ` Stephen Smalley
2004-12-13 21:08     ` Darrel Goeddel [this message]
2004-12-13 21:26       ` Stephen Smalley
2004-12-13 22:21 ` Karl MacMillan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41BE04D1.1090903@trustedcs.com \
    --to=dgoeddel@trustedcs.com \
    --cc=sds@epoch.ncsc.mil \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.