params.c (75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37) | params.c (aefcf2f4b58155d27340ba5f9ddbe9513da8286d) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* Helpers for initial module or kernel cmdline parsing 3 Copyright (C) 2001 Rusty Russell. 4 5*/ 6#include <linux/kernel.h> 7#include <linux/string.h> 8#include <linux/errno.h> 9#include <linux/module.h> 10#include <linux/moduleparam.h> 11#include <linux/device.h> 12#include <linux/err.h> 13#include <linux/slab.h> 14#include <linux/ctype.h> | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* Helpers for initial module or kernel cmdline parsing 3 Copyright (C) 2001 Rusty Russell. 4 5*/ 6#include <linux/kernel.h> 7#include <linux/string.h> 8#include <linux/errno.h> 9#include <linux/module.h> 10#include <linux/moduleparam.h> 11#include <linux/device.h> 12#include <linux/err.h> 13#include <linux/slab.h> 14#include <linux/ctype.h> |
15#include <linux/security.h> |
|
15 16#ifdef CONFIG_SYSFS 17/* Protects all built-in parameters, modules use their own param_lock */ 18static DEFINE_MUTEX(param_lock); 19 20/* Use the module's mutex, or if built-in use the built-in mutex */ 21#ifdef CONFIG_MODULES 22#define KPARAM_MUTEX(mod) ((mod) ? &(mod)->param_lock : ¶m_lock) --- 68 unchanged lines hidden (view full) --- 91 return true; 92} 93 94bool parameq(const char *a, const char *b) 95{ 96 return parameqn(a, b, strlen(a)+1); 97} 98 | 16 17#ifdef CONFIG_SYSFS 18/* Protects all built-in parameters, modules use their own param_lock */ 19static DEFINE_MUTEX(param_lock); 20 21/* Use the module's mutex, or if built-in use the built-in mutex */ 22#ifdef CONFIG_MODULES 23#define KPARAM_MUTEX(mod) ((mod) ? &(mod)->param_lock : ¶m_lock) --- 68 unchanged lines hidden (view full) --- 92 return true; 93} 94 95bool parameq(const char *a, const char *b) 96{ 97 return parameqn(a, b, strlen(a)+1); 98} 99 |
99static void param_check_unsafe(const struct kernel_param *kp) | 100static bool param_check_unsafe(const struct kernel_param *kp) |
100{ | 101{ |
102 if (kp->flags & KERNEL_PARAM_FL_HWPARAM && 103 security_locked_down(LOCKDOWN_MODULE_PARAMETERS)) 104 return false; 105 |
|
101 if (kp->flags & KERNEL_PARAM_FL_UNSAFE) { 102 pr_notice("Setting dangerous option %s - tainting kernel\n", 103 kp->name); 104 add_taint(TAINT_USER, LOCKDEP_STILL_OK); 105 } | 106 if (kp->flags & KERNEL_PARAM_FL_UNSAFE) { 107 pr_notice("Setting dangerous option %s - tainting kernel\n", 108 kp->name); 109 add_taint(TAINT_USER, LOCKDEP_STILL_OK); 110 } |
111 112 return true; |
|
106} 107 108static int parse_one(char *param, 109 char *val, 110 const char *doing, 111 const struct kernel_param *params, 112 unsigned num_params, 113 s16 min_level, --- 13 unchanged lines hidden (view full) --- 127 return 0; 128 /* No one handled NULL, so do it here. */ 129 if (!val && 130 !(params[i].ops->flags & KERNEL_PARAM_OPS_FL_NOARG)) 131 return -EINVAL; 132 pr_debug("handling %s with %p\n", param, 133 params[i].ops->set); 134 kernel_param_lock(params[i].mod); | 113} 114 115static int parse_one(char *param, 116 char *val, 117 const char *doing, 118 const struct kernel_param *params, 119 unsigned num_params, 120 s16 min_level, --- 13 unchanged lines hidden (view full) --- 134 return 0; 135 /* No one handled NULL, so do it here. */ 136 if (!val && 137 !(params[i].ops->flags & KERNEL_PARAM_OPS_FL_NOARG)) 138 return -EINVAL; 139 pr_debug("handling %s with %p\n", param, 140 params[i].ops->set); 141 kernel_param_lock(params[i].mod); |
135 param_check_unsafe(¶ms[i]); 136 err = params[i].ops->set(val, ¶ms[i]); | 142 if (param_check_unsafe(¶ms[i])) 143 err = params[i].ops->set(val, ¶ms[i]); 144 else 145 err = -EPERM; |
137 kernel_param_unlock(params[i].mod); 138 return err; 139 } 140 } 141 142 if (handle_unknown) { 143 pr_debug("doing %s: %s='%s'\n", doing, param, val); 144 return handle_unknown(param, val, doing, arg); --- 403 unchanged lines hidden (view full) --- 548{ 549 int err; 550 struct param_attribute *attribute = to_param_attr(mattr); 551 552 if (!attribute->param->ops->set) 553 return -EPERM; 554 555 kernel_param_lock(mk->mod); | 146 kernel_param_unlock(params[i].mod); 147 return err; 148 } 149 } 150 151 if (handle_unknown) { 152 pr_debug("doing %s: %s='%s'\n", doing, param, val); 153 return handle_unknown(param, val, doing, arg); --- 403 unchanged lines hidden (view full) --- 557{ 558 int err; 559 struct param_attribute *attribute = to_param_attr(mattr); 560 561 if (!attribute->param->ops->set) 562 return -EPERM; 563 564 kernel_param_lock(mk->mod); |
556 param_check_unsafe(attribute->param); 557 err = attribute->param->ops->set(buf, attribute->param); | 565 if (param_check_unsafe(attribute->param)) 566 err = attribute->param->ops->set(buf, attribute->param); 567 else 568 err = -EPERM; |
558 kernel_param_unlock(mk->mod); 559 if (!err) 560 return len; 561 return err; 562} 563#endif 564 565#ifdef CONFIG_MODULES --- 383 unchanged lines hidden --- | 569 kernel_param_unlock(mk->mod); 570 if (!err) 571 return len; 572 return err; 573} 574#endif 575 576#ifdef CONFIG_MODULES --- 383 unchanged lines hidden --- |