summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMatteo Croce <mcroce@redhat.com>2019-07-18 18:58:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-18 20:08:07 -0400
commiteec4844fae7c033a0c1fc1eb3b8517aeb8b6cc49 (patch)
treea7da379423835a85c020e116a43bea6acf3c9ace /kernel
parent371096949f0ad3950b06729989bd27de51b8c5f5 (diff)
proc/sysctl: add shared variables for range check
In the sysctl code the proc_dointvec_minmax() function is often used to validate the user supplied value between an allowed range. This function uses the extra1 and extra2 members from struct ctl_table as minimum and maximum allowed value. On sysctl handler declaration, in every source file there are some readonly variables containing just an integer which address is assigned to the extra1 and extra2 members, so the sysctl range is enforced. The special values 0, 1 and INT_MAX are very often used as range boundary, leading duplication of variables like zero=0, one=1, int_max=INT_MAX in different source files: $ git grep -E '\.extra[12].*&(zero|one|int_max)' |wc -l 248 Add a const int array containing the most commonly used values, some macros to refer more easily to the correct array member, and use them instead of creating a local one for every object file. This is the bloat-o-meter output comparing the old and new binary compiled with the default Fedora config: # scripts/bloat-o-meter -d vmlinux.o.old vmlinux.o add/remove: 2/2 grow/shrink: 0/2 up/down: 24/-188 (-164) Data old new delta sysctl_vals - 12 +12 __kstrtab_sysctl_vals - 12 +12 max 14 10 -4 int_max 16 - -16 one 68 - -68 zero 128 28 -100 Total: Before=20583249, After=20583085, chg -0.00% [mcroce@redhat.com: tipc: remove two unused variables] Link: http://lkml.kernel.org/r/20190530091952.4108-1-mcroce@redhat.com [akpm@linux-foundation.org: fix net/ipv6/sysctl_net_ipv6.c] [arnd@arndb.de: proc/sysctl: make firmware loader table conditional] Link: http://lkml.kernel.org/r/20190617130014.1713870-1-arnd@arndb.de [akpm@linux-foundation.org: fix fs/eventpoll.c] Link: http://lkml.kernel.org/r/20190430180111.10688-1-mcroce@redhat.com Signed-off-by: Matteo Croce <mcroce@redhat.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Kees Cook <keescook@chromium.org> Reviewed-by: Aaron Tomlin <atomlin@redhat.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/pid_namespace.c3
-rw-r--r--kernel/sysctl.c197
-rw-r--r--kernel/ucount.c6
3 files changed, 100 insertions, 106 deletions
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 6d726cef241c..a6a79f85c81a 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -291,14 +291,13 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
291} 291}
292 292
293extern int pid_max; 293extern int pid_max;
294static int zero = 0;
295static struct ctl_table pid_ns_ctl_table[] = { 294static struct ctl_table pid_ns_ctl_table[] = {
296 { 295 {
297 .procname = "ns_last_pid", 296 .procname = "ns_last_pid",
298 .maxlen = sizeof(int), 297 .maxlen = sizeof(int),
299 .mode = 0666, /* permissions are checked in the handler */ 298 .mode = 0666, /* permissions are checked in the handler */
300 .proc_handler = pid_ns_ctl_handler, 299 .proc_handler = pid_ns_ctl_handler,
301 .extra1 = &zero, 300 .extra1 = SYSCTL_ZERO,
302 .extra2 = &pid_max, 301 .extra2 = &pid_max,
303 }, 302 },
304 { } 303 { }
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 43186ccfa139..078950d9605b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -125,9 +125,6 @@ static int sixty = 60;
125#endif 125#endif
126 126
127static int __maybe_unused neg_one = -1; 127static int __maybe_unused neg_one = -1;
128
129static int zero;
130static int __maybe_unused one = 1;
131static int __maybe_unused two = 2; 128static int __maybe_unused two = 2;
132static int __maybe_unused four = 4; 129static int __maybe_unused four = 4;
133static unsigned long zero_ul; 130static unsigned long zero_ul;
@@ -385,8 +382,8 @@ static struct ctl_table kern_table[] = {
385 .maxlen = sizeof(unsigned int), 382 .maxlen = sizeof(unsigned int),
386 .mode = 0644, 383 .mode = 0644,
387 .proc_handler = sysctl_schedstats, 384 .proc_handler = sysctl_schedstats,
388 .extra1 = &zero, 385 .extra1 = SYSCTL_ZERO,
389 .extra2 = &one, 386 .extra2 = SYSCTL_ONE,
390 }, 387 },
391#endif /* CONFIG_SCHEDSTATS */ 388#endif /* CONFIG_SCHEDSTATS */
392#endif /* CONFIG_SMP */ 389#endif /* CONFIG_SMP */
@@ -418,7 +415,7 @@ static struct ctl_table kern_table[] = {
418 .maxlen = sizeof(unsigned int), 415 .maxlen = sizeof(unsigned int),
419 .mode = 0644, 416 .mode = 0644,
420 .proc_handler = proc_dointvec_minmax, 417 .proc_handler = proc_dointvec_minmax,
421 .extra1 = &one, 418 .extra1 = SYSCTL_ONE,
422 }, 419 },
423 { 420 {
424 .procname = "numa_balancing", 421 .procname = "numa_balancing",
@@ -426,8 +423,8 @@ static struct ctl_table kern_table[] = {
426 .maxlen = sizeof(unsigned int), 423 .maxlen = sizeof(unsigned int),
427 .mode = 0644, 424 .mode = 0644,
428 .proc_handler = sysctl_numa_balancing, 425 .proc_handler = sysctl_numa_balancing,
429 .extra1 = &zero, 426 .extra1 = SYSCTL_ZERO,
430 .extra2 = &one, 427 .extra2 = SYSCTL_ONE,
431 }, 428 },
432#endif /* CONFIG_NUMA_BALANCING */ 429#endif /* CONFIG_NUMA_BALANCING */
433#endif /* CONFIG_SCHED_DEBUG */ 430#endif /* CONFIG_SCHED_DEBUG */
@@ -475,8 +472,8 @@ static struct ctl_table kern_table[] = {
475 .maxlen = sizeof(unsigned int), 472 .maxlen = sizeof(unsigned int),
476 .mode = 0644, 473 .mode = 0644,
477 .proc_handler = proc_dointvec_minmax, 474 .proc_handler = proc_dointvec_minmax,
478 .extra1 = &zero, 475 .extra1 = SYSCTL_ZERO,
479 .extra2 = &one, 476 .extra2 = SYSCTL_ONE,
480 }, 477 },
481#endif 478#endif
482#ifdef CONFIG_CFS_BANDWIDTH 479#ifdef CONFIG_CFS_BANDWIDTH
@@ -486,7 +483,7 @@ static struct ctl_table kern_table[] = {
486 .maxlen = sizeof(unsigned int), 483 .maxlen = sizeof(unsigned int),
487 .mode = 0644, 484 .mode = 0644,
488 .proc_handler = proc_dointvec_minmax, 485 .proc_handler = proc_dointvec_minmax,
489 .extra1 = &one, 486 .extra1 = SYSCTL_ONE,
490 }, 487 },
491#endif 488#endif
492#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) 489#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
@@ -496,8 +493,8 @@ static struct ctl_table kern_table[] = {
496 .maxlen = sizeof(unsigned int), 493 .maxlen = sizeof(unsigned int),
497 .mode = 0644, 494 .mode = 0644,
498 .proc_handler = sched_energy_aware_handler, 495 .proc_handler = sched_energy_aware_handler,
499 .extra1 = &zero, 496 .extra1 = SYSCTL_ZERO,
500 .extra2 = &one, 497 .extra2 = SYSCTL_ONE,
501 }, 498 },
502#endif 499#endif
503#ifdef CONFIG_PROVE_LOCKING 500#ifdef CONFIG_PROVE_LOCKING
@@ -562,7 +559,7 @@ static struct ctl_table kern_table[] = {
562 .mode = 0644, 559 .mode = 0644,
563 .proc_handler = proc_dointvec_minmax, 560 .proc_handler = proc_dointvec_minmax,
564 .extra1 = &neg_one, 561 .extra1 = &neg_one,
565 .extra2 = &one, 562 .extra2 = SYSCTL_ONE,
566 }, 563 },
567#endif 564#endif
568#ifdef CONFIG_LATENCYTOP 565#ifdef CONFIG_LATENCYTOP
@@ -696,8 +693,8 @@ static struct ctl_table kern_table[] = {
696 .mode = 0644, 693 .mode = 0644,
697 /* only handle a transition from default "0" to "1" */ 694 /* only handle a transition from default "0" to "1" */
698 .proc_handler = proc_dointvec_minmax, 695 .proc_handler = proc_dointvec_minmax,
699 .extra1 = &one, 696 .extra1 = SYSCTL_ONE,
700 .extra2 = &one, 697 .extra2 = SYSCTL_ONE,
701 }, 698 },
702#endif 699#endif
703#ifdef CONFIG_MODULES 700#ifdef CONFIG_MODULES
@@ -715,8 +712,8 @@ static struct ctl_table kern_table[] = {
715 .mode = 0644, 712 .mode = 0644,
716 /* only handle a transition from default "0" to "1" */ 713 /* only handle a transition from default "0" to "1" */
717 .proc_handler = proc_dointvec_minmax, 714 .proc_handler = proc_dointvec_minmax,
718 .extra1 = &one, 715 .extra1 = SYSCTL_ONE,
719 .extra2 = &one, 716 .extra2 = SYSCTL_ONE,
720 }, 717 },
721#endif 718#endif
722#ifdef CONFIG_UEVENT_HELPER 719#ifdef CONFIG_UEVENT_HELPER
@@ -875,7 +872,7 @@ static struct ctl_table kern_table[] = {
875 .maxlen = sizeof(int), 872 .maxlen = sizeof(int),
876 .mode = 0644, 873 .mode = 0644,
877 .proc_handler = proc_dointvec_minmax, 874 .proc_handler = proc_dointvec_minmax,
878 .extra1 = &zero, 875 .extra1 = SYSCTL_ZERO,
879 .extra2 = &ten_thousand, 876 .extra2 = &ten_thousand,
880 }, 877 },
881 { 878 {
@@ -891,8 +888,8 @@ static struct ctl_table kern_table[] = {
891 .maxlen = sizeof(int), 888 .maxlen = sizeof(int),
892 .mode = 0644, 889 .mode = 0644,
893 .proc_handler = proc_dointvec_minmax_sysadmin, 890 .proc_handler = proc_dointvec_minmax_sysadmin,
894 .extra1 = &zero, 891 .extra1 = SYSCTL_ZERO,
895 .extra2 = &one, 892 .extra2 = SYSCTL_ONE,
896 }, 893 },
897 { 894 {
898 .procname = "kptr_restrict", 895 .procname = "kptr_restrict",
@@ -900,7 +897,7 @@ static struct ctl_table kern_table[] = {
900 .maxlen = sizeof(int), 897 .maxlen = sizeof(int),
901 .mode = 0644, 898 .mode = 0644,
902 .proc_handler = proc_dointvec_minmax_sysadmin, 899 .proc_handler = proc_dointvec_minmax_sysadmin,
903 .extra1 = &zero, 900 .extra1 = SYSCTL_ZERO,
904 .extra2 = &two, 901 .extra2 = &two,
905 }, 902 },
906#endif 903#endif
@@ -925,8 +922,8 @@ static struct ctl_table kern_table[] = {
925 .maxlen = sizeof(int), 922 .maxlen = sizeof(int),
926 .mode = 0644, 923 .mode = 0644,
927 .proc_handler = proc_watchdog, 924 .proc_handler = proc_watchdog,
928 .extra1 = &zero, 925 .extra1 = SYSCTL_ZERO,
929 .extra2 = &one, 926 .extra2 = SYSCTL_ONE,
930 }, 927 },
931 { 928 {
932 .procname = "watchdog_thresh", 929 .procname = "watchdog_thresh",
@@ -934,7 +931,7 @@ static struct ctl_table kern_table[] = {
934 .maxlen = sizeof(int), 931 .maxlen = sizeof(int),
935 .mode = 0644, 932 .mode = 0644,
936 .proc_handler = proc_watchdog_thresh, 933 .proc_handler = proc_watchdog_thresh,
937 .extra1 = &zero, 934 .extra1 = SYSCTL_ZERO,
938 .extra2 = &sixty, 935 .extra2 = &sixty,
939 }, 936 },
940 { 937 {
@@ -943,8 +940,8 @@ static struct ctl_table kern_table[] = {
943 .maxlen = sizeof(int), 940 .maxlen = sizeof(int),
944 .mode = NMI_WATCHDOG_SYSCTL_PERM, 941 .mode = NMI_WATCHDOG_SYSCTL_PERM,
945 .proc_handler = proc_nmi_watchdog, 942 .proc_handler = proc_nmi_watchdog,
946 .extra1 = &zero, 943 .extra1 = SYSCTL_ZERO,
947 .extra2 = &one, 944 .extra2 = SYSCTL_ONE,
948 }, 945 },
949 { 946 {
950 .procname = "watchdog_cpumask", 947 .procname = "watchdog_cpumask",
@@ -960,8 +957,8 @@ static struct ctl_table kern_table[] = {
960 .maxlen = sizeof(int), 957 .maxlen = sizeof(int),
961 .mode = 0644, 958 .mode = 0644,
962 .proc_handler = proc_soft_watchdog, 959 .proc_handler = proc_soft_watchdog,
963 .extra1 = &zero, 960 .extra1 = SYSCTL_ZERO,
964 .extra2 = &one, 961 .extra2 = SYSCTL_ONE,
965 }, 962 },
966 { 963 {
967 .procname = "softlockup_panic", 964 .procname = "softlockup_panic",
@@ -969,8 +966,8 @@ static struct ctl_table kern_table[] = {
969 .maxlen = sizeof(int), 966 .maxlen = sizeof(int),
970 .mode = 0644, 967 .mode = 0644,
971 .proc_handler = proc_dointvec_minmax, 968 .proc_handler = proc_dointvec_minmax,
972 .extra1 = &zero, 969 .extra1 = SYSCTL_ZERO,
973 .extra2 = &one, 970 .extra2 = SYSCTL_ONE,
974 }, 971 },
975#ifdef CONFIG_SMP 972#ifdef CONFIG_SMP
976 { 973 {
@@ -979,8 +976,8 @@ static struct ctl_table kern_table[] = {
979 .maxlen = sizeof(int), 976 .maxlen = sizeof(int),
980 .mode = 0644, 977 .mode = 0644,
981 .proc_handler = proc_dointvec_minmax, 978 .proc_handler = proc_dointvec_minmax,
982 .extra1 = &zero, 979 .extra1 = SYSCTL_ZERO,
983 .extra2 = &one, 980 .extra2 = SYSCTL_ONE,
984 }, 981 },
985#endif /* CONFIG_SMP */ 982#endif /* CONFIG_SMP */
986#endif 983#endif
@@ -991,8 +988,8 @@ static struct ctl_table kern_table[] = {
991 .maxlen = sizeof(int), 988 .maxlen = sizeof(int),
992 .mode = 0644, 989 .mode = 0644,
993 .proc_handler = proc_dointvec_minmax, 990 .proc_handler = proc_dointvec_minmax,
994 .extra1 = &zero, 991 .extra1 = SYSCTL_ZERO,
995 .extra2 = &one, 992 .extra2 = SYSCTL_ONE,
996 }, 993 },
997#ifdef CONFIG_SMP 994#ifdef CONFIG_SMP
998 { 995 {
@@ -1001,8 +998,8 @@ static struct ctl_table kern_table[] = {
1001 .maxlen = sizeof(int), 998 .maxlen = sizeof(int),
1002 .mode = 0644, 999 .mode = 0644,
1003 .proc_handler = proc_dointvec_minmax, 1000 .proc_handler = proc_dointvec_minmax,
1004 .extra1 = &zero, 1001 .extra1 = SYSCTL_ZERO,
1005 .extra2 = &one, 1002 .extra2 = SYSCTL_ONE,
1006 }, 1003 },
1007#endif /* CONFIG_SMP */ 1004#endif /* CONFIG_SMP */
1008#endif 1005#endif
@@ -1115,8 +1112,8 @@ static struct ctl_table kern_table[] = {
1115 .maxlen = sizeof(int), 1112 .maxlen = sizeof(int),
1116 .mode = 0644, 1113 .mode = 0644,
1117 .proc_handler = proc_dointvec_minmax, 1114 .proc_handler = proc_dointvec_minmax,
1118 .extra1 = &zero, 1115 .extra1 = SYSCTL_ZERO,
1119 .extra2 = &one, 1116 .extra2 = SYSCTL_ONE,
1120 }, 1117 },
1121 { 1118 {
1122 .procname = "hung_task_check_count", 1119 .procname = "hung_task_check_count",
@@ -1124,7 +1121,7 @@ static struct ctl_table kern_table[] = {
1124 .maxlen = sizeof(int), 1121 .maxlen = sizeof(int),
1125 .mode = 0644, 1122 .mode = 0644,
1126 .proc_handler = proc_dointvec_minmax, 1123 .proc_handler = proc_dointvec_minmax,
1127 .extra1 = &zero, 1124 .extra1 = SYSCTL_ZERO,
1128 }, 1125 },
1129 { 1126 {
1130 .procname = "hung_task_timeout_secs", 1127 .procname = "hung_task_timeout_secs",
@@ -1201,7 +1198,7 @@ static struct ctl_table kern_table[] = {
1201 .maxlen = sizeof(sysctl_perf_event_sample_rate), 1198 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1202 .mode = 0644, 1199 .mode = 0644,
1203 .proc_handler = perf_proc_update_handler, 1200 .proc_handler = perf_proc_update_handler,
1204 .extra1 = &one, 1201 .extra1 = SYSCTL_ONE,
1205 }, 1202 },
1206 { 1203 {
1207 .procname = "perf_cpu_time_max_percent", 1204 .procname = "perf_cpu_time_max_percent",
@@ -1209,7 +1206,7 @@ static struct ctl_table kern_table[] = {
1209 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), 1206 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1210 .mode = 0644, 1207 .mode = 0644,
1211 .proc_handler = perf_cpu_time_max_percent_handler, 1208 .proc_handler = perf_cpu_time_max_percent_handler,
1212 .extra1 = &zero, 1209 .extra1 = SYSCTL_ZERO,
1213 .extra2 = &one_hundred, 1210 .extra2 = &one_hundred,
1214 }, 1211 },
1215 { 1212 {
@@ -1218,7 +1215,7 @@ static struct ctl_table kern_table[] = {
1218 .maxlen = sizeof(sysctl_perf_event_max_stack), 1215 .maxlen = sizeof(sysctl_perf_event_max_stack),
1219 .mode = 0644, 1216 .mode = 0644,
1220 .proc_handler = perf_event_max_stack_handler, 1217 .proc_handler = perf_event_max_stack_handler,
1221 .extra1 = &zero, 1218 .extra1 = SYSCTL_ZERO,
1222 .extra2 = &six_hundred_forty_kb, 1219 .extra2 = &six_hundred_forty_kb,
1223 }, 1220 },
1224 { 1221 {
@@ -1227,7 +1224,7 @@ static struct ctl_table kern_table[] = {
1227 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), 1224 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1228 .mode = 0644, 1225 .mode = 0644,
1229 .proc_handler = perf_event_max_stack_handler, 1226 .proc_handler = perf_event_max_stack_handler,
1230 .extra1 = &zero, 1227 .extra1 = SYSCTL_ZERO,
1231 .extra2 = &one_thousand, 1228 .extra2 = &one_thousand,
1232 }, 1229 },
1233#endif 1230#endif
@@ -1237,8 +1234,8 @@ static struct ctl_table kern_table[] = {
1237 .maxlen = sizeof(int), 1234 .maxlen = sizeof(int),
1238 .mode = 0644, 1235 .mode = 0644,
1239 .proc_handler = proc_dointvec_minmax, 1236 .proc_handler = proc_dointvec_minmax,
1240 .extra1 = &zero, 1237 .extra1 = SYSCTL_ZERO,
1241 .extra2 = &one, 1238 .extra2 = SYSCTL_ONE,
1242 }, 1239 },
1243#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON) 1240#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1244 { 1241 {
@@ -1247,8 +1244,8 @@ static struct ctl_table kern_table[] = {
1247 .maxlen = sizeof(unsigned int), 1244 .maxlen = sizeof(unsigned int),
1248 .mode = 0644, 1245 .mode = 0644,
1249 .proc_handler = timer_migration_handler, 1246 .proc_handler = timer_migration_handler,
1250 .extra1 = &zero, 1247 .extra1 = SYSCTL_ZERO,
1251 .extra2 = &one, 1248 .extra2 = SYSCTL_ONE,
1252 }, 1249 },
1253#endif 1250#endif
1254#ifdef CONFIG_BPF_SYSCALL 1251#ifdef CONFIG_BPF_SYSCALL
@@ -1259,8 +1256,8 @@ static struct ctl_table kern_table[] = {
1259 .mode = 0644, 1256 .mode = 0644,
1260 /* only handle a transition from default "0" to "1" */ 1257 /* only handle a transition from default "0" to "1" */
1261 .proc_handler = proc_dointvec_minmax, 1258 .proc_handler = proc_dointvec_minmax,
1262 .extra1 = &one, 1259 .extra1 = SYSCTL_ONE,
1263 .extra2 = &one, 1260 .extra2 = SYSCTL_ONE,
1264 }, 1261 },
1265 { 1262 {
1266 .procname = "bpf_stats_enabled", 1263 .procname = "bpf_stats_enabled",
@@ -1277,8 +1274,8 @@ static struct ctl_table kern_table[] = {
1277 .maxlen = sizeof(sysctl_panic_on_rcu_stall), 1274 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1278 .mode = 0644, 1275 .mode = 0644,
1279 .proc_handler = proc_dointvec_minmax, 1276 .proc_handler = proc_dointvec_minmax,
1280 .extra1 = &zero, 1277 .extra1 = SYSCTL_ZERO,
1281 .extra2 = &one, 1278 .extra2 = SYSCTL_ONE,
1282 }, 1279 },
1283#endif 1280#endif
1284#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE 1281#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
@@ -1288,8 +1285,8 @@ static struct ctl_table kern_table[] = {
1288 .maxlen = sizeof(int), 1285 .maxlen = sizeof(int),
1289 .mode = 0600, 1286 .mode = 0600,
1290 .proc_handler = stack_erasing_sysctl, 1287 .proc_handler = stack_erasing_sysctl,
1291 .extra1 = &zero, 1288 .extra1 = SYSCTL_ZERO,
1292 .extra2 = &one, 1289 .extra2 = SYSCTL_ONE,
1293 }, 1290 },
1294#endif 1291#endif
1295 { } 1292 { }
@@ -1302,7 +1299,7 @@ static struct ctl_table vm_table[] = {
1302 .maxlen = sizeof(sysctl_overcommit_memory), 1299 .maxlen = sizeof(sysctl_overcommit_memory),
1303 .mode = 0644, 1300 .mode = 0644,
1304 .proc_handler = proc_dointvec_minmax, 1301 .proc_handler = proc_dointvec_minmax,
1305 .extra1 = &zero, 1302 .extra1 = SYSCTL_ZERO,
1306 .extra2 = &two, 1303 .extra2 = &two,
1307 }, 1304 },
1308 { 1305 {
@@ -1311,7 +1308,7 @@ static struct ctl_table vm_table[] = {
1311 .maxlen = sizeof(sysctl_panic_on_oom), 1308 .maxlen = sizeof(sysctl_panic_on_oom),
1312 .mode = 0644, 1309 .mode = 0644,
1313 .proc_handler = proc_dointvec_minmax, 1310 .proc_handler = proc_dointvec_minmax,
1314 .extra1 = &zero, 1311 .extra1 = SYSCTL_ZERO,
1315 .extra2 = &two, 1312 .extra2 = &two,
1316 }, 1313 },
1317 { 1314 {
@@ -1348,7 +1345,7 @@ static struct ctl_table vm_table[] = {
1348 .maxlen = sizeof(int), 1345 .maxlen = sizeof(int),
1349 .mode = 0644, 1346 .mode = 0644,
1350 .proc_handler = proc_dointvec_minmax, 1347 .proc_handler = proc_dointvec_minmax,
1351 .extra1 = &zero, 1348 .extra1 = SYSCTL_ZERO,
1352 }, 1349 },
1353 { 1350 {
1354 .procname = "dirty_background_ratio", 1351 .procname = "dirty_background_ratio",
@@ -1356,7 +1353,7 @@ static struct ctl_table vm_table[] = {
1356 .maxlen = sizeof(dirty_background_ratio), 1353 .maxlen = sizeof(dirty_background_ratio),
1357 .mode = 0644, 1354 .mode = 0644,
1358 .proc_handler = dirty_background_ratio_handler, 1355 .proc_handler = dirty_background_ratio_handler,
1359 .extra1 = &zero, 1356 .extra1 = SYSCTL_ZERO,
1360 .extra2 = &one_hundred, 1357 .extra2 = &one_hundred,
1361 }, 1358 },
1362 { 1359 {
@@ -1373,7 +1370,7 @@ static struct ctl_table vm_table[] = {
1373 .maxlen = sizeof(vm_dirty_ratio), 1370 .maxlen = sizeof(vm_dirty_ratio),
1374 .mode = 0644, 1371 .mode = 0644,
1375 .proc_handler = dirty_ratio_handler, 1372 .proc_handler = dirty_ratio_handler,
1376 .extra1 = &zero, 1373 .extra1 = SYSCTL_ZERO,
1377 .extra2 = &one_hundred, 1374 .extra2 = &one_hundred,
1378 }, 1375 },
1379 { 1376 {
@@ -1397,7 +1394,7 @@ static struct ctl_table vm_table[] = {
1397 .maxlen = sizeof(dirty_expire_interval), 1394 .maxlen = sizeof(dirty_expire_interval),
1398 .mode = 0644, 1395 .mode = 0644,
1399 .proc_handler = proc_dointvec_minmax, 1396 .proc_handler = proc_dointvec_minmax,
1400 .extra1 = &zero, 1397 .extra1 = SYSCTL_ZERO,
1401 }, 1398 },
1402 { 1399 {
1403 .procname = "dirtytime_expire_seconds", 1400 .procname = "dirtytime_expire_seconds",
@@ -1405,7 +1402,7 @@ static struct ctl_table vm_table[] = {
1405 .maxlen = sizeof(dirtytime_expire_interval), 1402 .maxlen = sizeof(dirtytime_expire_interval),
1406 .mode = 0644, 1403 .mode = 0644,
1407 .proc_handler = dirtytime_interval_handler, 1404 .proc_handler = dirtytime_interval_handler,
1408 .extra1 = &zero, 1405 .extra1 = SYSCTL_ZERO,
1409 }, 1406 },
1410 { 1407 {
1411 .procname = "swappiness", 1408 .procname = "swappiness",
@@ -1413,7 +1410,7 @@ static struct ctl_table vm_table[] = {
1413 .maxlen = sizeof(vm_swappiness), 1410 .maxlen = sizeof(vm_swappiness),
1414 .mode = 0644, 1411 .mode = 0644,
1415 .proc_handler = proc_dointvec_minmax, 1412 .proc_handler = proc_dointvec_minmax,
1416 .extra1 = &zero, 1413 .extra1 = SYSCTL_ZERO,
1417 .extra2 = &one_hundred, 1414 .extra2 = &one_hundred,
1418 }, 1415 },
1419#ifdef CONFIG_HUGETLB_PAGE 1416#ifdef CONFIG_HUGETLB_PAGE
@@ -1438,8 +1435,8 @@ static struct ctl_table vm_table[] = {
1438 .maxlen = sizeof(int), 1435 .maxlen = sizeof(int),
1439 .mode = 0644, 1436 .mode = 0644,
1440 .proc_handler = sysctl_vm_numa_stat_handler, 1437 .proc_handler = sysctl_vm_numa_stat_handler,
1441 .extra1 = &zero, 1438 .extra1 = SYSCTL_ZERO,
1442 .extra2 = &one, 1439 .extra2 = SYSCTL_ONE,
1443 }, 1440 },
1444#endif 1441#endif
1445 { 1442 {
@@ -1470,7 +1467,7 @@ static struct ctl_table vm_table[] = {
1470 .maxlen = sizeof(int), 1467 .maxlen = sizeof(int),
1471 .mode = 0644, 1468 .mode = 0644,
1472 .proc_handler = drop_caches_sysctl_handler, 1469 .proc_handler = drop_caches_sysctl_handler,
1473 .extra1 = &one, 1470 .extra1 = SYSCTL_ONE,
1474 .extra2 = &four, 1471 .extra2 = &four,
1475 }, 1472 },
1476#ifdef CONFIG_COMPACTION 1473#ifdef CONFIG_COMPACTION
@@ -1496,8 +1493,8 @@ static struct ctl_table vm_table[] = {
1496 .maxlen = sizeof(int), 1493 .maxlen = sizeof(int),
1497 .mode = 0644, 1494 .mode = 0644,
1498 .proc_handler = proc_dointvec, 1495 .proc_handler = proc_dointvec,
1499 .extra1 = &zero, 1496 .extra1 = SYSCTL_ZERO,
1500 .extra2 = &one, 1497 .extra2 = SYSCTL_ONE,
1501 }, 1498 },
1502 1499
1503#endif /* CONFIG_COMPACTION */ 1500#endif /* CONFIG_COMPACTION */
@@ -1507,7 +1504,7 @@ static struct ctl_table vm_table[] = {
1507 .maxlen = sizeof(min_free_kbytes), 1504 .maxlen = sizeof(min_free_kbytes),
1508 .mode = 0644, 1505 .mode = 0644,
1509 .proc_handler = min_free_kbytes_sysctl_handler, 1506 .proc_handler = min_free_kbytes_sysctl_handler,
1510 .extra1 = &zero, 1507 .extra1 = SYSCTL_ZERO,
1511 }, 1508 },
1512 { 1509 {
1513 .procname = "watermark_boost_factor", 1510 .procname = "watermark_boost_factor",
@@ -1515,7 +1512,7 @@ static struct ctl_table vm_table[] = {
1515 .maxlen = sizeof(watermark_boost_factor), 1512 .maxlen = sizeof(watermark_boost_factor),
1516 .mode = 0644, 1513 .mode = 0644,
1517 .proc_handler = watermark_boost_factor_sysctl_handler, 1514 .proc_handler = watermark_boost_factor_sysctl_handler,
1518 .extra1 = &zero, 1515 .extra1 = SYSCTL_ZERO,
1519 }, 1516 },
1520 { 1517 {
1521 .procname = "watermark_scale_factor", 1518 .procname = "watermark_scale_factor",
@@ -1523,7 +1520,7 @@ static struct ctl_table vm_table[] = {
1523 .maxlen = sizeof(watermark_scale_factor), 1520 .maxlen = sizeof(watermark_scale_factor),
1524 .mode = 0644, 1521 .mode = 0644,
1525 .proc_handler = watermark_scale_factor_sysctl_handler, 1522 .proc_handler = watermark_scale_factor_sysctl_handler,
1526 .extra1 = &one, 1523 .extra1 = SYSCTL_ONE,
1527 .extra2 = &one_thousand, 1524 .extra2 = &one_thousand,
1528 }, 1525 },
1529 { 1526 {
@@ -1532,7 +1529,7 @@ static struct ctl_table vm_table[] = {
1532 .maxlen = sizeof(percpu_pagelist_fraction), 1529 .maxlen = sizeof(percpu_pagelist_fraction),
1533 .mode = 0644, 1530 .mode = 0644,
1534 .proc_handler = percpu_pagelist_fraction_sysctl_handler, 1531 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1535 .extra1 = &zero, 1532 .extra1 = SYSCTL_ZERO,
1536 }, 1533 },
1537#ifdef CONFIG_MMU 1534#ifdef CONFIG_MMU
1538 { 1535 {
@@ -1541,7 +1538,7 @@ static struct ctl_table vm_table[] = {
1541 .maxlen = sizeof(sysctl_max_map_count), 1538 .maxlen = sizeof(sysctl_max_map_count),
1542 .mode = 0644, 1539 .mode = 0644,
1543 .proc_handler = proc_dointvec_minmax, 1540 .proc_handler = proc_dointvec_minmax,
1544 .extra1 = &zero, 1541 .extra1 = SYSCTL_ZERO,
1545 }, 1542 },
1546#else 1543#else
1547 { 1544 {
@@ -1550,7 +1547,7 @@ static struct ctl_table vm_table[] = {
1550 .maxlen = sizeof(sysctl_nr_trim_pages), 1547 .maxlen = sizeof(sysctl_nr_trim_pages),
1551 .mode = 0644, 1548 .mode = 0644,
1552 .proc_handler = proc_dointvec_minmax, 1549 .proc_handler = proc_dointvec_minmax,
1553 .extra1 = &zero, 1550 .extra1 = SYSCTL_ZERO,
1554 }, 1551 },
1555#endif 1552#endif
1556 { 1553 {
@@ -1566,7 +1563,7 @@ static struct ctl_table vm_table[] = {
1566 .maxlen = sizeof(block_dump), 1563 .maxlen = sizeof(block_dump),
1567 .mode = 0644, 1564 .mode = 0644,
1568 .proc_handler = proc_dointvec, 1565 .proc_handler = proc_dointvec,
1569 .extra1 = &zero, 1566 .extra1 = SYSCTL_ZERO,
1570 }, 1567 },
1571 { 1568 {
1572 .procname = "vfs_cache_pressure", 1569 .procname = "vfs_cache_pressure",
@@ -1574,7 +1571,7 @@ static struct ctl_table vm_table[] = {
1574 .maxlen = sizeof(sysctl_vfs_cache_pressure), 1571 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1575 .mode = 0644, 1572 .mode = 0644,
1576 .proc_handler = proc_dointvec, 1573 .proc_handler = proc_dointvec,
1577 .extra1 = &zero, 1574 .extra1 = SYSCTL_ZERO,
1578 }, 1575 },
1579#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 1576#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1580 { 1577 {
@@ -1583,7 +1580,7 @@ static struct ctl_table vm_table[] = {
1583 .maxlen = sizeof(sysctl_legacy_va_layout), 1580 .maxlen = sizeof(sysctl_legacy_va_layout),
1584 .mode = 0644, 1581 .mode = 0644,
1585 .proc_handler = proc_dointvec, 1582 .proc_handler = proc_dointvec,
1586 .extra1 = &zero, 1583 .extra1 = SYSCTL_ZERO,
1587 }, 1584 },
1588#endif 1585#endif
1589#ifdef CONFIG_NUMA 1586#ifdef CONFIG_NUMA
@@ -1593,7 +1590,7 @@ static struct ctl_table vm_table[] = {
1593 .maxlen = sizeof(node_reclaim_mode), 1590 .maxlen = sizeof(node_reclaim_mode),
1594 .mode = 0644, 1591 .mode = 0644,
1595 .proc_handler = proc_dointvec, 1592 .proc_handler = proc_dointvec,
1596 .extra1 = &zero, 1593 .extra1 = SYSCTL_ZERO,
1597 }, 1594 },
1598 { 1595 {
1599 .procname = "min_unmapped_ratio", 1596 .procname = "min_unmapped_ratio",
@@ -1601,7 +1598,7 @@ static struct ctl_table vm_table[] = {
1601 .maxlen = sizeof(sysctl_min_unmapped_ratio), 1598 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1602 .mode = 0644, 1599 .mode = 0644,
1603 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, 1600 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1604 .extra1 = &zero, 1601 .extra1 = SYSCTL_ZERO,
1605 .extra2 = &one_hundred, 1602 .extra2 = &one_hundred,
1606 }, 1603 },
1607 { 1604 {
@@ -1610,7 +1607,7 @@ static struct ctl_table vm_table[] = {
1610 .maxlen = sizeof(sysctl_min_slab_ratio), 1607 .maxlen = sizeof(sysctl_min_slab_ratio),
1611 .mode = 0644, 1608 .mode = 0644,
1612 .proc_handler = sysctl_min_slab_ratio_sysctl_handler, 1609 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1613 .extra1 = &zero, 1610 .extra1 = SYSCTL_ZERO,
1614 .extra2 = &one_hundred, 1611 .extra2 = &one_hundred,
1615 }, 1612 },
1616#endif 1613#endif
@@ -1661,7 +1658,7 @@ static struct ctl_table vm_table[] = {
1661#endif 1658#endif
1662 .mode = 0644, 1659 .mode = 0644,
1663 .proc_handler = proc_dointvec, 1660 .proc_handler = proc_dointvec,
1664 .extra1 = &zero, 1661 .extra1 = SYSCTL_ZERO,
1665 }, 1662 },
1666#endif 1663#endif
1667#ifdef CONFIG_HIGHMEM 1664#ifdef CONFIG_HIGHMEM
@@ -1671,8 +1668,8 @@ static struct ctl_table vm_table[] = {
1671 .maxlen = sizeof(vm_highmem_is_dirtyable), 1668 .maxlen = sizeof(vm_highmem_is_dirtyable),
1672 .mode = 0644, 1669 .mode = 0644,
1673 .proc_handler = proc_dointvec_minmax, 1670 .proc_handler = proc_dointvec_minmax,
1674 .extra1 = &zero, 1671 .extra1 = SYSCTL_ZERO,
1675 .extra2 = &one, 1672 .extra2 = SYSCTL_ONE,
1676 }, 1673 },
1677#endif 1674#endif
1678#ifdef CONFIG_MEMORY_FAILURE 1675#ifdef CONFIG_MEMORY_FAILURE
@@ -1682,8 +1679,8 @@ static struct ctl_table vm_table[] = {
1682 .maxlen = sizeof(sysctl_memory_failure_early_kill), 1679 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1683 .mode = 0644, 1680 .mode = 0644,
1684 .proc_handler = proc_dointvec_minmax, 1681 .proc_handler = proc_dointvec_minmax,
1685 .extra1 = &zero, 1682 .extra1 = SYSCTL_ZERO,
1686 .extra2 = &one, 1683 .extra2 = SYSCTL_ONE,
1687 }, 1684 },
1688 { 1685 {
1689 .procname = "memory_failure_recovery", 1686 .procname = "memory_failure_recovery",
@@ -1691,8 +1688,8 @@ static struct ctl_table vm_table[] = {
1691 .maxlen = sizeof(sysctl_memory_failure_recovery), 1688 .maxlen = sizeof(sysctl_memory_failure_recovery),
1692 .mode = 0644, 1689 .mode = 0644,
1693 .proc_handler = proc_dointvec_minmax, 1690 .proc_handler = proc_dointvec_minmax,
1694 .extra1 = &zero, 1691 .extra1 = SYSCTL_ZERO,
1695 .extra2 = &one, 1692 .extra2 = SYSCTL_ONE,
1696 }, 1693 },
1697#endif 1694#endif
1698 { 1695 {
@@ -1738,8 +1735,8 @@ static struct ctl_table vm_table[] = {
1738 .maxlen = sizeof(sysctl_unprivileged_userfaultfd), 1735 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1739 .mode = 0644, 1736 .mode = 0644,
1740 .proc_handler = proc_dointvec_minmax, 1737 .proc_handler = proc_dointvec_minmax,
1741 .extra1 = &zero, 1738 .extra1 = SYSCTL_ZERO,
1742 .extra2 = &one, 1739 .extra2 = SYSCTL_ONE,
1743 }, 1740 },
1744#endif 1741#endif
1745 { } 1742 { }
@@ -1875,8 +1872,8 @@ static struct ctl_table fs_table[] = {
1875 .maxlen = sizeof(int), 1872 .maxlen = sizeof(int),
1876 .mode = 0600, 1873 .mode = 0600,
1877 .proc_handler = proc_dointvec_minmax, 1874 .proc_handler = proc_dointvec_minmax,
1878 .extra1 = &zero, 1875 .extra1 = SYSCTL_ZERO,
1879 .extra2 = &one, 1876 .extra2 = SYSCTL_ONE,
1880 }, 1877 },
1881 { 1878 {
1882 .procname = "protected_hardlinks", 1879 .procname = "protected_hardlinks",
@@ -1884,8 +1881,8 @@ static struct ctl_table fs_table[] = {
1884 .maxlen = sizeof(int), 1881 .maxlen = sizeof(int),
1885 .mode = 0600, 1882 .mode = 0600,
1886 .proc_handler = proc_dointvec_minmax, 1883 .proc_handler = proc_dointvec_minmax,
1887 .extra1 = &zero, 1884 .extra1 = SYSCTL_ZERO,
1888 .extra2 = &one, 1885 .extra2 = SYSCTL_ONE,
1889 }, 1886 },
1890 { 1887 {
1891 .procname = "protected_fifos", 1888 .procname = "protected_fifos",
@@ -1893,7 +1890,7 @@ static struct ctl_table fs_table[] = {
1893 .maxlen = sizeof(int), 1890 .maxlen = sizeof(int),
1894 .mode = 0600, 1891 .mode = 0600,
1895 .proc_handler = proc_dointvec_minmax, 1892 .proc_handler = proc_dointvec_minmax,
1896 .extra1 = &zero, 1893 .extra1 = SYSCTL_ZERO,
1897 .extra2 = &two, 1894 .extra2 = &two,
1898 }, 1895 },
1899 { 1896 {
@@ -1902,7 +1899,7 @@ static struct ctl_table fs_table[] = {
1902 .maxlen = sizeof(int), 1899 .maxlen = sizeof(int),
1903 .mode = 0600, 1900 .mode = 0600,
1904 .proc_handler = proc_dointvec_minmax, 1901 .proc_handler = proc_dointvec_minmax,
1905 .extra1 = &zero, 1902 .extra1 = SYSCTL_ZERO,
1906 .extra2 = &two, 1903 .extra2 = &two,
1907 }, 1904 },
1908 { 1905 {
@@ -1911,7 +1908,7 @@ static struct ctl_table fs_table[] = {
1911 .maxlen = sizeof(int), 1908 .maxlen = sizeof(int),
1912 .mode = 0644, 1909 .mode = 0644,
1913 .proc_handler = proc_dointvec_minmax_coredump, 1910 .proc_handler = proc_dointvec_minmax_coredump,
1914 .extra1 = &zero, 1911 .extra1 = SYSCTL_ZERO,
1915 .extra2 = &two, 1912 .extra2 = &two,
1916 }, 1913 },
1917#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1914#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
@@ -1948,7 +1945,7 @@ static struct ctl_table fs_table[] = {
1948 .maxlen = sizeof(unsigned int), 1945 .maxlen = sizeof(unsigned int),
1949 .mode = 0644, 1946 .mode = 0644,
1950 .proc_handler = proc_dointvec_minmax, 1947 .proc_handler = proc_dointvec_minmax,
1951 .extra1 = &one, 1948 .extra1 = SYSCTL_ONE,
1952 }, 1949 },
1953 { } 1950 { }
1954}; 1951};
@@ -1970,8 +1967,8 @@ static struct ctl_table debug_table[] = {
1970 .maxlen = sizeof(int), 1967 .maxlen = sizeof(int),
1971 .mode = 0644, 1968 .mode = 0644,
1972 .proc_handler = proc_kprobes_optimization_handler, 1969 .proc_handler = proc_kprobes_optimization_handler,
1973 .extra1 = &zero, 1970 .extra1 = SYSCTL_ZERO,
1974 .extra2 = &one, 1971 .extra2 = SYSCTL_ONE,
1975 }, 1972 },
1976#endif 1973#endif
1977 { } 1974 { }
@@ -3395,8 +3392,8 @@ int proc_do_static_key(struct ctl_table *table, int write,
3395 .data = &val, 3392 .data = &val,
3396 .maxlen = sizeof(val), 3393 .maxlen = sizeof(val),
3397 .mode = table->mode, 3394 .mode = table->mode,
3398 .extra1 = &zero, 3395 .extra1 = SYSCTL_ZERO,
3399 .extra2 = &one, 3396 .extra2 = SYSCTL_ONE,
3400 }; 3397 };
3401 3398
3402 if (write && !capable(CAP_SYS_ADMIN)) 3399 if (write && !capable(CAP_SYS_ADMIN))
diff --git a/kernel/ucount.c b/kernel/ucount.c
index feb128c7b5d9..a53cc2b4179c 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -52,16 +52,14 @@ static struct ctl_table_root set_root = {
52 .permissions = set_permissions, 52 .permissions = set_permissions,
53}; 53};
54 54
55static int zero = 0;
56static int int_max = INT_MAX;
57#define UCOUNT_ENTRY(name) \ 55#define UCOUNT_ENTRY(name) \
58 { \ 56 { \
59 .procname = name, \ 57 .procname = name, \
60 .maxlen = sizeof(int), \ 58 .maxlen = sizeof(int), \
61 .mode = 0644, \ 59 .mode = 0644, \
62 .proc_handler = proc_dointvec_minmax, \ 60 .proc_handler = proc_dointvec_minmax, \
63 .extra1 = &zero, \ 61 .extra1 = SYSCTL_ZERO, \
64 .extra2 = &int_max, \ 62 .extra2 = SYSCTL_INT_MAX, \
65 } 63 }
66static struct ctl_table user_table[] = { 64static struct ctl_table user_table[] = {
67 UCOUNT_ENTRY("max_user_namespaces"), 65 UCOUNT_ENTRY("max_user_namespaces"),