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