Revert "FROMLIST: arm64: Introduce uaccess_{disable,enable} functionality based on...
[firefly-linux-kernel-4.4.55.git] / kernel / sysctl.c
1 /*
2  * sysctl.c: General linux system control interface
3  *
4  * Begun 24 March 1995, Stephen Tweedie
5  * Added /proc support, Dec 1995
6  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9  * Dynamic registration fixes, Stephen Tweedie.
10  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12  *  Horn.
13  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16  *  Wendling.
17  * The list_for_each() macro wasn't appropriate for the sysctl loop.
18  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
19  */
20
21 #include <linux/module.h>
22 #include <linux/aio.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemcheck.h>
34 #include <linux/kmemleak.h>
35 #include <linux/fs.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68
69 #include <asm/uaccess.h>
70 #include <asm/processor.h>
71
72 #ifdef CONFIG_X86
73 #include <asm/nmi.h>
74 #include <asm/stacktrace.h>
75 #include <asm/io.h>
76 #endif
77 #ifdef CONFIG_SPARC
78 #include <asm/setup.h>
79 #endif
80 #ifdef CONFIG_BSD_PROCESS_ACCT
81 #include <linux/acct.h>
82 #endif
83 #ifdef CONFIG_RT_MUTEXES
84 #include <linux/rtmutex.h>
85 #endif
86 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
87 #include <linux/lockdep.h>
88 #endif
89 #ifdef CONFIG_CHR_DEV_SG
90 #include <scsi/sg.h>
91 #endif
92
93 #ifdef CONFIG_LOCKUP_DETECTOR
94 #include <linux/nmi.h>
95 #endif
96
97 #if defined(CONFIG_SYSCTL)
98
99 /* External variables not in a header file. */
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
105 #endif
106 extern int pid_max;
107 extern int extra_free_kbytes;
108 extern int pid_max_min, pid_max_max;
109 extern int percpu_pagelist_fraction;
110 extern int compat_log;
111 extern int latencytop_enabled;
112 extern int sysctl_nr_open_min, sysctl_nr_open_max;
113 #ifndef CONFIG_MMU
114 extern int sysctl_nr_trim_pages;
115 #endif
116
117 /* Constants used for minimum and  maximum */
118 #ifdef CONFIG_LOCKUP_DETECTOR
119 static int sixty = 60;
120 #endif
121
122 static int __maybe_unused neg_one = -1;
123
124 static int zero;
125 static int __maybe_unused one = 1;
126 static int __maybe_unused two = 2;
127 static int __maybe_unused four = 4;
128 static unsigned long one_ul = 1;
129 static int one_hundred = 100;
130 #ifdef CONFIG_PRINTK
131 static int ten_thousand = 10000;
132 #endif
133
134 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136
137 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138 static int maxolduid = 65535;
139 static int minolduid;
140
141 static int ngroups_max = NGROUPS_MAX;
142 static const int cap_last_cap = CAP_LAST_CAP;
143
144 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145 #ifdef CONFIG_DETECT_HUNG_TASK
146 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
147 #endif
148
149 #ifdef CONFIG_INOTIFY_USER
150 #include <linux/inotify.h>
151 #endif
152 #ifdef CONFIG_SPARC
153 #endif
154
155 #ifdef __hppa__
156 extern int pwrsw_enabled;
157 #endif
158
159 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
160 extern int unaligned_enabled;
161 #endif
162
163 #ifdef CONFIG_IA64
164 extern int unaligned_dump_stack;
165 #endif
166
167 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168 extern int no_unaligned_warning;
169 #endif
170
171 #ifdef CONFIG_PROC_SYSCTL
172
173 #define SYSCTL_WRITES_LEGACY    -1
174 #define SYSCTL_WRITES_WARN       0
175 #define SYSCTL_WRITES_STRICT     1
176
177 static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
178
179 static int proc_do_cad_pid(struct ctl_table *table, int write,
180                   void __user *buffer, size_t *lenp, loff_t *ppos);
181 static int proc_taint(struct ctl_table *table, int write,
182                                void __user *buffer, size_t *lenp, loff_t *ppos);
183 #endif
184
185 #ifdef CONFIG_PRINTK
186 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
187                                 void __user *buffer, size_t *lenp, loff_t *ppos);
188 #endif
189
190 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
191                 void __user *buffer, size_t *lenp, loff_t *ppos);
192 #ifdef CONFIG_COREDUMP
193 static int proc_dostring_coredump(struct ctl_table *table, int write,
194                 void __user *buffer, size_t *lenp, loff_t *ppos);
195 #endif
196
197 #ifdef CONFIG_MAGIC_SYSRQ
198 /* Note: sysrq code uses it's own private copy */
199 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
200
201 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
202                                 void __user *buffer, size_t *lenp,
203                                 loff_t *ppos)
204 {
205         int error;
206
207         error = proc_dointvec(table, write, buffer, lenp, ppos);
208         if (error)
209                 return error;
210
211         if (write)
212                 sysrq_toggle_support(__sysrq_enabled);
213
214         return 0;
215 }
216
217 #endif
218
219 static struct ctl_table kern_table[];
220 static struct ctl_table vm_table[];
221 static struct ctl_table fs_table[];
222 static struct ctl_table debug_table[];
223 static struct ctl_table dev_table[];
224 extern struct ctl_table random_table[];
225 #ifdef CONFIG_EPOLL
226 extern struct ctl_table epoll_table[];
227 #endif
228
229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230 int sysctl_legacy_va_layout;
231 #endif
232
233 /* The default sysctl tables: */
234
235 static struct ctl_table sysctl_base_table[] = {
236         {
237                 .procname       = "kernel",
238                 .mode           = 0555,
239                 .child          = kern_table,
240         },
241         {
242                 .procname       = "vm",
243                 .mode           = 0555,
244                 .child          = vm_table,
245         },
246         {
247                 .procname       = "fs",
248                 .mode           = 0555,
249                 .child          = fs_table,
250         },
251         {
252                 .procname       = "debug",
253                 .mode           = 0555,
254                 .child          = debug_table,
255         },
256         {
257                 .procname       = "dev",
258                 .mode           = 0555,
259                 .child          = dev_table,
260         },
261         { }
262 };
263
264 #ifdef CONFIG_SCHED_DEBUG
265 static int min_sched_granularity_ns = 100000;           /* 100 usecs */
266 static int max_sched_granularity_ns = NSEC_PER_SEC;     /* 1 second */
267 static int min_wakeup_granularity_ns;                   /* 0 usecs */
268 static int max_wakeup_granularity_ns = NSEC_PER_SEC;    /* 1 second */
269 #ifdef CONFIG_SMP
270 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
271 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
272 #endif /* CONFIG_SMP */
273 #endif /* CONFIG_SCHED_DEBUG */
274
275 #ifdef CONFIG_COMPACTION
276 static int min_extfrag_threshold;
277 static int max_extfrag_threshold = 1000;
278 #endif
279
280 static struct ctl_table kern_table[] = {
281         {
282                 .procname       = "sched_child_runs_first",
283                 .data           = &sysctl_sched_child_runs_first,
284                 .maxlen         = sizeof(unsigned int),
285                 .mode           = 0644,
286                 .proc_handler   = proc_dointvec,
287         },
288 #ifdef CONFIG_SCHED_DEBUG
289         {
290                 .procname       = "sched_min_granularity_ns",
291                 .data           = &sysctl_sched_min_granularity,
292                 .maxlen         = sizeof(unsigned int),
293                 .mode           = 0644,
294                 .proc_handler   = sched_proc_update_handler,
295                 .extra1         = &min_sched_granularity_ns,
296                 .extra2         = &max_sched_granularity_ns,
297         },
298         {
299                 .procname       = "sched_latency_ns",
300                 .data           = &sysctl_sched_latency,
301                 .maxlen         = sizeof(unsigned int),
302                 .mode           = 0644,
303                 .proc_handler   = sched_proc_update_handler,
304                 .extra1         = &min_sched_granularity_ns,
305                 .extra2         = &max_sched_granularity_ns,
306         },
307         {
308                 .procname       = "sched_is_big_little",
309                 .data           = &sysctl_sched_is_big_little,
310                 .maxlen         = sizeof(unsigned int),
311                 .mode           = 0644,
312                 .proc_handler   = proc_dointvec,
313         },
314 #ifdef CONFIG_SCHED_WALT
315         {
316                 .procname       = "sched_use_walt_cpu_util",
317                 .data           = &sysctl_sched_use_walt_cpu_util,
318                 .maxlen         = sizeof(unsigned int),
319                 .mode           = 0644,
320                 .proc_handler   = proc_dointvec,
321         },
322         {
323                 .procname       = "sched_use_walt_task_util",
324                 .data           = &sysctl_sched_use_walt_task_util,
325                 .maxlen         = sizeof(unsigned int),
326                 .mode           = 0644,
327                 .proc_handler   = proc_dointvec,
328         },
329         {
330                 .procname       = "sched_walt_init_task_load_pct",
331                 .data           = &sysctl_sched_walt_init_task_load_pct,
332                 .maxlen         = sizeof(unsigned int),
333                 .mode           = 0644,
334                 .proc_handler   = proc_dointvec,
335         },
336         {
337                 .procname       = "sched_walt_cpu_high_irqload",
338                 .data           = &sysctl_sched_walt_cpu_high_irqload,
339                 .maxlen         = sizeof(unsigned int),
340                 .mode           = 0644,
341                 .proc_handler   = proc_dointvec,
342         },
343 #endif
344         {
345                 .procname       = "sched_sync_hint_enable",
346                 .data           = &sysctl_sched_sync_hint_enable,
347                 .maxlen         = sizeof(unsigned int),
348                 .mode           = 0644,
349                 .proc_handler   = proc_dointvec,
350         },
351         {
352                 .procname       = "sched_initial_task_util",
353                 .data           = &sysctl_sched_initial_task_util,
354                 .maxlen         = sizeof(unsigned int),
355                 .mode           = 0644,
356                 .proc_handler   = proc_dointvec,
357         },
358         {
359                 .procname       = "sched_cstate_aware",
360                 .data           = &sysctl_sched_cstate_aware,
361                 .maxlen         = sizeof(unsigned int),
362                 .mode           = 0644,
363                 .proc_handler   = proc_dointvec,
364         },
365         {
366                 .procname       = "sched_wakeup_granularity_ns",
367                 .data           = &sysctl_sched_wakeup_granularity,
368                 .maxlen         = sizeof(unsigned int),
369                 .mode           = 0644,
370                 .proc_handler   = sched_proc_update_handler,
371                 .extra1         = &min_wakeup_granularity_ns,
372                 .extra2         = &max_wakeup_granularity_ns,
373         },
374 #ifdef CONFIG_SMP
375         {
376                 .procname       = "sched_tunable_scaling",
377                 .data           = &sysctl_sched_tunable_scaling,
378                 .maxlen         = sizeof(enum sched_tunable_scaling),
379                 .mode           = 0644,
380                 .proc_handler   = sched_proc_update_handler,
381                 .extra1         = &min_sched_tunable_scaling,
382                 .extra2         = &max_sched_tunable_scaling,
383         },
384         {
385                 .procname       = "sched_migration_cost_ns",
386                 .data           = &sysctl_sched_migration_cost,
387                 .maxlen         = sizeof(unsigned int),
388                 .mode           = 0644,
389                 .proc_handler   = proc_dointvec,
390         },
391         {
392                 .procname       = "sched_nr_migrate",
393                 .data           = &sysctl_sched_nr_migrate,
394                 .maxlen         = sizeof(unsigned int),
395                 .mode           = 0644,
396                 .proc_handler   = proc_dointvec,
397         },
398         {
399                 .procname       = "sched_time_avg_ms",
400                 .data           = &sysctl_sched_time_avg,
401                 .maxlen         = sizeof(unsigned int),
402                 .mode           = 0644,
403                 .proc_handler   = proc_dointvec,
404         },
405         {
406                 .procname       = "sched_shares_window_ns",
407                 .data           = &sysctl_sched_shares_window,
408                 .maxlen         = sizeof(unsigned int),
409                 .mode           = 0644,
410                 .proc_handler   = proc_dointvec,
411         },
412 #endif /* CONFIG_SMP */
413 #ifdef CONFIG_NUMA_BALANCING
414         {
415                 .procname       = "numa_balancing_scan_delay_ms",
416                 .data           = &sysctl_numa_balancing_scan_delay,
417                 .maxlen         = sizeof(unsigned int),
418                 .mode           = 0644,
419                 .proc_handler   = proc_dointvec,
420         },
421         {
422                 .procname       = "numa_balancing_scan_period_min_ms",
423                 .data           = &sysctl_numa_balancing_scan_period_min,
424                 .maxlen         = sizeof(unsigned int),
425                 .mode           = 0644,
426                 .proc_handler   = proc_dointvec,
427         },
428         {
429                 .procname       = "numa_balancing_scan_period_max_ms",
430                 .data           = &sysctl_numa_balancing_scan_period_max,
431                 .maxlen         = sizeof(unsigned int),
432                 .mode           = 0644,
433                 .proc_handler   = proc_dointvec,
434         },
435         {
436                 .procname       = "numa_balancing_scan_size_mb",
437                 .data           = &sysctl_numa_balancing_scan_size,
438                 .maxlen         = sizeof(unsigned int),
439                 .mode           = 0644,
440                 .proc_handler   = proc_dointvec_minmax,
441                 .extra1         = &one,
442         },
443         {
444                 .procname       = "numa_balancing",
445                 .data           = NULL, /* filled in by handler */
446                 .maxlen         = sizeof(unsigned int),
447                 .mode           = 0644,
448                 .proc_handler   = sysctl_numa_balancing,
449                 .extra1         = &zero,
450                 .extra2         = &one,
451         },
452 #endif /* CONFIG_NUMA_BALANCING */
453 #endif /* CONFIG_SCHED_DEBUG */
454         {
455                 .procname       = "sched_rt_period_us",
456                 .data           = &sysctl_sched_rt_period,
457                 .maxlen         = sizeof(unsigned int),
458                 .mode           = 0644,
459                 .proc_handler   = sched_rt_handler,
460         },
461         {
462                 .procname       = "sched_rt_runtime_us",
463                 .data           = &sysctl_sched_rt_runtime,
464                 .maxlen         = sizeof(int),
465                 .mode           = 0644,
466                 .proc_handler   = sched_rt_handler,
467         },
468         {
469                 .procname       = "sched_rr_timeslice_ms",
470                 .data           = &sched_rr_timeslice,
471                 .maxlen         = sizeof(int),
472                 .mode           = 0644,
473                 .proc_handler   = sched_rr_handler,
474         },
475 #ifdef CONFIG_SCHED_AUTOGROUP
476         {
477                 .procname       = "sched_autogroup_enabled",
478                 .data           = &sysctl_sched_autogroup_enabled,
479                 .maxlen         = sizeof(unsigned int),
480                 .mode           = 0644,
481                 .proc_handler   = proc_dointvec_minmax,
482                 .extra1         = &zero,
483                 .extra2         = &one,
484         },
485 #endif
486 #ifdef CONFIG_CFS_BANDWIDTH
487         {
488                 .procname       = "sched_cfs_bandwidth_slice_us",
489                 .data           = &sysctl_sched_cfs_bandwidth_slice,
490                 .maxlen         = sizeof(unsigned int),
491                 .mode           = 0644,
492                 .proc_handler   = proc_dointvec_minmax,
493                 .extra1         = &one,
494         },
495 #endif
496 #ifdef CONFIG_SCHED_TUNE
497         {
498                 .procname       = "sched_cfs_boost",
499                 .data           = &sysctl_sched_cfs_boost,
500                 .maxlen         = sizeof(sysctl_sched_cfs_boost),
501 #ifdef CONFIG_CGROUP_SCHEDTUNE
502                 .mode           = 0444,
503 #else
504                 .mode           = 0644,
505 #endif
506                 .proc_handler   = &sysctl_sched_cfs_boost_handler,
507                 .extra1         = &zero,
508                 .extra2         = &one_hundred,
509         },
510 #endif
511 #ifdef CONFIG_PROVE_LOCKING
512         {
513                 .procname       = "prove_locking",
514                 .data           = &prove_locking,
515                 .maxlen         = sizeof(int),
516                 .mode           = 0644,
517                 .proc_handler   = proc_dointvec,
518         },
519 #endif
520 #ifdef CONFIG_LOCK_STAT
521         {
522                 .procname       = "lock_stat",
523                 .data           = &lock_stat,
524                 .maxlen         = sizeof(int),
525                 .mode           = 0644,
526                 .proc_handler   = proc_dointvec,
527         },
528 #endif
529         {
530                 .procname       = "panic",
531                 .data           = &panic_timeout,
532                 .maxlen         = sizeof(int),
533                 .mode           = 0644,
534                 .proc_handler   = proc_dointvec,
535         },
536 #ifdef CONFIG_COREDUMP
537         {
538                 .procname       = "core_uses_pid",
539                 .data           = &core_uses_pid,
540                 .maxlen         = sizeof(int),
541                 .mode           = 0644,
542                 .proc_handler   = proc_dointvec,
543         },
544         {
545                 .procname       = "core_pattern",
546                 .data           = core_pattern,
547                 .maxlen         = CORENAME_MAX_SIZE,
548                 .mode           = 0644,
549                 .proc_handler   = proc_dostring_coredump,
550         },
551         {
552                 .procname       = "core_pipe_limit",
553                 .data           = &core_pipe_limit,
554                 .maxlen         = sizeof(unsigned int),
555                 .mode           = 0644,
556                 .proc_handler   = proc_dointvec,
557         },
558 #endif
559 #ifdef CONFIG_PROC_SYSCTL
560         {
561                 .procname       = "tainted",
562                 .maxlen         = sizeof(long),
563                 .mode           = 0644,
564                 .proc_handler   = proc_taint,
565         },
566         {
567                 .procname       = "sysctl_writes_strict",
568                 .data           = &sysctl_writes_strict,
569                 .maxlen         = sizeof(int),
570                 .mode           = 0644,
571                 .proc_handler   = proc_dointvec_minmax,
572                 .extra1         = &neg_one,
573                 .extra2         = &one,
574         },
575 #endif
576 #ifdef CONFIG_LATENCYTOP
577         {
578                 .procname       = "latencytop",
579                 .data           = &latencytop_enabled,
580                 .maxlen         = sizeof(int),
581                 .mode           = 0644,
582                 .proc_handler   = proc_dointvec,
583         },
584 #endif
585 #ifdef CONFIG_BLK_DEV_INITRD
586         {
587                 .procname       = "real-root-dev",
588                 .data           = &real_root_dev,
589                 .maxlen         = sizeof(int),
590                 .mode           = 0644,
591                 .proc_handler   = proc_dointvec,
592         },
593 #endif
594         {
595                 .procname       = "print-fatal-signals",
596                 .data           = &print_fatal_signals,
597                 .maxlen         = sizeof(int),
598                 .mode           = 0644,
599                 .proc_handler   = proc_dointvec,
600         },
601 #ifdef CONFIG_SPARC
602         {
603                 .procname       = "reboot-cmd",
604                 .data           = reboot_command,
605                 .maxlen         = 256,
606                 .mode           = 0644,
607                 .proc_handler   = proc_dostring,
608         },
609         {
610                 .procname       = "stop-a",
611                 .data           = &stop_a_enabled,
612                 .maxlen         = sizeof (int),
613                 .mode           = 0644,
614                 .proc_handler   = proc_dointvec,
615         },
616         {
617                 .procname       = "scons-poweroff",
618                 .data           = &scons_pwroff,
619                 .maxlen         = sizeof (int),
620                 .mode           = 0644,
621                 .proc_handler   = proc_dointvec,
622         },
623 #endif
624 #ifdef CONFIG_SPARC64
625         {
626                 .procname       = "tsb-ratio",
627                 .data           = &sysctl_tsb_ratio,
628                 .maxlen         = sizeof (int),
629                 .mode           = 0644,
630                 .proc_handler   = proc_dointvec,
631         },
632 #endif
633 #ifdef __hppa__
634         {
635                 .procname       = "soft-power",
636                 .data           = &pwrsw_enabled,
637                 .maxlen         = sizeof (int),
638                 .mode           = 0644,
639                 .proc_handler   = proc_dointvec,
640         },
641 #endif
642 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
643         {
644                 .procname       = "unaligned-trap",
645                 .data           = &unaligned_enabled,
646                 .maxlen         = sizeof (int),
647                 .mode           = 0644,
648                 .proc_handler   = proc_dointvec,
649         },
650 #endif
651         {
652                 .procname       = "ctrl-alt-del",
653                 .data           = &C_A_D,
654                 .maxlen         = sizeof(int),
655                 .mode           = 0644,
656                 .proc_handler   = proc_dointvec,
657         },
658 #ifdef CONFIG_FUNCTION_TRACER
659         {
660                 .procname       = "ftrace_enabled",
661                 .data           = &ftrace_enabled,
662                 .maxlen         = sizeof(int),
663                 .mode           = 0644,
664                 .proc_handler   = ftrace_enable_sysctl,
665         },
666 #endif
667 #ifdef CONFIG_STACK_TRACER
668         {
669                 .procname       = "stack_tracer_enabled",
670                 .data           = &stack_tracer_enabled,
671                 .maxlen         = sizeof(int),
672                 .mode           = 0644,
673                 .proc_handler   = stack_trace_sysctl,
674         },
675 #endif
676 #ifdef CONFIG_TRACING
677         {
678                 .procname       = "ftrace_dump_on_oops",
679                 .data           = &ftrace_dump_on_oops,
680                 .maxlen         = sizeof(int),
681                 .mode           = 0644,
682                 .proc_handler   = proc_dointvec,
683         },
684         {
685                 .procname       = "traceoff_on_warning",
686                 .data           = &__disable_trace_on_warning,
687                 .maxlen         = sizeof(__disable_trace_on_warning),
688                 .mode           = 0644,
689                 .proc_handler   = proc_dointvec,
690         },
691         {
692                 .procname       = "tracepoint_printk",
693                 .data           = &tracepoint_printk,
694                 .maxlen         = sizeof(tracepoint_printk),
695                 .mode           = 0644,
696                 .proc_handler   = proc_dointvec,
697         },
698 #endif
699 #ifdef CONFIG_KEXEC_CORE
700         {
701                 .procname       = "kexec_load_disabled",
702                 .data           = &kexec_load_disabled,
703                 .maxlen         = sizeof(int),
704                 .mode           = 0644,
705                 /* only handle a transition from default "0" to "1" */
706                 .proc_handler   = proc_dointvec_minmax,
707                 .extra1         = &one,
708                 .extra2         = &one,
709         },
710 #endif
711 #ifdef CONFIG_MODULES
712         {
713                 .procname       = "modprobe",
714                 .data           = &modprobe_path,
715                 .maxlen         = KMOD_PATH_LEN,
716                 .mode           = 0644,
717                 .proc_handler   = proc_dostring,
718         },
719         {
720                 .procname       = "modules_disabled",
721                 .data           = &modules_disabled,
722                 .maxlen         = sizeof(int),
723                 .mode           = 0644,
724                 /* only handle a transition from default "0" to "1" */
725                 .proc_handler   = proc_dointvec_minmax,
726                 .extra1         = &one,
727                 .extra2         = &one,
728         },
729 #endif
730 #ifdef CONFIG_UEVENT_HELPER
731         {
732                 .procname       = "hotplug",
733                 .data           = &uevent_helper,
734                 .maxlen         = UEVENT_HELPER_PATH_LEN,
735                 .mode           = 0644,
736                 .proc_handler   = proc_dostring,
737         },
738 #endif
739 #ifdef CONFIG_CHR_DEV_SG
740         {
741                 .procname       = "sg-big-buff",
742                 .data           = &sg_big_buff,
743                 .maxlen         = sizeof (int),
744                 .mode           = 0444,
745                 .proc_handler   = proc_dointvec,
746         },
747 #endif
748 #ifdef CONFIG_BSD_PROCESS_ACCT
749         {
750                 .procname       = "acct",
751                 .data           = &acct_parm,
752                 .maxlen         = 3*sizeof(int),
753                 .mode           = 0644,
754                 .proc_handler   = proc_dointvec,
755         },
756 #endif
757 #ifdef CONFIG_MAGIC_SYSRQ
758         {
759                 .procname       = "sysrq",
760                 .data           = &__sysrq_enabled,
761                 .maxlen         = sizeof (int),
762                 .mode           = 0644,
763                 .proc_handler   = sysrq_sysctl_handler,
764         },
765 #endif
766 #ifdef CONFIG_PROC_SYSCTL
767         {
768                 .procname       = "cad_pid",
769                 .data           = NULL,
770                 .maxlen         = sizeof (int),
771                 .mode           = 0600,
772                 .proc_handler   = proc_do_cad_pid,
773         },
774 #endif
775         {
776                 .procname       = "threads-max",
777                 .data           = NULL,
778                 .maxlen         = sizeof(int),
779                 .mode           = 0644,
780                 .proc_handler   = sysctl_max_threads,
781         },
782         {
783                 .procname       = "random",
784                 .mode           = 0555,
785                 .child          = random_table,
786         },
787         {
788                 .procname       = "usermodehelper",
789                 .mode           = 0555,
790                 .child          = usermodehelper_table,
791         },
792         {
793                 .procname       = "overflowuid",
794                 .data           = &overflowuid,
795                 .maxlen         = sizeof(int),
796                 .mode           = 0644,
797                 .proc_handler   = proc_dointvec_minmax,
798                 .extra1         = &minolduid,
799                 .extra2         = &maxolduid,
800         },
801         {
802                 .procname       = "overflowgid",
803                 .data           = &overflowgid,
804                 .maxlen         = sizeof(int),
805                 .mode           = 0644,
806                 .proc_handler   = proc_dointvec_minmax,
807                 .extra1         = &minolduid,
808                 .extra2         = &maxolduid,
809         },
810 #ifdef CONFIG_S390
811 #ifdef CONFIG_MATHEMU
812         {
813                 .procname       = "ieee_emulation_warnings",
814                 .data           = &sysctl_ieee_emulation_warnings,
815                 .maxlen         = sizeof(int),
816                 .mode           = 0644,
817                 .proc_handler   = proc_dointvec,
818         },
819 #endif
820         {
821                 .procname       = "userprocess_debug",
822                 .data           = &show_unhandled_signals,
823                 .maxlen         = sizeof(int),
824                 .mode           = 0644,
825                 .proc_handler   = proc_dointvec,
826         },
827 #endif
828         {
829                 .procname       = "pid_max",
830                 .data           = &pid_max,
831                 .maxlen         = sizeof (int),
832                 .mode           = 0644,
833                 .proc_handler   = proc_dointvec_minmax,
834                 .extra1         = &pid_max_min,
835                 .extra2         = &pid_max_max,
836         },
837         {
838                 .procname       = "panic_on_oops",
839                 .data           = &panic_on_oops,
840                 .maxlen         = sizeof(int),
841                 .mode           = 0644,
842                 .proc_handler   = proc_dointvec,
843         },
844 #if defined CONFIG_PRINTK
845         {
846                 .procname       = "printk",
847                 .data           = &console_loglevel,
848                 .maxlen         = 4*sizeof(int),
849                 .mode           = 0644,
850                 .proc_handler   = proc_dointvec,
851         },
852         {
853                 .procname       = "printk_ratelimit",
854                 .data           = &printk_ratelimit_state.interval,
855                 .maxlen         = sizeof(int),
856                 .mode           = 0644,
857                 .proc_handler   = proc_dointvec_jiffies,
858         },
859         {
860                 .procname       = "printk_ratelimit_burst",
861                 .data           = &printk_ratelimit_state.burst,
862                 .maxlen         = sizeof(int),
863                 .mode           = 0644,
864                 .proc_handler   = proc_dointvec,
865         },
866         {
867                 .procname       = "printk_delay",
868                 .data           = &printk_delay_msec,
869                 .maxlen         = sizeof(int),
870                 .mode           = 0644,
871                 .proc_handler   = proc_dointvec_minmax,
872                 .extra1         = &zero,
873                 .extra2         = &ten_thousand,
874         },
875         {
876                 .procname       = "dmesg_restrict",
877                 .data           = &dmesg_restrict,
878                 .maxlen         = sizeof(int),
879                 .mode           = 0644,
880                 .proc_handler   = proc_dointvec_minmax_sysadmin,
881                 .extra1         = &zero,
882                 .extra2         = &one,
883         },
884         {
885                 .procname       = "kptr_restrict",
886                 .data           = &kptr_restrict,
887                 .maxlen         = sizeof(int),
888                 .mode           = 0644,
889                 .proc_handler   = proc_dointvec_minmax_sysadmin,
890                 .extra1         = &zero,
891                 .extra2         = &two,
892         },
893 #endif
894         {
895                 .procname       = "ngroups_max",
896                 .data           = &ngroups_max,
897                 .maxlen         = sizeof (int),
898                 .mode           = 0444,
899                 .proc_handler   = proc_dointvec,
900         },
901         {
902                 .procname       = "cap_last_cap",
903                 .data           = (void *)&cap_last_cap,
904                 .maxlen         = sizeof(int),
905                 .mode           = 0444,
906                 .proc_handler   = proc_dointvec,
907         },
908 #if defined(CONFIG_LOCKUP_DETECTOR)
909         {
910                 .procname       = "watchdog",
911                 .data           = &watchdog_user_enabled,
912                 .maxlen         = sizeof (int),
913                 .mode           = 0644,
914                 .proc_handler   = proc_watchdog,
915                 .extra1         = &zero,
916                 .extra2         = &one,
917         },
918         {
919                 .procname       = "watchdog_thresh",
920                 .data           = &watchdog_thresh,
921                 .maxlen         = sizeof(int),
922                 .mode           = 0644,
923                 .proc_handler   = proc_watchdog_thresh,
924                 .extra1         = &zero,
925                 .extra2         = &sixty,
926         },
927         {
928                 .procname       = "nmi_watchdog",
929                 .data           = &nmi_watchdog_enabled,
930                 .maxlen         = sizeof (int),
931                 .mode           = 0644,
932                 .proc_handler   = proc_nmi_watchdog,
933                 .extra1         = &zero,
934 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
935                 .extra2         = &one,
936 #else
937                 .extra2         = &zero,
938 #endif
939         },
940         {
941                 .procname       = "soft_watchdog",
942                 .data           = &soft_watchdog_enabled,
943                 .maxlen         = sizeof (int),
944                 .mode           = 0644,
945                 .proc_handler   = proc_soft_watchdog,
946                 .extra1         = &zero,
947                 .extra2         = &one,
948         },
949         {
950                 .procname       = "watchdog_cpumask",
951                 .data           = &watchdog_cpumask_bits,
952                 .maxlen         = NR_CPUS,
953                 .mode           = 0644,
954                 .proc_handler   = proc_watchdog_cpumask,
955         },
956         {
957                 .procname       = "softlockup_panic",
958                 .data           = &softlockup_panic,
959                 .maxlen         = sizeof(int),
960                 .mode           = 0644,
961                 .proc_handler   = proc_dointvec_minmax,
962                 .extra1         = &zero,
963                 .extra2         = &one,
964         },
965 #ifdef CONFIG_HARDLOCKUP_DETECTOR
966         {
967                 .procname       = "hardlockup_panic",
968                 .data           = &hardlockup_panic,
969                 .maxlen         = sizeof(int),
970                 .mode           = 0644,
971                 .proc_handler   = proc_dointvec_minmax,
972                 .extra1         = &zero,
973                 .extra2         = &one,
974         },
975 #endif
976 #ifdef CONFIG_SMP
977         {
978                 .procname       = "softlockup_all_cpu_backtrace",
979                 .data           = &sysctl_softlockup_all_cpu_backtrace,
980                 .maxlen         = sizeof(int),
981                 .mode           = 0644,
982                 .proc_handler   = proc_dointvec_minmax,
983                 .extra1         = &zero,
984                 .extra2         = &one,
985         },
986         {
987                 .procname       = "hardlockup_all_cpu_backtrace",
988                 .data           = &sysctl_hardlockup_all_cpu_backtrace,
989                 .maxlen         = sizeof(int),
990                 .mode           = 0644,
991                 .proc_handler   = proc_dointvec_minmax,
992                 .extra1         = &zero,
993                 .extra2         = &one,
994         },
995 #endif /* CONFIG_SMP */
996 #endif
997 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
998         {
999                 .procname       = "unknown_nmi_panic",
1000                 .data           = &unknown_nmi_panic,
1001                 .maxlen         = sizeof (int),
1002                 .mode           = 0644,
1003                 .proc_handler   = proc_dointvec,
1004         },
1005 #endif
1006 #if defined(CONFIG_X86)
1007         {
1008                 .procname       = "panic_on_unrecovered_nmi",
1009                 .data           = &panic_on_unrecovered_nmi,
1010                 .maxlen         = sizeof(int),
1011                 .mode           = 0644,
1012                 .proc_handler   = proc_dointvec,
1013         },
1014         {
1015                 .procname       = "panic_on_io_nmi",
1016                 .data           = &panic_on_io_nmi,
1017                 .maxlen         = sizeof(int),
1018                 .mode           = 0644,
1019                 .proc_handler   = proc_dointvec,
1020         },
1021 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1022         {
1023                 .procname       = "panic_on_stackoverflow",
1024                 .data           = &sysctl_panic_on_stackoverflow,
1025                 .maxlen         = sizeof(int),
1026                 .mode           = 0644,
1027                 .proc_handler   = proc_dointvec,
1028         },
1029 #endif
1030         {
1031                 .procname       = "bootloader_type",
1032                 .data           = &bootloader_type,
1033                 .maxlen         = sizeof (int),
1034                 .mode           = 0444,
1035                 .proc_handler   = proc_dointvec,
1036         },
1037         {
1038                 .procname       = "bootloader_version",
1039                 .data           = &bootloader_version,
1040                 .maxlen         = sizeof (int),
1041                 .mode           = 0444,
1042                 .proc_handler   = proc_dointvec,
1043         },
1044         {
1045                 .procname       = "kstack_depth_to_print",
1046                 .data           = &kstack_depth_to_print,
1047                 .maxlen         = sizeof(int),
1048                 .mode           = 0644,
1049                 .proc_handler   = proc_dointvec,
1050         },
1051         {
1052                 .procname       = "io_delay_type",
1053                 .data           = &io_delay_type,
1054                 .maxlen         = sizeof(int),
1055                 .mode           = 0644,
1056                 .proc_handler   = proc_dointvec,
1057         },
1058 #endif
1059 #if defined(CONFIG_MMU)
1060         {
1061                 .procname       = "randomize_va_space",
1062                 .data           = &randomize_va_space,
1063                 .maxlen         = sizeof(int),
1064                 .mode           = 0644,
1065                 .proc_handler   = proc_dointvec,
1066         },
1067 #endif
1068 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1069         {
1070                 .procname       = "spin_retry",
1071                 .data           = &spin_retry,
1072                 .maxlen         = sizeof (int),
1073                 .mode           = 0644,
1074                 .proc_handler   = proc_dointvec,
1075         },
1076 #endif
1077 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1078         {
1079                 .procname       = "acpi_video_flags",
1080                 .data           = &acpi_realmode_flags,
1081                 .maxlen         = sizeof (unsigned long),
1082                 .mode           = 0644,
1083                 .proc_handler   = proc_doulongvec_minmax,
1084         },
1085 #endif
1086 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1087         {
1088                 .procname       = "ignore-unaligned-usertrap",
1089                 .data           = &no_unaligned_warning,
1090                 .maxlen         = sizeof (int),
1091                 .mode           = 0644,
1092                 .proc_handler   = proc_dointvec,
1093         },
1094 #endif
1095 #ifdef CONFIG_IA64
1096         {
1097                 .procname       = "unaligned-dump-stack",
1098                 .data           = &unaligned_dump_stack,
1099                 .maxlen         = sizeof (int),
1100                 .mode           = 0644,
1101                 .proc_handler   = proc_dointvec,
1102         },
1103 #endif
1104 #ifdef CONFIG_DETECT_HUNG_TASK
1105         {
1106                 .procname       = "hung_task_panic",
1107                 .data           = &sysctl_hung_task_panic,
1108                 .maxlen         = sizeof(int),
1109                 .mode           = 0644,
1110                 .proc_handler   = proc_dointvec_minmax,
1111                 .extra1         = &zero,
1112                 .extra2         = &one,
1113         },
1114         {
1115                 .procname       = "hung_task_check_count",
1116                 .data           = &sysctl_hung_task_check_count,
1117                 .maxlen         = sizeof(int),
1118                 .mode           = 0644,
1119                 .proc_handler   = proc_dointvec_minmax,
1120                 .extra1         = &zero,
1121         },
1122         {
1123                 .procname       = "hung_task_timeout_secs",
1124                 .data           = &sysctl_hung_task_timeout_secs,
1125                 .maxlen         = sizeof(unsigned long),
1126                 .mode           = 0644,
1127                 .proc_handler   = proc_dohung_task_timeout_secs,
1128                 .extra2         = &hung_task_timeout_max,
1129         },
1130         {
1131                 .procname       = "hung_task_warnings",
1132                 .data           = &sysctl_hung_task_warnings,
1133                 .maxlen         = sizeof(int),
1134                 .mode           = 0644,
1135                 .proc_handler   = proc_dointvec_minmax,
1136                 .extra1         = &neg_one,
1137         },
1138 #endif
1139 #ifdef CONFIG_COMPAT
1140         {
1141                 .procname       = "compat-log",
1142                 .data           = &compat_log,
1143                 .maxlen         = sizeof (int),
1144                 .mode           = 0644,
1145                 .proc_handler   = proc_dointvec,
1146         },
1147 #endif
1148 #ifdef CONFIG_RT_MUTEXES
1149         {
1150                 .procname       = "max_lock_depth",
1151                 .data           = &max_lock_depth,
1152                 .maxlen         = sizeof(int),
1153                 .mode           = 0644,
1154                 .proc_handler   = proc_dointvec,
1155         },
1156 #endif
1157         {
1158                 .procname       = "poweroff_cmd",
1159                 .data           = &poweroff_cmd,
1160                 .maxlen         = POWEROFF_CMD_PATH_LEN,
1161                 .mode           = 0644,
1162                 .proc_handler   = proc_dostring,
1163         },
1164 #ifdef CONFIG_KEYS
1165         {
1166                 .procname       = "keys",
1167                 .mode           = 0555,
1168                 .child          = key_sysctls,
1169         },
1170 #endif
1171 #ifdef CONFIG_PERF_EVENTS
1172         /*
1173          * User-space scripts rely on the existence of this file
1174          * as a feature check for perf_events being enabled.
1175          *
1176          * So it's an ABI, do not remove!
1177          */
1178         {
1179                 .procname       = "perf_event_paranoid",
1180                 .data           = &sysctl_perf_event_paranoid,
1181                 .maxlen         = sizeof(sysctl_perf_event_paranoid),
1182                 .mode           = 0644,
1183                 .proc_handler   = proc_dointvec,
1184         },
1185         {
1186                 .procname       = "perf_event_mlock_kb",
1187                 .data           = &sysctl_perf_event_mlock,
1188                 .maxlen         = sizeof(sysctl_perf_event_mlock),
1189                 .mode           = 0644,
1190                 .proc_handler   = proc_dointvec,
1191         },
1192         {
1193                 .procname       = "perf_event_max_sample_rate",
1194                 .data           = &sysctl_perf_event_sample_rate,
1195                 .maxlen         = sizeof(sysctl_perf_event_sample_rate),
1196                 .mode           = 0644,
1197                 .proc_handler   = perf_proc_update_handler,
1198                 .extra1         = &one,
1199         },
1200         {
1201                 .procname       = "perf_cpu_time_max_percent",
1202                 .data           = &sysctl_perf_cpu_time_max_percent,
1203                 .maxlen         = sizeof(sysctl_perf_cpu_time_max_percent),
1204                 .mode           = 0644,
1205                 .proc_handler   = perf_cpu_time_max_percent_handler,
1206                 .extra1         = &zero,
1207                 .extra2         = &one_hundred,
1208         },
1209 #endif
1210 #ifdef CONFIG_KMEMCHECK
1211         {
1212                 .procname       = "kmemcheck",
1213                 .data           = &kmemcheck_enabled,
1214                 .maxlen         = sizeof(int),
1215                 .mode           = 0644,
1216                 .proc_handler   = proc_dointvec,
1217         },
1218 #endif
1219         {
1220                 .procname       = "panic_on_warn",
1221                 .data           = &panic_on_warn,
1222                 .maxlen         = sizeof(int),
1223                 .mode           = 0644,
1224                 .proc_handler   = proc_dointvec_minmax,
1225                 .extra1         = &zero,
1226                 .extra2         = &one,
1227         },
1228 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1229         {
1230                 .procname       = "timer_migration",
1231                 .data           = &sysctl_timer_migration,
1232                 .maxlen         = sizeof(unsigned int),
1233                 .mode           = 0644,
1234                 .proc_handler   = timer_migration_handler,
1235         },
1236 #endif
1237 #ifdef CONFIG_BPF_SYSCALL
1238         {
1239                 .procname       = "unprivileged_bpf_disabled",
1240                 .data           = &sysctl_unprivileged_bpf_disabled,
1241                 .maxlen         = sizeof(sysctl_unprivileged_bpf_disabled),
1242                 .mode           = 0644,
1243                 /* only handle a transition from default "0" to "1" */
1244                 .proc_handler   = proc_dointvec_minmax,
1245                 .extra1         = &one,
1246                 .extra2         = &one,
1247         },
1248 #endif
1249         { }
1250 };
1251
1252 static struct ctl_table vm_table[] = {
1253         {
1254                 .procname       = "overcommit_memory",
1255                 .data           = &sysctl_overcommit_memory,
1256                 .maxlen         = sizeof(sysctl_overcommit_memory),
1257                 .mode           = 0644,
1258                 .proc_handler   = proc_dointvec_minmax,
1259                 .extra1         = &zero,
1260                 .extra2         = &two,
1261         },
1262         {
1263                 .procname       = "panic_on_oom",
1264                 .data           = &sysctl_panic_on_oom,
1265                 .maxlen         = sizeof(sysctl_panic_on_oom),
1266                 .mode           = 0644,
1267                 .proc_handler   = proc_dointvec_minmax,
1268                 .extra1         = &zero,
1269                 .extra2         = &two,
1270         },
1271         {
1272                 .procname       = "oom_kill_allocating_task",
1273                 .data           = &sysctl_oom_kill_allocating_task,
1274                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
1275                 .mode           = 0644,
1276                 .proc_handler   = proc_dointvec,
1277         },
1278         {
1279                 .procname       = "oom_dump_tasks",
1280                 .data           = &sysctl_oom_dump_tasks,
1281                 .maxlen         = sizeof(sysctl_oom_dump_tasks),
1282                 .mode           = 0644,
1283                 .proc_handler   = proc_dointvec,
1284         },
1285         {
1286                 .procname       = "overcommit_ratio",
1287                 .data           = &sysctl_overcommit_ratio,
1288                 .maxlen         = sizeof(sysctl_overcommit_ratio),
1289                 .mode           = 0644,
1290                 .proc_handler   = overcommit_ratio_handler,
1291         },
1292         {
1293                 .procname       = "overcommit_kbytes",
1294                 .data           = &sysctl_overcommit_kbytes,
1295                 .maxlen         = sizeof(sysctl_overcommit_kbytes),
1296                 .mode           = 0644,
1297                 .proc_handler   = overcommit_kbytes_handler,
1298         },
1299         {
1300                 .procname       = "page-cluster", 
1301                 .data           = &page_cluster,
1302                 .maxlen         = sizeof(int),
1303                 .mode           = 0644,
1304                 .proc_handler   = proc_dointvec_minmax,
1305                 .extra1         = &zero,
1306         },
1307         {
1308                 .procname       = "dirty_background_ratio",
1309                 .data           = &dirty_background_ratio,
1310                 .maxlen         = sizeof(dirty_background_ratio),
1311                 .mode           = 0644,
1312                 .proc_handler   = dirty_background_ratio_handler,
1313                 .extra1         = &zero,
1314                 .extra2         = &one_hundred,
1315         },
1316         {
1317                 .procname       = "dirty_background_bytes",
1318                 .data           = &dirty_background_bytes,
1319                 .maxlen         = sizeof(dirty_background_bytes),
1320                 .mode           = 0644,
1321                 .proc_handler   = dirty_background_bytes_handler,
1322                 .extra1         = &one_ul,
1323         },
1324         {
1325                 .procname       = "dirty_ratio",
1326                 .data           = &vm_dirty_ratio,
1327                 .maxlen         = sizeof(vm_dirty_ratio),
1328                 .mode           = 0644,
1329                 .proc_handler   = dirty_ratio_handler,
1330                 .extra1         = &zero,
1331                 .extra2         = &one_hundred,
1332         },
1333         {
1334                 .procname       = "dirty_bytes",
1335                 .data           = &vm_dirty_bytes,
1336                 .maxlen         = sizeof(vm_dirty_bytes),
1337                 .mode           = 0644,
1338                 .proc_handler   = dirty_bytes_handler,
1339                 .extra1         = &dirty_bytes_min,
1340         },
1341         {
1342                 .procname       = "dirty_writeback_centisecs",
1343                 .data           = &dirty_writeback_interval,
1344                 .maxlen         = sizeof(dirty_writeback_interval),
1345                 .mode           = 0644,
1346                 .proc_handler   = dirty_writeback_centisecs_handler,
1347         },
1348         {
1349                 .procname       = "dirty_expire_centisecs",
1350                 .data           = &dirty_expire_interval,
1351                 .maxlen         = sizeof(dirty_expire_interval),
1352                 .mode           = 0644,
1353                 .proc_handler   = proc_dointvec_minmax,
1354                 .extra1         = &zero,
1355         },
1356         {
1357                 .procname       = "dirtytime_expire_seconds",
1358                 .data           = &dirtytime_expire_interval,
1359                 .maxlen         = sizeof(dirty_expire_interval),
1360                 .mode           = 0644,
1361                 .proc_handler   = dirtytime_interval_handler,
1362                 .extra1         = &zero,
1363         },
1364         {
1365                 .procname       = "nr_pdflush_threads",
1366                 .mode           = 0444 /* read-only */,
1367                 .proc_handler   = pdflush_proc_obsolete,
1368         },
1369         {
1370                 .procname       = "swappiness",
1371                 .data           = &vm_swappiness,
1372                 .maxlen         = sizeof(vm_swappiness),
1373                 .mode           = 0644,
1374                 .proc_handler   = proc_dointvec_minmax,
1375                 .extra1         = &zero,
1376                 .extra2         = &one_hundred,
1377         },
1378 #ifdef CONFIG_HUGETLB_PAGE
1379         {
1380                 .procname       = "nr_hugepages",
1381                 .data           = NULL,
1382                 .maxlen         = sizeof(unsigned long),
1383                 .mode           = 0644,
1384                 .proc_handler   = hugetlb_sysctl_handler,
1385         },
1386 #ifdef CONFIG_NUMA
1387         {
1388                 .procname       = "nr_hugepages_mempolicy",
1389                 .data           = NULL,
1390                 .maxlen         = sizeof(unsigned long),
1391                 .mode           = 0644,
1392                 .proc_handler   = &hugetlb_mempolicy_sysctl_handler,
1393         },
1394 #endif
1395          {
1396                 .procname       = "hugetlb_shm_group",
1397                 .data           = &sysctl_hugetlb_shm_group,
1398                 .maxlen         = sizeof(gid_t),
1399                 .mode           = 0644,
1400                 .proc_handler   = proc_dointvec,
1401          },
1402          {
1403                 .procname       = "hugepages_treat_as_movable",
1404                 .data           = &hugepages_treat_as_movable,
1405                 .maxlen         = sizeof(int),
1406                 .mode           = 0644,
1407                 .proc_handler   = proc_dointvec,
1408         },
1409         {
1410                 .procname       = "nr_overcommit_hugepages",
1411                 .data           = NULL,
1412                 .maxlen         = sizeof(unsigned long),
1413                 .mode           = 0644,
1414                 .proc_handler   = hugetlb_overcommit_handler,
1415         },
1416 #endif
1417         {
1418                 .procname       = "lowmem_reserve_ratio",
1419                 .data           = &sysctl_lowmem_reserve_ratio,
1420                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
1421                 .mode           = 0644,
1422                 .proc_handler   = lowmem_reserve_ratio_sysctl_handler,
1423         },
1424         {
1425                 .procname       = "drop_caches",
1426                 .data           = &sysctl_drop_caches,
1427                 .maxlen         = sizeof(int),
1428                 .mode           = 0644,
1429                 .proc_handler   = drop_caches_sysctl_handler,
1430                 .extra1         = &one,
1431                 .extra2         = &four,
1432         },
1433 #ifdef CONFIG_COMPACTION
1434         {
1435                 .procname       = "compact_memory",
1436                 .data           = &sysctl_compact_memory,
1437                 .maxlen         = sizeof(int),
1438                 .mode           = 0200,
1439                 .proc_handler   = sysctl_compaction_handler,
1440         },
1441         {
1442                 .procname       = "extfrag_threshold",
1443                 .data           = &sysctl_extfrag_threshold,
1444                 .maxlen         = sizeof(int),
1445                 .mode           = 0644,
1446                 .proc_handler   = sysctl_extfrag_handler,
1447                 .extra1         = &min_extfrag_threshold,
1448                 .extra2         = &max_extfrag_threshold,
1449         },
1450         {
1451                 .procname       = "compact_unevictable_allowed",
1452                 .data           = &sysctl_compact_unevictable_allowed,
1453                 .maxlen         = sizeof(int),
1454                 .mode           = 0644,
1455                 .proc_handler   = proc_dointvec,
1456                 .extra1         = &zero,
1457                 .extra2         = &one,
1458         },
1459
1460 #endif /* CONFIG_COMPACTION */
1461         {
1462                 .procname       = "min_free_kbytes",
1463                 .data           = &min_free_kbytes,
1464                 .maxlen         = sizeof(min_free_kbytes),
1465                 .mode           = 0644,
1466                 .proc_handler   = min_free_kbytes_sysctl_handler,
1467                 .extra1         = &zero,
1468         },
1469         {
1470                 .procname       = "extra_free_kbytes",
1471                 .data           = &extra_free_kbytes,
1472                 .maxlen         = sizeof(extra_free_kbytes),
1473                 .mode           = 0644,
1474                 .proc_handler   = min_free_kbytes_sysctl_handler,
1475                 .extra1         = &zero,
1476         },
1477         {
1478                 .procname       = "percpu_pagelist_fraction",
1479                 .data           = &percpu_pagelist_fraction,
1480                 .maxlen         = sizeof(percpu_pagelist_fraction),
1481                 .mode           = 0644,
1482                 .proc_handler   = percpu_pagelist_fraction_sysctl_handler,
1483                 .extra1         = &zero,
1484         },
1485 #ifdef CONFIG_MMU
1486         {
1487                 .procname       = "max_map_count",
1488                 .data           = &sysctl_max_map_count,
1489                 .maxlen         = sizeof(sysctl_max_map_count),
1490                 .mode           = 0644,
1491                 .proc_handler   = proc_dointvec_minmax,
1492                 .extra1         = &zero,
1493         },
1494 #else
1495         {
1496                 .procname       = "nr_trim_pages",
1497                 .data           = &sysctl_nr_trim_pages,
1498                 .maxlen         = sizeof(sysctl_nr_trim_pages),
1499                 .mode           = 0644,
1500                 .proc_handler   = proc_dointvec_minmax,
1501                 .extra1         = &zero,
1502         },
1503 #endif
1504         {
1505                 .procname       = "laptop_mode",
1506                 .data           = &laptop_mode,
1507                 .maxlen         = sizeof(laptop_mode),
1508                 .mode           = 0644,
1509                 .proc_handler   = proc_dointvec_jiffies,
1510         },
1511         {
1512                 .procname       = "block_dump",
1513                 .data           = &block_dump,
1514                 .maxlen         = sizeof(block_dump),
1515                 .mode           = 0644,
1516                 .proc_handler   = proc_dointvec,
1517                 .extra1         = &zero,
1518         },
1519         {
1520                 .procname       = "vfs_cache_pressure",
1521                 .data           = &sysctl_vfs_cache_pressure,
1522                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
1523                 .mode           = 0644,
1524                 .proc_handler   = proc_dointvec,
1525                 .extra1         = &zero,
1526         },
1527 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1528         {
1529                 .procname       = "legacy_va_layout",
1530                 .data           = &sysctl_legacy_va_layout,
1531                 .maxlen         = sizeof(sysctl_legacy_va_layout),
1532                 .mode           = 0644,
1533                 .proc_handler   = proc_dointvec,
1534                 .extra1         = &zero,
1535         },
1536 #endif
1537 #ifdef CONFIG_NUMA
1538         {
1539                 .procname       = "zone_reclaim_mode",
1540                 .data           = &zone_reclaim_mode,
1541                 .maxlen         = sizeof(zone_reclaim_mode),
1542                 .mode           = 0644,
1543                 .proc_handler   = proc_dointvec,
1544                 .extra1         = &zero,
1545         },
1546         {
1547                 .procname       = "min_unmapped_ratio",
1548                 .data           = &sysctl_min_unmapped_ratio,
1549                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1550                 .mode           = 0644,
1551                 .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
1552                 .extra1         = &zero,
1553                 .extra2         = &one_hundred,
1554         },
1555         {
1556                 .procname       = "min_slab_ratio",
1557                 .data           = &sysctl_min_slab_ratio,
1558                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1559                 .mode           = 0644,
1560                 .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
1561                 .extra1         = &zero,
1562                 .extra2         = &one_hundred,
1563         },
1564 #endif
1565 #ifdef CONFIG_SMP
1566         {
1567                 .procname       = "stat_interval",
1568                 .data           = &sysctl_stat_interval,
1569                 .maxlen         = sizeof(sysctl_stat_interval),
1570                 .mode           = 0644,
1571                 .proc_handler   = proc_dointvec_jiffies,
1572         },
1573 #endif
1574 #ifdef CONFIG_MMU
1575         {
1576                 .procname       = "mmap_min_addr",
1577                 .data           = &dac_mmap_min_addr,
1578                 .maxlen         = sizeof(unsigned long),
1579                 .mode           = 0644,
1580                 .proc_handler   = mmap_min_addr_handler,
1581         },
1582 #endif
1583 #ifdef CONFIG_NUMA
1584         {
1585                 .procname       = "numa_zonelist_order",
1586                 .data           = &numa_zonelist_order,
1587                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1588                 .mode           = 0644,
1589                 .proc_handler   = numa_zonelist_order_handler,
1590         },
1591 #endif
1592 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1593    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1594         {
1595                 .procname       = "vdso_enabled",
1596 #ifdef CONFIG_X86_32
1597                 .data           = &vdso32_enabled,
1598                 .maxlen         = sizeof(vdso32_enabled),
1599 #else
1600                 .data           = &vdso_enabled,
1601                 .maxlen         = sizeof(vdso_enabled),
1602 #endif
1603                 .mode           = 0644,
1604                 .proc_handler   = proc_dointvec,
1605                 .extra1         = &zero,
1606         },
1607 #endif
1608 #ifdef CONFIG_HIGHMEM
1609         {
1610                 .procname       = "highmem_is_dirtyable",
1611                 .data           = &vm_highmem_is_dirtyable,
1612                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
1613                 .mode           = 0644,
1614                 .proc_handler   = proc_dointvec_minmax,
1615                 .extra1         = &zero,
1616                 .extra2         = &one,
1617         },
1618 #endif
1619 #ifdef CONFIG_MEMORY_FAILURE
1620         {
1621                 .procname       = "memory_failure_early_kill",
1622                 .data           = &sysctl_memory_failure_early_kill,
1623                 .maxlen         = sizeof(sysctl_memory_failure_early_kill),
1624                 .mode           = 0644,
1625                 .proc_handler   = proc_dointvec_minmax,
1626                 .extra1         = &zero,
1627                 .extra2         = &one,
1628         },
1629         {
1630                 .procname       = "memory_failure_recovery",
1631                 .data           = &sysctl_memory_failure_recovery,
1632                 .maxlen         = sizeof(sysctl_memory_failure_recovery),
1633                 .mode           = 0644,
1634                 .proc_handler   = proc_dointvec_minmax,
1635                 .extra1         = &zero,
1636                 .extra2         = &one,
1637         },
1638 #endif
1639         {
1640                 .procname       = "user_reserve_kbytes",
1641                 .data           = &sysctl_user_reserve_kbytes,
1642                 .maxlen         = sizeof(sysctl_user_reserve_kbytes),
1643                 .mode           = 0644,
1644                 .proc_handler   = proc_doulongvec_minmax,
1645         },
1646         {
1647                 .procname       = "admin_reserve_kbytes",
1648                 .data           = &sysctl_admin_reserve_kbytes,
1649                 .maxlen         = sizeof(sysctl_admin_reserve_kbytes),
1650                 .mode           = 0644,
1651                 .proc_handler   = proc_doulongvec_minmax,
1652         },
1653 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1654         {
1655                 .procname       = "mmap_rnd_bits",
1656                 .data           = &mmap_rnd_bits,
1657                 .maxlen         = sizeof(mmap_rnd_bits),
1658                 .mode           = 0600,
1659                 .proc_handler   = proc_dointvec_minmax,
1660                 .extra1         = (void *)&mmap_rnd_bits_min,
1661                 .extra2         = (void *)&mmap_rnd_bits_max,
1662         },
1663 #endif
1664 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1665         {
1666                 .procname       = "mmap_rnd_compat_bits",
1667                 .data           = &mmap_rnd_compat_bits,
1668                 .maxlen         = sizeof(mmap_rnd_compat_bits),
1669                 .mode           = 0600,
1670                 .proc_handler   = proc_dointvec_minmax,
1671                 .extra1         = (void *)&mmap_rnd_compat_bits_min,
1672                 .extra2         = (void *)&mmap_rnd_compat_bits_max,
1673         },
1674 #endif
1675         { }
1676 };
1677
1678 static struct ctl_table fs_table[] = {
1679         {
1680                 .procname       = "inode-nr",
1681                 .data           = &inodes_stat,
1682                 .maxlen         = 2*sizeof(long),
1683                 .mode           = 0444,
1684                 .proc_handler   = proc_nr_inodes,
1685         },
1686         {
1687                 .procname       = "inode-state",
1688                 .data           = &inodes_stat,
1689                 .maxlen         = 7*sizeof(long),
1690                 .mode           = 0444,
1691                 .proc_handler   = proc_nr_inodes,
1692         },
1693         {
1694                 .procname       = "file-nr",
1695                 .data           = &files_stat,
1696                 .maxlen         = sizeof(files_stat),
1697                 .mode           = 0444,
1698                 .proc_handler   = proc_nr_files,
1699         },
1700         {
1701                 .procname       = "file-max",
1702                 .data           = &files_stat.max_files,
1703                 .maxlen         = sizeof(files_stat.max_files),
1704                 .mode           = 0644,
1705                 .proc_handler   = proc_doulongvec_minmax,
1706         },
1707         {
1708                 .procname       = "nr_open",
1709                 .data           = &sysctl_nr_open,
1710                 .maxlen         = sizeof(int),
1711                 .mode           = 0644,
1712                 .proc_handler   = proc_dointvec_minmax,
1713                 .extra1         = &sysctl_nr_open_min,
1714                 .extra2         = &sysctl_nr_open_max,
1715         },
1716         {
1717                 .procname       = "dentry-state",
1718                 .data           = &dentry_stat,
1719                 .maxlen         = 6*sizeof(long),
1720                 .mode           = 0444,
1721                 .proc_handler   = proc_nr_dentry,
1722         },
1723         {
1724                 .procname       = "overflowuid",
1725                 .data           = &fs_overflowuid,
1726                 .maxlen         = sizeof(int),
1727                 .mode           = 0644,
1728                 .proc_handler   = proc_dointvec_minmax,
1729                 .extra1         = &minolduid,
1730                 .extra2         = &maxolduid,
1731         },
1732         {
1733                 .procname       = "overflowgid",
1734                 .data           = &fs_overflowgid,
1735                 .maxlen         = sizeof(int),
1736                 .mode           = 0644,
1737                 .proc_handler   = proc_dointvec_minmax,
1738                 .extra1         = &minolduid,
1739                 .extra2         = &maxolduid,
1740         },
1741 #ifdef CONFIG_FILE_LOCKING
1742         {
1743                 .procname       = "leases-enable",
1744                 .data           = &leases_enable,
1745                 .maxlen         = sizeof(int),
1746                 .mode           = 0644,
1747                 .proc_handler   = proc_dointvec,
1748         },
1749 #endif
1750 #ifdef CONFIG_DNOTIFY
1751         {
1752                 .procname       = "dir-notify-enable",
1753                 .data           = &dir_notify_enable,
1754                 .maxlen         = sizeof(int),
1755                 .mode           = 0644,
1756                 .proc_handler   = proc_dointvec,
1757         },
1758 #endif
1759 #ifdef CONFIG_MMU
1760 #ifdef CONFIG_FILE_LOCKING
1761         {
1762                 .procname       = "lease-break-time",
1763                 .data           = &lease_break_time,
1764                 .maxlen         = sizeof(int),
1765                 .mode           = 0644,
1766                 .proc_handler   = proc_dointvec,
1767         },
1768 #endif
1769 #ifdef CONFIG_AIO
1770         {
1771                 .procname       = "aio-nr",
1772                 .data           = &aio_nr,
1773                 .maxlen         = sizeof(aio_nr),
1774                 .mode           = 0444,
1775                 .proc_handler   = proc_doulongvec_minmax,
1776         },
1777         {
1778                 .procname       = "aio-max-nr",
1779                 .data           = &aio_max_nr,
1780                 .maxlen         = sizeof(aio_max_nr),
1781                 .mode           = 0644,
1782                 .proc_handler   = proc_doulongvec_minmax,
1783         },
1784 #endif /* CONFIG_AIO */
1785 #ifdef CONFIG_INOTIFY_USER
1786         {
1787                 .procname       = "inotify",
1788                 .mode           = 0555,
1789                 .child          = inotify_table,
1790         },
1791 #endif  
1792 #ifdef CONFIG_EPOLL
1793         {
1794                 .procname       = "epoll",
1795                 .mode           = 0555,
1796                 .child          = epoll_table,
1797         },
1798 #endif
1799 #endif
1800         {
1801                 .procname       = "protected_symlinks",
1802                 .data           = &sysctl_protected_symlinks,
1803                 .maxlen         = sizeof(int),
1804                 .mode           = 0600,
1805                 .proc_handler   = proc_dointvec_minmax,
1806                 .extra1         = &zero,
1807                 .extra2         = &one,
1808         },
1809         {
1810                 .procname       = "protected_hardlinks",
1811                 .data           = &sysctl_protected_hardlinks,
1812                 .maxlen         = sizeof(int),
1813                 .mode           = 0600,
1814                 .proc_handler   = proc_dointvec_minmax,
1815                 .extra1         = &zero,
1816                 .extra2         = &one,
1817         },
1818         {
1819                 .procname       = "suid_dumpable",
1820                 .data           = &suid_dumpable,
1821                 .maxlen         = sizeof(int),
1822                 .mode           = 0644,
1823                 .proc_handler   = proc_dointvec_minmax_coredump,
1824                 .extra1         = &zero,
1825                 .extra2         = &two,
1826         },
1827 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1828         {
1829                 .procname       = "binfmt_misc",
1830                 .mode           = 0555,
1831                 .child          = sysctl_mount_point,
1832         },
1833 #endif
1834         {
1835                 .procname       = "pipe-max-size",
1836                 .data           = &pipe_max_size,
1837                 .maxlen         = sizeof(int),
1838                 .mode           = 0644,
1839                 .proc_handler   = &pipe_proc_fn,
1840                 .extra1         = &pipe_min_size,
1841         },
1842         {
1843                 .procname       = "pipe-user-pages-hard",
1844                 .data           = &pipe_user_pages_hard,
1845                 .maxlen         = sizeof(pipe_user_pages_hard),
1846                 .mode           = 0644,
1847                 .proc_handler   = proc_doulongvec_minmax,
1848         },
1849         {
1850                 .procname       = "pipe-user-pages-soft",
1851                 .data           = &pipe_user_pages_soft,
1852                 .maxlen         = sizeof(pipe_user_pages_soft),
1853                 .mode           = 0644,
1854                 .proc_handler   = proc_doulongvec_minmax,
1855         },
1856         { }
1857 };
1858
1859 static struct ctl_table debug_table[] = {
1860 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1861         {
1862                 .procname       = "exception-trace",
1863                 .data           = &show_unhandled_signals,
1864                 .maxlen         = sizeof(int),
1865                 .mode           = 0644,
1866                 .proc_handler   = proc_dointvec
1867         },
1868 #endif
1869 #if defined(CONFIG_OPTPROBES)
1870         {
1871                 .procname       = "kprobes-optimization",
1872                 .data           = &sysctl_kprobes_optimization,
1873                 .maxlen         = sizeof(int),
1874                 .mode           = 0644,
1875                 .proc_handler   = proc_kprobes_optimization_handler,
1876                 .extra1         = &zero,
1877                 .extra2         = &one,
1878         },
1879 #endif
1880         { }
1881 };
1882
1883 static struct ctl_table dev_table[] = {
1884         { }
1885 };
1886
1887 int __init sysctl_init(void)
1888 {
1889         struct ctl_table_header *hdr;
1890
1891         hdr = register_sysctl_table(sysctl_base_table);
1892         kmemleak_not_leak(hdr);
1893         return 0;
1894 }
1895
1896 #endif /* CONFIG_SYSCTL */
1897
1898 /*
1899  * /proc/sys support
1900  */
1901
1902 #ifdef CONFIG_PROC_SYSCTL
1903
1904 static int _proc_do_string(char *data, int maxlen, int write,
1905                            char __user *buffer,
1906                            size_t *lenp, loff_t *ppos)
1907 {
1908         size_t len;
1909         char __user *p;
1910         char c;
1911
1912         if (!data || !maxlen || !*lenp) {
1913                 *lenp = 0;
1914                 return 0;
1915         }
1916
1917         if (write) {
1918                 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1919                         /* Only continue writes not past the end of buffer. */
1920                         len = strlen(data);
1921                         if (len > maxlen - 1)
1922                                 len = maxlen - 1;
1923
1924                         if (*ppos > len)
1925                                 return 0;
1926                         len = *ppos;
1927                 } else {
1928                         /* Start writing from beginning of buffer. */
1929                         len = 0;
1930                 }
1931
1932                 *ppos += *lenp;
1933                 p = buffer;
1934                 while ((p - buffer) < *lenp && len < maxlen - 1) {
1935                         if (get_user(c, p++))
1936                                 return -EFAULT;
1937                         if (c == 0 || c == '\n')
1938                                 break;
1939                         data[len++] = c;
1940                 }
1941                 data[len] = 0;
1942         } else {
1943                 len = strlen(data);
1944                 if (len > maxlen)
1945                         len = maxlen;
1946
1947                 if (*ppos > len) {
1948                         *lenp = 0;
1949                         return 0;
1950                 }
1951
1952                 data += *ppos;
1953                 len  -= *ppos;
1954
1955                 if (len > *lenp)
1956                         len = *lenp;
1957                 if (len)
1958                         if (copy_to_user(buffer, data, len))
1959                                 return -EFAULT;
1960                 if (len < *lenp) {
1961                         if (put_user('\n', buffer + len))
1962                                 return -EFAULT;
1963                         len++;
1964                 }
1965                 *lenp = len;
1966                 *ppos += len;
1967         }
1968         return 0;
1969 }
1970
1971 static void warn_sysctl_write(struct ctl_table *table)
1972 {
1973         pr_warn_once("%s wrote to %s when file position was not 0!\n"
1974                 "This will not be supported in the future. To silence this\n"
1975                 "warning, set kernel.sysctl_writes_strict = -1\n",
1976                 current->comm, table->procname);
1977 }
1978
1979 /**
1980  * proc_dostring - read a string sysctl
1981  * @table: the sysctl table
1982  * @write: %TRUE if this is a write to the sysctl file
1983  * @buffer: the user buffer
1984  * @lenp: the size of the user buffer
1985  * @ppos: file position
1986  *
1987  * Reads/writes a string from/to the user buffer. If the kernel
1988  * buffer provided is not large enough to hold the string, the
1989  * string is truncated. The copied string is %NULL-terminated.
1990  * If the string is being read by the user process, it is copied
1991  * and a newline '\n' is added. It is truncated if the buffer is
1992  * not large enough.
1993  *
1994  * Returns 0 on success.
1995  */
1996 int proc_dostring(struct ctl_table *table, int write,
1997                   void __user *buffer, size_t *lenp, loff_t *ppos)
1998 {
1999         if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
2000                 warn_sysctl_write(table);
2001
2002         return _proc_do_string((char *)(table->data), table->maxlen, write,
2003                                (char __user *)buffer, lenp, ppos);
2004 }
2005
2006 static size_t proc_skip_spaces(char **buf)
2007 {
2008         size_t ret;
2009         char *tmp = skip_spaces(*buf);
2010         ret = tmp - *buf;
2011         *buf = tmp;
2012         return ret;
2013 }
2014
2015 static void proc_skip_char(char **buf, size_t *size, const char v)
2016 {
2017         while (*size) {
2018                 if (**buf != v)
2019                         break;
2020                 (*size)--;
2021                 (*buf)++;
2022         }
2023 }
2024
2025 #define TMPBUFLEN 22
2026 /**
2027  * proc_get_long - reads an ASCII formatted integer from a user buffer
2028  *
2029  * @buf: a kernel buffer
2030  * @size: size of the kernel buffer
2031  * @val: this is where the number will be stored
2032  * @neg: set to %TRUE if number is negative
2033  * @perm_tr: a vector which contains the allowed trailers
2034  * @perm_tr_len: size of the perm_tr vector
2035  * @tr: pointer to store the trailer character
2036  *
2037  * In case of success %0 is returned and @buf and @size are updated with
2038  * the amount of bytes read. If @tr is non-NULL and a trailing
2039  * character exists (size is non-zero after returning from this
2040  * function), @tr is updated with the trailing character.
2041  */
2042 static int proc_get_long(char **buf, size_t *size,
2043                           unsigned long *val, bool *neg,
2044                           const char *perm_tr, unsigned perm_tr_len, char *tr)
2045 {
2046         int len;
2047         char *p, tmp[TMPBUFLEN];
2048
2049         if (!*size)
2050                 return -EINVAL;
2051
2052         len = *size;
2053         if (len > TMPBUFLEN - 1)
2054                 len = TMPBUFLEN - 1;
2055
2056         memcpy(tmp, *buf, len);
2057
2058         tmp[len] = 0;
2059         p = tmp;
2060         if (*p == '-' && *size > 1) {
2061                 *neg = true;
2062                 p++;
2063         } else
2064                 *neg = false;
2065         if (!isdigit(*p))
2066                 return -EINVAL;
2067
2068         *val = simple_strtoul(p, &p, 0);
2069
2070         len = p - tmp;
2071
2072         /* We don't know if the next char is whitespace thus we may accept
2073          * invalid integers (e.g. 1234...a) or two integers instead of one
2074          * (e.g. 123...1). So lets not allow such large numbers. */
2075         if (len == TMPBUFLEN - 1)
2076                 return -EINVAL;
2077
2078         if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2079                 return -EINVAL;
2080
2081         if (tr && (len < *size))
2082                 *tr = *p;
2083
2084         *buf += len;
2085         *size -= len;
2086
2087         return 0;
2088 }
2089
2090 /**
2091  * proc_put_long - converts an integer to a decimal ASCII formatted string
2092  *
2093  * @buf: the user buffer
2094  * @size: the size of the user buffer
2095  * @val: the integer to be converted
2096  * @neg: sign of the number, %TRUE for negative
2097  *
2098  * In case of success %0 is returned and @buf and @size are updated with
2099  * the amount of bytes written.
2100  */
2101 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2102                           bool neg)
2103 {
2104         int len;
2105         char tmp[TMPBUFLEN], *p = tmp;
2106
2107         sprintf(p, "%s%lu", neg ? "-" : "", val);
2108         len = strlen(tmp);
2109         if (len > *size)
2110                 len = *size;
2111         if (copy_to_user(*buf, tmp, len))
2112                 return -EFAULT;
2113         *size -= len;
2114         *buf += len;
2115         return 0;
2116 }
2117 #undef TMPBUFLEN
2118
2119 static int proc_put_char(void __user **buf, size_t *size, char c)
2120 {
2121         if (*size) {
2122                 char __user **buffer = (char __user **)buf;
2123                 if (put_user(c, *buffer))
2124                         return -EFAULT;
2125                 (*size)--, (*buffer)++;
2126                 *buf = *buffer;
2127         }
2128         return 0;
2129 }
2130
2131 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2132                                  int *valp,
2133                                  int write, void *data)
2134 {
2135         if (write) {
2136                 if (*negp) {
2137                         if (*lvalp > (unsigned long) INT_MAX + 1)
2138                                 return -EINVAL;
2139                         *valp = -*lvalp;
2140                 } else {
2141                         if (*lvalp > (unsigned long) INT_MAX)
2142                                 return -EINVAL;
2143                         *valp = *lvalp;
2144                 }
2145         } else {
2146                 int val = *valp;
2147                 if (val < 0) {
2148                         *negp = true;
2149                         *lvalp = -(unsigned long)val;
2150                 } else {
2151                         *negp = false;
2152                         *lvalp = (unsigned long)val;
2153                 }
2154         }
2155         return 0;
2156 }
2157
2158 static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2159                                  int *valp,
2160                                  int write, void *data)
2161 {
2162         if (write) {
2163                 if (*negp)
2164                         return -EINVAL;
2165                 *valp = *lvalp;
2166         } else {
2167                 unsigned int val = *valp;
2168                 *lvalp = (unsigned long)val;
2169         }
2170         return 0;
2171 }
2172
2173 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2174
2175 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2176                   int write, void __user *buffer,
2177                   size_t *lenp, loff_t *ppos,
2178                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2179                               int write, void *data),
2180                   void *data)
2181 {
2182         int *i, vleft, first = 1, err = 0;
2183         unsigned long page = 0;
2184         size_t left;
2185         char *kbuf;
2186         
2187         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2188                 *lenp = 0;
2189                 return 0;
2190         }
2191         
2192         i = (int *) tbl_data;
2193         vleft = table->maxlen / sizeof(*i);
2194         left = *lenp;
2195
2196         if (!conv)
2197                 conv = do_proc_dointvec_conv;
2198
2199         if (write) {
2200                 if (*ppos) {
2201                         switch (sysctl_writes_strict) {
2202                         case SYSCTL_WRITES_STRICT:
2203                                 goto out;
2204                         case SYSCTL_WRITES_WARN:
2205                                 warn_sysctl_write(table);
2206                                 break;
2207                         default:
2208                                 break;
2209                         }
2210                 }
2211
2212                 if (left > PAGE_SIZE - 1)
2213                         left = PAGE_SIZE - 1;
2214                 page = __get_free_page(GFP_TEMPORARY);
2215                 kbuf = (char *) page;
2216                 if (!kbuf)
2217                         return -ENOMEM;
2218                 if (copy_from_user(kbuf, buffer, left)) {
2219                         err = -EFAULT;
2220                         goto free;
2221                 }
2222                 kbuf[left] = 0;
2223         }
2224
2225         for (; left && vleft--; i++, first=0) {
2226                 unsigned long lval;
2227                 bool neg;
2228
2229                 if (write) {
2230                         left -= proc_skip_spaces(&kbuf);
2231
2232                         if (!left)
2233                                 break;
2234                         err = proc_get_long(&kbuf, &left, &lval, &neg,
2235                                              proc_wspace_sep,
2236                                              sizeof(proc_wspace_sep), NULL);
2237                         if (err)
2238                                 break;
2239                         if (conv(&neg, &lval, i, 1, data)) {
2240                                 err = -EINVAL;
2241                                 break;
2242                         }
2243                 } else {
2244                         if (conv(&neg, &lval, i, 0, data)) {
2245                                 err = -EINVAL;
2246                                 break;
2247                         }
2248                         if (!first)
2249                                 err = proc_put_char(&buffer, &left, '\t');
2250                         if (err)
2251                                 break;
2252                         err = proc_put_long(&buffer, &left, lval, neg);
2253                         if (err)
2254                                 break;
2255                 }
2256         }
2257
2258         if (!write && !first && left && !err)
2259                 err = proc_put_char(&buffer, &left, '\n');
2260         if (write && !err && left)
2261                 left -= proc_skip_spaces(&kbuf);
2262 free:
2263         if (write) {
2264                 free_page(page);
2265                 if (first)
2266                         return err ? : -EINVAL;
2267         }
2268         *lenp -= left;
2269 out:
2270         *ppos += *lenp;
2271         return err;
2272 }
2273
2274 static int do_proc_dointvec(struct ctl_table *table, int write,
2275                   void __user *buffer, size_t *lenp, loff_t *ppos,
2276                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2277                               int write, void *data),
2278                   void *data)
2279 {
2280         return __do_proc_dointvec(table->data, table, write,
2281                         buffer, lenp, ppos, conv, data);
2282 }
2283
2284 /**
2285  * proc_dointvec - read a vector of integers
2286  * @table: the sysctl table
2287  * @write: %TRUE if this is a write to the sysctl file
2288  * @buffer: the user buffer
2289  * @lenp: the size of the user buffer
2290  * @ppos: file position
2291  *
2292  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2293  * values from/to the user buffer, treated as an ASCII string. 
2294  *
2295  * Returns 0 on success.
2296  */
2297 int proc_dointvec(struct ctl_table *table, int write,
2298                      void __user *buffer, size_t *lenp, loff_t *ppos)
2299 {
2300         return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2301 }
2302
2303 /**
2304  * proc_douintvec - read a vector of unsigned integers
2305  * @table: the sysctl table
2306  * @write: %TRUE if this is a write to the sysctl file
2307  * @buffer: the user buffer
2308  * @lenp: the size of the user buffer
2309  * @ppos: file position
2310  *
2311  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2312  * values from/to the user buffer, treated as an ASCII string.
2313  *
2314  * Returns 0 on success.
2315  */
2316 int proc_douintvec(struct ctl_table *table, int write,
2317                      void __user *buffer, size_t *lenp, loff_t *ppos)
2318 {
2319         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2320                                 do_proc_douintvec_conv, NULL);
2321 }
2322
2323 /*
2324  * Taint values can only be increased
2325  * This means we can safely use a temporary.
2326  */
2327 static int proc_taint(struct ctl_table *table, int write,
2328                                void __user *buffer, size_t *lenp, loff_t *ppos)
2329 {
2330         struct ctl_table t;
2331         unsigned long tmptaint = get_taint();
2332         int err;
2333
2334         if (write && !capable(CAP_SYS_ADMIN))
2335                 return -EPERM;
2336
2337         t = *table;
2338         t.data = &tmptaint;
2339         err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2340         if (err < 0)
2341                 return err;
2342
2343         if (write) {
2344                 /*
2345                  * Poor man's atomic or. Not worth adding a primitive
2346                  * to everyone's atomic.h for this
2347                  */
2348                 int i;
2349                 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2350                         if ((tmptaint >> i) & 1)
2351                                 add_taint(i, LOCKDEP_STILL_OK);
2352                 }
2353         }
2354
2355         return err;
2356 }
2357
2358 #ifdef CONFIG_PRINTK
2359 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2360                                 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 {
2362         if (write && !capable(CAP_SYS_ADMIN))
2363                 return -EPERM;
2364
2365         return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2366 }
2367 #endif
2368
2369 struct do_proc_dointvec_minmax_conv_param {
2370         int *min;
2371         int *max;
2372 };
2373
2374 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2375                                         int *valp,
2376                                         int write, void *data)
2377 {
2378         struct do_proc_dointvec_minmax_conv_param *param = data;
2379         if (write) {
2380                 int val = *negp ? -*lvalp : *lvalp;
2381                 if ((param->min && *param->min > val) ||
2382                     (param->max && *param->max < val))
2383                         return -EINVAL;
2384                 *valp = val;
2385         } else {
2386                 int val = *valp;
2387                 if (val < 0) {
2388                         *negp = true;
2389                         *lvalp = -(unsigned long)val;
2390                 } else {
2391                         *negp = false;
2392                         *lvalp = (unsigned long)val;
2393                 }
2394         }
2395         return 0;
2396 }
2397
2398 /**
2399  * proc_dointvec_minmax - read a vector of integers with min/max values
2400  * @table: the sysctl table
2401  * @write: %TRUE if this is a write to the sysctl file
2402  * @buffer: the user buffer
2403  * @lenp: the size of the user buffer
2404  * @ppos: file position
2405  *
2406  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2407  * values from/to the user buffer, treated as an ASCII string.
2408  *
2409  * This routine will ensure the values are within the range specified by
2410  * table->extra1 (min) and table->extra2 (max).
2411  *
2412  * Returns 0 on success.
2413  */
2414 int proc_dointvec_minmax(struct ctl_table *table, int write,
2415                   void __user *buffer, size_t *lenp, loff_t *ppos)
2416 {
2417         struct do_proc_dointvec_minmax_conv_param param = {
2418                 .min = (int *) table->extra1,
2419                 .max = (int *) table->extra2,
2420         };
2421         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2422                                 do_proc_dointvec_minmax_conv, &param);
2423 }
2424
2425 static void validate_coredump_safety(void)
2426 {
2427 #ifdef CONFIG_COREDUMP
2428         if (suid_dumpable == SUID_DUMP_ROOT &&
2429             core_pattern[0] != '/' && core_pattern[0] != '|') {
2430                 printk(KERN_WARNING "Unsafe core_pattern used with "\
2431                         "suid_dumpable=2. Pipe handler or fully qualified "\
2432                         "core dump path required.\n");
2433         }
2434 #endif
2435 }
2436
2437 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2438                 void __user *buffer, size_t *lenp, loff_t *ppos)
2439 {
2440         int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2441         if (!error)
2442                 validate_coredump_safety();
2443         return error;
2444 }
2445
2446 #ifdef CONFIG_COREDUMP
2447 static int proc_dostring_coredump(struct ctl_table *table, int write,
2448                   void __user *buffer, size_t *lenp, loff_t *ppos)
2449 {
2450         int error = proc_dostring(table, write, buffer, lenp, ppos);
2451         if (!error)
2452                 validate_coredump_safety();
2453         return error;
2454 }
2455 #endif
2456
2457 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2458                                      void __user *buffer,
2459                                      size_t *lenp, loff_t *ppos,
2460                                      unsigned long convmul,
2461                                      unsigned long convdiv)
2462 {
2463         unsigned long *i, *min, *max;
2464         int vleft, first = 1, err = 0;
2465         unsigned long page = 0;
2466         size_t left;
2467         char *kbuf;
2468
2469         if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2470                 *lenp = 0;
2471                 return 0;
2472         }
2473
2474         i = (unsigned long *) data;
2475         min = (unsigned long *) table->extra1;
2476         max = (unsigned long *) table->extra2;
2477         vleft = table->maxlen / sizeof(unsigned long);
2478         left = *lenp;
2479
2480         if (write) {
2481                 if (*ppos) {
2482                         switch (sysctl_writes_strict) {
2483                         case SYSCTL_WRITES_STRICT:
2484                                 goto out;
2485                         case SYSCTL_WRITES_WARN:
2486                                 warn_sysctl_write(table);
2487                                 break;
2488                         default:
2489                                 break;
2490                         }
2491                 }
2492
2493                 if (left > PAGE_SIZE - 1)
2494                         left = PAGE_SIZE - 1;
2495                 page = __get_free_page(GFP_TEMPORARY);
2496                 kbuf = (char *) page;
2497                 if (!kbuf)
2498                         return -ENOMEM;
2499                 if (copy_from_user(kbuf, buffer, left)) {
2500                         err = -EFAULT;
2501                         goto free;
2502                 }
2503                 kbuf[left] = 0;
2504         }
2505
2506         for (; left && vleft--; i++, first = 0) {
2507                 unsigned long val;
2508
2509                 if (write) {
2510                         bool neg;
2511
2512                         left -= proc_skip_spaces(&kbuf);
2513
2514                         err = proc_get_long(&kbuf, &left, &val, &neg,
2515                                              proc_wspace_sep,
2516                                              sizeof(proc_wspace_sep), NULL);
2517                         if (err)
2518                                 break;
2519                         if (neg)
2520                                 continue;
2521                         if ((min && val < *min) || (max && val > *max))
2522                                 continue;
2523                         *i = val;
2524                 } else {
2525                         val = convdiv * (*i) / convmul;
2526                         if (!first) {
2527                                 err = proc_put_char(&buffer, &left, '\t');
2528                                 if (err)
2529                                         break;
2530                         }
2531                         err = proc_put_long(&buffer, &left, val, false);
2532                         if (err)
2533                                 break;
2534                 }
2535         }
2536
2537         if (!write && !first && left && !err)
2538                 err = proc_put_char(&buffer, &left, '\n');
2539         if (write && !err)
2540                 left -= proc_skip_spaces(&kbuf);
2541 free:
2542         if (write) {
2543                 free_page(page);
2544                 if (first)
2545                         return err ? : -EINVAL;
2546         }
2547         *lenp -= left;
2548 out:
2549         *ppos += *lenp;
2550         return err;
2551 }
2552
2553 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2554                                      void __user *buffer,
2555                                      size_t *lenp, loff_t *ppos,
2556                                      unsigned long convmul,
2557                                      unsigned long convdiv)
2558 {
2559         return __do_proc_doulongvec_minmax(table->data, table, write,
2560                         buffer, lenp, ppos, convmul, convdiv);
2561 }
2562
2563 /**
2564  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2565  * @table: the sysctl table
2566  * @write: %TRUE if this is a write to the sysctl file
2567  * @buffer: the user buffer
2568  * @lenp: the size of the user buffer
2569  * @ppos: file position
2570  *
2571  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2572  * values from/to the user buffer, treated as an ASCII string.
2573  *
2574  * This routine will ensure the values are within the range specified by
2575  * table->extra1 (min) and table->extra2 (max).
2576  *
2577  * Returns 0 on success.
2578  */
2579 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2580                            void __user *buffer, size_t *lenp, loff_t *ppos)
2581 {
2582     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2583 }
2584
2585 /**
2586  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2587  * @table: the sysctl table
2588  * @write: %TRUE if this is a write to the sysctl file
2589  * @buffer: the user buffer
2590  * @lenp: the size of the user buffer
2591  * @ppos: file position
2592  *
2593  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2594  * values from/to the user buffer, treated as an ASCII string. The values
2595  * are treated as milliseconds, and converted to jiffies when they are stored.
2596  *
2597  * This routine will ensure the values are within the range specified by
2598  * table->extra1 (min) and table->extra2 (max).
2599  *
2600  * Returns 0 on success.
2601  */
2602 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2603                                       void __user *buffer,
2604                                       size_t *lenp, loff_t *ppos)
2605 {
2606     return do_proc_doulongvec_minmax(table, write, buffer,
2607                                      lenp, ppos, HZ, 1000l);
2608 }
2609
2610
2611 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2612                                          int *valp,
2613                                          int write, void *data)
2614 {
2615         if (write) {
2616                 if (*lvalp > LONG_MAX / HZ)
2617                         return 1;
2618                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2619         } else {
2620                 int val = *valp;
2621                 unsigned long lval;
2622                 if (val < 0) {
2623                         *negp = true;
2624                         lval = -(unsigned long)val;
2625                 } else {
2626                         *negp = false;
2627                         lval = (unsigned long)val;
2628                 }
2629                 *lvalp = lval / HZ;
2630         }
2631         return 0;
2632 }
2633
2634 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2635                                                 int *valp,
2636                                                 int write, void *data)
2637 {
2638         if (write) {
2639                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2640                         return 1;
2641                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2642         } else {
2643                 int val = *valp;
2644                 unsigned long lval;
2645                 if (val < 0) {
2646                         *negp = true;
2647                         lval = -(unsigned long)val;
2648                 } else {
2649                         *negp = false;
2650                         lval = (unsigned long)val;
2651                 }
2652                 *lvalp = jiffies_to_clock_t(lval);
2653         }
2654         return 0;
2655 }
2656
2657 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2658                                             int *valp,
2659                                             int write, void *data)
2660 {
2661         if (write) {
2662                 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2663
2664                 if (jif > INT_MAX)
2665                         return 1;
2666                 *valp = (int)jif;
2667         } else {
2668                 int val = *valp;
2669                 unsigned long lval;
2670                 if (val < 0) {
2671                         *negp = true;
2672                         lval = -(unsigned long)val;
2673                 } else {
2674                         *negp = false;
2675                         lval = (unsigned long)val;
2676                 }
2677                 *lvalp = jiffies_to_msecs(lval);
2678         }
2679         return 0;
2680 }
2681
2682 /**
2683  * proc_dointvec_jiffies - read a vector of integers as seconds
2684  * @table: the sysctl table
2685  * @write: %TRUE if this is a write to the sysctl file
2686  * @buffer: the user buffer
2687  * @lenp: the size of the user buffer
2688  * @ppos: file position
2689  *
2690  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2691  * values from/to the user buffer, treated as an ASCII string. 
2692  * The values read are assumed to be in seconds, and are converted into
2693  * jiffies.
2694  *
2695  * Returns 0 on success.
2696  */
2697 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2698                           void __user *buffer, size_t *lenp, loff_t *ppos)
2699 {
2700     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2701                             do_proc_dointvec_jiffies_conv,NULL);
2702 }
2703
2704 /**
2705  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2706  * @table: the sysctl table
2707  * @write: %TRUE if this is a write to the sysctl file
2708  * @buffer: the user buffer
2709  * @lenp: the size of the user buffer
2710  * @ppos: pointer to the file position
2711  *
2712  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2713  * values from/to the user buffer, treated as an ASCII string. 
2714  * The values read are assumed to be in 1/USER_HZ seconds, and 
2715  * are converted into jiffies.
2716  *
2717  * Returns 0 on success.
2718  */
2719 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2720                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2721 {
2722     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2723                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2724 }
2725
2726 /**
2727  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2728  * @table: the sysctl table
2729  * @write: %TRUE if this is a write to the sysctl file
2730  * @buffer: the user buffer
2731  * @lenp: the size of the user buffer
2732  * @ppos: file position
2733  * @ppos: the current position in the file
2734  *
2735  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2736  * values from/to the user buffer, treated as an ASCII string. 
2737  * The values read are assumed to be in 1/1000 seconds, and 
2738  * are converted into jiffies.
2739  *
2740  * Returns 0 on success.
2741  */
2742 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2743                              void __user *buffer, size_t *lenp, loff_t *ppos)
2744 {
2745         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2746                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2747 }
2748
2749 static int proc_do_cad_pid(struct ctl_table *table, int write,
2750                            void __user *buffer, size_t *lenp, loff_t *ppos)
2751 {
2752         struct pid *new_pid;
2753         pid_t tmp;
2754         int r;
2755
2756         tmp = pid_vnr(cad_pid);
2757
2758         r = __do_proc_dointvec(&tmp, table, write, buffer,
2759                                lenp, ppos, NULL, NULL);
2760         if (r || !write)
2761                 return r;
2762
2763         new_pid = find_get_pid(tmp);
2764         if (!new_pid)
2765                 return -ESRCH;
2766
2767         put_pid(xchg(&cad_pid, new_pid));
2768         return 0;
2769 }
2770
2771 /**
2772  * proc_do_large_bitmap - read/write from/to a large bitmap
2773  * @table: the sysctl table
2774  * @write: %TRUE if this is a write to the sysctl file
2775  * @buffer: the user buffer
2776  * @lenp: the size of the user buffer
2777  * @ppos: file position
2778  *
2779  * The bitmap is stored at table->data and the bitmap length (in bits)
2780  * in table->maxlen.
2781  *
2782  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2783  * large bitmaps may be represented in a compact manner. Writing into
2784  * the file will clear the bitmap then update it with the given input.
2785  *
2786  * Returns 0 on success.
2787  */
2788 int proc_do_large_bitmap(struct ctl_table *table, int write,
2789                          void __user *buffer, size_t *lenp, loff_t *ppos)
2790 {
2791         int err = 0;
2792         bool first = 1;
2793         size_t left = *lenp;
2794         unsigned long bitmap_len = table->maxlen;
2795         unsigned long *bitmap = *(unsigned long **) table->data;
2796         unsigned long *tmp_bitmap = NULL;
2797         char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2798
2799         if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2800                 *lenp = 0;
2801                 return 0;
2802         }
2803
2804         if (write) {
2805                 unsigned long page = 0;
2806                 char *kbuf;
2807
2808                 if (left > PAGE_SIZE - 1)
2809                         left = PAGE_SIZE - 1;
2810
2811                 page = __get_free_page(GFP_TEMPORARY);
2812                 kbuf = (char *) page;
2813                 if (!kbuf)
2814                         return -ENOMEM;
2815                 if (copy_from_user(kbuf, buffer, left)) {
2816                         free_page(page);
2817                         return -EFAULT;
2818                 }
2819                 kbuf[left] = 0;
2820
2821                 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2822                                      GFP_KERNEL);
2823                 if (!tmp_bitmap) {
2824                         free_page(page);
2825                         return -ENOMEM;
2826                 }
2827                 proc_skip_char(&kbuf, &left, '\n');
2828                 while (!err && left) {
2829                         unsigned long val_a, val_b;
2830                         bool neg;
2831
2832                         err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2833                                              sizeof(tr_a), &c);
2834                         if (err)
2835                                 break;
2836                         if (val_a >= bitmap_len || neg) {
2837                                 err = -EINVAL;
2838                                 break;
2839                         }
2840
2841                         val_b = val_a;
2842                         if (left) {
2843                                 kbuf++;
2844                                 left--;
2845                         }
2846
2847                         if (c == '-') {
2848                                 err = proc_get_long(&kbuf, &left, &val_b,
2849                                                      &neg, tr_b, sizeof(tr_b),
2850                                                      &c);
2851                                 if (err)
2852                                         break;
2853                                 if (val_b >= bitmap_len || neg ||
2854                                     val_a > val_b) {
2855                                         err = -EINVAL;
2856                                         break;
2857                                 }
2858                                 if (left) {
2859                                         kbuf++;
2860                                         left--;
2861                                 }
2862                         }
2863
2864                         bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2865                         first = 0;
2866                         proc_skip_char(&kbuf, &left, '\n');
2867                 }
2868                 free_page(page);
2869         } else {
2870                 unsigned long bit_a, bit_b = 0;
2871
2872                 while (left) {
2873                         bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2874                         if (bit_a >= bitmap_len)
2875                                 break;
2876                         bit_b = find_next_zero_bit(bitmap, bitmap_len,
2877                                                    bit_a + 1) - 1;
2878
2879                         if (!first) {
2880                                 err = proc_put_char(&buffer, &left, ',');
2881                                 if (err)
2882                                         break;
2883                         }
2884                         err = proc_put_long(&buffer, &left, bit_a, false);
2885                         if (err)
2886                                 break;
2887                         if (bit_a != bit_b) {
2888                                 err = proc_put_char(&buffer, &left, '-');
2889                                 if (err)
2890                                         break;
2891                                 err = proc_put_long(&buffer, &left, bit_b, false);
2892                                 if (err)
2893                                         break;
2894                         }
2895
2896                         first = 0; bit_b++;
2897                 }
2898                 if (!err)
2899                         err = proc_put_char(&buffer, &left, '\n');
2900         }
2901
2902         if (!err) {
2903                 if (write) {
2904                         if (*ppos)
2905                                 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2906                         else
2907                                 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2908                 }
2909                 kfree(tmp_bitmap);
2910                 *lenp -= left;
2911                 *ppos += *lenp;
2912                 return 0;
2913         } else {
2914                 kfree(tmp_bitmap);
2915                 return err;
2916         }
2917 }
2918
2919 #else /* CONFIG_PROC_SYSCTL */
2920
2921 int proc_dostring(struct ctl_table *table, int write,
2922                   void __user *buffer, size_t *lenp, loff_t *ppos)
2923 {
2924         return -ENOSYS;
2925 }
2926
2927 int proc_dointvec(struct ctl_table *table, int write,
2928                   void __user *buffer, size_t *lenp, loff_t *ppos)
2929 {
2930         return -ENOSYS;
2931 }
2932
2933 int proc_douintvec(struct ctl_table *table, int write,
2934                   void __user *buffer, size_t *lenp, loff_t *ppos)
2935 {
2936         return -ENOSYS;
2937 }
2938
2939 int proc_dointvec_minmax(struct ctl_table *table, int write,
2940                     void __user *buffer, size_t *lenp, loff_t *ppos)
2941 {
2942         return -ENOSYS;
2943 }
2944
2945 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2946                     void __user *buffer, size_t *lenp, loff_t *ppos)
2947 {
2948         return -ENOSYS;
2949 }
2950
2951 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2952                     void __user *buffer, size_t *lenp, loff_t *ppos)
2953 {
2954         return -ENOSYS;
2955 }
2956
2957 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2958                              void __user *buffer, size_t *lenp, loff_t *ppos)
2959 {
2960         return -ENOSYS;
2961 }
2962
2963 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2964                     void __user *buffer, size_t *lenp, loff_t *ppos)
2965 {
2966         return -ENOSYS;
2967 }
2968
2969 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2970                                       void __user *buffer,
2971                                       size_t *lenp, loff_t *ppos)
2972 {
2973     return -ENOSYS;
2974 }
2975
2976
2977 #endif /* CONFIG_PROC_SYSCTL */
2978
2979 /*
2980  * No sense putting this after each symbol definition, twice,
2981  * exception granted :-)
2982  */
2983 EXPORT_SYMBOL(proc_dointvec);
2984 EXPORT_SYMBOL(proc_douintvec);
2985 EXPORT_SYMBOL(proc_dointvec_jiffies);
2986 EXPORT_SYMBOL(proc_dointvec_minmax);
2987 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2988 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2989 EXPORT_SYMBOL(proc_dostring);
2990 EXPORT_SYMBOL(proc_doulongvec_minmax);
2991 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);