kernel/param: consolidate __{start,stop}___param[] in <linux/moduleparam.h>
[cascardo/linux.git] / kernel / params.c
index 34f5270..db97b79 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/slab.h>
@@ -83,6 +84,15 @@ bool parameq(const char *a, const char *b)
        return parameqn(a, b, strlen(a)+1);
 }
 
+static void param_check_unsafe(const struct kernel_param *kp)
+{
+       if (kp->flags & KERNEL_PARAM_FL_UNSAFE) {
+               pr_warn("Setting dangerous option %s - tainting kernel\n",
+                       kp->name);
+               add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+       }
+}
+
 static int parse_one(char *param,
                     char *val,
                     const char *doing,
@@ -104,11 +114,12 @@ static int parse_one(char *param,
                                return 0;
                        /* No one handled NULL, so do it here. */
                        if (!val &&
-                           !(params[i].ops->flags & KERNEL_PARAM_FL_NOARG))
+                           !(params[i].ops->flags & KERNEL_PARAM_OPS_FL_NOARG))
                                return -EINVAL;
                        pr_debug("handling %s with %p\n", param,
                                params[i].ops->set);
                        mutex_lock(&param_lock);
+                       param_check_unsafe(&params[i]);
                        err = params[i].ops->set(val, &params[i]);
                        mutex_unlock(&param_lock);
                        return err;
@@ -318,7 +329,7 @@ int param_get_bool(char *buffer, const struct kernel_param *kp)
 EXPORT_SYMBOL(param_get_bool);
 
 struct kernel_param_ops param_ops_bool = {
-       .flags = KERNEL_PARAM_FL_NOARG,
+       .flags = KERNEL_PARAM_OPS_FL_NOARG,
        .set = param_set_bool,
        .get = param_get_bool,
 };
@@ -369,7 +380,7 @@ int param_set_bint(const char *val, const struct kernel_param *kp)
 EXPORT_SYMBOL(param_set_bint);
 
 struct kernel_param_ops param_ops_bint = {
-       .flags = KERNEL_PARAM_FL_NOARG,
+       .flags = KERNEL_PARAM_OPS_FL_NOARG,
        .set = param_set_bint,
        .get = param_get_int,
 };
@@ -503,8 +514,6 @@ EXPORT_SYMBOL(param_ops_string);
 #define to_module_attr(n) container_of(n, struct module_attribute, attr)
 #define to_module_kobject(n) container_of(n, struct module_kobject, kobj)
 
-extern struct kernel_param __start___param[], __stop___param[];
-
 struct param_attribute
 {
        struct module_attribute mattr;
@@ -552,6 +561,7 @@ static ssize_t param_attr_store(struct module_attribute *mattr,
                return -EPERM;
 
        mutex_lock(&param_lock);
+       param_check_unsafe(attribute->param);
        err = attribute->param->ops->set(buf, attribute->param);
        mutex_unlock(&param_lock);
        if (!err)
@@ -763,7 +773,7 @@ static struct module_kobject * __init locate_module_kobject(const char *name)
 }
 
 static void __init kernel_add_sysfs_param(const char *name,
-                                         struct kernel_param *kparam,
+                                         const struct kernel_param *kparam,
                                          unsigned int name_skip)
 {
        struct module_kobject *mk;
@@ -798,7 +808,7 @@ static void __init kernel_add_sysfs_param(const char *name,
  */
 static void __init param_sysfs_builtin(void)
 {
-       struct kernel_param *kp;
+       const struct kernel_param *kp;
        unsigned int name_len;
        char modname[MODULE_NAME_LEN];