PERFORCE change 91460 for review

Todd Miller millert at FreeBSD.org
Thu Feb 9 20:24:13 GMT 2006


http://perforce.freebsd.org/chv.cgi?CH=91460

Change 91460 by millert at millert_ibook on 2006/02/09 20:23:46

	Some style(9)
	Add a syscall for loading the migscs file (for loadpolicy)
	Syscall number for this was chosen arbitrarily

Affected files ...

.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd_syscall.c#7 edit
.. //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd_syscalls.h#5 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd_syscall.c#7 (text+ko) ====

@@ -48,6 +48,8 @@
 
 #define MAX_UC 510
 
+int sebsd_load_migscs(void *, size_t); /* XXX - move to header file */
+
 struct lp_args
 {
 	void  *data;
@@ -57,19 +59,41 @@
 static int
 sys_load_policy(struct proc *td, void *data, size_t len)
 {
+	void *kdata;
+	int rc;
+	
+	rc = cred_has_security(td->p_ucred, SECURITY__LOAD_POLICY);
+	if (rc)
+		return (rc);
+
+	kdata = malloc(len, M_SEBSD, M_WAITOK);
+	rc = copyin(data, kdata, len);
+	if (rc)
+		return (rc);
+
+	rc = security_load_policy(kdata, len);
+	free(kdata, M_SEBSD);
+
+	return (rc);
+}
+
+static int
+sys_load_migscs(struct proc *td, void *data, size_t len)
+{
+	void *kdata;
 	int rc;
 	
 	rc = cred_has_security(td->p_ucred, SECURITY__LOAD_POLICY);
 	if (rc)
 		return (rc);
 
-	void *kdata = malloc (len, M_SEBSD, M_WAITOK);
-	rc = copyin (data, kdata, len);
+	kdata = malloc(len, M_SEBSD, M_WAITOK);
+	rc = copyin(data, kdata, len);
 	if (rc)
 		return (rc);
 
-	rc = security_load_policy (kdata, len);
-	free (kdata, M_SEBSD);
+	rc = sebsd_load_migscs(kdata, len);
+	free(kdata, M_SEBSD);
 
 	return (rc);
 }
@@ -80,9 +104,8 @@
  *
  * or, lists the SIDs that a given context can relabel files to. (username is ignored)
  */
-
 static int
-sys_get_sids (int function, char *context, char *username, char *out, int *outlen)
+sys_get_sids(int function, char *context, char *username, char *out, int *outlen)
 {
 	u_int32_t n, nsids, scontext_len;
 	security_id_t *sids, sid;
@@ -91,11 +114,10 @@
 	int olen = 1;
 	int ubufsz;
 
-	if (copyin (outlen, &ubufsz, sizeof (int)))
-	  {
-	    error = EFAULT;
-	    goto out;
-	  }
+	if (copyin(outlen, &ubufsz, sizeof(int))) {
+		error = EFAULT;
+		goto out;
+	}
 
 	/*
 	 * XXX We need POLICY_RDLOCK here, but it's not exported!
@@ -103,19 +125,20 @@
 	error = security_context_to_sid(context, strlen (context), &sid);
 	if (error)
 		goto out;
-	switch (function)
-	  {
-	  case SEBSDCALL_GETUSERSIDS:
-	    error = security_get_user_sids(sid, username, &sids, &nsids);
-	    break;
+	switch (function) {
+	case SEBSDCALL_GETUSERSIDS:
+		error = security_get_user_sids(sid, username, &sids, &nsids);
+		break;
 
-	  case SEBSDCALL_GETFILESIDS:
-	    error = security_get_file_sids(sid, SECCLASS_FILE, &sids, &nsids);
-	    break;
+	case SEBSDCALL_GETFILESIDS:
+		error = security_get_file_sids(sid, SECCLASS_FILE, &sids,
+		    &nsids);
+		break;
 
-	  default:
-	    error = ENOSYS;
-	  }
+	default:
+		error = ENOSYS;
+		break;
+	}
 	if (error)
 		goto out;
 	for (n = 0; n < nsids; n++) {
@@ -123,19 +146,17 @@
 		    &scontext_len);
 		if (error)
 			goto out2;
-		if (out && olen + scontext_len <= ubufsz)
-		  {
-		    error = copyout (scontext, out, scontext_len);
-		    out += scontext_len;
-		  }
-		else if (out)
-		  error = ENOMEM;
+		if (out && olen + scontext_len <= ubufsz) {
+			error = copyout(scontext, out, scontext_len);
+			out += scontext_len;
+		} else if (out)
+			error = ENOMEM;
 		olen += scontext_len;
 		security_free_context(scontext);
 		if (error)
-		  goto out2;
+			goto out2;
 	}
-	error = copyout (&olen, outlen, sizeof(int));
+	error = copyout(&olen, outlen, sizeof(int));
 out2:
 	sebsd_free(sids);
 out:
@@ -143,181 +164,194 @@
 }
 
 static int
-sys_change_sid (char *domains, char *sources, char *sclasss, char *out, int *outlen)
+sys_change_sid(char *domains, char *sources, char *sclasss, char *out,
+    int *outlen)
 {
-  security_id_t       domain, source;
-  struct class_datum *cld;
-  security_context_t  outc;
-  int error;
-  int ubufsz, outclen;
+	security_id_t       domain, source;
+	struct class_datum *cld;
+	security_context_t  outc;
+	int error;
+	int ubufsz, outclen;
 
-  if (copyin (outlen, &ubufsz, sizeof (int)))
-    return EFAULT;
+	if (copyin(outlen, &ubufsz, sizeof(int)))
+		return (EFAULT);
 
-  /*
-   * XXX We need POLICY_RDLOCK here, but it's not exported!
-   */
-  error = security_context_to_sid (sources, strlen (sources), &source);
-  if (error)
-    return error;
+	/*
+	 * XXX We need POLICY_RDLOCK here, but it's not exported!
+	 */
+	error = security_context_to_sid(sources, strlen (sources), &source);
+	if (error)
+		return (error);
 
-  error = security_context_to_sid (domains, strlen (domains), &domain);
-  if (error)
-    return error;
+	error = security_context_to_sid(domains, strlen (domains), &domain);
+	if (error)
+		return (error);
 
-  cld = hashtab_search (policydb.p_classes.table, sclasss);
-  if (cld == NULL)
-    return EINVAL;
+	cld = hashtab_search(policydb.p_classes.table, sclasss);
+	if (cld == NULL)
+		return (EINVAL);
 
-  error = security_change_sid (domain, source, cld->value, &source);
-  if (error)
-    return error;
-  error = security_sid_to_context (source, &outc, &outclen);
-  if (error)
-    return error;
-  if (out) {
-    if (outclen > ubufsz) {
-      error = ENOMEM;
-      goto out;
-    }
-    error = copyout (outc, out, outclen);
-    if (error)
-      goto out;
-  }
-  error = copyout (&outclen, outlen, sizeof(int));
+	error = security_change_sid(domain, source, cld->value, &source);
+	if (error)
+		return (error);
+	error = security_sid_to_context(source, &outc, &outclen);
+	if (error)
+		return (error);
+	if (out) {
+		if (outclen > ubufsz) {
+			error = ENOMEM;
+			goto out;
+		}
+		error = copyout(outc, out, outclen);
+		if (error)
+			goto out;
+	}
+	error = copyout(&outclen, outlen, sizeof(int));
 
- out:
-  security_free_context (outc);
-  return error;
+out:
+	security_free_context (outc);
+	return (error);
 }
 
-struct getsid_args
-{
-  char *ctx;
-  char *usr;
-  char *out;
-  int  *outlen;
+struct getsid_args {
+	char *ctx;
+	char *usr;
+	char *out;
+	int  *outlen;
 };
 
-struct changesid_args
-{
-  char *domain;
-  char *source;
-  char *sclass;
-  char *out;
-  int  *outlen;
+struct changesid_args {
+	char *domain;
+	char *source;
+	char *sclass;
+	char *out;
+	int  *outlen;
 };
 
 static int
 sebsd_get_bools(struct proc *td, struct sebsd_get_bools *gb)
 {
 	char *out = NULL;
+	int error;
+
 	if (gb->out)
 		out = malloc(gb->len, M_SEBSD, M_WAITOK);
-	int err = security_get_bool_string(&gb->len, out);
-	if (out && err == 0)
-		err = copyout(out, gb->out, gb->len);
+	error = security_get_bool_string(&gb->len, out);
+	if (out && error == 0)
+		error = copyout(out, gb->out, gb->len);
 	if (out)
 		free(out, M_SEBSD);
-	return (err);
+	return (error);
 }
 
 int
 sebsd_syscall(struct proc *td, int call, void *args, int *retv)
 {
-	int err = EINVAL;
 	struct lp_args p;
-	struct sebsd_get_bools gb;
+	int error = EINVAL;
 
 	switch(call) {
 	case SEBSDCALL_LOAD_POLICY:
-		if (copyin (args, &p, sizeof (struct lp_args)))
+		if (copyin(args, &p, sizeof(struct lp_args)))
+			return (EFAULT);
+		error = sys_load_policy(td, p.data, p.len);
+		break;
+
+	case SEBSDCALL_LOAD_MIGSCS:
+		if (copyin(args, &p, sizeof(struct lp_args)))
 			return (EFAULT);
-		err = sys_load_policy (td, p.data, p.len);
+		error = sys_load_migscs(td, p.data, p.len);
 		break;
 
 	case SEBSDCALL_GETUSERSIDS:
 	case SEBSDCALL_GETFILESIDS:
-	  {
-	    struct getsid_args uap;
-	    err = copyin (args, &uap, sizeof (struct getsid_args));
-	    if (err)
-	      return err;
-	    size_t dummy;
-	    char *ctx = sebsd_malloc (MAX_UC, M_WAITOK);
-	    err = copyinstr(uap.ctx, ctx, MAX_UC, &dummy);
-	    if (err) {
-	      sebsd_free (ctx);
-	      return err;
-	    }
-	    char *usr = sebsd_malloc (MAX_UC, M_WAITOK);
-	    err = copyinstr(uap.usr, usr, MAX_UC, &dummy);
-	    if (err) {
-	      sebsd_free (ctx);
-	      sebsd_free (usr);
-	      return err;
-	    }
-	    ctx[MAX_UC-1] = 0;
-	    usr[MAX_UC-1] = 0;
-	    err = sys_get_sids (call, ctx, usr, uap.out, uap.outlen);
-	    sebsd_free (ctx);
-	    sebsd_free (usr);
-	  }
-	  break;
+	{
+		struct getsid_args uap;
+		size_t dummy;
+		char *ctx, *usr;
+
+		error = copyin(args, &uap, sizeof(struct getsid_args));
+		if (error)
+			return (error);
+		ctx = sebsd_malloc(MAX_UC, M_WAITOK);
+		error = copyinstr(uap.ctx, ctx, MAX_UC, &dummy);
+		if (error) {
+			sebsd_free(ctx);
+			return (error);
+		}
+		usr = sebsd_malloc(MAX_UC, M_WAITOK);
+		error = copyinstr(uap.usr, usr, MAX_UC, &dummy);
+		if (error) {
+			sebsd_free(ctx);
+			sebsd_free(usr);
+			return (error);
+		}
+		ctx[MAX_UC-1] = 0;
+		usr[MAX_UC-1] = 0;
+		error = sys_get_sids(call, ctx, usr, uap.out, uap.outlen);
+		sebsd_free(ctx);
+		sebsd_free(usr);
+		break;
+	}
 
 	case SEBSDCALL_CHANGE_SID:
-	  {
-	    struct changesid_args uap;
-	    err = copyin (args, &uap, sizeof (struct changesid_args));
-	    if (err)
-	      return err;
-	    size_t dummy;
-	    char *doms = sebsd_malloc (MAX_UC, M_WAITOK);
-	    err = copyinstr(uap.domain, doms, MAX_UC, &dummy);
-	    if (err) {
-	      sebsd_free (doms);
-	      return err;
-	    }
-	    char *srcs = sebsd_malloc (MAX_UC, M_WAITOK);
-	    err = copyinstr(uap.source, srcs, MAX_UC, &dummy);
-	    if (err) {
-	      sebsd_free (doms);
-	      sebsd_free (srcs);
-	      return err;
-	    }
-	    char *scs = sebsd_malloc (MAX_UC, M_WAITOK);
-	    err = copyinstr(uap.sclass, scs, MAX_UC, &dummy);
-	    if (err) {
-	      sebsd_free (doms);
-	      sebsd_free (srcs);
-	      sebsd_free (scs);
-	      return err;
-	    }
-	    err = sys_change_sid (doms, srcs, scs, uap.out, uap.outlen);
-	    sebsd_free (doms);
-	    sebsd_free (srcs);
-	    sebsd_free (scs);
-	    return err;
-	  }
-	  break;
+	{
+		struct changesid_args uap;
+		size_t dummy;
+		char *doms, *srcs, *scs;
 
+		error = copyin(args, &uap, sizeof(struct changesid_args));
+		if (error)
+			return (error);
+		doms = sebsd_malloc(MAX_UC, M_WAITOK);
+		error = copyinstr(uap.domain, doms, MAX_UC, &dummy);
+		if (error) {
+			sebsd_free(doms);
+			return (error);
+		}
+		srcs = sebsd_malloc(MAX_UC, M_WAITOK);
+		error = copyinstr(uap.source, srcs, MAX_UC, &dummy);
+		if (error) {
+			sebsd_free(doms);
+			sebsd_free(srcs);
+			return (error);
+		}
+		scs = sebsd_malloc(MAX_UC, M_WAITOK);
+		error = copyinstr(uap.sclass, scs, MAX_UC, &dummy);
+		if (error) {
+			sebsd_free(doms);
+			sebsd_free(srcs);
+			sebsd_free(scs);
+			return (error);
+		}
+		error = sys_change_sid(doms, srcs, scs, uap.out, uap.outlen);
+		sebsd_free(doms);
+		sebsd_free(srcs);
+		sebsd_free(scs);
+		return (error);
+	}
 
 	case SEBSDCALL_GET_BOOLS:
-		if (copyin(args, &gb, sizeof (struct sebsd_get_bools)))
+	{
+		struct sebsd_get_bools gb;
+
+		if (copyin(args, &gb, sizeof(struct sebsd_get_bools)))
 			return (EFAULT);
-		err = sebsd_get_bools(td, &gb);
-		if (copyout(&gb, args, sizeof (struct sebsd_get_bools)))
+		error = sebsd_get_bools(td, &gb);
+		if (copyout(&gb, args, sizeof(struct sebsd_get_bools)))
 			return (EFAULT);
 		break;
+	}
 
 	case SEBSDCALL_GET_BOOL:
 	{
+		size_t dummy;
 		char str[128];
-		int  active, pending;
-		size_t dummy;
-		err = copyinstr(args,str, 128, &dummy);
-		if (err)
-			return (err);
+		int active, pending;
+
+		error = copyinstr(args, str, sizeof(str), &dummy);
+		if (error)
+			return (error);
 		security_get_bool(str, &active, &pending);
 		*retv = active | (pending << 1);
 		return (0);
@@ -327,11 +361,11 @@
 	{
 		char *str;
 
-		err = cred_has_security(td->p_ucred, SECURITY__SETBOOL);
-		if (err)
-			return (err);
+		error = cred_has_security(td->p_ucred, SECURITY__SETBOOL);
+		if (error)
+			return (error);
 
-		if (copyin(args, &p, sizeof (struct lp_args)))
+		if (copyin(args, &p, sizeof(struct lp_args)))
 			return (EFAULT);
 		str = malloc(p.len, M_SEBSD, M_WAITOK);
 		if (!str)
@@ -342,22 +376,21 @@
 		}
 
 		str[p.len-1] = 0;
-		err = security_set_bool(str+1, str[0]-'0');
+		error = security_set_bool(str+1, str[0]-'0');
 		free(str, M_SEBSD);
 		break;
 	}
 
 	case SEBSDCALL_COMMIT_BOOLS:
-		err = cred_has_security(td->p_ucred, SECURITY__SETBOOL);
-		if (err)
-			return (err);
+		error = cred_has_security(td->p_ucred, SECURITY__SETBOOL);
+		if (error)
+			return (error);
+		return (security_commit_pending_bools());
 
-		return security_commit_pending_bools();
-
 	default:
-		err = EINVAL;
+		error = EINVAL;
 		break;
 	}
 
-	return err;
+	return (error);
 }

==== //depot/projects/trustedbsd/sedarwin7/src/sedarwin/sedarwin/sebsd_syscalls.h#5 (text+ko) ====

@@ -7,6 +7,7 @@
  * TBD: Should we really try to line up with SELinux?
  */
 #define SEBSDCALL_LOAD_POLICY		7
+#define SEBSDCALL_LOAD_MIGSCS		12	/* XXX */
 #define SEBSDCALL_GET_BOOLS	        8
 #define SEBSDCALL_GET_BOOL		9
 #define SEBSDCALL_SET_BOOL		10
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list