Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 May 2002 18:03:02 -0700 (PDT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 12234 for review
Message-ID:  <200206010103.g51132t33985@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=12234

Change 12234 by rwatson@rwatson_curry on 2002/05/31 18:02:08

	Define and employe mac_biba_valid() to validate labels from
	various suspect sources (largely user processes :-)

Affected files ...

... //depot/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c#39 edit

Differences ...

==== //depot/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c#39 (text+ko) ====

@@ -215,6 +215,72 @@
 	return (mac_biba_equal_element(&a->mb_single, &b->mb_single));
 }
 
+static int
+mac_biba_valid(struct mac_biba *mac_biba)
+{
+
+	if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) {
+		switch (mac_biba->mb_single.mbe_type) {
+		case MAC_BIBA_TYPE_GRADE:
+			break;
+
+		case MAC_BIBA_TYPE_EQUAL:
+		case MAC_BIBA_TYPE_HIGH:
+		case MAC_BIBA_TYPE_LOW:
+			if (mac_biba->mb_single.mbe_grade != 0)
+				return (EINVAL);
+			break;
+
+		default:
+			return (EINVAL);
+		}
+	} else {
+		if (mac_biba->mb_single.mbe_type != MAC_BIBA_TYPE_UNDEF)
+			return (EINVAL);
+	}
+
+	if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) {
+		switch (mac_biba->mb_rangelow.mbe_type) {
+		case MAC_BIBA_TYPE_GRADE:
+			break;
+
+		case MAC_BIBA_TYPE_EQUAL:
+		case MAC_BIBA_TYPE_HIGH:
+		case MAC_BIBA_TYPE_LOW:
+			if (mac_biba->mb_rangelow.mbe_grade != 0)
+				return (EINVAL);
+			break;
+
+		default:
+			return (EINVAL);
+		}
+
+		switch (mac_biba->mb_rangehigh.mbe_type) {
+		case MAC_BIBA_TYPE_GRADE:
+			break;
+
+		case MAC_BIBA_TYPE_EQUAL:
+		case MAC_BIBA_TYPE_HIGH:
+		case MAC_BIBA_TYPE_LOW:
+			if (mac_biba->mb_rangehigh.mbe_grade != 0)
+				return (EINVAL);
+			break;
+
+		default:
+			return (EINVAL);
+		}
+		if (!mac_biba_dominate_element(&mac_biba->mb_rangehigh,
+		    &mac_biba->mb_rangelow))
+			return (EINVAL);
+	} else {
+		if (mac_biba->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF ||
+		    mac_biba->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF)
+			return (EINVAL);
+	}
+
+	return (0);
+}
+
 static void
 mac_biba_set_range(struct mac_biba *mac_biba, u_short typelow,
     u_short gradelow, u_short typehigh, u_short gradehigh)
@@ -475,10 +541,14 @@
 mac_biba_internalize(struct label *label, struct mac *extmac)
 {
 	struct mac_biba *mac_biba;
+	int error;
+
+	mac_biba = SLOT(label);
 
-	/* XXX: validity check here. */
+	error = mac_biba_valid(mac_biba);
+	if (error)
+		return (error);
 
-	mac_biba = SLOT(label);
 	*mac_biba = extmac->m_biba;
 
 	return (0);
@@ -1006,10 +1076,13 @@
     struct label *ifnetlabel, struct label *newlabel)
 {
 	struct mac_biba *new;
+	int error;
 
 	new = SLOT(newlabel);
 
-	/* XXX: validity check */
+	error = mac_biba_valid(new);
+	if (error)
+		return (error);
 
 	if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAGS_BOTH)
 		return (EINVAL);
@@ -1022,10 +1095,13 @@
     struct label *socketlabel, struct label *newlabel)
 {
 	struct mac_biba *new;
+	int error;
 
 	new = SLOT(newlabel);
 
-	/* XXX: validity check */
+	error = mac_biba_valid(new);
+	if (error)
+		return (error);
 
 	if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE)
 		return (EINVAL);
@@ -1039,10 +1115,13 @@
 mac_biba_cred_check_relabel_subject(struct ucred *cred, struct label *newlabel)
 {
 	struct mac_biba *new;
+	int error;
 
 	new = SLOT(newlabel);
 
-	/* XXX: validity check */
+	error = mac_biba_valid(new);
+	if (error)
+		return (error);
 
 	if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAGS_BOTH)
 		return (EINVAL);
@@ -1060,12 +1139,15 @@
     struct label *vnodelabel, struct label *newlabel)
 {
 	struct mac_biba *old, *new, *subj;
+	int error;
 
 	old = SLOT(vnodelabel);
 	new = SLOT(newlabel);
 	subj = SLOT(&cred->cr_label);
 
-	/* XXX: validity check */
+	error = mac_biba_valid(new);
+	if (error)
+		return (error);
 
 	if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE)
 		return (EINVAL);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206010103.g51132t33985>