Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/jmcneill-usbmp]: src/sys/secmodel/extensions merge from -current (not su...
details: https://anonhg.NetBSD.org/src/rev/1bdfa1178149
branches: jmcneill-usbmp
changeset: 771790:1bdfa1178149
user: mrg <mrg%NetBSD.org@localhost>
date: Sat Feb 18 07:58:23 2012 +0000
description:
merge from -current (not sure why these were missed).
diffstat:
sys/secmodel/extensions/extensions.h | 35 +
sys/secmodel/extensions/files.extensions | 5 +
sys/secmodel/extensions/secmodel_extensions.c | 459 ++++++++++++++++++++++++++
3 files changed, 499 insertions(+), 0 deletions(-)
diffs (truncated from 511 to 300 lines):
diff -r 0ad8576a9eea -r 1bdfa1178149 sys/secmodel/extensions/extensions.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/secmodel/extensions/extensions.h Sat Feb 18 07:58:23 2012 +0000
@@ -0,0 +1,35 @@
+/* $NetBSD: extensions.h,v 1.1.4.2 2012/02/18 07:58:23 mrg Exp $ */
+/*-
+ * Copyright (c) 2011 Elad Efrat <elad%NetBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SECMODEL_EXTENSIONS_EXTENSIONS_H_
+#define _SECMODEL_EXTENSIONS_EXTENSIONS_H_
+
+#define SECMODEL_EXTENSIONS_ID "org.netbsd.secmodel.extensions"
+#define SECMODEL_EXTENSIONS_NAME "Traditional NetBSD: Extensions"
+
+#endif /* !_SECMODEL_EXTENSIONS_EXTENSIONS_H_ */
diff -r 0ad8576a9eea -r 1bdfa1178149 sys/secmodel/extensions/files.extensions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/secmodel/extensions/files.extensions Sat Feb 18 07:58:23 2012 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: files.extensions,v 1.1.4.2 2012/02/18 07:58:23 mrg Exp $
+
+defflag secmodel_extensions
+
+file secmodel/extensions/secmodel_extensions.c secmodel_extensions
diff -r 0ad8576a9eea -r 1bdfa1178149 sys/secmodel/extensions/secmodel_extensions.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/secmodel/extensions/secmodel_extensions.c Sat Feb 18 07:58:23 2012 +0000
@@ -0,0 +1,459 @@
+/* $NetBSD: secmodel_extensions.c,v 1.2.4.2 2012/02/18 07:58:24 mrg Exp $ */
+/*-
+ * Copyright (c) 2011 Elad Efrat <elad%NetBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: secmodel_extensions.c,v 1.2.4.2 2012/02/18 07:58:24 mrg Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/kauth.h>
+
+#include <sys/mount.h>
+#include <sys/vnode.h>
+#include <sys/socketvar.h>
+#include <sys/sysctl.h>
+#include <sys/proc.h>
+#include <sys/module.h>
+
+#include <secmodel/secmodel.h>
+#include <secmodel/extensions/extensions.h>
+
+MODULE(MODULE_CLASS_SECMODEL, extensions, NULL);
+
+/* static */ int dovfsusermount;
+static int curtain;
+static int user_set_cpu_affinity;
+
+static kauth_listener_t l_system, l_process, l_network;
+
+static secmodel_t extensions_sm;
+static struct sysctllog *extensions_sysctl_log;
+
+static void secmodel_extensions_init(void);
+static void secmodel_extensions_start(void);
+static void secmodel_extensions_stop(void);
+
+static void sysctl_security_extensions_setup(struct sysctllog **);
+static int sysctl_extensions_user_handler(SYSCTLFN_PROTO);
+static int sysctl_extensions_curtain_handler(SYSCTLFN_PROTO);
+static bool is_securelevel_above(int);
+
+static int secmodel_extensions_system_cb(kauth_cred_t, kauth_action_t,
+ void *, void *, void *, void *, void *);
+static int secmodel_extensions_process_cb(kauth_cred_t, kauth_action_t,
+ void *, void *, void *, void *, void *);
+static int secmodel_extensions_network_cb(kauth_cred_t, kauth_action_t,
+ void *, void *, void *, void *, void *);
+
+static void
+sysctl_security_extensions_setup(struct sysctllog **clog)
+{
+ const struct sysctlnode *rnode;
+
+ sysctl_createv(clog, 0, NULL, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "security", NULL,
+ NULL, 0, NULL, 0,
+ CTL_SECURITY, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "models", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "extensions", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_STRING, "name", NULL,
+ NULL, 0, __UNCONST(SECMODEL_EXTENSIONS_NAME), 0,
+ CTL_CREATE, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "usermount",
+ SYSCTL_DESCR("Whether unprivileged users may mount "
+ "filesystems"),
+ sysctl_extensions_user_handler, 0, &dovfsusermount, 0,
+ CTL_CREATE, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "curtain",
+ SYSCTL_DESCR("Curtain information about objects to "\
+ "users not owning them."),
+ sysctl_extensions_curtain_handler, 0, &curtain, 0,
+ CTL_CREATE, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "user_set_cpu_affinity",
+ SYSCTL_DESCR("Whether unprivileged users may control "\
+ "CPU affinity."),
+ sysctl_extensions_user_handler, 0,
+ &user_set_cpu_affinity, 0,
+ CTL_CREATE, CTL_EOL);
+
+ /* Compatibility: vfs.generic.usermount */
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "vfs", NULL,
+ NULL, 0, NULL, 0,
+ CTL_VFS, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "generic",
+ SYSCTL_DESCR("Non-specific vfs related information"),
+ NULL, 0, NULL, 0,
+ CTL_VFS, VFS_GENERIC, CTL_EOL);
+
+ sysctl_createv(clog, 0, NULL, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "usermount",
+ SYSCTL_DESCR("Whether unprivileged users may mount "
+ "filesystems"),
+ sysctl_extensions_user_handler, 0, &dovfsusermount, 0,
+ CTL_VFS, VFS_GENERIC, VFS_USERMOUNT, CTL_EOL);
+
+ /* Compatibility: security.curtain */
+ sysctl_createv(clog, 0, NULL, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "security", NULL,
+ NULL, 0, NULL, 0,
+ CTL_SECURITY, CTL_EOL);
+
+ sysctl_createv(clog, 0, &rnode, NULL,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "curtain",
+ SYSCTL_DESCR("Curtain information about objects to "\
+ "users not owning them."),
+ sysctl_extensions_curtain_handler, 0, &curtain, 0,
+ CTL_CREATE, CTL_EOL);
+}
+
+static int
+sysctl_extensions_curtain_handler(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node;
+ int val, error;
+
+ val = *(int *)rnode->sysctl_data;
+
+ node = *rnode;
+ node.sysctl_data = &val;
+
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ /* shortcut */
+ if (val == *(int *)rnode->sysctl_data)
+ return 0;
+
+ /* curtain cannot be disabled when securelevel is above 0 */
+ if (val == 0 && is_securelevel_above(0)) {
+ return EPERM;
+ }
+
+ *(int *)rnode->sysctl_data = val;
+ return 0;
+}
+
+/*
+ * Generic sysctl extensions handler for user mount and set CPU affinity
+ * rights. Checks the following conditions:
+ * - setting value to 0 is always permitted (decrease user rights)
+ * - setting value != 0 is not permitted when securelevel is above 0 (increase
+ * user rights).
+ */
+static int
+sysctl_extensions_user_handler(SYSCTLFN_ARGS)
+{
+ struct sysctlnode node;
+ int val, error;
+
+ val = *(int *)rnode->sysctl_data;
+
+ node = *rnode;
+ node.sysctl_data = &val;
+
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ /* shortcut */
+ if (val == *(int *)rnode->sysctl_data)
+ return 0;
+
+ /* we cannot grant more rights to users when securelevel is above 0 */
+ if (val != 0 && is_securelevel_above(0)) {
+ return EPERM;
+ }
+
+ *(int *)rnode->sysctl_data = val;
+ return 0;
+}
+
+/*
+ * Query secmodel_securelevel(9) to know whether securelevel is strictly
+ * above 'level' or not.
+ * Returns true if it is, false otherwise (when securelevel is absent or
+ * securelevel is at or below 'level').
+ */
+static bool
+is_securelevel_above(int level)
+{
+ bool above;
+ int error;
+
+ error = secmodel_eval("org.netbsd.secmodel.securelevel",
+ "is-securelevel-above", KAUTH_ARG(level), &above);
+ if (error == 0 && above)
+ return true;
+ else
+ return false;
+}
+
+static void
Home |
Main Index |
Thread Index |
Old Index