hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/kernel/params.c
....@@ -1,19 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* Helpers for initial module or kernel cmdline parsing
23 Copyright (C) 2001 Rusty Russell.
34
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
175 */
186 #include <linux/kernel.h>
197 #include <linux/string.h>
....@@ -24,6 +12,7 @@
2412 #include <linux/err.h>
2513 #include <linux/slab.h>
2614 #include <linux/ctype.h>
15
+#include <linux/security.h>
2716
2817 #ifdef CONFIG_SYSFS
2918 /* Protects all built-in parameters, modules use their own param_lock */
....@@ -108,13 +97,19 @@
10897 return parameqn(a, b, strlen(a)+1);
10998 }
11099
111
-static void param_check_unsafe(const struct kernel_param *kp)
100
+static bool param_check_unsafe(const struct kernel_param *kp)
112101 {
102
+ if (kp->flags & KERNEL_PARAM_FL_HWPARAM &&
103
+ security_locked_down(LOCKDOWN_MODULE_PARAMETERS))
104
+ return false;
105
+
113106 if (kp->flags & KERNEL_PARAM_FL_UNSAFE) {
114107 pr_notice("Setting dangerous option %s - tainting kernel\n",
115108 kp->name);
116109 add_taint(TAINT_USER, LOCKDEP_STILL_OK);
117110 }
111
+
112
+ return true;
118113 }
119114
120115 static int parse_one(char *param,
....@@ -144,8 +139,10 @@
144139 pr_debug("handling %s with %p\n", param,
145140 params[i].ops->set);
146141 kernel_param_lock(params[i].mod);
147
- param_check_unsafe(&params[i]);
148
- err = params[i].ops->set(val, &params[i]);
142
+ if (param_check_unsafe(&params[i]))
143
+ err = params[i].ops->set(val, &params[i]);
144
+ else
145
+ err = -EPERM;
149146 kernel_param_unlock(params[i].mod);
150147 return err;
151148 }
....@@ -236,14 +233,15 @@
236233 EXPORT_SYMBOL(param_ops_##name)
237234
238235
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);
247245
248246 int param_set_charp(const char *val, const struct kernel_param *kp)
249247 {
....@@ -532,7 +530,7 @@
532530 {
533531 unsigned int num;
534532 struct attribute_group grp;
535
- struct param_attribute attrs[0];
533
+ struct param_attribute attrs[];
536534 };
537535
538536 #ifdef CONFIG_SYSFS
....@@ -565,8 +563,10 @@
565563 return -EPERM;
566564
567565 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;
570570 kernel_param_unlock(mk->mod);
571571 if (!err)
572572 return len;
....@@ -924,7 +924,6 @@
924924 };
925925
926926 struct kset *module_kset;
927
-EXPORT_SYMBOL_GPL(module_kset);
928927 int module_sysfs_initialized;
929928
930929 static void module_kobj_release(struct kobject *kobj)
....@@ -937,7 +936,6 @@
937936 .release = module_kobj_release,
938937 .sysfs_ops = &module_sysfs_ops,
939938 };
940
-EXPORT_SYMBOL_GPL(module_ktype);
941939
942940 /*
943941 * param_sysfs_init - wrapper for built-in params support
....@@ -957,10 +955,6 @@
957955
958956 return 0;
959957 }
960
-#ifdef CONFIG_ROCKCHIP_THUNDER_BOOT
961
-arch_initcall_sync(param_sysfs_init);
962
-#else
963958 subsys_initcall(param_sysfs_init);
964
-#endif
965959
966960 #endif /* CONFIG_SYSFS */