summaryrefslogtreecommitdiffstats
path: root/kernel/params.c
diff options
context:
space:
mode:
authorJani Nikula <jani.nikula@intel.com>2014-08-26 16:52:23 -0400
committerRusty Russell <rusty@rustcorp.com.au>2014-08-27 08:24:08 -0400
commit91f9d330cc14932084c37751997213cb0e7ea882 (patch)
tree8a7494e64787ea72ce4ed86c5298a1b1b7195111 /kernel/params.c
parent6a4c264313c4ae32dc53821a9c57e0dc9696fb81 (diff)
module: make it possible to have unsafe, tainting module params
Add flags field to struct kernel_params, and add the first flag: unsafe parameter. Modifying a kernel parameter with the unsafe flag set, either via the kernel command line or sysfs, will issue a warning and taint the kernel. Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Jean Delvare <khali@linux-fr.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Li Zhong <zhong@linux.vnet.ibm.com> Cc: Jon Mason <jon.mason@intel.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Jani Nikula <jani.nikula@intel.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'kernel/params.c')
-rw-r--r--kernel/params.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/kernel/params.c b/kernel/params.c
index 8a484fc8bde8..ad8d04563c3a 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -233,6 +233,7 @@ char *parse_args(const char *doing,
233#define STANDARD_PARAM_DEF(name, type, format, strtolfn) \ 233#define STANDARD_PARAM_DEF(name, type, format, strtolfn) \
234 int param_set_##name(const char *val, const struct kernel_param *kp) \ 234 int param_set_##name(const char *val, const struct kernel_param *kp) \
235 { \ 235 { \
236 param_check_unsafe(kp); \
236 return strtolfn(val, 0, (type *)kp->arg); \ 237 return strtolfn(val, 0, (type *)kp->arg); \
237 } \ 238 } \
238 int param_get_##name(char *buffer, const struct kernel_param *kp) \ 239 int param_get_##name(char *buffer, const struct kernel_param *kp) \
@@ -265,6 +266,8 @@ int param_set_charp(const char *val, const struct kernel_param *kp)
265 return -ENOSPC; 266 return -ENOSPC;
266 } 267 }
267 268
269 param_check_unsafe(kp);
270
268 maybe_kfree_parameter(*(char **)kp->arg); 271 maybe_kfree_parameter(*(char **)kp->arg);
269 272
270 /* This is a hack. We can't kmalloc in early boot, and we 273 /* This is a hack. We can't kmalloc in early boot, and we
@@ -302,6 +305,8 @@ EXPORT_SYMBOL(param_ops_charp);
302/* Actually could be a bool or an int, for historical reasons. */ 305/* Actually could be a bool or an int, for historical reasons. */
303int param_set_bool(const char *val, const struct kernel_param *kp) 306int param_set_bool(const char *val, const struct kernel_param *kp)
304{ 307{
308 param_check_unsafe(kp);
309
305 /* No equals means "set"... */ 310 /* No equals means "set"... */
306 if (!val) val = "1"; 311 if (!val) val = "1";
307 312
@@ -331,6 +336,8 @@ int param_set_invbool(const char *val, const struct kernel_param *kp)
331 bool boolval; 336 bool boolval;
332 struct kernel_param dummy; 337 struct kernel_param dummy;
333 338
339 param_check_unsafe(kp);
340
334 dummy.arg = &boolval; 341 dummy.arg = &boolval;
335 ret = param_set_bool(val, &dummy); 342 ret = param_set_bool(val, &dummy);
336 if (ret == 0) 343 if (ret == 0)
@@ -357,6 +364,8 @@ int param_set_bint(const char *val, const struct kernel_param *kp)
357 bool v; 364 bool v;
358 int ret; 365 int ret;
359 366
367 param_check_unsafe(kp);
368
360 /* Match bool exactly, by re-using it. */ 369 /* Match bool exactly, by re-using it. */
361 boolkp = *kp; 370 boolkp = *kp;
362 boolkp.arg = &v; 371 boolkp.arg = &v;
@@ -476,6 +485,8 @@ int param_set_copystring(const char *val, const struct kernel_param *kp)
476{ 485{
477 const struct kparam_string *kps = kp->str; 486 const struct kparam_string *kps = kp->str;
478 487
488 param_check_unsafe(kp);
489
479 if (strlen(val)+1 > kps->maxlen) { 490 if (strlen(val)+1 > kps->maxlen) {
480 pr_err("%s: string doesn't fit in %u chars.\n", 491 pr_err("%s: string doesn't fit in %u chars.\n",
481 kp->name, kps->maxlen-1); 492 kp->name, kps->maxlen-1);