Merge tag 'full-dynticks-cputime-for-mingo' of git://git.kernel.org/pub/scm/linux...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / sysctl.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
21#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
5a04cca6 26#include <linux/bitmap.h>
d33ed52d 27#include <linux/signal.h>
455cd5ab 28#include <linux/printk.h>
1da177e4 29#include <linux/proc_fs.h>
72c2d582 30#include <linux/security.h>
1da177e4 31#include <linux/ctype.h>
dfec072e 32#include <linux/kmemcheck.h>
fd4b616b 33#include <linux/kmemleak.h>
62239ac2 34#include <linux/fs.h>
1da177e4
LT
35#include <linux/init.h>
36#include <linux/kernel.h>
0296b228 37#include <linux/kobject.h>
20380731 38#include <linux/net.h>
1da177e4
LT
39#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
3fff4c42 42#include <linux/ratelimit.h>
76ab0f53 43#include <linux/compaction.h>
1da177e4 44#include <linux/hugetlb.h>
1da177e4 45#include <linux/initrd.h>
0b77f5bf 46#include <linux/key.h>
1da177e4
LT
47#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
6e006701 50#include <linux/dnotify.h>
1da177e4 51#include <linux/syscalls.h>
c748e134 52#include <linux/vmstat.h>
c255d844
PM
53#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
10a0a8d4 55#include <linux/reboot.h>
b0fc494f 56#include <linux/ftrace.h>
cdd6c482 57#include <linux/perf_event.h>
b2be84df 58#include <linux/kprobes.h>
b492e95b 59#include <linux/pipe_fs_i.h>
8e4228e1 60#include <linux/oom.h>
17f60a7d 61#include <linux/kmod.h>
73efc039 62#include <linux/capability.h>
40401530 63#include <linux/binfmts.h>
1da177e4
LT
64
65#include <asm/uaccess.h>
66#include <asm/processor.h>
67
29cbc78b
AK
68#ifdef CONFIG_X86
69#include <asm/nmi.h>
0741f4d2 70#include <asm/stacktrace.h>
6e7c4025 71#include <asm/io.h>
29cbc78b 72#endif
d550bbd4
DH
73#ifdef CONFIG_SPARC
74#include <asm/setup.h>
75#endif
c55b7c3e
DY
76#ifdef CONFIG_BSD_PROCESS_ACCT
77#include <linux/acct.h>
78#endif
4f0e056f
DY
79#ifdef CONFIG_RT_MUTEXES
80#include <linux/rtmutex.h>
81#endif
2edf5e49
DY
82#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
83#include <linux/lockdep.h>
84#endif
15485a46
DY
85#ifdef CONFIG_CHR_DEV_SG
86#include <scsi/sg.h>
87#endif
29cbc78b 88
58687acb 89#ifdef CONFIG_LOCKUP_DETECTOR
504d7cf1
DZ
90#include <linux/nmi.h>
91#endif
92
7058cb02 93
1da177e4
LT
94#if defined(CONFIG_SYSCTL)
95
96/* External variables not in a header file. */
1da177e4
LT
97extern int sysctl_overcommit_memory;
98extern int sysctl_overcommit_ratio;
99extern int max_threads;
d6e71144 100extern int suid_dumpable;
046d662f
AK
101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
1da177e4 103extern char core_pattern[];
a293980c 104extern unsigned int core_pipe_limit;
046d662f 105#endif
1da177e4
LT
106extern int pid_max;
107extern int min_free_kbytes;
1da177e4 108extern int pid_max_min, pid_max_max;
9d0243bc 109extern int sysctl_drop_caches;
8ad4b1fb 110extern int percpu_pagelist_fraction;
bebfa101 111extern int compat_log;
9745512c 112extern int latencytop_enabled;
eceea0b3 113extern int sysctl_nr_open_min, sysctl_nr_open_max;
dd8632a1
PM
114#ifndef CONFIG_MMU
115extern int sysctl_nr_trim_pages;
116#endif
cb684b5b 117#ifdef CONFIG_BLOCK
5e605b64 118extern int blk_iopoll_enabled;
cb684b5b 119#endif
1da177e4 120
c4f3b63f 121/* Constants used for minimum and maximum */
2508ce18 122#ifdef CONFIG_LOCKUP_DETECTOR
c4f3b63f 123static int sixty = 60;
9383d967 124static int neg_one = -1;
c4f3b63f
RT
125#endif
126
c4f3b63f 127static int zero;
cd5f9a4c
LT
128static int __maybe_unused one = 1;
129static int __maybe_unused two = 2;
cb16e95f 130static int __maybe_unused three = 3;
fc3501d4 131static unsigned long one_ul = 1;
c4f3b63f 132static int one_hundred = 100;
af91322e
DY
133#ifdef CONFIG_PRINTK
134static int ten_thousand = 10000;
135#endif
c4f3b63f 136
9e4a5bda
AR
137/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
139
1da177e4
LT
140/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141static int maxolduid = 65535;
142static int minolduid;
8ad4b1fb 143static int min_percpu_pagelist_fract = 8;
1da177e4
LT
144
145static int ngroups_max = NGROUPS_MAX;
73efc039 146static const int cap_last_cap = CAP_LAST_CAP;
1da177e4 147
d14f1729
DY
148#ifdef CONFIG_INOTIFY_USER
149#include <linux/inotify.h>
150#endif
72c57ed5 151#ifdef CONFIG_SPARC
1da177e4
LT
152#endif
153
0871420f
DM
154#ifdef CONFIG_SPARC64
155extern int sysctl_tsb_ratio;
156#endif
157
1da177e4
LT
158#ifdef __hppa__
159extern int pwrsw_enabled;
160extern int unaligned_enabled;
161#endif
1da177e4 162
d2b176ed
JS
163#ifdef CONFIG_IA64
164extern int no_unaligned_warning;
88fc241f 165extern int unaligned_dump_stack;
d2b176ed
JS
166#endif
167
d6f8ff73 168#ifdef CONFIG_PROC_SYSCTL
8d65af78 169static int proc_do_cad_pid(struct ctl_table *table, int write,
9ec52099 170 void __user *buffer, size_t *lenp, loff_t *ppos);
8d65af78 171static int proc_taint(struct ctl_table *table, int write,
34f5a398 172 void __user *buffer, size_t *lenp, loff_t *ppos);
d6f8ff73 173#endif
9ec52099 174
bfdc0b49 175#ifdef CONFIG_PRINTK
620f6e8e 176static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
bfdc0b49
RW
177 void __user *buffer, size_t *lenp, loff_t *ppos);
178#endif
179
54b50199
KC
180static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
046d662f 182#ifdef CONFIG_COREDUMP
54b50199
KC
183static int proc_dostring_coredump(struct ctl_table *table, int write,
184 void __user *buffer, size_t *lenp, loff_t *ppos);
046d662f 185#endif
54b50199 186
97f5f0cd 187#ifdef CONFIG_MAGIC_SYSRQ
8c6a98b2
AW
188/* Note: sysrq code uses it's own private copy */
189static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
97f5f0cd
DT
190
191static int sysrq_sysctl_handler(ctl_table *table, int write,
192 void __user *buffer, size_t *lenp,
193 loff_t *ppos)
194{
195 int error;
196
197 error = proc_dointvec(table, write, buffer, lenp, ppos);
198 if (error)
199 return error;
200
201 if (write)
202 sysrq_toggle_support(__sysrq_enabled);
203
204 return 0;
205}
206
207#endif
208
d8217f07
EB
209static struct ctl_table kern_table[];
210static struct ctl_table vm_table[];
211static struct ctl_table fs_table[];
212static struct ctl_table debug_table[];
213static struct ctl_table dev_table[];
214extern struct ctl_table random_table[];
7ef9964e
DL
215#ifdef CONFIG_EPOLL
216extern struct ctl_table epoll_table[];
217#endif
1da177e4
LT
218
219#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220int sysctl_legacy_va_layout;
221#endif
222
1da177e4
LT
223/* The default sysctl tables: */
224
de4e83bd 225static struct ctl_table sysctl_base_table[] = {
1da177e4 226 {
1da177e4
LT
227 .procname = "kernel",
228 .mode = 0555,
229 .child = kern_table,
230 },
231 {
1da177e4
LT
232 .procname = "vm",
233 .mode = 0555,
234 .child = vm_table,
235 },
1da177e4 236 {
1da177e4
LT
237 .procname = "fs",
238 .mode = 0555,
239 .child = fs_table,
240 },
241 {
1da177e4
LT
242 .procname = "debug",
243 .mode = 0555,
244 .child = debug_table,
245 },
246 {
1da177e4
LT
247 .procname = "dev",
248 .mode = 0555,
249 .child = dev_table,
250 },
6fce56ec 251 { }
1da177e4
LT
252};
253
77e54a1f 254#ifdef CONFIG_SCHED_DEBUG
73c4efd2
ED
255static int min_sched_granularity_ns = 100000; /* 100 usecs */
256static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257static int min_wakeup_granularity_ns; /* 0 usecs */
258static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
cbee9f88 259#ifdef CONFIG_SMP
1983a922
CE
260static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
cbee9f88
PZ
262#endif /* CONFIG_SMP */
263#endif /* CONFIG_SCHED_DEBUG */
77e54a1f 264
5e771905
MG
265#ifdef CONFIG_COMPACTION
266static int min_extfrag_threshold;
267static int max_extfrag_threshold = 1000;
268#endif
269
d8217f07 270static struct ctl_table kern_table[] = {
2bba22c5 271 {
2bba22c5
MG
272 .procname = "sched_child_runs_first",
273 .data = &sysctl_sched_child_runs_first,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
6d456111 276 .proc_handler = proc_dointvec,
2bba22c5 277 },
77e54a1f
IM
278#ifdef CONFIG_SCHED_DEBUG
279 {
b2be5e96
PZ
280 .procname = "sched_min_granularity_ns",
281 .data = &sysctl_sched_min_granularity,
77e54a1f
IM
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
702a7c76 284 .proc_handler = sched_proc_update_handler,
b2be5e96
PZ
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
77e54a1f 287 },
21805085 288 {
21805085
PZ
289 .procname = "sched_latency_ns",
290 .data = &sysctl_sched_latency,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
702a7c76 293 .proc_handler = sched_proc_update_handler,
21805085
PZ
294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
296 },
77e54a1f 297 {
77e54a1f
IM
298 .procname = "sched_wakeup_granularity_ns",
299 .data = &sysctl_sched_wakeup_granularity,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
702a7c76 302 .proc_handler = sched_proc_update_handler,
77e54a1f
IM
303 .extra1 = &min_wakeup_granularity_ns,
304 .extra2 = &max_wakeup_granularity_ns,
305 },
cbee9f88 306#ifdef CONFIG_SMP
1983a922 307 {
1983a922
CE
308 .procname = "sched_tunable_scaling",
309 .data = &sysctl_sched_tunable_scaling,
310 .maxlen = sizeof(enum sched_tunable_scaling),
311 .mode = 0644,
702a7c76 312 .proc_handler = sched_proc_update_handler,
1983a922
CE
313 .extra1 = &min_sched_tunable_scaling,
314 .extra2 = &max_sched_tunable_scaling,
2398f2c6 315 },
da84d961 316 {
d00535db 317 .procname = "sched_migration_cost_ns",
da84d961
IM
318 .data = &sysctl_sched_migration_cost,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
6d456111 321 .proc_handler = proc_dointvec,
da84d961 322 },
b82d9fdd 323 {
b82d9fdd
PZ
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
fa85ae24 327 .mode = 0644,
6d456111 328 .proc_handler = proc_dointvec,
fa85ae24 329 },
e9e9250b 330 {
d00535db 331 .procname = "sched_time_avg_ms",
e9e9250b
PZ
332 .data = &sysctl_sched_time_avg,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
6d456111 335 .proc_handler = proc_dointvec,
e9e9250b 336 },
a7a4f8a7 337 {
d00535db 338 .procname = "sched_shares_window_ns",
a7a4f8a7
PT
339 .data = &sysctl_sched_shares_window,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = proc_dointvec,
343 },
cd1bb94b 344 {
cd1bb94b
AB
345 .procname = "timer_migration",
346 .data = &sysctl_timer_migration,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
6d456111 349 .proc_handler = proc_dointvec_minmax,
bfdb4d9f
AB
350 .extra1 = &zero,
351 .extra2 = &one,
fa85ae24 352 },
cbee9f88
PZ
353#endif /* CONFIG_SMP */
354#ifdef CONFIG_NUMA_BALANCING
4b96a29b
PZ
355 {
356 .procname = "numa_balancing_scan_delay_ms",
357 .data = &sysctl_numa_balancing_scan_delay,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
360 .proc_handler = proc_dointvec,
361 },
cbee9f88
PZ
362 {
363 .procname = "numa_balancing_scan_period_min_ms",
364 .data = &sysctl_numa_balancing_scan_period_min,
365 .maxlen = sizeof(unsigned int),
366 .mode = 0644,
367 .proc_handler = proc_dointvec,
368 },
b8593bfd
MG
369 {
370 .procname = "numa_balancing_scan_period_reset",
371 .data = &sysctl_numa_balancing_scan_period_reset,
372 .maxlen = sizeof(unsigned int),
373 .mode = 0644,
374 .proc_handler = proc_dointvec,
375 },
cbee9f88
PZ
376 {
377 .procname = "numa_balancing_scan_period_max_ms",
378 .data = &sysctl_numa_balancing_scan_period_max,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
381 .proc_handler = proc_dointvec,
382 },
6e5fb223
PZ
383 {
384 .procname = "numa_balancing_scan_size_mb",
385 .data = &sysctl_numa_balancing_scan_size,
386 .maxlen = sizeof(unsigned int),
387 .mode = 0644,
388 .proc_handler = proc_dointvec,
389 },
cbee9f88
PZ
390#endif /* CONFIG_NUMA_BALANCING */
391#endif /* CONFIG_SCHED_DEBUG */
9f0c1e56 392 {
9f0c1e56
PZ
393 .procname = "sched_rt_period_us",
394 .data = &sysctl_sched_rt_period,
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
6d456111 397 .proc_handler = sched_rt_handler,
9f0c1e56
PZ
398 },
399 {
9f0c1e56
PZ
400 .procname = "sched_rt_runtime_us",
401 .data = &sysctl_sched_rt_runtime,
402 .maxlen = sizeof(int),
403 .mode = 0644,
6d456111 404 .proc_handler = sched_rt_handler,
9f0c1e56 405 },
5091faa4
MG
406#ifdef CONFIG_SCHED_AUTOGROUP
407 {
408 .procname = "sched_autogroup_enabled",
409 .data = &sysctl_sched_autogroup_enabled,
410 .maxlen = sizeof(unsigned int),
411 .mode = 0644,
1747b21f 412 .proc_handler = proc_dointvec_minmax,
5091faa4
MG
413 .extra1 = &zero,
414 .extra2 = &one,
415 },
416#endif
ec12cb7f
PT
417#ifdef CONFIG_CFS_BANDWIDTH
418 {
419 .procname = "sched_cfs_bandwidth_slice_us",
420 .data = &sysctl_sched_cfs_bandwidth_slice,
421 .maxlen = sizeof(unsigned int),
422 .mode = 0644,
423 .proc_handler = proc_dointvec_minmax,
424 .extra1 = &one,
425 },
426#endif
f20786ff
PZ
427#ifdef CONFIG_PROVE_LOCKING
428 {
f20786ff
PZ
429 .procname = "prove_locking",
430 .data = &prove_locking,
431 .maxlen = sizeof(int),
432 .mode = 0644,
6d456111 433 .proc_handler = proc_dointvec,
f20786ff
PZ
434 },
435#endif
436#ifdef CONFIG_LOCK_STAT
437 {
f20786ff
PZ
438 .procname = "lock_stat",
439 .data = &lock_stat,
440 .maxlen = sizeof(int),
441 .mode = 0644,
6d456111 442 .proc_handler = proc_dointvec,
f20786ff 443 },
77e54a1f 444#endif
1da177e4 445 {
1da177e4
LT
446 .procname = "panic",
447 .data = &panic_timeout,
448 .maxlen = sizeof(int),
449 .mode = 0644,
6d456111 450 .proc_handler = proc_dointvec,
1da177e4 451 },
046d662f 452#ifdef CONFIG_COREDUMP
1da177e4 453 {
1da177e4
LT
454 .procname = "core_uses_pid",
455 .data = &core_uses_pid,
456 .maxlen = sizeof(int),
457 .mode = 0644,
6d456111 458 .proc_handler = proc_dointvec,
1da177e4
LT
459 },
460 {
1da177e4
LT
461 .procname = "core_pattern",
462 .data = core_pattern,
71ce92f3 463 .maxlen = CORENAME_MAX_SIZE,
1da177e4 464 .mode = 0644,
54b50199 465 .proc_handler = proc_dostring_coredump,
1da177e4 466 },
a293980c 467 {
a293980c
NH
468 .procname = "core_pipe_limit",
469 .data = &core_pipe_limit,
470 .maxlen = sizeof(unsigned int),
471 .mode = 0644,
6d456111 472 .proc_handler = proc_dointvec,
a293980c 473 },
046d662f 474#endif
34f5a398 475#ifdef CONFIG_PROC_SYSCTL
1da177e4 476 {
1da177e4 477 .procname = "tainted",
25ddbb18 478 .maxlen = sizeof(long),
34f5a398 479 .mode = 0644,
6d456111 480 .proc_handler = proc_taint,
1da177e4 481 },
34f5a398 482#endif
9745512c
AV
483#ifdef CONFIG_LATENCYTOP
484 {
485 .procname = "latencytop",
486 .data = &latencytop_enabled,
487 .maxlen = sizeof(int),
488 .mode = 0644,
6d456111 489 .proc_handler = proc_dointvec,
9745512c
AV
490 },
491#endif
1da177e4
LT
492#ifdef CONFIG_BLK_DEV_INITRD
493 {
1da177e4
LT
494 .procname = "real-root-dev",
495 .data = &real_root_dev,
496 .maxlen = sizeof(int),
497 .mode = 0644,
6d456111 498 .proc_handler = proc_dointvec,
1da177e4
LT
499 },
500#endif
45807a1d 501 {
45807a1d
IM
502 .procname = "print-fatal-signals",
503 .data = &print_fatal_signals,
504 .maxlen = sizeof(int),
505 .mode = 0644,
6d456111 506 .proc_handler = proc_dointvec,
45807a1d 507 },
72c57ed5 508#ifdef CONFIG_SPARC
1da177e4 509 {
1da177e4
LT
510 .procname = "reboot-cmd",
511 .data = reboot_command,
512 .maxlen = 256,
513 .mode = 0644,
6d456111 514 .proc_handler = proc_dostring,
1da177e4
LT
515 },
516 {
1da177e4
LT
517 .procname = "stop-a",
518 .data = &stop_a_enabled,
519 .maxlen = sizeof (int),
520 .mode = 0644,
6d456111 521 .proc_handler = proc_dointvec,
1da177e4
LT
522 },
523 {
1da177e4
LT
524 .procname = "scons-poweroff",
525 .data = &scons_pwroff,
526 .maxlen = sizeof (int),
527 .mode = 0644,
6d456111 528 .proc_handler = proc_dointvec,
1da177e4
LT
529 },
530#endif
0871420f
DM
531#ifdef CONFIG_SPARC64
532 {
0871420f
DM
533 .procname = "tsb-ratio",
534 .data = &sysctl_tsb_ratio,
535 .maxlen = sizeof (int),
536 .mode = 0644,
6d456111 537 .proc_handler = proc_dointvec,
0871420f
DM
538 },
539#endif
1da177e4
LT
540#ifdef __hppa__
541 {
1da177e4
LT
542 .procname = "soft-power",
543 .data = &pwrsw_enabled,
544 .maxlen = sizeof (int),
545 .mode = 0644,
6d456111 546 .proc_handler = proc_dointvec,
1da177e4
LT
547 },
548 {
1da177e4
LT
549 .procname = "unaligned-trap",
550 .data = &unaligned_enabled,
551 .maxlen = sizeof (int),
552 .mode = 0644,
6d456111 553 .proc_handler = proc_dointvec,
1da177e4
LT
554 },
555#endif
556 {
1da177e4
LT
557 .procname = "ctrl-alt-del",
558 .data = &C_A_D,
559 .maxlen = sizeof(int),
560 .mode = 0644,
6d456111 561 .proc_handler = proc_dointvec,
1da177e4 562 },
606576ce 563#ifdef CONFIG_FUNCTION_TRACER
b0fc494f 564 {
b0fc494f
SR
565 .procname = "ftrace_enabled",
566 .data = &ftrace_enabled,
567 .maxlen = sizeof(int),
568 .mode = 0644,
6d456111 569 .proc_handler = ftrace_enable_sysctl,
b0fc494f
SR
570 },
571#endif
f38f1d2a
SR
572#ifdef CONFIG_STACK_TRACER
573 {
f38f1d2a
SR
574 .procname = "stack_tracer_enabled",
575 .data = &stack_tracer_enabled,
576 .maxlen = sizeof(int),
577 .mode = 0644,
6d456111 578 .proc_handler = stack_trace_sysctl,
f38f1d2a
SR
579 },
580#endif
944ac425
SR
581#ifdef CONFIG_TRACING
582 {
3299b4dd 583 .procname = "ftrace_dump_on_oops",
944ac425
SR
584 .data = &ftrace_dump_on_oops,
585 .maxlen = sizeof(int),
586 .mode = 0644,
6d456111 587 .proc_handler = proc_dointvec,
944ac425
SR
588 },
589#endif
a1ef5adb 590#ifdef CONFIG_MODULES
1da177e4 591 {
1da177e4
LT
592 .procname = "modprobe",
593 .data = &modprobe_path,
594 .maxlen = KMOD_PATH_LEN,
595 .mode = 0644,
6d456111 596 .proc_handler = proc_dostring,
1da177e4 597 },
3d43321b 598 {
3d43321b
KC
599 .procname = "modules_disabled",
600 .data = &modules_disabled,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 /* only handle a transition from default "0" to "1" */
6d456111 604 .proc_handler = proc_dointvec_minmax,
3d43321b
KC
605 .extra1 = &one,
606 .extra2 = &one,
607 },
1da177e4 608#endif
3b572b50 609
1da177e4 610 {
1da177e4 611 .procname = "hotplug",
312c004d
KS
612 .data = &uevent_helper,
613 .maxlen = UEVENT_HELPER_PATH_LEN,
1da177e4 614 .mode = 0644,
6d456111 615 .proc_handler = proc_dostring,
1da177e4 616 },
3b572b50 617
1da177e4
LT
618#ifdef CONFIG_CHR_DEV_SG
619 {
1da177e4
LT
620 .procname = "sg-big-buff",
621 .data = &sg_big_buff,
622 .maxlen = sizeof (int),
623 .mode = 0444,
6d456111 624 .proc_handler = proc_dointvec,
1da177e4
LT
625 },
626#endif
627#ifdef CONFIG_BSD_PROCESS_ACCT
628 {
1da177e4
LT
629 .procname = "acct",
630 .data = &acct_parm,
631 .maxlen = 3*sizeof(int),
632 .mode = 0644,
6d456111 633 .proc_handler = proc_dointvec,
1da177e4
LT
634 },
635#endif
1da177e4
LT
636#ifdef CONFIG_MAGIC_SYSRQ
637 {
1da177e4 638 .procname = "sysrq",
5d6f647f 639 .data = &__sysrq_enabled,
1da177e4
LT
640 .maxlen = sizeof (int),
641 .mode = 0644,
97f5f0cd 642 .proc_handler = sysrq_sysctl_handler,
1da177e4
LT
643 },
644#endif
d6f8ff73 645#ifdef CONFIG_PROC_SYSCTL
1da177e4 646 {
1da177e4 647 .procname = "cad_pid",
9ec52099 648 .data = NULL,
1da177e4
LT
649 .maxlen = sizeof (int),
650 .mode = 0600,
6d456111 651 .proc_handler = proc_do_cad_pid,
1da177e4 652 },
d6f8ff73 653#endif
1da177e4 654 {
1da177e4
LT
655 .procname = "threads-max",
656 .data = &max_threads,
657 .maxlen = sizeof(int),
658 .mode = 0644,
6d456111 659 .proc_handler = proc_dointvec,
1da177e4
LT
660 },
661 {
1da177e4
LT
662 .procname = "random",
663 .mode = 0555,
664 .child = random_table,
665 },
17f60a7d
EP
666 {
667 .procname = "usermodehelper",
668 .mode = 0555,
669 .child = usermodehelper_table,
670 },
1da177e4 671 {
1da177e4
LT
672 .procname = "overflowuid",
673 .data = &overflowuid,
674 .maxlen = sizeof(int),
675 .mode = 0644,
6d456111 676 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
677 .extra1 = &minolduid,
678 .extra2 = &maxolduid,
679 },
680 {
1da177e4
LT
681 .procname = "overflowgid",
682 .data = &overflowgid,
683 .maxlen = sizeof(int),
684 .mode = 0644,
6d456111 685 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
686 .extra1 = &minolduid,
687 .extra2 = &maxolduid,
688 },
347a8dc3 689#ifdef CONFIG_S390
1da177e4
LT
690#ifdef CONFIG_MATHEMU
691 {
1da177e4
LT
692 .procname = "ieee_emulation_warnings",
693 .data = &sysctl_ieee_emulation_warnings,
694 .maxlen = sizeof(int),
695 .mode = 0644,
6d456111 696 .proc_handler = proc_dointvec,
1da177e4 697 },
1da177e4
LT
698#endif
699 {
1da177e4 700 .procname = "userprocess_debug",
ab3c68ee 701 .data = &show_unhandled_signals,
1da177e4
LT
702 .maxlen = sizeof(int),
703 .mode = 0644,
6d456111 704 .proc_handler = proc_dointvec,
1da177e4
LT
705 },
706#endif
707 {
1da177e4
LT
708 .procname = "pid_max",
709 .data = &pid_max,
710 .maxlen = sizeof (int),
711 .mode = 0644,
6d456111 712 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
713 .extra1 = &pid_max_min,
714 .extra2 = &pid_max_max,
715 },
716 {
1da177e4
LT
717 .procname = "panic_on_oops",
718 .data = &panic_on_oops,
719 .maxlen = sizeof(int),
720 .mode = 0644,
6d456111 721 .proc_handler = proc_dointvec,
1da177e4 722 },
7ef3d2fd
JP
723#if defined CONFIG_PRINTK
724 {
7ef3d2fd
JP
725 .procname = "printk",
726 .data = &console_loglevel,
727 .maxlen = 4*sizeof(int),
728 .mode = 0644,
6d456111 729 .proc_handler = proc_dointvec,
7ef3d2fd 730 },
1da177e4 731 {
1da177e4 732 .procname = "printk_ratelimit",
717115e1 733 .data = &printk_ratelimit_state.interval,
1da177e4
LT
734 .maxlen = sizeof(int),
735 .mode = 0644,
6d456111 736 .proc_handler = proc_dointvec_jiffies,
1da177e4
LT
737 },
738 {
1da177e4 739 .procname = "printk_ratelimit_burst",
717115e1 740 .data = &printk_ratelimit_state.burst,
1da177e4
LT
741 .maxlen = sizeof(int),
742 .mode = 0644,
6d456111 743 .proc_handler = proc_dointvec,
1da177e4 744 },
af91322e 745 {
af91322e
DY
746 .procname = "printk_delay",
747 .data = &printk_delay_msec,
748 .maxlen = sizeof(int),
749 .mode = 0644,
6d456111 750 .proc_handler = proc_dointvec_minmax,
af91322e
DY
751 .extra1 = &zero,
752 .extra2 = &ten_thousand,
753 },
eaf06b24
DR
754 {
755 .procname = "dmesg_restrict",
756 .data = &dmesg_restrict,
757 .maxlen = sizeof(int),
758 .mode = 0644,
620f6e8e 759 .proc_handler = proc_dointvec_minmax_sysadmin,
eaf06b24
DR
760 .extra1 = &zero,
761 .extra2 = &one,
762 },
455cd5ab
DR
763 {
764 .procname = "kptr_restrict",
765 .data = &kptr_restrict,
766 .maxlen = sizeof(int),
767 .mode = 0644,
620f6e8e 768 .proc_handler = proc_dointvec_minmax_sysadmin,
455cd5ab
DR
769 .extra1 = &zero,
770 .extra2 = &two,
771 },
df6e61d4 772#endif
1da177e4 773 {
1da177e4
LT
774 .procname = "ngroups_max",
775 .data = &ngroups_max,
776 .maxlen = sizeof (int),
777 .mode = 0444,
6d456111 778 .proc_handler = proc_dointvec,
1da177e4 779 },
73efc039
DB
780 {
781 .procname = "cap_last_cap",
782 .data = (void *)&cap_last_cap,
783 .maxlen = sizeof(int),
784 .mode = 0444,
785 .proc_handler = proc_dointvec,
786 },
58687acb 787#if defined(CONFIG_LOCKUP_DETECTOR)
504d7cf1 788 {
58687acb
DZ
789 .procname = "watchdog",
790 .data = &watchdog_enabled,
504d7cf1
DZ
791 .maxlen = sizeof (int),
792 .mode = 0644,
586692a5
MSB
793 .proc_handler = proc_dowatchdog,
794 .extra1 = &zero,
795 .extra2 = &one,
58687acb
DZ
796 },
797 {
798 .procname = "watchdog_thresh",
586692a5 799 .data = &watchdog_thresh,
58687acb
DZ
800 .maxlen = sizeof(int),
801 .mode = 0644,
586692a5 802 .proc_handler = proc_dowatchdog,
58687acb
DZ
803 .extra1 = &neg_one,
804 .extra2 = &sixty,
504d7cf1 805 },
2508ce18
DZ
806 {
807 .procname = "softlockup_panic",
808 .data = &softlockup_panic,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = proc_dointvec_minmax,
812 .extra1 = &zero,
813 .extra2 = &one,
814 },
5dc30558
DZ
815 {
816 .procname = "nmi_watchdog",
817 .data = &watchdog_enabled,
818 .maxlen = sizeof (int),
819 .mode = 0644,
586692a5
MSB
820 .proc_handler = proc_dowatchdog,
821 .extra1 = &zero,
822 .extra2 = &one,
5dc30558
DZ
823 },
824#endif
825#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
826 {
827 .procname = "unknown_nmi_panic",
828 .data = &unknown_nmi_panic,
829 .maxlen = sizeof (int),
830 .mode = 0644,
831 .proc_handler = proc_dointvec,
832 },
504d7cf1 833#endif
1da177e4 834#if defined(CONFIG_X86)
8da5adda 835 {
8da5adda
DZ
836 .procname = "panic_on_unrecovered_nmi",
837 .data = &panic_on_unrecovered_nmi,
838 .maxlen = sizeof(int),
839 .mode = 0644,
6d456111 840 .proc_handler = proc_dointvec,
8da5adda 841 },
5211a242 842 {
5211a242
KG
843 .procname = "panic_on_io_nmi",
844 .data = &panic_on_io_nmi,
845 .maxlen = sizeof(int),
846 .mode = 0644,
6d456111 847 .proc_handler = proc_dointvec,
5211a242 848 },
55af7796
MH
849#ifdef CONFIG_DEBUG_STACKOVERFLOW
850 {
851 .procname = "panic_on_stackoverflow",
852 .data = &sysctl_panic_on_stackoverflow,
853 .maxlen = sizeof(int),
854 .mode = 0644,
855 .proc_handler = proc_dointvec,
856 },
857#endif
1da177e4 858 {
1da177e4
LT
859 .procname = "bootloader_type",
860 .data = &bootloader_type,
861 .maxlen = sizeof (int),
862 .mode = 0444,
6d456111 863 .proc_handler = proc_dointvec,
1da177e4 864 },
5031296c 865 {
5031296c
PA
866 .procname = "bootloader_version",
867 .data = &bootloader_version,
868 .maxlen = sizeof (int),
869 .mode = 0444,
6d456111 870 .proc_handler = proc_dointvec,
5031296c 871 },
0741f4d2 872 {
0741f4d2
CE
873 .procname = "kstack_depth_to_print",
874 .data = &kstack_depth_to_print,
875 .maxlen = sizeof(int),
876 .mode = 0644,
6d456111 877 .proc_handler = proc_dointvec,
0741f4d2 878 },
6e7c4025 879 {
6e7c4025
IM
880 .procname = "io_delay_type",
881 .data = &io_delay_type,
882 .maxlen = sizeof(int),
883 .mode = 0644,
6d456111 884 .proc_handler = proc_dointvec,
6e7c4025 885 },
1da177e4 886#endif
7a9166e3 887#if defined(CONFIG_MMU)
1da177e4 888 {
1da177e4
LT
889 .procname = "randomize_va_space",
890 .data = &randomize_va_space,
891 .maxlen = sizeof(int),
892 .mode = 0644,
6d456111 893 .proc_handler = proc_dointvec,
1da177e4 894 },
7a9166e3 895#endif
0152fb37 896#if defined(CONFIG_S390) && defined(CONFIG_SMP)
951f22d5 897 {
951f22d5
MS
898 .procname = "spin_retry",
899 .data = &spin_retry,
900 .maxlen = sizeof (int),
901 .mode = 0644,
6d456111 902 .proc_handler = proc_dointvec,
951f22d5 903 },
c255d844 904#endif
673d5b43 905#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
c255d844 906 {
c255d844 907 .procname = "acpi_video_flags",
77afcf78 908 .data = &acpi_realmode_flags,
c255d844
PM
909 .maxlen = sizeof (unsigned long),
910 .mode = 0644,
6d456111 911 .proc_handler = proc_doulongvec_minmax,
c255d844 912 },
d2b176ed
JS
913#endif
914#ifdef CONFIG_IA64
915 {
d2b176ed
JS
916 .procname = "ignore-unaligned-usertrap",
917 .data = &no_unaligned_warning,
918 .maxlen = sizeof (int),
919 .mode = 0644,
6d456111 920 .proc_handler = proc_dointvec,
d2b176ed 921 },
88fc241f 922 {
88fc241f
DC
923 .procname = "unaligned-dump-stack",
924 .data = &unaligned_dump_stack,
925 .maxlen = sizeof (int),
926 .mode = 0644,
6d456111 927 .proc_handler = proc_dointvec,
88fc241f 928 },
bebfa101 929#endif
e162b39a
MSB
930#ifdef CONFIG_DETECT_HUNG_TASK
931 {
e162b39a
MSB
932 .procname = "hung_task_panic",
933 .data = &sysctl_hung_task_panic,
934 .maxlen = sizeof(int),
935 .mode = 0644,
6d456111 936 .proc_handler = proc_dointvec_minmax,
e162b39a
MSB
937 .extra1 = &zero,
938 .extra2 = &one,
939 },
82a1fcb9 940 {
82a1fcb9
IM
941 .procname = "hung_task_check_count",
942 .data = &sysctl_hung_task_check_count,
90739081 943 .maxlen = sizeof(unsigned long),
82a1fcb9 944 .mode = 0644,
6d456111 945 .proc_handler = proc_doulongvec_minmax,
82a1fcb9
IM
946 },
947 {
82a1fcb9
IM
948 .procname = "hung_task_timeout_secs",
949 .data = &sysctl_hung_task_timeout_secs,
90739081 950 .maxlen = sizeof(unsigned long),
82a1fcb9 951 .mode = 0644,
6d456111 952 .proc_handler = proc_dohung_task_timeout_secs,
82a1fcb9
IM
953 },
954 {
82a1fcb9
IM
955 .procname = "hung_task_warnings",
956 .data = &sysctl_hung_task_warnings,
90739081 957 .maxlen = sizeof(unsigned long),
82a1fcb9 958 .mode = 0644,
6d456111 959 .proc_handler = proc_doulongvec_minmax,
82a1fcb9 960 },
c4f3b63f 961#endif
bebfa101
AK
962#ifdef CONFIG_COMPAT
963 {
bebfa101
AK
964 .procname = "compat-log",
965 .data = &compat_log,
966 .maxlen = sizeof (int),
967 .mode = 0644,
6d456111 968 .proc_handler = proc_dointvec,
bebfa101 969 },
951f22d5 970#endif
23f78d4a
IM
971#ifdef CONFIG_RT_MUTEXES
972 {
23f78d4a
IM
973 .procname = "max_lock_depth",
974 .data = &max_lock_depth,
975 .maxlen = sizeof(int),
976 .mode = 0644,
6d456111 977 .proc_handler = proc_dointvec,
23f78d4a 978 },
5096add8 979#endif
10a0a8d4 980 {
10a0a8d4
JF
981 .procname = "poweroff_cmd",
982 .data = &poweroff_cmd,
983 .maxlen = POWEROFF_CMD_PATH_LEN,
984 .mode = 0644,
6d456111 985 .proc_handler = proc_dostring,
10a0a8d4 986 },
0b77f5bf
DH
987#ifdef CONFIG_KEYS
988 {
0b77f5bf
DH
989 .procname = "keys",
990 .mode = 0555,
991 .child = key_sysctls,
992 },
993#endif
31a72bce
PM
994#ifdef CONFIG_RCU_TORTURE_TEST
995 {
31a72bce
PM
996 .procname = "rcutorture_runnable",
997 .data = &rcutorture_runnable,
998 .maxlen = sizeof(int),
999 .mode = 0644,
6d456111 1000 .proc_handler = proc_dointvec,
31a72bce
PM
1001 },
1002#endif
cdd6c482 1003#ifdef CONFIG_PERF_EVENTS
aa4a2218
VW
1004 /*
1005 * User-space scripts rely on the existence of this file
1006 * as a feature check for perf_events being enabled.
1007 *
1008 * So it's an ABI, do not remove!
1009 */
1ccd1549 1010 {
cdd6c482
IM
1011 .procname = "perf_event_paranoid",
1012 .data = &sysctl_perf_event_paranoid,
1013 .maxlen = sizeof(sysctl_perf_event_paranoid),
1ccd1549 1014 .mode = 0644,
6d456111 1015 .proc_handler = proc_dointvec,
1ccd1549 1016 },
c5078f78 1017 {
cdd6c482
IM
1018 .procname = "perf_event_mlock_kb",
1019 .data = &sysctl_perf_event_mlock,
1020 .maxlen = sizeof(sysctl_perf_event_mlock),
c5078f78 1021 .mode = 0644,
6d456111 1022 .proc_handler = proc_dointvec,
c5078f78 1023 },
a78ac325 1024 {
cdd6c482
IM
1025 .procname = "perf_event_max_sample_rate",
1026 .data = &sysctl_perf_event_sample_rate,
1027 .maxlen = sizeof(sysctl_perf_event_sample_rate),
a78ac325 1028 .mode = 0644,
163ec435 1029 .proc_handler = perf_proc_update_handler,
a78ac325 1030 },
1ccd1549 1031#endif
dfec072e
VN
1032#ifdef CONFIG_KMEMCHECK
1033 {
dfec072e
VN
1034 .procname = "kmemcheck",
1035 .data = &kmemcheck_enabled,
1036 .maxlen = sizeof(int),
1037 .mode = 0644,
6d456111 1038 .proc_handler = proc_dointvec,
dfec072e
VN
1039 },
1040#endif
cb684b5b 1041#ifdef CONFIG_BLOCK
5e605b64 1042 {
5e605b64
JA
1043 .procname = "blk_iopoll",
1044 .data = &blk_iopoll_enabled,
1045 .maxlen = sizeof(int),
1046 .mode = 0644,
6d456111 1047 .proc_handler = proc_dointvec,
5e605b64 1048 },
cb684b5b 1049#endif
6fce56ec 1050 { }
1da177e4
LT
1051};
1052
d8217f07 1053static struct ctl_table vm_table[] = {
1da177e4 1054 {
1da177e4
LT
1055 .procname = "overcommit_memory",
1056 .data = &sysctl_overcommit_memory,
1057 .maxlen = sizeof(sysctl_overcommit_memory),
1058 .mode = 0644,
cb16e95f
PH
1059 .proc_handler = proc_dointvec_minmax,
1060 .extra1 = &zero,
1061 .extra2 = &two,
1da177e4 1062 },
fadd8fbd 1063 {
fadd8fbd
KH
1064 .procname = "panic_on_oom",
1065 .data = &sysctl_panic_on_oom,
1066 .maxlen = sizeof(sysctl_panic_on_oom),
1067 .mode = 0644,
cb16e95f
PH
1068 .proc_handler = proc_dointvec_minmax,
1069 .extra1 = &zero,
1070 .extra2 = &two,
fadd8fbd 1071 },
fe071d7e 1072 {
fe071d7e
DR
1073 .procname = "oom_kill_allocating_task",
1074 .data = &sysctl_oom_kill_allocating_task,
1075 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1076 .mode = 0644,
6d456111 1077 .proc_handler = proc_dointvec,
fe071d7e 1078 },
fef1bdd6 1079 {
fef1bdd6
DR
1080 .procname = "oom_dump_tasks",
1081 .data = &sysctl_oom_dump_tasks,
1082 .maxlen = sizeof(sysctl_oom_dump_tasks),
1083 .mode = 0644,
6d456111 1084 .proc_handler = proc_dointvec,
fef1bdd6 1085 },
1da177e4 1086 {
1da177e4
LT
1087 .procname = "overcommit_ratio",
1088 .data = &sysctl_overcommit_ratio,
1089 .maxlen = sizeof(sysctl_overcommit_ratio),
1090 .mode = 0644,
6d456111 1091 .proc_handler = proc_dointvec,
1da177e4
LT
1092 },
1093 {
1da177e4
LT
1094 .procname = "page-cluster",
1095 .data = &page_cluster,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
cb16e95f
PH
1098 .proc_handler = proc_dointvec_minmax,
1099 .extra1 = &zero,
1da177e4
LT
1100 },
1101 {
1da177e4
LT
1102 .procname = "dirty_background_ratio",
1103 .data = &dirty_background_ratio,
1104 .maxlen = sizeof(dirty_background_ratio),
1105 .mode = 0644,
6d456111 1106 .proc_handler = dirty_background_ratio_handler,
1da177e4
LT
1107 .extra1 = &zero,
1108 .extra2 = &one_hundred,
1109 },
2da02997 1110 {
2da02997
DR
1111 .procname = "dirty_background_bytes",
1112 .data = &dirty_background_bytes,
1113 .maxlen = sizeof(dirty_background_bytes),
1114 .mode = 0644,
6d456111 1115 .proc_handler = dirty_background_bytes_handler,
fc3501d4 1116 .extra1 = &one_ul,
2da02997 1117 },
1da177e4 1118 {
1da177e4
LT
1119 .procname = "dirty_ratio",
1120 .data = &vm_dirty_ratio,
1121 .maxlen = sizeof(vm_dirty_ratio),
1122 .mode = 0644,
6d456111 1123 .proc_handler = dirty_ratio_handler,
1da177e4
LT
1124 .extra1 = &zero,
1125 .extra2 = &one_hundred,
1126 },
2da02997 1127 {
2da02997
DR
1128 .procname = "dirty_bytes",
1129 .data = &vm_dirty_bytes,
1130 .maxlen = sizeof(vm_dirty_bytes),
1131 .mode = 0644,
6d456111 1132 .proc_handler = dirty_bytes_handler,
9e4a5bda 1133 .extra1 = &dirty_bytes_min,
2da02997 1134 },
1da177e4 1135 {
1da177e4 1136 .procname = "dirty_writeback_centisecs",
f6ef9438
BS
1137 .data = &dirty_writeback_interval,
1138 .maxlen = sizeof(dirty_writeback_interval),
1da177e4 1139 .mode = 0644,
6d456111 1140 .proc_handler = dirty_writeback_centisecs_handler,
1da177e4
LT
1141 },
1142 {
1da177e4 1143 .procname = "dirty_expire_centisecs",
f6ef9438
BS
1144 .data = &dirty_expire_interval,
1145 .maxlen = sizeof(dirty_expire_interval),
1da177e4 1146 .mode = 0644,
cb16e95f
PH
1147 .proc_handler = proc_dointvec_minmax,
1148 .extra1 = &zero,
1da177e4
LT
1149 },
1150 {
3965c9ae
WL
1151 .procname = "nr_pdflush_threads",
1152 .mode = 0444 /* read-only */,
1153 .proc_handler = pdflush_proc_obsolete,
1da177e4
LT
1154 },
1155 {
1da177e4
LT
1156 .procname = "swappiness",
1157 .data = &vm_swappiness,
1158 .maxlen = sizeof(vm_swappiness),
1159 .mode = 0644,
6d456111 1160 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1161 .extra1 = &zero,
1162 .extra2 = &one_hundred,
1163 },
1164#ifdef CONFIG_HUGETLB_PAGE
06808b08 1165 {
1da177e4 1166 .procname = "nr_hugepages",
e5ff2159 1167 .data = NULL,
1da177e4
LT
1168 .maxlen = sizeof(unsigned long),
1169 .mode = 0644,
6d456111 1170 .proc_handler = hugetlb_sysctl_handler,
1da177e4
LT
1171 .extra1 = (void *)&hugetlb_zero,
1172 .extra2 = (void *)&hugetlb_infinity,
06808b08
LS
1173 },
1174#ifdef CONFIG_NUMA
1175 {
1176 .procname = "nr_hugepages_mempolicy",
1177 .data = NULL,
1178 .maxlen = sizeof(unsigned long),
1179 .mode = 0644,
1180 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1181 .extra1 = (void *)&hugetlb_zero,
1182 .extra2 = (void *)&hugetlb_infinity,
1183 },
1184#endif
1da177e4 1185 {
1da177e4
LT
1186 .procname = "hugetlb_shm_group",
1187 .data = &sysctl_hugetlb_shm_group,
1188 .maxlen = sizeof(gid_t),
1189 .mode = 0644,
6d456111 1190 .proc_handler = proc_dointvec,
1da177e4 1191 },
396faf03 1192 {
396faf03
MG
1193 .procname = "hugepages_treat_as_movable",
1194 .data = &hugepages_treat_as_movable,
1195 .maxlen = sizeof(int),
1196 .mode = 0644,
6d456111 1197 .proc_handler = hugetlb_treat_movable_handler,
396faf03 1198 },
d1c3fb1f 1199 {
d1c3fb1f 1200 .procname = "nr_overcommit_hugepages",
e5ff2159
AK
1201 .data = NULL,
1202 .maxlen = sizeof(unsigned long),
d1c3fb1f 1203 .mode = 0644,
6d456111 1204 .proc_handler = hugetlb_overcommit_handler,
e5ff2159
AK
1205 .extra1 = (void *)&hugetlb_zero,
1206 .extra2 = (void *)&hugetlb_infinity,
d1c3fb1f 1207 },
1da177e4
LT
1208#endif
1209 {
1da177e4
LT
1210 .procname = "lowmem_reserve_ratio",
1211 .data = &sysctl_lowmem_reserve_ratio,
1212 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1213 .mode = 0644,
6d456111 1214 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1da177e4 1215 },
9d0243bc 1216 {
9d0243bc
AM
1217 .procname = "drop_caches",
1218 .data = &sysctl_drop_caches,
1219 .maxlen = sizeof(int),
1220 .mode = 0644,
1221 .proc_handler = drop_caches_sysctl_handler,
cb16e95f
PH
1222 .extra1 = &one,
1223 .extra2 = &three,
9d0243bc 1224 },
76ab0f53
MG
1225#ifdef CONFIG_COMPACTION
1226 {
1227 .procname = "compact_memory",
1228 .data = &sysctl_compact_memory,
1229 .maxlen = sizeof(int),
1230 .mode = 0200,
1231 .proc_handler = sysctl_compaction_handler,
1232 },
5e771905
MG
1233 {
1234 .procname = "extfrag_threshold",
1235 .data = &sysctl_extfrag_threshold,
1236 .maxlen = sizeof(int),
1237 .mode = 0644,
1238 .proc_handler = sysctl_extfrag_handler,
1239 .extra1 = &min_extfrag_threshold,
1240 .extra2 = &max_extfrag_threshold,
1241 },
1242
76ab0f53 1243#endif /* CONFIG_COMPACTION */
1da177e4 1244 {
1da177e4
LT
1245 .procname = "min_free_kbytes",
1246 .data = &min_free_kbytes,
1247 .maxlen = sizeof(min_free_kbytes),
1248 .mode = 0644,
6d456111 1249 .proc_handler = min_free_kbytes_sysctl_handler,
1da177e4
LT
1250 .extra1 = &zero,
1251 },
8ad4b1fb 1252 {
8ad4b1fb
RS
1253 .procname = "percpu_pagelist_fraction",
1254 .data = &percpu_pagelist_fraction,
1255 .maxlen = sizeof(percpu_pagelist_fraction),
1256 .mode = 0644,
6d456111 1257 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
8ad4b1fb
RS
1258 .extra1 = &min_percpu_pagelist_fract,
1259 },
1da177e4
LT
1260#ifdef CONFIG_MMU
1261 {
1da177e4
LT
1262 .procname = "max_map_count",
1263 .data = &sysctl_max_map_count,
1264 .maxlen = sizeof(sysctl_max_map_count),
1265 .mode = 0644,
3e26120c 1266 .proc_handler = proc_dointvec_minmax,
70da2340 1267 .extra1 = &zero,
1da177e4 1268 },
dd8632a1
PM
1269#else
1270 {
dd8632a1
PM
1271 .procname = "nr_trim_pages",
1272 .data = &sysctl_nr_trim_pages,
1273 .maxlen = sizeof(sysctl_nr_trim_pages),
1274 .mode = 0644,
6d456111 1275 .proc_handler = proc_dointvec_minmax,
dd8632a1
PM
1276 .extra1 = &zero,
1277 },
1da177e4
LT
1278#endif
1279 {
1da177e4
LT
1280 .procname = "laptop_mode",
1281 .data = &laptop_mode,
1282 .maxlen = sizeof(laptop_mode),
1283 .mode = 0644,
6d456111 1284 .proc_handler = proc_dointvec_jiffies,
1da177e4
LT
1285 },
1286 {
1da177e4
LT
1287 .procname = "block_dump",
1288 .data = &block_dump,
1289 .maxlen = sizeof(block_dump),
1290 .mode = 0644,
6d456111 1291 .proc_handler = proc_dointvec,
1da177e4
LT
1292 .extra1 = &zero,
1293 },
1294 {
1da177e4
LT
1295 .procname = "vfs_cache_pressure",
1296 .data = &sysctl_vfs_cache_pressure,
1297 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1298 .mode = 0644,
6d456111 1299 .proc_handler = proc_dointvec,
1da177e4
LT
1300 .extra1 = &zero,
1301 },
1302#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1303 {
1da177e4
LT
1304 .procname = "legacy_va_layout",
1305 .data = &sysctl_legacy_va_layout,
1306 .maxlen = sizeof(sysctl_legacy_va_layout),
1307 .mode = 0644,
6d456111 1308 .proc_handler = proc_dointvec,
1da177e4
LT
1309 .extra1 = &zero,
1310 },
1311#endif
1743660b
CL
1312#ifdef CONFIG_NUMA
1313 {
1743660b
CL
1314 .procname = "zone_reclaim_mode",
1315 .data = &zone_reclaim_mode,
1316 .maxlen = sizeof(zone_reclaim_mode),
1317 .mode = 0644,
6d456111 1318 .proc_handler = proc_dointvec,
c84db23c 1319 .extra1 = &zero,
1743660b 1320 },
9614634f 1321 {
9614634f
CL
1322 .procname = "min_unmapped_ratio",
1323 .data = &sysctl_min_unmapped_ratio,
1324 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1325 .mode = 0644,
6d456111 1326 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
9614634f
CL
1327 .extra1 = &zero,
1328 .extra2 = &one_hundred,
1329 },
0ff38490 1330 {
0ff38490
CL
1331 .procname = "min_slab_ratio",
1332 .data = &sysctl_min_slab_ratio,
1333 .maxlen = sizeof(sysctl_min_slab_ratio),
1334 .mode = 0644,
6d456111 1335 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
0ff38490
CL
1336 .extra1 = &zero,
1337 .extra2 = &one_hundred,
1338 },
e6e5494c 1339#endif
77461ab3
CL
1340#ifdef CONFIG_SMP
1341 {
77461ab3
CL
1342 .procname = "stat_interval",
1343 .data = &sysctl_stat_interval,
1344 .maxlen = sizeof(sysctl_stat_interval),
1345 .mode = 0644,
6d456111 1346 .proc_handler = proc_dointvec_jiffies,
77461ab3
CL
1347 },
1348#endif
6e141546 1349#ifdef CONFIG_MMU
ed032189 1350 {
ed032189 1351 .procname = "mmap_min_addr",
788084ab
EP
1352 .data = &dac_mmap_min_addr,
1353 .maxlen = sizeof(unsigned long),
ed032189 1354 .mode = 0644,
6d456111 1355 .proc_handler = mmap_min_addr_handler,
ed032189 1356 },
6e141546 1357#endif
f0c0b2b8
KH
1358#ifdef CONFIG_NUMA
1359 {
f0c0b2b8
KH
1360 .procname = "numa_zonelist_order",
1361 .data = &numa_zonelist_order,
1362 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1363 .mode = 0644,
6d456111 1364 .proc_handler = numa_zonelist_order_handler,
f0c0b2b8
KH
1365 },
1366#endif
2b8232ce 1367#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
5c36e657 1368 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
e6e5494c 1369 {
e6e5494c
IM
1370 .procname = "vdso_enabled",
1371 .data = &vdso_enabled,
1372 .maxlen = sizeof(vdso_enabled),
1373 .mode = 0644,
6d456111 1374 .proc_handler = proc_dointvec,
e6e5494c
IM
1375 .extra1 = &zero,
1376 },
1da177e4 1377#endif
195cf453
BG
1378#ifdef CONFIG_HIGHMEM
1379 {
195cf453
BG
1380 .procname = "highmem_is_dirtyable",
1381 .data = &vm_highmem_is_dirtyable,
1382 .maxlen = sizeof(vm_highmem_is_dirtyable),
1383 .mode = 0644,
6d456111 1384 .proc_handler = proc_dointvec_minmax,
195cf453
BG
1385 .extra1 = &zero,
1386 .extra2 = &one,
1387 },
1388#endif
4be6f6bb 1389 {
4be6f6bb
PZ
1390 .procname = "scan_unevictable_pages",
1391 .data = &scan_unevictable_pages,
1392 .maxlen = sizeof(scan_unevictable_pages),
1393 .mode = 0644,
6d456111 1394 .proc_handler = scan_unevictable_handler,
4be6f6bb 1395 },
6a46079c
AK
1396#ifdef CONFIG_MEMORY_FAILURE
1397 {
6a46079c
AK
1398 .procname = "memory_failure_early_kill",
1399 .data = &sysctl_memory_failure_early_kill,
1400 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1401 .mode = 0644,
6d456111 1402 .proc_handler = proc_dointvec_minmax,
6a46079c
AK
1403 .extra1 = &zero,
1404 .extra2 = &one,
1405 },
1406 {
6a46079c
AK
1407 .procname = "memory_failure_recovery",
1408 .data = &sysctl_memory_failure_recovery,
1409 .maxlen = sizeof(sysctl_memory_failure_recovery),
1410 .mode = 0644,
6d456111 1411 .proc_handler = proc_dointvec_minmax,
6a46079c
AK
1412 .extra1 = &zero,
1413 .extra2 = &one,
1414 },
1415#endif
6fce56ec 1416 { }
1da177e4
LT
1417};
1418
2abc26fc 1419#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
d8217f07 1420static struct ctl_table binfmt_misc_table[] = {
6fce56ec 1421 { }
2abc26fc
EB
1422};
1423#endif
1424
d8217f07 1425static struct ctl_table fs_table[] = {
1da177e4 1426 {
1da177e4
LT
1427 .procname = "inode-nr",
1428 .data = &inodes_stat,
1429 .maxlen = 2*sizeof(int),
1430 .mode = 0444,
cffbc8aa 1431 .proc_handler = proc_nr_inodes,
1da177e4
LT
1432 },
1433 {
1da177e4
LT
1434 .procname = "inode-state",
1435 .data = &inodes_stat,
1436 .maxlen = 7*sizeof(int),
1437 .mode = 0444,
cffbc8aa 1438 .proc_handler = proc_nr_inodes,
1da177e4
LT
1439 },
1440 {
1da177e4
LT
1441 .procname = "file-nr",
1442 .data = &files_stat,
518de9b3 1443 .maxlen = sizeof(files_stat),
1da177e4 1444 .mode = 0444,
6d456111 1445 .proc_handler = proc_nr_files,
1da177e4
LT
1446 },
1447 {
1da177e4
LT
1448 .procname = "file-max",
1449 .data = &files_stat.max_files,
518de9b3 1450 .maxlen = sizeof(files_stat.max_files),
1da177e4 1451 .mode = 0644,
518de9b3 1452 .proc_handler = proc_doulongvec_minmax,
1da177e4 1453 },
9cfe015a 1454 {
9cfe015a
ED
1455 .procname = "nr_open",
1456 .data = &sysctl_nr_open,
1457 .maxlen = sizeof(int),
1458 .mode = 0644,
6d456111 1459 .proc_handler = proc_dointvec_minmax,
eceea0b3
AV
1460 .extra1 = &sysctl_nr_open_min,
1461 .extra2 = &sysctl_nr_open_max,
9cfe015a 1462 },
1da177e4 1463 {
1da177e4
LT
1464 .procname = "dentry-state",
1465 .data = &dentry_stat,
1466 .maxlen = 6*sizeof(int),
1467 .mode = 0444,
312d3ca8 1468 .proc_handler = proc_nr_dentry,
1da177e4
LT
1469 },
1470 {
1da177e4
LT
1471 .procname = "overflowuid",
1472 .data = &fs_overflowuid,
1473 .maxlen = sizeof(int),
1474 .mode = 0644,
6d456111 1475 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1476 .extra1 = &minolduid,
1477 .extra2 = &maxolduid,
1478 },
1479 {
1da177e4
LT
1480 .procname = "overflowgid",
1481 .data = &fs_overflowgid,
1482 .maxlen = sizeof(int),
1483 .mode = 0644,
6d456111 1484 .proc_handler = proc_dointvec_minmax,
1da177e4
LT
1485 .extra1 = &minolduid,
1486 .extra2 = &maxolduid,
1487 },
bfcd17a6 1488#ifdef CONFIG_FILE_LOCKING
1da177e4 1489 {
1da177e4
LT
1490 .procname = "leases-enable",
1491 .data = &leases_enable,
1492 .maxlen = sizeof(int),
1493 .mode = 0644,
6d456111 1494 .proc_handler = proc_dointvec,
1da177e4 1495 },
bfcd17a6 1496#endif
1da177e4
LT
1497#ifdef CONFIG_DNOTIFY
1498 {
1da177e4
LT
1499 .procname = "dir-notify-enable",
1500 .data = &dir_notify_enable,
1501 .maxlen = sizeof(int),
1502 .mode = 0644,
6d456111 1503 .proc_handler = proc_dointvec,
1da177e4
LT
1504 },
1505#endif
1506#ifdef CONFIG_MMU
bfcd17a6 1507#ifdef CONFIG_FILE_LOCKING
1da177e4 1508 {
1da177e4
LT
1509 .procname = "lease-break-time",
1510 .data = &lease_break_time,
1511 .maxlen = sizeof(int),
1512 .mode = 0644,
6d456111 1513 .proc_handler = proc_dointvec,
1da177e4 1514 },
bfcd17a6 1515#endif
ebf3f09c 1516#ifdef CONFIG_AIO
1da177e4 1517 {
1da177e4
LT
1518 .procname = "aio-nr",
1519 .data = &aio_nr,
1520 .maxlen = sizeof(aio_nr),
1521 .mode = 0444,
6d456111 1522 .proc_handler = proc_doulongvec_minmax,
1da177e4
LT
1523 },
1524 {
1da177e4
LT
1525 .procname = "aio-max-nr",
1526 .data = &aio_max_nr,
1527 .maxlen = sizeof(aio_max_nr),
1528 .mode = 0644,
6d456111 1529 .proc_handler = proc_doulongvec_minmax,
1da177e4 1530 },
ebf3f09c 1531#endif /* CONFIG_AIO */
2d9048e2 1532#ifdef CONFIG_INOTIFY_USER
0399cb08 1533 {
0399cb08
RL
1534 .procname = "inotify",
1535 .mode = 0555,
1536 .child = inotify_table,
1537 },
1538#endif
7ef9964e
DL
1539#ifdef CONFIG_EPOLL
1540 {
1541 .procname = "epoll",
1542 .mode = 0555,
1543 .child = epoll_table,
1544 },
1545#endif
1da177e4 1546#endif
800179c9
KC
1547 {
1548 .procname = "protected_symlinks",
1549 .data = &sysctl_protected_symlinks,
1550 .maxlen = sizeof(int),
1551 .mode = 0600,
1552 .proc_handler = proc_dointvec_minmax,
1553 .extra1 = &zero,
1554 .extra2 = &one,
1555 },
1556 {
1557 .procname = "protected_hardlinks",
1558 .data = &sysctl_protected_hardlinks,
1559 .maxlen = sizeof(int),
1560 .mode = 0600,
1561 .proc_handler = proc_dointvec_minmax,
1562 .extra1 = &zero,
1563 .extra2 = &one,
1564 },
d6e71144 1565 {
d6e71144
AC
1566 .procname = "suid_dumpable",
1567 .data = &suid_dumpable,
1568 .maxlen = sizeof(int),
1569 .mode = 0644,
54b50199 1570 .proc_handler = proc_dointvec_minmax_coredump,
8e654fba
MW
1571 .extra1 = &zero,
1572 .extra2 = &two,
d6e71144 1573 },
2abc26fc
EB
1574#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1575 {
2abc26fc
EB
1576 .procname = "binfmt_misc",
1577 .mode = 0555,
1578 .child = binfmt_misc_table,
1579 },
1580#endif
b492e95b 1581 {
ff9da691
JA
1582 .procname = "pipe-max-size",
1583 .data = &pipe_max_size,
b492e95b
JA
1584 .maxlen = sizeof(int),
1585 .mode = 0644,
ff9da691
JA
1586 .proc_handler = &pipe_proc_fn,
1587 .extra1 = &pipe_min_size,
b492e95b 1588 },
6fce56ec 1589 { }
1da177e4
LT
1590};
1591
d8217f07 1592static struct ctl_table debug_table[] = {
7ac57a89 1593#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
abd4f750 1594 {
abd4f750
MAS
1595 .procname = "exception-trace",
1596 .data = &show_unhandled_signals,
1597 .maxlen = sizeof(int),
1598 .mode = 0644,
1599 .proc_handler = proc_dointvec
1600 },
b2be84df
MH
1601#endif
1602#if defined(CONFIG_OPTPROBES)
1603 {
1604 .procname = "kprobes-optimization",
1605 .data = &sysctl_kprobes_optimization,
1606 .maxlen = sizeof(int),
1607 .mode = 0644,
1608 .proc_handler = proc_kprobes_optimization_handler,
1609 .extra1 = &zero,
1610 .extra2 = &one,
1611 },
abd4f750 1612#endif
6fce56ec 1613 { }
1da177e4
LT
1614};
1615
d8217f07 1616static struct ctl_table dev_table[] = {
6fce56ec 1617 { }
0eeca283 1618};
1da177e4 1619
de4e83bd 1620int __init sysctl_init(void)
d912b0cc 1621{
fd4b616b
SR
1622 struct ctl_table_header *hdr;
1623
1624 hdr = register_sysctl_table(sysctl_base_table);
1625 kmemleak_not_leak(hdr);
d912b0cc
EB
1626 return 0;
1627}
1628
b89a8171
EB
1629#endif /* CONFIG_SYSCTL */
1630
1da177e4
LT
1631/*
1632 * /proc/sys support
1633 */
1634
b89a8171 1635#ifdef CONFIG_PROC_SYSCTL
1da177e4 1636
b1ba4ddd 1637static int _proc_do_string(void* data, int maxlen, int write,
8d65af78 1638 void __user *buffer,
b1ba4ddd 1639 size_t *lenp, loff_t *ppos)
1da177e4
LT
1640{
1641 size_t len;
1642 char __user *p;
1643 char c;
8d060877
ON
1644
1645 if (!data || !maxlen || !*lenp) {
1da177e4
LT
1646 *lenp = 0;
1647 return 0;
1648 }
8d060877 1649
1da177e4
LT
1650 if (write) {
1651 len = 0;
1652 p = buffer;
1653 while (len < *lenp) {
1654 if (get_user(c, p++))
1655 return -EFAULT;
1656 if (c == 0 || c == '\n')
1657 break;
1658 len++;
1659 }
f5dd3d6f
SV
1660 if (len >= maxlen)
1661 len = maxlen-1;
1662 if(copy_from_user(data, buffer, len))
1da177e4 1663 return -EFAULT;
f5dd3d6f 1664 ((char *) data)[len] = 0;
1da177e4
LT
1665 *ppos += *lenp;
1666 } else {
f5dd3d6f
SV
1667 len = strlen(data);
1668 if (len > maxlen)
1669 len = maxlen;
8d060877
ON
1670
1671 if (*ppos > len) {
1672 *lenp = 0;
1673 return 0;
1674 }
1675
1676 data += *ppos;
1677 len -= *ppos;
1678
1da177e4
LT
1679 if (len > *lenp)
1680 len = *lenp;
1681 if (len)
f5dd3d6f 1682 if(copy_to_user(buffer, data, len))
1da177e4
LT
1683 return -EFAULT;
1684 if (len < *lenp) {
1685 if(put_user('\n', ((char __user *) buffer) + len))
1686 return -EFAULT;
1687 len++;
1688 }
1689 *lenp = len;
1690 *ppos += len;
1691 }
1692 return 0;
1693}
1694
f5dd3d6f
SV
1695/**
1696 * proc_dostring - read a string sysctl
1697 * @table: the sysctl table
1698 * @write: %TRUE if this is a write to the sysctl file
f5dd3d6f
SV
1699 * @buffer: the user buffer
1700 * @lenp: the size of the user buffer
1701 * @ppos: file position
1702 *
1703 * Reads/writes a string from/to the user buffer. If the kernel
1704 * buffer provided is not large enough to hold the string, the
1705 * string is truncated. The copied string is %NULL-terminated.
1706 * If the string is being read by the user process, it is copied
1707 * and a newline '\n' is added. It is truncated if the buffer is
1708 * not large enough.
1709 *
1710 * Returns 0 on success.
1711 */
8d65af78 1712int proc_dostring(struct ctl_table *table, int write,
f5dd3d6f
SV
1713 void __user *buffer, size_t *lenp, loff_t *ppos)
1714{
8d65af78 1715 return _proc_do_string(table->data, table->maxlen, write,
f5dd3d6f
SV
1716 buffer, lenp, ppos);
1717}
1718
00b7c339
AW
1719static size_t proc_skip_spaces(char **buf)
1720{
1721 size_t ret;
1722 char *tmp = skip_spaces(*buf);
1723 ret = tmp - *buf;
1724 *buf = tmp;
1725 return ret;
1726}
1727
9f977fb7
OP
1728static void proc_skip_char(char **buf, size_t *size, const char v)
1729{
1730 while (*size) {
1731 if (**buf != v)
1732 break;
1733 (*size)--;
1734 (*buf)++;
1735 }
1736}
1737
00b7c339
AW
1738#define TMPBUFLEN 22
1739/**
0fc377bd 1740 * proc_get_long - reads an ASCII formatted integer from a user buffer
00b7c339 1741 *
0fc377bd
RD
1742 * @buf: a kernel buffer
1743 * @size: size of the kernel buffer
1744 * @val: this is where the number will be stored
1745 * @neg: set to %TRUE if number is negative
1746 * @perm_tr: a vector which contains the allowed trailers
1747 * @perm_tr_len: size of the perm_tr vector
1748 * @tr: pointer to store the trailer character
00b7c339 1749 *
0fc377bd
RD
1750 * In case of success %0 is returned and @buf and @size are updated with
1751 * the amount of bytes read. If @tr is non-NULL and a trailing
1752 * character exists (size is non-zero after returning from this
1753 * function), @tr is updated with the trailing character.
00b7c339
AW
1754 */
1755static int proc_get_long(char **buf, size_t *size,
1756 unsigned long *val, bool *neg,
1757 const char *perm_tr, unsigned perm_tr_len, char *tr)
1758{
1759 int len;
1760 char *p, tmp[TMPBUFLEN];
1761
1762 if (!*size)
1763 return -EINVAL;
1764
1765 len = *size;
1766 if (len > TMPBUFLEN - 1)
1767 len = TMPBUFLEN - 1;
1768
1769 memcpy(tmp, *buf, len);
1770
1771 tmp[len] = 0;
1772 p = tmp;
1773 if (*p == '-' && *size > 1) {
1774 *neg = true;
1775 p++;
1776 } else
1777 *neg = false;
1778 if (!isdigit(*p))
1779 return -EINVAL;
1780
1781 *val = simple_strtoul(p, &p, 0);
1782
1783 len = p - tmp;
1784
1785 /* We don't know if the next char is whitespace thus we may accept
1786 * invalid integers (e.g. 1234...a) or two integers instead of one
1787 * (e.g. 123...1). So lets not allow such large numbers. */
1788 if (len == TMPBUFLEN - 1)
1789 return -EINVAL;
1790
1791 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1792 return -EINVAL;
1da177e4 1793
00b7c339
AW
1794 if (tr && (len < *size))
1795 *tr = *p;
1796
1797 *buf += len;
1798 *size -= len;
1799
1800 return 0;
1801}
1802
1803/**
0fc377bd 1804 * proc_put_long - converts an integer to a decimal ASCII formatted string
00b7c339 1805 *
0fc377bd
RD
1806 * @buf: the user buffer
1807 * @size: the size of the user buffer
1808 * @val: the integer to be converted
1809 * @neg: sign of the number, %TRUE for negative
00b7c339 1810 *
0fc377bd
RD
1811 * In case of success %0 is returned and @buf and @size are updated with
1812 * the amount of bytes written.
00b7c339
AW
1813 */
1814static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1815 bool neg)
1816{
1817 int len;
1818 char tmp[TMPBUFLEN], *p = tmp;
1819
1820 sprintf(p, "%s%lu", neg ? "-" : "", val);
1821 len = strlen(tmp);
1822 if (len > *size)
1823 len = *size;
1824 if (copy_to_user(*buf, tmp, len))
1825 return -EFAULT;
1826 *size -= len;
1827 *buf += len;
1828 return 0;
1829}
1830#undef TMPBUFLEN
1831
1832static int proc_put_char(void __user **buf, size_t *size, char c)
1833{
1834 if (*size) {
1835 char __user **buffer = (char __user **)buf;
1836 if (put_user(c, *buffer))
1837 return -EFAULT;
1838 (*size)--, (*buffer)++;
1839 *buf = *buffer;
1840 }
1841 return 0;
1842}
1da177e4 1843
00b7c339 1844static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
1845 int *valp,
1846 int write, void *data)
1847{
1848 if (write) {
1849 *valp = *negp ? -*lvalp : *lvalp;
1850 } else {
1851 int val = *valp;
1852 if (val < 0) {
00b7c339 1853 *negp = true;
1da177e4
LT
1854 *lvalp = (unsigned long)-val;
1855 } else {
00b7c339 1856 *negp = false;
1da177e4
LT
1857 *lvalp = (unsigned long)val;
1858 }
1859 }
1860 return 0;
1861}
1862
00b7c339
AW
1863static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1864
d8217f07 1865static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
8d65af78 1866 int write, void __user *buffer,
fcfbd547 1867 size_t *lenp, loff_t *ppos,
00b7c339 1868 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1da177e4
LT
1869 int write, void *data),
1870 void *data)
1871{
00b7c339
AW
1872 int *i, vleft, first = 1, err = 0;
1873 unsigned long page = 0;
1874 size_t left;
1875 char *kbuf;
1da177e4 1876
00b7c339 1877 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1da177e4
LT
1878 *lenp = 0;
1879 return 0;
1880 }
1881
fcfbd547 1882 i = (int *) tbl_data;
1da177e4
LT
1883 vleft = table->maxlen / sizeof(*i);
1884 left = *lenp;
1885
1886 if (!conv)
1887 conv = do_proc_dointvec_conv;
1888
00b7c339
AW
1889 if (write) {
1890 if (left > PAGE_SIZE - 1)
1891 left = PAGE_SIZE - 1;
1892 page = __get_free_page(GFP_TEMPORARY);
1893 kbuf = (char *) page;
1894 if (!kbuf)
1895 return -ENOMEM;
1896 if (copy_from_user(kbuf, buffer, left)) {
1897 err = -EFAULT;
1898 goto free;
1899 }
1900 kbuf[left] = 0;
1901 }
1902
1da177e4 1903 for (; left && vleft--; i++, first=0) {
00b7c339
AW
1904 unsigned long lval;
1905 bool neg;
1da177e4 1906
00b7c339
AW
1907 if (write) {
1908 left -= proc_skip_spaces(&kbuf);
1da177e4 1909
563b0467
O
1910 if (!left)
1911 break;
00b7c339
AW
1912 err = proc_get_long(&kbuf, &left, &lval, &neg,
1913 proc_wspace_sep,
1914 sizeof(proc_wspace_sep), NULL);
1915 if (err)
1da177e4 1916 break;
00b7c339
AW
1917 if (conv(&neg, &lval, i, 1, data)) {
1918 err = -EINVAL;
1da177e4 1919 break;
00b7c339 1920 }
1da177e4 1921 } else {
00b7c339
AW
1922 if (conv(&neg, &lval, i, 0, data)) {
1923 err = -EINVAL;
1924 break;
1925 }
1da177e4 1926 if (!first)
00b7c339
AW
1927 err = proc_put_char(&buffer, &left, '\t');
1928 if (err)
1929 break;
1930 err = proc_put_long(&buffer, &left, lval, neg);
1931 if (err)
1da177e4 1932 break;
1da177e4
LT
1933 }
1934 }
1935
00b7c339
AW
1936 if (!write && !first && left && !err)
1937 err = proc_put_char(&buffer, &left, '\n');
563b0467 1938 if (write && !err && left)
00b7c339
AW
1939 left -= proc_skip_spaces(&kbuf);
1940free:
1da177e4 1941 if (write) {
00b7c339
AW
1942 free_page(page);
1943 if (first)
1944 return err ? : -EINVAL;
1da177e4 1945 }
1da177e4
LT
1946 *lenp -= left;
1947 *ppos += *lenp;
00b7c339 1948 return err;
1da177e4
LT
1949}
1950
8d65af78 1951static int do_proc_dointvec(struct ctl_table *table, int write,
fcfbd547 1952 void __user *buffer, size_t *lenp, loff_t *ppos,
00b7c339 1953 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
fcfbd547
KK
1954 int write, void *data),
1955 void *data)
1956{
8d65af78 1957 return __do_proc_dointvec(table->data, table, write,
fcfbd547
KK
1958 buffer, lenp, ppos, conv, data);
1959}
1960
1da177e4
LT
1961/**
1962 * proc_dointvec - read a vector of integers
1963 * @table: the sysctl table
1964 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
1965 * @buffer: the user buffer
1966 * @lenp: the size of the user buffer
1967 * @ppos: file position
1968 *
1969 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1970 * values from/to the user buffer, treated as an ASCII string.
1971 *
1972 * Returns 0 on success.
1973 */
8d65af78 1974int proc_dointvec(struct ctl_table *table, int write,
1da177e4
LT
1975 void __user *buffer, size_t *lenp, loff_t *ppos)
1976{
8d65af78 1977 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
1978 NULL,NULL);
1979}
1980
34f5a398 1981/*
25ddbb18
AK
1982 * Taint values can only be increased
1983 * This means we can safely use a temporary.
34f5a398 1984 */
8d65af78 1985static int proc_taint(struct ctl_table *table, int write,
34f5a398
TT
1986 void __user *buffer, size_t *lenp, loff_t *ppos)
1987{
25ddbb18
AK
1988 struct ctl_table t;
1989 unsigned long tmptaint = get_taint();
1990 int err;
34f5a398 1991
91fcd412 1992 if (write && !capable(CAP_SYS_ADMIN))
34f5a398
TT
1993 return -EPERM;
1994
25ddbb18
AK
1995 t = *table;
1996 t.data = &tmptaint;
8d65af78 1997 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
25ddbb18
AK
1998 if (err < 0)
1999 return err;
2000
2001 if (write) {
2002 /*
2003 * Poor man's atomic or. Not worth adding a primitive
2004 * to everyone's atomic.h for this
2005 */
2006 int i;
2007 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2008 if ((tmptaint >> i) & 1)
2009 add_taint(i);
2010 }
2011 }
2012
2013 return err;
34f5a398
TT
2014}
2015
bfdc0b49 2016#ifdef CONFIG_PRINTK
620f6e8e 2017static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
bfdc0b49
RW
2018 void __user *buffer, size_t *lenp, loff_t *ppos)
2019{
2020 if (write && !capable(CAP_SYS_ADMIN))
2021 return -EPERM;
2022
2023 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2024}
2025#endif
2026
1da177e4
LT
2027struct do_proc_dointvec_minmax_conv_param {
2028 int *min;
2029 int *max;
2030};
2031
00b7c339
AW
2032static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2033 int *valp,
1da177e4
LT
2034 int write, void *data)
2035{
2036 struct do_proc_dointvec_minmax_conv_param *param = data;
2037 if (write) {
2038 int val = *negp ? -*lvalp : *lvalp;
2039 if ((param->min && *param->min > val) ||
2040 (param->max && *param->max < val))
2041 return -EINVAL;
2042 *valp = val;
2043 } else {
2044 int val = *valp;
2045 if (val < 0) {
00b7c339 2046 *negp = true;
1da177e4
LT
2047 *lvalp = (unsigned long)-val;
2048 } else {
00b7c339 2049 *negp = false;
1da177e4
LT
2050 *lvalp = (unsigned long)val;
2051 }
2052 }
2053 return 0;
2054}
2055
2056/**
2057 * proc_dointvec_minmax - read a vector of integers with min/max values
2058 * @table: the sysctl table
2059 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2060 * @buffer: the user buffer
2061 * @lenp: the size of the user buffer
2062 * @ppos: file position
2063 *
2064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2065 * values from/to the user buffer, treated as an ASCII string.
2066 *
2067 * This routine will ensure the values are within the range specified by
2068 * table->extra1 (min) and table->extra2 (max).
2069 *
2070 * Returns 0 on success.
2071 */
8d65af78 2072int proc_dointvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2073 void __user *buffer, size_t *lenp, loff_t *ppos)
2074{
2075 struct do_proc_dointvec_minmax_conv_param param = {
2076 .min = (int *) table->extra1,
2077 .max = (int *) table->extra2,
2078 };
8d65af78 2079 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1da177e4
LT
2080 do_proc_dointvec_minmax_conv, &param);
2081}
2082
54b50199
KC
2083static void validate_coredump_safety(void)
2084{
046d662f 2085#ifdef CONFIG_COREDUMP
54b50199
KC
2086 if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2087 core_pattern[0] != '/' && core_pattern[0] != '|') {
2088 printk(KERN_WARNING "Unsafe core_pattern used with "\
2089 "suid_dumpable=2. Pipe handler or fully qualified "\
2090 "core dump path required.\n");
2091 }
046d662f 2092#endif
54b50199
KC
2093}
2094
2095static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2096 void __user *buffer, size_t *lenp, loff_t *ppos)
2097{
2098 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2099 if (!error)
2100 validate_coredump_safety();
2101 return error;
2102}
2103
046d662f 2104#ifdef CONFIG_COREDUMP
54b50199
KC
2105static int proc_dostring_coredump(struct ctl_table *table, int write,
2106 void __user *buffer, size_t *lenp, loff_t *ppos)
2107{
2108 int error = proc_dostring(table, write, buffer, lenp, ppos);
2109 if (!error)
2110 validate_coredump_safety();
2111 return error;
2112}
046d662f 2113#endif
54b50199 2114
d8217f07 2115static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1da177e4
LT
2116 void __user *buffer,
2117 size_t *lenp, loff_t *ppos,
2118 unsigned long convmul,
2119 unsigned long convdiv)
2120{
00b7c339
AW
2121 unsigned long *i, *min, *max;
2122 int vleft, first = 1, err = 0;
2123 unsigned long page = 0;
2124 size_t left;
2125 char *kbuf;
2126
2127 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1da177e4
LT
2128 *lenp = 0;
2129 return 0;
2130 }
00b7c339 2131
fcfbd547 2132 i = (unsigned long *) data;
1da177e4
LT
2133 min = (unsigned long *) table->extra1;
2134 max = (unsigned long *) table->extra2;
2135 vleft = table->maxlen / sizeof(unsigned long);
2136 left = *lenp;
00b7c339
AW
2137
2138 if (write) {
2139 if (left > PAGE_SIZE - 1)
2140 left = PAGE_SIZE - 1;
2141 page = __get_free_page(GFP_TEMPORARY);
2142 kbuf = (char *) page;
2143 if (!kbuf)
2144 return -ENOMEM;
2145 if (copy_from_user(kbuf, buffer, left)) {
2146 err = -EFAULT;
2147 goto free;
2148 }
2149 kbuf[left] = 0;
2150 }
2151
27b3d80a 2152 for (; left && vleft--; i++, first = 0) {
00b7c339
AW
2153 unsigned long val;
2154
1da177e4 2155 if (write) {
00b7c339
AW
2156 bool neg;
2157
2158 left -= proc_skip_spaces(&kbuf);
2159
2160 err = proc_get_long(&kbuf, &left, &val, &neg,
2161 proc_wspace_sep,
2162 sizeof(proc_wspace_sep), NULL);
2163 if (err)
1da177e4
LT
2164 break;
2165 if (neg)
1da177e4
LT
2166 continue;
2167 if ((min && val < *min) || (max && val > *max))
2168 continue;
2169 *i = val;
2170 } else {
00b7c339 2171 val = convdiv * (*i) / convmul;
1da177e4 2172 if (!first)
00b7c339
AW
2173 err = proc_put_char(&buffer, &left, '\t');
2174 err = proc_put_long(&buffer, &left, val, false);
2175 if (err)
2176 break;
1da177e4
LT
2177 }
2178 }
2179
00b7c339
AW
2180 if (!write && !first && left && !err)
2181 err = proc_put_char(&buffer, &left, '\n');
2182 if (write && !err)
2183 left -= proc_skip_spaces(&kbuf);
2184free:
1da177e4 2185 if (write) {
00b7c339
AW
2186 free_page(page);
2187 if (first)
2188 return err ? : -EINVAL;
1da177e4 2189 }
1da177e4
LT
2190 *lenp -= left;
2191 *ppos += *lenp;
00b7c339 2192 return err;
1da177e4
LT
2193}
2194
d8217f07 2195static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
fcfbd547
KK
2196 void __user *buffer,
2197 size_t *lenp, loff_t *ppos,
2198 unsigned long convmul,
2199 unsigned long convdiv)
2200{
2201 return __do_proc_doulongvec_minmax(table->data, table, write,
8d65af78 2202 buffer, lenp, ppos, convmul, convdiv);
fcfbd547
KK
2203}
2204
1da177e4
LT
2205/**
2206 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
2211 * @ppos: file position
2212 *
2213 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2214 * values from/to the user buffer, treated as an ASCII string.
2215 *
2216 * This routine will ensure the values are within the range specified by
2217 * table->extra1 (min) and table->extra2 (max).
2218 *
2219 * Returns 0 on success.
2220 */
8d65af78 2221int proc_doulongvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2222 void __user *buffer, size_t *lenp, loff_t *ppos)
2223{
8d65af78 2224 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1da177e4
LT
2225}
2226
2227/**
2228 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2231 * @buffer: the user buffer
2232 * @lenp: the size of the user buffer
2233 * @ppos: file position
2234 *
2235 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2236 * values from/to the user buffer, treated as an ASCII string. The values
2237 * are treated as milliseconds, and converted to jiffies when they are stored.
2238 *
2239 * This routine will ensure the values are within the range specified by
2240 * table->extra1 (min) and table->extra2 (max).
2241 *
2242 * Returns 0 on success.
2243 */
d8217f07 2244int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2245 void __user *buffer,
2246 size_t *lenp, loff_t *ppos)
2247{
8d65af78 2248 return do_proc_doulongvec_minmax(table, write, buffer,
1da177e4
LT
2249 lenp, ppos, HZ, 1000l);
2250}
2251
2252
00b7c339 2253static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2254 int *valp,
2255 int write, void *data)
2256{
2257 if (write) {
cba9f33d
BS
2258 if (*lvalp > LONG_MAX / HZ)
2259 return 1;
1da177e4
LT
2260 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2261 } else {
2262 int val = *valp;
2263 unsigned long lval;
2264 if (val < 0) {
00b7c339 2265 *negp = true;
1da177e4
LT
2266 lval = (unsigned long)-val;
2267 } else {
00b7c339 2268 *negp = false;
1da177e4
LT
2269 lval = (unsigned long)val;
2270 }
2271 *lvalp = lval / HZ;
2272 }
2273 return 0;
2274}
2275
00b7c339 2276static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2277 int *valp,
2278 int write, void *data)
2279{
2280 if (write) {
cba9f33d
BS
2281 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2282 return 1;
1da177e4
LT
2283 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2284 } else {
2285 int val = *valp;
2286 unsigned long lval;
2287 if (val < 0) {
00b7c339 2288 *negp = true;
1da177e4
LT
2289 lval = (unsigned long)-val;
2290 } else {
00b7c339 2291 *negp = false;
1da177e4
LT
2292 lval = (unsigned long)val;
2293 }
2294 *lvalp = jiffies_to_clock_t(lval);
2295 }
2296 return 0;
2297}
2298
00b7c339 2299static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1da177e4
LT
2300 int *valp,
2301 int write, void *data)
2302{
2303 if (write) {
2304 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2305 } else {
2306 int val = *valp;
2307 unsigned long lval;
2308 if (val < 0) {
00b7c339 2309 *negp = true;
1da177e4
LT
2310 lval = (unsigned long)-val;
2311 } else {
00b7c339 2312 *negp = false;
1da177e4
LT
2313 lval = (unsigned long)val;
2314 }
2315 *lvalp = jiffies_to_msecs(lval);
2316 }
2317 return 0;
2318}
2319
2320/**
2321 * proc_dointvec_jiffies - read a vector of integers as seconds
2322 * @table: the sysctl table
2323 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2327 *
2328 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2329 * values from/to the user buffer, treated as an ASCII string.
2330 * The values read are assumed to be in seconds, and are converted into
2331 * jiffies.
2332 *
2333 * Returns 0 on success.
2334 */
8d65af78 2335int proc_dointvec_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
2337{
8d65af78 2338 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2339 do_proc_dointvec_jiffies_conv,NULL);
2340}
2341
2342/**
2343 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2346 * @buffer: the user buffer
2347 * @lenp: the size of the user buffer
1e5d5331 2348 * @ppos: pointer to the file position
1da177e4
LT
2349 *
2350 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2351 * values from/to the user buffer, treated as an ASCII string.
2352 * The values read are assumed to be in 1/USER_HZ seconds, and
2353 * are converted into jiffies.
2354 *
2355 * Returns 0 on success.
2356 */
8d65af78 2357int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2358 void __user *buffer, size_t *lenp, loff_t *ppos)
2359{
8d65af78 2360 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1da177e4
LT
2361 do_proc_dointvec_userhz_jiffies_conv,NULL);
2362}
2363
2364/**
2365 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2366 * @table: the sysctl table
2367 * @write: %TRUE if this is a write to the sysctl file
1da177e4
LT
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
67be2dd1
MW
2370 * @ppos: file position
2371 * @ppos: the current position in the file
1da177e4
LT
2372 *
2373 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2374 * values from/to the user buffer, treated as an ASCII string.
2375 * The values read are assumed to be in 1/1000 seconds, and
2376 * are converted into jiffies.
2377 *
2378 * Returns 0 on success.
2379 */
8d65af78 2380int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
8d65af78 2383 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1da177e4
LT
2384 do_proc_dointvec_ms_jiffies_conv, NULL);
2385}
2386
8d65af78 2387static int proc_do_cad_pid(struct ctl_table *table, int write,
9ec52099
CLG
2388 void __user *buffer, size_t *lenp, loff_t *ppos)
2389{
2390 struct pid *new_pid;
2391 pid_t tmp;
2392 int r;
2393
6c5f3e7b 2394 tmp = pid_vnr(cad_pid);
9ec52099 2395
8d65af78 2396 r = __do_proc_dointvec(&tmp, table, write, buffer,
9ec52099
CLG
2397 lenp, ppos, NULL, NULL);
2398 if (r || !write)
2399 return r;
2400
2401 new_pid = find_get_pid(tmp);
2402 if (!new_pid)
2403 return -ESRCH;
2404
2405 put_pid(xchg(&cad_pid, new_pid));
2406 return 0;
2407}
2408
9f977fb7
OP
2409/**
2410 * proc_do_large_bitmap - read/write from/to a large bitmap
2411 * @table: the sysctl table
2412 * @write: %TRUE if this is a write to the sysctl file
2413 * @buffer: the user buffer
2414 * @lenp: the size of the user buffer
2415 * @ppos: file position
2416 *
2417 * The bitmap is stored at table->data and the bitmap length (in bits)
2418 * in table->maxlen.
2419 *
2420 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2421 * large bitmaps may be represented in a compact manner. Writing into
2422 * the file will clear the bitmap then update it with the given input.
2423 *
2424 * Returns 0 on success.
2425 */
2426int proc_do_large_bitmap(struct ctl_table *table, int write,
2427 void __user *buffer, size_t *lenp, loff_t *ppos)
2428{
2429 int err = 0;
2430 bool first = 1;
2431 size_t left = *lenp;
2432 unsigned long bitmap_len = table->maxlen;
2433 unsigned long *bitmap = (unsigned long *) table->data;
2434 unsigned long *tmp_bitmap = NULL;
2435 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2436
2437 if (!bitmap_len || !left || (*ppos && !write)) {
2438 *lenp = 0;
2439 return 0;
2440 }
2441
2442 if (write) {
2443 unsigned long page = 0;
2444 char *kbuf;
2445
2446 if (left > PAGE_SIZE - 1)
2447 left = PAGE_SIZE - 1;
2448
2449 page = __get_free_page(GFP_TEMPORARY);
2450 kbuf = (char *) page;
2451 if (!kbuf)
2452 return -ENOMEM;
2453 if (copy_from_user(kbuf, buffer, left)) {
2454 free_page(page);
2455 return -EFAULT;
2456 }
2457 kbuf[left] = 0;
2458
2459 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2460 GFP_KERNEL);
2461 if (!tmp_bitmap) {
2462 free_page(page);
2463 return -ENOMEM;
2464 }
2465 proc_skip_char(&kbuf, &left, '\n');
2466 while (!err && left) {
2467 unsigned long val_a, val_b;
2468 bool neg;
2469
2470 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2471 sizeof(tr_a), &c);
2472 if (err)
2473 break;
2474 if (val_a >= bitmap_len || neg) {
2475 err = -EINVAL;
2476 break;
2477 }
2478
2479 val_b = val_a;
2480 if (left) {
2481 kbuf++;
2482 left--;
2483 }
2484
2485 if (c == '-') {
2486 err = proc_get_long(&kbuf, &left, &val_b,
2487 &neg, tr_b, sizeof(tr_b),
2488 &c);
2489 if (err)
2490 break;
2491 if (val_b >= bitmap_len || neg ||
2492 val_a > val_b) {
2493 err = -EINVAL;
2494 break;
2495 }
2496 if (left) {
2497 kbuf++;
2498 left--;
2499 }
2500 }
2501
5a04cca6 2502 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
9f977fb7
OP
2503 first = 0;
2504 proc_skip_char(&kbuf, &left, '\n');
2505 }
2506 free_page(page);
2507 } else {
2508 unsigned long bit_a, bit_b = 0;
2509
2510 while (left) {
2511 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2512 if (bit_a >= bitmap_len)
2513 break;
2514 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2515 bit_a + 1) - 1;
2516
2517 if (!first) {
2518 err = proc_put_char(&buffer, &left, ',');
2519 if (err)
2520 break;
2521 }
2522 err = proc_put_long(&buffer, &left, bit_a, false);
2523 if (err)
2524 break;
2525 if (bit_a != bit_b) {
2526 err = proc_put_char(&buffer, &left, '-');
2527 if (err)
2528 break;
2529 err = proc_put_long(&buffer, &left, bit_b, false);
2530 if (err)
2531 break;
2532 }
2533
2534 first = 0; bit_b++;
2535 }
2536 if (!err)
2537 err = proc_put_char(&buffer, &left, '\n');
2538 }
2539
2540 if (!err) {
2541 if (write) {
2542 if (*ppos)
2543 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2544 else
5a04cca6 2545 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
9f977fb7
OP
2546 }
2547 kfree(tmp_bitmap);
2548 *lenp -= left;
2549 *ppos += *lenp;
2550 return 0;
2551 } else {
2552 kfree(tmp_bitmap);
2553 return err;
2554 }
2555}
2556
55610500 2557#else /* CONFIG_PROC_SYSCTL */
1da177e4 2558
8d65af78 2559int proc_dostring(struct ctl_table *table, int write,
1da177e4
LT
2560 void __user *buffer, size_t *lenp, loff_t *ppos)
2561{
2562 return -ENOSYS;
2563}
2564
8d65af78 2565int proc_dointvec(struct ctl_table *table, int write,
1da177e4 2566 void __user *buffer, size_t *lenp, loff_t *ppos)
1da177e4
LT
2567{
2568 return -ENOSYS;
2569}
2570
8d65af78 2571int proc_dointvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2572 void __user *buffer, size_t *lenp, loff_t *ppos)
2573{
2574 return -ENOSYS;
2575}
2576
8d65af78 2577int proc_dointvec_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2578 void __user *buffer, size_t *lenp, loff_t *ppos)
2579{
2580 return -ENOSYS;
2581}
2582
8d65af78 2583int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2584 void __user *buffer, size_t *lenp, loff_t *ppos)
2585{
2586 return -ENOSYS;
2587}
2588
8d65af78 2589int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1da177e4
LT
2590 void __user *buffer, size_t *lenp, loff_t *ppos)
2591{
2592 return -ENOSYS;
2593}
2594
8d65af78 2595int proc_doulongvec_minmax(struct ctl_table *table, int write,
1da177e4
LT
2596 void __user *buffer, size_t *lenp, loff_t *ppos)
2597{
2598 return -ENOSYS;
2599}
2600
d8217f07 2601int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2602 void __user *buffer,
2603 size_t *lenp, loff_t *ppos)
2604{
2605 return -ENOSYS;
2606}
2607
2608
55610500 2609#endif /* CONFIG_PROC_SYSCTL */
1da177e4 2610
1da177e4
LT
2611/*
2612 * No sense putting this after each symbol definition, twice,
2613 * exception granted :-)
2614 */
2615EXPORT_SYMBOL(proc_dointvec);
2616EXPORT_SYMBOL(proc_dointvec_jiffies);
2617EXPORT_SYMBOL(proc_dointvec_minmax);
2618EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2619EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2620EXPORT_SYMBOL(proc_dostring);
2621EXPORT_SYMBOL(proc_doulongvec_minmax);
2622EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);