summaryrefslogtreecommitdiff
path: root/sys/secmodel/securelevel
diff options
context:
space:
mode:
authorjym <jym@NetBSD.org>2011-12-04 19:24:58 +0000
committerjym <jym@NetBSD.org>2011-12-04 19:24:58 +0000
commit6519e39ddd31a3a04e7f4a91345bcbbe8ca8efdc (patch)
tree7535e85ea2a89ab05e6a1a1c69a1c90a982cae2e /sys/secmodel/securelevel
parent982b01a29bee0addbe89b37157465fdbd0c6c024 (diff)
Implement the register/deregister/evaluation API for secmodel(9). It
allows registration of callbacks that can be used later for cross-secmodel "safe" communication. When a secmodel wishes to know a property maintained by another secmodel, it has to submit a request to it so the other secmodel can proceed to evaluating the request. This is done through the secmodel_eval(9) call; example: bool isroot; error = secmodel_eval("org.netbsd.secmodel.suser", "is-root", cred, &isroot); if (error == 0 && !isroot) result = KAUTH_RESULT_DENY; This one asks the suser module if the credentials are assumed to be root when evaluated by suser module. If the module is present, it will respond. If absent, the call will return an error. Args and command are arbitrarily defined; it's up to the secmodel(9) to document what it expects. Typical example is securelevel testing: when someone wants to know whether securelevel is raised above a certain level or not, the caller has to request this property to the secmodel_securelevel(9) module. Given that securelevel module may be absent from system's context (thus making access to the global "securelevel" variable impossible or unsafe), this API can cope with this absence and return an error. We are using secmodel_eval(9) to implement a secmodel_extensions(9) module, which plugs with the bsd44, suser and securelevel secmodels to provide the logic behind curtain, usermount and user_set_cpu_affinity modes, without adding hooks to traditional secmodels. This solves a real issue with the current secmodel(9) code, as usermount or user_set_cpu_affinity are not really tied to secmodel_suser(9). The secmodel_eval(9) is also used to restrict security.models settings when securelevel is above 0, through the "is-securelevel-above" evaluation: - curtain can be enabled any time, but cannot be disabled if securelevel is above 0. - usermount/user_set_cpu_affinity can be disabled any time, but cannot be enabled if securelevel is above 0. Regarding sysctl(7) entries: curtain and usermount are now found under security.models.extensions tree. The security.curtain and vfs.generic.usermount are still accessible for backwards compat. Documentation is incoming, I am proof-reading my writings. Written by elad@, reviewed and tested (anita test + interact for rights tests) by me. ok elad@. See also http://mail-index.netbsd.org/tech-security/2011/11/29/msg000422.html XXX might consider va0 mapping too. XXX Having a secmodel(9) specific printf (like aprint_*) for reporting secmodel(9) errors might be a good idea, but I am not sure on how to design such a function right now.
Diffstat (limited to 'sys/secmodel/securelevel')
-rw-r--r--sys/secmodel/securelevel/secmodel_securelevel.c38
-rw-r--r--sys/secmodel/securelevel/securelevel.h5
2 files changed, 39 insertions, 4 deletions
diff --git a/sys/secmodel/securelevel/secmodel_securelevel.c b/sys/secmodel/securelevel/secmodel_securelevel.c
index adc19cd952f..d6d41a240ca 100644
--- a/sys/secmodel/securelevel/secmodel_securelevel.c
+++ b/sys/secmodel/securelevel/secmodel_securelevel.c
@@ -1,4 +1,4 @@
-/* $NetBSD: secmodel_securelevel.c,v 1.22 2011/11/28 20:57:51 jym Exp $ */
+/* $NetBSD: secmodel_securelevel.c,v 1.23 2011/12/04 19:25:00 jym Exp $ */
/*-
* Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
* All rights reserved.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: secmodel_securelevel.c,v 1.22 2011/11/28 20:57:51 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: secmodel_securelevel.c,v 1.23 2011/12/04 19:25:00 jym Exp $");
#ifdef _KERNEL_OPT
#include "opt_insecure.h"
@@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: secmodel_securelevel.c,v 1.22 2011/11/28 20:57:51 jy
#include <miscfs/specfs/specdev.h>
+#include <secmodel/secmodel.h>
#include <secmodel/securelevel/securelevel.h>
MODULE(MODULE_CLASS_SECMODEL, securelevel, NULL);
@@ -63,6 +64,7 @@ static int securelevel;
static kauth_listener_t l_system, l_process, l_network, l_machdep, l_device,
l_vnode;
+static secmodel_t securelevel_sm;
static struct sysctllog *securelevel_sysctl_log;
/*
@@ -116,7 +118,7 @@ sysctl_security_securelevel_setup(struct sysctllog **clog)
sysctl_createv(clog, 0, &rnode, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_STRING, "name", NULL,
- NULL, 0, __UNCONST("Traditional NetBSD: Securelevel"), 0,
+ NULL, 0, __UNCONST(SECMODEL_SECURELEVEL_NAME), 0,
CTL_CREATE, CTL_EOL);
sysctl_createv(clog, 0, &rnode, NULL,
@@ -180,12 +182,36 @@ secmodel_securelevel_stop(void)
}
static int
+securelevel_eval(const char *what, void *arg, void *ret)
+{
+ int error = 0;
+
+ if (strcasecmp(what, "is-securelevel-above") == 0) {
+ int level = (int)(uintptr_t)arg;
+ bool *bp = ret;
+
+ *bp = (securelevel > level);
+ } else {
+ error = ENOENT;
+ }
+
+ return error;
+}
+
+static int
securelevel_modcmd(modcmd_t cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
+ error = secmodel_register(&securelevel_sm,
+ SECMODEL_SECURELEVEL_ID, SECMODEL_SECURELEVEL_NAME,
+ NULL, securelevel_eval, NULL);
+ if (error != 0)
+ printf("securelevel_modcmd::init: secmodel_register "
+ "returned %d\n", error);
+
secmodel_securelevel_init();
secmodel_securelevel_start();
sysctl_security_securelevel_setup(&securelevel_sysctl_log);
@@ -194,6 +220,12 @@ securelevel_modcmd(modcmd_t cmd, void *arg)
case MODULE_CMD_FINI:
sysctl_teardown(&securelevel_sysctl_log);
secmodel_securelevel_stop();
+
+ error = secmodel_deregister(securelevel_sm);
+ if (error != 0)
+ printf("securelevel_modcmd::fini: secmodel_deregister "
+ "returned %d\n", error);
+
break;
case MODULE_CMD_AUTOUNLOAD:
diff --git a/sys/secmodel/securelevel/securelevel.h b/sys/secmodel/securelevel/securelevel.h
index 9ce22fdfa0a..86ad594acd4 100644
--- a/sys/secmodel/securelevel/securelevel.h
+++ b/sys/secmodel/securelevel/securelevel.h
@@ -1,4 +1,4 @@
-/* $NetBSD: securelevel.h,v 1.3 2009/10/02 18:50:14 elad Exp $ */
+/* $NetBSD: securelevel.h,v 1.4 2011/12/04 19:25:00 jym Exp $ */
/*-
* Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
* All rights reserved.
@@ -29,6 +29,9 @@
#ifndef _SECMODEL_SECURELEVEL_SECURELEVEL_H_
#define _SECMODEL_SECURELEVEL_SECURELEVEL_H_
+#define SECMODEL_SECURELEVEL_ID "org.netbsd.secmodel.securelevel"
+#define SECMODEL_SECURELEVEL_NAME "Traditional NetBSD: Securelevel"
+
int secmodel_securelevel_sysctl(SYSCTLFN_PROTO);
void secmodel_securelevel_init(void);