| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* Helpers for initial module or kernel cmdline parsing |
|---|
| 2 | 3 | Copyright (C) 2001 Rusty Russell. |
|---|
| 3 | 4 | |
|---|
| 4 | | - This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - it under the terms of the GNU General Public License as published by |
|---|
| 6 | | - the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | | - (at your option) any later version. |
|---|
| 8 | | - |
|---|
| 9 | | - This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - GNU General Public License for more details. |
|---|
| 13 | | - |
|---|
| 14 | | - You should have received a copy of the GNU General Public License |
|---|
| 15 | | - along with this program; if not, write to the Free Software |
|---|
| 16 | | - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 | 5 | */ |
|---|
| 18 | 6 | #include <linux/kernel.h> |
|---|
| 19 | 7 | #include <linux/string.h> |
|---|
| .. | .. |
|---|
| 24 | 12 | #include <linux/err.h> |
|---|
| 25 | 13 | #include <linux/slab.h> |
|---|
| 26 | 14 | #include <linux/ctype.h> |
|---|
| 15 | +#include <linux/security.h> |
|---|
| 27 | 16 | |
|---|
| 28 | 17 | #ifdef CONFIG_SYSFS |
|---|
| 29 | 18 | /* Protects all built-in parameters, modules use their own param_lock */ |
|---|
| .. | .. |
|---|
| 108 | 97 | return parameqn(a, b, strlen(a)+1); |
|---|
| 109 | 98 | } |
|---|
| 110 | 99 | |
|---|
| 111 | | -static void param_check_unsafe(const struct kernel_param *kp) |
|---|
| 100 | +static bool param_check_unsafe(const struct kernel_param *kp) |
|---|
| 112 | 101 | { |
|---|
| 102 | + if (kp->flags & KERNEL_PARAM_FL_HWPARAM && |
|---|
| 103 | + security_locked_down(LOCKDOWN_MODULE_PARAMETERS)) |
|---|
| 104 | + return false; |
|---|
| 105 | + |
|---|
| 113 | 106 | if (kp->flags & KERNEL_PARAM_FL_UNSAFE) { |
|---|
| 114 | 107 | pr_notice("Setting dangerous option %s - tainting kernel\n", |
|---|
| 115 | 108 | kp->name); |
|---|
| 116 | 109 | add_taint(TAINT_USER, LOCKDEP_STILL_OK); |
|---|
| 117 | 110 | } |
|---|
| 111 | + |
|---|
| 112 | + return true; |
|---|
| 118 | 113 | } |
|---|
| 119 | 114 | |
|---|
| 120 | 115 | static int parse_one(char *param, |
|---|
| .. | .. |
|---|
| 144 | 139 | pr_debug("handling %s with %p\n", param, |
|---|
| 145 | 140 | params[i].ops->set); |
|---|
| 146 | 141 | kernel_param_lock(params[i].mod); |
|---|
| 147 | | - param_check_unsafe(¶ms[i]); |
|---|
| 148 | | - 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; |
|---|
| 149 | 146 | kernel_param_unlock(params[i].mod); |
|---|
| 150 | 147 | return err; |
|---|
| 151 | 148 | } |
|---|
| .. | .. |
|---|
| 236 | 233 | EXPORT_SYMBOL(param_ops_##name) |
|---|
| 237 | 234 | |
|---|
| 238 | 235 | |
|---|
| 239 | | -STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", kstrtou8); |
|---|
| 240 | | -STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16); |
|---|
| 241 | | -STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", kstrtou16); |
|---|
| 242 | | -STANDARD_PARAM_DEF(int, int, "%i", kstrtoint); |
|---|
| 243 | | -STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint); |
|---|
| 244 | | -STANDARD_PARAM_DEF(long, long, "%li", kstrtol); |
|---|
| 245 | | -STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul); |
|---|
| 246 | | -STANDARD_PARAM_DEF(ullong, unsigned long long, "%llu", kstrtoull); |
|---|
| 236 | +STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", kstrtou8); |
|---|
| 237 | +STANDARD_PARAM_DEF(short, short, "%hi", kstrtos16); |
|---|
| 238 | +STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", kstrtou16); |
|---|
| 239 | +STANDARD_PARAM_DEF(int, int, "%i", kstrtoint); |
|---|
| 240 | +STANDARD_PARAM_DEF(uint, unsigned int, "%u", kstrtouint); |
|---|
| 241 | +STANDARD_PARAM_DEF(long, long, "%li", kstrtol); |
|---|
| 242 | +STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", kstrtoul); |
|---|
| 243 | +STANDARD_PARAM_DEF(ullong, unsigned long long, "%llu", kstrtoull); |
|---|
| 244 | +STANDARD_PARAM_DEF(hexint, unsigned int, "%#08x", kstrtouint); |
|---|
| 247 | 245 | |
|---|
| 248 | 246 | int param_set_charp(const char *val, const struct kernel_param *kp) |
|---|
| 249 | 247 | { |
|---|
| .. | .. |
|---|
| 532 | 530 | { |
|---|
| 533 | 531 | unsigned int num; |
|---|
| 534 | 532 | struct attribute_group grp; |
|---|
| 535 | | - struct param_attribute attrs[0]; |
|---|
| 533 | + struct param_attribute attrs[]; |
|---|
| 536 | 534 | }; |
|---|
| 537 | 535 | |
|---|
| 538 | 536 | #ifdef CONFIG_SYSFS |
|---|
| .. | .. |
|---|
| 565 | 563 | return -EPERM; |
|---|
| 566 | 564 | |
|---|
| 567 | 565 | kernel_param_lock(mk->mod); |
|---|
| 568 | | - param_check_unsafe(attribute->param); |
|---|
| 569 | | - err = attribute->param->ops->set(buf, attribute->param); |
|---|
| 566 | + if (param_check_unsafe(attribute->param)) |
|---|
| 567 | + err = attribute->param->ops->set(buf, attribute->param); |
|---|
| 568 | + else |
|---|
| 569 | + err = -EPERM; |
|---|
| 570 | 570 | kernel_param_unlock(mk->mod); |
|---|
| 571 | 571 | if (!err) |
|---|
| 572 | 572 | return len; |
|---|
| .. | .. |
|---|
| 924 | 924 | }; |
|---|
| 925 | 925 | |
|---|
| 926 | 926 | struct kset *module_kset; |
|---|
| 927 | | -EXPORT_SYMBOL_GPL(module_kset); |
|---|
| 928 | 927 | int module_sysfs_initialized; |
|---|
| 929 | 928 | |
|---|
| 930 | 929 | static void module_kobj_release(struct kobject *kobj) |
|---|
| .. | .. |
|---|
| 937 | 936 | .release = module_kobj_release, |
|---|
| 938 | 937 | .sysfs_ops = &module_sysfs_ops, |
|---|
| 939 | 938 | }; |
|---|
| 940 | | -EXPORT_SYMBOL_GPL(module_ktype); |
|---|
| 941 | 939 | |
|---|
| 942 | 940 | /* |
|---|
| 943 | 941 | * param_sysfs_init - wrapper for built-in params support |
|---|
| .. | .. |
|---|
| 957 | 955 | |
|---|
| 958 | 956 | return 0; |
|---|
| 959 | 957 | } |
|---|
| 960 | | -#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT |
|---|
| 961 | | -arch_initcall_sync(param_sysfs_init); |
|---|
| 962 | | -#else |
|---|
| 963 | 958 | subsys_initcall(param_sysfs_init); |
|---|
| 964 | | -#endif |
|---|
| 965 | 959 | |
|---|
| 966 | 960 | #endif /* CONFIG_SYSFS */ |
|---|