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