diff options
| author | christos <christos@NetBSD.org> | 2010-12-23 20:07:13 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2010-12-23 20:07:13 +0000 |
| commit | c2499757066174f45e9d2d7c52f285ddae7625d6 (patch) | |
| tree | c78d5da67d1890fe7b8729c19b8135d4a79b1f03 /sys/dev | |
| parent | 45e6b06845a6a61cc2343c16868577e9591816ea (diff) | |
Now that we have allowed operator to access the control node, make sure
that he cannot cause damage, by only allowing the superuser to do ioctls
that can cause damage.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/dm/device-mapper.c | 44 | ||||
| -rw-r--r-- | sys/dev/dm/dm.h | 6 |
2 files changed, 29 insertions, 21 deletions
diff --git a/sys/dev/dm/device-mapper.c b/sys/dev/dm/device-mapper.c index de8c33f6bda..66f09288a38 100644 --- a/sys/dev/dm/device-mapper.c +++ b/sys/dev/dm/device-mapper.c @@ -1,4 +1,4 @@ -/* $NetBSD: device-mapper.c,v 1.27 2010/12/23 14:58:13 mlelstv Exp $ */ +/* $NetBSD: device-mapper.c,v 1.28 2010/12/23 20:07:13 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -45,6 +45,7 @@ #include <sys/ioctl.h> #include <sys/ioccom.h> #include <sys/kmem.h> +#include <sys/kauth.h> #include "netbsd-dm.h" #include "dm.h" @@ -121,23 +122,23 @@ extern uint32_t dm_dev_counter; * ioctl to kernel but will do another things in userspace. * */ -struct cmd_function cmd_fn[] = { - { .cmd = "version", .fn = dm_get_version_ioctl}, - { .cmd = "targets", .fn = dm_list_versions_ioctl}, - { .cmd = "create", .fn = dm_dev_create_ioctl}, - { .cmd = "info", .fn = dm_dev_status_ioctl}, - { .cmd = "mknodes", .fn = dm_dev_status_ioctl}, - { .cmd = "names", .fn = dm_dev_list_ioctl}, - { .cmd = "suspend", .fn = dm_dev_suspend_ioctl}, - { .cmd = "remove", .fn = dm_dev_remove_ioctl}, - { .cmd = "rename", .fn = dm_dev_rename_ioctl}, - { .cmd = "resume", .fn = dm_dev_resume_ioctl}, - { .cmd = "clear", .fn = dm_table_clear_ioctl}, - { .cmd = "deps", .fn = dm_table_deps_ioctl}, - { .cmd = "reload", .fn = dm_table_load_ioctl}, - { .cmd = "status", .fn = dm_table_status_ioctl}, - { .cmd = "table", .fn = dm_table_status_ioctl}, - {NULL, NULL} +static const struct cmd_function cmd_fn[] = { + { .cmd = "version", .fn = dm_get_version_ioctl, .allowed = 1 }, + { .cmd = "targets", .fn = dm_list_versions_ioctl, .allowed = 1 }, + { .cmd = "create", .fn = dm_dev_create_ioctl, .allowed = 0 }, + { .cmd = "info", .fn = dm_dev_status_ioctl, .allowed = 1 }, + { .cmd = "mknodes", .fn = dm_dev_status_ioctl, .allowed = 1 }, + { .cmd = "names", .fn = dm_dev_list_ioctl, .allowed = 1 }, + { .cmd = "suspend", .fn = dm_dev_suspend_ioctl, .allowed = 0 }, + { .cmd = "remove", .fn = dm_dev_remove_ioctl, .allowed = 0 }, + { .cmd = "rename", .fn = dm_dev_rename_ioctl, .allowed = 0 }, + { .cmd = "resume", .fn = dm_dev_resume_ioctl, .allowed = 0 }, + { .cmd = "clear", .fn = dm_table_clear_ioctl, .allowed = 0 }, + { .cmd = "deps", .fn = dm_table_deps_ioctl, .allowed = 1 }, + { .cmd = "reload", .fn = dm_table_load_ioctl, .allowed = 0 }, + { .cmd = "status", .fn = dm_table_status_ioctl, .allowed = 1 }, + { .cmd = "table", .fn = dm_table_status_ioctl, .allowed = 1 }, + { .cmd = NULL, .fn = NULL, .allowed = 0 } }; #ifdef _MODULE @@ -382,7 +383,7 @@ cleanup_exit: * Translate command sent from libdevmapper to func. */ static int -dm_cmd_to_fun(prop_dictionary_t dm_dict){ +dm_cmd_to_fun(prop_dictionary_t dm_dict) { int i, r; prop_string_t command; @@ -395,6 +396,11 @@ dm_cmd_to_fun(prop_dictionary_t dm_dict){ if (prop_string_equals_cstring(command, cmd_fn[i].cmd)) break; + if (!cmd_fn[i].allowed && + (r = kauth_authorize_generic(kauth_cred_get(), + KAUTH_GENERIC_ISSUSER, NULL)) != 0) + return r; + if (cmd_fn[i].cmd == NULL) return EINVAL; diff --git a/sys/dev/dm/dm.h b/sys/dev/dm/dm.h index aae86ac747a..af38ac35b39 100644 --- a/sys/dev/dm/dm.h +++ b/sys/dev/dm/dm.h @@ -1,4 +1,4 @@ -/* $NetBSD: dm.h,v 1.21 2010/12/23 14:58:13 mlelstv Exp $ */ +/* $NetBSD: dm.h,v 1.22 2010/12/23 20:07:13 christos Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -258,11 +258,13 @@ typedef struct dm_target { * This structure is used to translate command sent to kernel driver in * <key>command</key> * <value></value> - * to function which I can call. + * to function which I can call, and if the command is allowed for + * non-superusers. */ struct cmd_function { const char *cmd; int (*fn)(prop_dictionary_t); + int allowed; }; /* device-mapper */ |
