hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/kernel/sysctl.c
....@@ -114,15 +114,9 @@
114114 static int sixty = 60;
115115 #endif
116116
117
-static int __maybe_unused neg_one = -1;
118
-static int __maybe_unused two = 2;
119
-static int __maybe_unused four = 4;
120117 static unsigned long zero_ul;
121118 static unsigned long one_ul = 1;
122119 static unsigned long long_max = LONG_MAX;
123
-static int one_hundred = 100;
124
-static int two_hundred = 200;
125
-static int one_thousand = 1000;
126120 #ifdef CONFIG_PRINTK
127121 static int ten_thousand = 10000;
128122 #endif
....@@ -1064,6 +1058,65 @@
10641058 do_proc_douintvec_minmax_conv, &param);
10651059 }
10661060
1061
+/**
1062
+ * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
1063
+ * @table: the sysctl table
1064
+ * @write: %TRUE if this is a write to the sysctl file
1065
+ * @buffer: the user buffer
1066
+ * @lenp: the size of the user buffer
1067
+ * @ppos: file position
1068
+ *
1069
+ * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
1070
+ * values from/to the user buffer, treated as an ASCII string. Negative
1071
+ * strings are not allowed.
1072
+ *
1073
+ * This routine will ensure the values are within the range specified by
1074
+ * table->extra1 (min) and table->extra2 (max).
1075
+ *
1076
+ * Returns 0 on success or an error on write when the range check fails.
1077
+ */
1078
+int proc_dou8vec_minmax(struct ctl_table *table, int write,
1079
+ void *buffer, size_t *lenp, loff_t *ppos)
1080
+{
1081
+ struct ctl_table tmp;
1082
+ unsigned int min = 0, max = 255U, val;
1083
+ u8 *data = table->data;
1084
+ struct do_proc_douintvec_minmax_conv_param param = {
1085
+ .min = &min,
1086
+ .max = &max,
1087
+ };
1088
+ int res;
1089
+
1090
+ /* Do not support arrays yet. */
1091
+ if (table->maxlen != sizeof(u8))
1092
+ return -EINVAL;
1093
+
1094
+ if (table->extra1) {
1095
+ min = *(unsigned int *) table->extra1;
1096
+ if (min > 255U)
1097
+ return -EINVAL;
1098
+ }
1099
+ if (table->extra2) {
1100
+ max = *(unsigned int *) table->extra2;
1101
+ if (max > 255U)
1102
+ return -EINVAL;
1103
+ }
1104
+
1105
+ tmp = *table;
1106
+
1107
+ tmp.maxlen = sizeof(val);
1108
+ tmp.data = &val;
1109
+ val = READ_ONCE(*data);
1110
+ res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1111
+ do_proc_douintvec_minmax_conv, &param);
1112
+ if (res)
1113
+ return res;
1114
+ if (write)
1115
+ WRITE_ONCE(*data, val);
1116
+ return 0;
1117
+}
1118
+EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1119
+
10671120 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
10681121 unsigned int *valp,
10691122 int write, void *data)
....@@ -1615,6 +1668,12 @@
16151668 return -ENOSYS;
16161669 }
16171670
1671
+int proc_dou8vec_minmax(struct ctl_table *table, int write,
1672
+ void *buffer, size_t *lenp, loff_t *ppos)
1673
+{
1674
+ return -ENOSYS;
1675
+}
1676
+
16181677 int proc_dointvec_jiffies(struct ctl_table *table, int write,
16191678 void *buffer, size_t *lenp, loff_t *ppos)
16201679 {
....@@ -1964,7 +2023,7 @@
19642023 .maxlen = sizeof(int),
19652024 .mode = 0644,
19662025 .proc_handler = proc_dointvec_minmax,
1967
- .extra1 = &neg_one,
2026
+ .extra1 = SYSCTL_NEG_ONE,
19682027 .extra2 = SYSCTL_ONE,
19692028 },
19702029 #endif
....@@ -2218,17 +2277,6 @@
22182277 .proc_handler = proc_dointvec,
22192278 },
22202279 #endif
2221
-#ifdef CONFIG_SMP
2222
- {
2223
- .procname = "oops_all_cpu_backtrace",
2224
- .data = &sysctl_oops_all_cpu_backtrace,
2225
- .maxlen = sizeof(int),
2226
- .mode = 0644,
2227
- .proc_handler = proc_dointvec_minmax,
2228
- .extra1 = SYSCTL_ZERO,
2229
- .extra2 = SYSCTL_ONE,
2230
- },
2231
-#endif /* CONFIG_SMP */
22322280 {
22332281 .procname = "pid_max",
22342282 .data = &pid_max,
....@@ -2306,7 +2354,7 @@
23062354 .mode = 0644,
23072355 .proc_handler = proc_dointvec_minmax_sysadmin,
23082356 .extra1 = SYSCTL_ZERO,
2309
- .extra2 = &two,
2357
+ .extra2 = SYSCTL_TWO,
23102358 },
23112359 #endif
23122360 {
....@@ -2566,7 +2614,7 @@
25662614 .maxlen = sizeof(int),
25672615 .mode = 0644,
25682616 .proc_handler = proc_dointvec_minmax,
2569
- .extra1 = &neg_one,
2617
+ .extra1 = SYSCTL_NEG_ONE,
25702618 },
25712619 #endif
25722620 #ifdef CONFIG_RT_MUTEXES
....@@ -2628,7 +2676,7 @@
26282676 .mode = 0644,
26292677 .proc_handler = perf_cpu_time_max_percent_handler,
26302678 .extra1 = SYSCTL_ZERO,
2631
- .extra2 = &one_hundred,
2679
+ .extra2 = SYSCTL_ONE_HUNDRED,
26322680 },
26332681 {
26342682 .procname = "perf_event_max_stack",
....@@ -2646,7 +2694,7 @@
26462694 .mode = 0644,
26472695 .proc_handler = perf_event_max_stack_handler,
26482696 .extra1 = SYSCTL_ZERO,
2649
- .extra2 = &one_thousand,
2697
+ .extra2 = SYSCTL_ONE_THOUSAND,
26502698 },
26512699 #endif
26522700 {
....@@ -2677,7 +2725,7 @@
26772725 .mode = 0644,
26782726 .proc_handler = bpf_unpriv_handler,
26792727 .extra1 = SYSCTL_ZERO,
2680
- .extra2 = &two,
2728
+ .extra2 = SYSCTL_TWO,
26812729 },
26822730 {
26832731 .procname = "bpf_stats_enabled",
....@@ -2720,7 +2768,7 @@
27202768 .mode = 0644,
27212769 .proc_handler = overcommit_policy_handler,
27222770 .extra1 = SYSCTL_ZERO,
2723
- .extra2 = &two,
2771
+ .extra2 = SYSCTL_TWO,
27242772 },
27252773 {
27262774 .procname = "panic_on_oom",
....@@ -2729,7 +2777,7 @@
27292777 .mode = 0644,
27302778 .proc_handler = proc_dointvec_minmax,
27312779 .extra1 = SYSCTL_ZERO,
2732
- .extra2 = &two,
2780
+ .extra2 = SYSCTL_TWO,
27332781 },
27342782 {
27352783 .procname = "oom_kill_allocating_task",
....@@ -2774,7 +2822,7 @@
27742822 .mode = 0644,
27752823 .proc_handler = dirty_background_ratio_handler,
27762824 .extra1 = SYSCTL_ZERO,
2777
- .extra2 = &one_hundred,
2825
+ .extra2 = SYSCTL_ONE_HUNDRED,
27782826 },
27792827 {
27802828 .procname = "dirty_background_bytes",
....@@ -2791,7 +2839,7 @@
27912839 .mode = 0644,
27922840 .proc_handler = dirty_ratio_handler,
27932841 .extra1 = SYSCTL_ZERO,
2794
- .extra2 = &one_hundred,
2842
+ .extra2 = SYSCTL_ONE_HUNDRED,
27952843 },
27962844 {
27972845 .procname = "dirty_bytes",
....@@ -2831,7 +2879,7 @@
28312879 .mode = 0644,
28322880 .proc_handler = proc_dointvec_minmax,
28332881 .extra1 = SYSCTL_ZERO,
2834
- .extra2 = &two_hundred,
2882
+ .extra2 = SYSCTL_TWO_HUNDRED,
28352883 },
28362884 #ifdef CONFIG_NUMA
28372885 {
....@@ -2890,7 +2938,7 @@
28902938 .mode = 0200,
28912939 .proc_handler = drop_caches_sysctl_handler,
28922940 .extra1 = SYSCTL_ONE,
2893
- .extra2 = &four,
2941
+ .extra2 = SYSCTL_FOUR,
28942942 },
28952943 #ifdef CONFIG_COMPACTION
28962944 {
....@@ -2907,7 +2955,7 @@
29072955 .mode = 0644,
29082956 .proc_handler = compaction_proactiveness_sysctl_handler,
29092957 .extra1 = SYSCTL_ZERO,
2910
- .extra2 = &one_hundred,
2958
+ .extra2 = SYSCTL_ONE_HUNDRED,
29112959 },
29122960 {
29132961 .procname = "extfrag_threshold",
....@@ -2952,7 +3000,7 @@
29523000 .mode = 0644,
29533001 .proc_handler = watermark_scale_factor_sysctl_handler,
29543002 .extra1 = SYSCTL_ONE,
2955
- .extra2 = &one_thousand,
3003
+ .extra2 = SYSCTL_THREE_THOUSAND,
29563004 },
29573005 {
29583006 .procname = "extra_free_kbytes",
....@@ -3047,7 +3095,7 @@
30473095 .mode = 0644,
30483096 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
30493097 .extra1 = SYSCTL_ZERO,
3050
- .extra2 = &one_hundred,
3098
+ .extra2 = SYSCTL_ONE_HUNDRED,
30513099 },
30523100 {
30533101 .procname = "min_slab_ratio",
....@@ -3056,7 +3104,7 @@
30563104 .mode = 0644,
30573105 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
30583106 .extra1 = SYSCTL_ZERO,
3059
- .extra2 = &one_hundred,
3107
+ .extra2 = SYSCTL_ONE_HUNDRED,
30603108 },
30613109 #endif
30623110 #ifdef CONFIG_SMP
....@@ -3339,7 +3387,7 @@
33393387 .mode = 0600,
33403388 .proc_handler = proc_dointvec_minmax,
33413389 .extra1 = SYSCTL_ZERO,
3342
- .extra2 = &two,
3390
+ .extra2 = SYSCTL_TWO,
33433391 },
33443392 {
33453393 .procname = "protected_regular",
....@@ -3348,7 +3396,7 @@
33483396 .mode = 0600,
33493397 .proc_handler = proc_dointvec_minmax,
33503398 .extra1 = SYSCTL_ZERO,
3351
- .extra2 = &two,
3399
+ .extra2 = SYSCTL_TWO,
33523400 },
33533401 {
33543402 .procname = "suid_dumpable",
....@@ -3357,7 +3405,7 @@
33573405 .mode = 0644,
33583406 .proc_handler = proc_dointvec_minmax_coredump,
33593407 .extra1 = SYSCTL_ZERO,
3360
- .extra2 = &two,
3408
+ .extra2 = SYSCTL_TWO,
33613409 },
33623410 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
33633411 {