]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/sysctl.c
memcontrol: move oom task exclusion to tasklist scan
[mirror_ubuntu-zesty-kernel.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>
26#include <linux/proc_fs.h>
72c2d582 27#include <linux/security.h>
1da177e4
LT
28#include <linux/ctype.h>
29#include <linux/utsname.h>
1da177e4 30#include <linux/smp_lock.h>
62239ac2 31#include <linux/fs.h>
1da177e4
LT
32#include <linux/init.h>
33#include <linux/kernel.h>
0296b228 34#include <linux/kobject.h>
20380731 35#include <linux/net.h>
1da177e4
LT
36#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
40#include <linux/security.h>
41#include <linux/initrd.h>
42#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
c255d844
PM
46#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
10a0a8d4 48#include <linux/reboot.h>
1da177e4
LT
49
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
29cbc78b
AK
53#ifdef CONFIG_X86
54#include <asm/nmi.h>
0741f4d2 55#include <asm/stacktrace.h>
6e7c4025 56#include <asm/io.h>
29cbc78b
AK
57#endif
58
7058cb02
EB
59static int deprecated_sysctl_warning(struct __sysctl_args *args);
60
1da177e4
LT
61#if defined(CONFIG_SYSCTL)
62
63/* External variables not in a header file. */
64extern int C_A_D;
45807a1d 65extern int print_fatal_signals;
1da177e4
LT
66extern int sysctl_overcommit_memory;
67extern int sysctl_overcommit_ratio;
fadd8fbd 68extern int sysctl_panic_on_oom;
fe071d7e 69extern int sysctl_oom_kill_allocating_task;
1da177e4 70extern int max_threads;
1da177e4 71extern int core_uses_pid;
d6e71144 72extern int suid_dumpable;
1da177e4 73extern char core_pattern[];
1da177e4
LT
74extern int pid_max;
75extern int min_free_kbytes;
76extern int printk_ratelimit_jiffies;
77extern int printk_ratelimit_burst;
78extern int pid_max_min, pid_max_max;
9d0243bc 79extern int sysctl_drop_caches;
8ad4b1fb 80extern int percpu_pagelist_fraction;
bebfa101 81extern int compat_log;
5096add8 82extern int maps_protect;
77461ab3 83extern int sysctl_stat_interval;
9745512c 84extern int latencytop_enabled;
1da177e4 85
c4f3b63f 86/* Constants used for minimum and maximum */
195cf453 87#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
c4f3b63f 88static int one = 1;
195cf453
BG
89#endif
90
91#ifdef CONFIG_DETECT_SOFTLOCKUP
c4f3b63f
RT
92static int sixty = 60;
93#endif
94
95#ifdef CONFIG_MMU
96static int two = 2;
97#endif
98
99static int zero;
100static int one_hundred = 100;
101
1da177e4
LT
102/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
103static int maxolduid = 65535;
104static int minolduid;
8ad4b1fb 105static int min_percpu_pagelist_fract = 8;
1da177e4
LT
106
107static int ngroups_max = NGROUPS_MAX;
108
109#ifdef CONFIG_KMOD
110extern char modprobe_path[];
111#endif
1da177e4
LT
112#ifdef CONFIG_CHR_DEV_SG
113extern int sg_big_buff;
114#endif
1da177e4
LT
115
116#ifdef __sparc__
117extern char reboot_command [];
118extern int stop_a_enabled;
119extern int scons_pwroff;
120#endif
121
122#ifdef __hppa__
123extern int pwrsw_enabled;
124extern int unaligned_enabled;
125#endif
126
347a8dc3 127#ifdef CONFIG_S390
1da177e4
LT
128#ifdef CONFIG_MATHEMU
129extern int sysctl_ieee_emulation_warnings;
130#endif
131extern int sysctl_userprocess_debug;
951f22d5 132extern int spin_retry;
1da177e4
LT
133#endif
134
135extern int sysctl_hz_timer;
136
137#ifdef CONFIG_BSD_PROCESS_ACCT
138extern int acct_parm[];
139#endif
140
d2b176ed
JS
141#ifdef CONFIG_IA64
142extern int no_unaligned_warning;
143#endif
144
23f78d4a
IM
145#ifdef CONFIG_RT_MUTEXES
146extern int max_lock_depth;
147#endif
148
b89a8171
EB
149#ifdef CONFIG_SYSCTL_SYSCALL
150static int parse_table(int __user *, int, void __user *, size_t __user *,
d8217f07 151 void __user *, size_t, struct ctl_table *);
b89a8171
EB
152#endif
153
6b49a257 154
d6f8ff73 155#ifdef CONFIG_PROC_SYSCTL
d8217f07 156static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
9ec52099 157 void __user *buffer, size_t *lenp, loff_t *ppos);
d8217f07 158static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
34f5a398 159 void __user *buffer, size_t *lenp, loff_t *ppos);
d6f8ff73 160#endif
9ec52099 161
d8217f07 162static struct ctl_table root_table[];
e51b6ba0
EB
163static struct ctl_table_root sysctl_table_root;
164static struct ctl_table_header root_table_header = {
165 .ctl_table = root_table,
166 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
167 .root = &sysctl_table_root,
168};
169static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
171 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172};
1da177e4 173
d8217f07
EB
174static struct ctl_table kern_table[];
175static struct ctl_table vm_table[];
176static struct ctl_table fs_table[];
177static struct ctl_table debug_table[];
178static struct ctl_table dev_table[];
179extern struct ctl_table random_table[];
2d9048e2 180#ifdef CONFIG_INOTIFY_USER
d8217f07 181extern struct ctl_table inotify_table[];
0399cb08 182#endif
1da177e4
LT
183
184#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
185int sysctl_legacy_va_layout;
186#endif
187
f20786ff
PZ
188extern int prove_locking;
189extern int lock_stat;
9bc9a6bd 190
1da177e4
LT
191/* The default sysctl tables: */
192
d8217f07 193static struct ctl_table root_table[] = {
1da177e4
LT
194 {
195 .ctl_name = CTL_KERN,
196 .procname = "kernel",
197 .mode = 0555,
198 .child = kern_table,
199 },
200 {
201 .ctl_name = CTL_VM,
202 .procname = "vm",
203 .mode = 0555,
204 .child = vm_table,
205 },
1da177e4
LT
206 {
207 .ctl_name = CTL_FS,
208 .procname = "fs",
209 .mode = 0555,
210 .child = fs_table,
211 },
212 {
213 .ctl_name = CTL_DEBUG,
214 .procname = "debug",
215 .mode = 0555,
216 .child = debug_table,
217 },
218 {
219 .ctl_name = CTL_DEV,
220 .procname = "dev",
221 .mode = 0555,
222 .child = dev_table,
223 },
2be7fe07
AM
224/*
225 * NOTE: do not add new entries to this table unless you have read
226 * Documentation/sysctl/ctl_unnumbered.txt
227 */
1da177e4
LT
228 { .ctl_name = 0 }
229};
230
77e54a1f 231#ifdef CONFIG_SCHED_DEBUG
73c4efd2
ED
232static int min_sched_granularity_ns = 100000; /* 100 usecs */
233static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
234static int min_wakeup_granularity_ns; /* 0 usecs */
235static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
77e54a1f
IM
236#endif
237
d8217f07 238static struct ctl_table kern_table[] = {
77e54a1f
IM
239#ifdef CONFIG_SCHED_DEBUG
240 {
241 .ctl_name = CTL_UNNUMBERED,
b2be5e96
PZ
242 .procname = "sched_min_granularity_ns",
243 .data = &sysctl_sched_min_granularity,
77e54a1f
IM
244 .maxlen = sizeof(unsigned int),
245 .mode = 0644,
b2be5e96
PZ
246 .proc_handler = &sched_nr_latency_handler,
247 .strategy = &sysctl_intvec,
248 .extra1 = &min_sched_granularity_ns,
249 .extra2 = &max_sched_granularity_ns,
77e54a1f 250 },
21805085
PZ
251 {
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "sched_latency_ns",
254 .data = &sysctl_sched_latency,
255 .maxlen = sizeof(unsigned int),
256 .mode = 0644,
b2be5e96 257 .proc_handler = &sched_nr_latency_handler,
21805085
PZ
258 .strategy = &sysctl_intvec,
259 .extra1 = &min_sched_granularity_ns,
260 .extra2 = &max_sched_granularity_ns,
261 },
77e54a1f
IM
262 {
263 .ctl_name = CTL_UNNUMBERED,
264 .procname = "sched_wakeup_granularity_ns",
265 .data = &sysctl_sched_wakeup_granularity,
266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
268 .proc_handler = &proc_dointvec_minmax,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_wakeup_granularity_ns,
271 .extra2 = &max_wakeup_granularity_ns,
272 },
273 {
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_batch_wakeup_granularity_ns",
276 .data = &sysctl_sched_batch_wakeup_granularity,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = &proc_dointvec_minmax,
280 .strategy = &sysctl_intvec,
281 .extra1 = &min_wakeup_granularity_ns,
282 .extra2 = &max_wakeup_granularity_ns,
283 },
77e54a1f
IM
284 {
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec,
291 },
1fc84aaa
PZ
292 {
293 .ctl_name = CTL_UNNUMBERED,
294 .procname = "sched_features",
295 .data = &sysctl_sched_features,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = &proc_dointvec,
299 },
da84d961
IM
300 {
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_migration_cost",
303 .data = &sysctl_sched_migration_cost,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
b82d9fdd
PZ
308 {
309 .ctl_name = CTL_UNNUMBERED,
310 .procname = "sched_nr_migrate",
311 .data = &sysctl_sched_nr_migrate,
312 .maxlen = sizeof(unsigned int),
fa85ae24
PZ
313 .mode = 0644,
314 .proc_handler = &proc_dointvec,
315 },
316 {
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_rt_period_ms",
319 .data = &sysctl_sched_rt_period,
320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
323 },
324 {
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_rt_ratio",
327 .data = &sysctl_sched_rt_ratio,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
b82d9fdd
PZ
330 .proc_handler = &proc_dointvec,
331 },
6b2d7700
SV
332#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
333 {
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "sched_min_bal_int_shares",
336 .data = &sysctl_sched_min_bal_int_shares,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "sched_max_bal_int_shares",
344 .data = &sysctl_sched_max_bal_int_shares,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
348 },
349#endif
1fc84aaa 350#endif
1799e35d
IM
351 {
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "sched_compat_yield",
354 .data = &sysctl_sched_compat_yield,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
358 },
f20786ff
PZ
359#ifdef CONFIG_PROVE_LOCKING
360 {
361 .ctl_name = CTL_UNNUMBERED,
362 .procname = "prove_locking",
363 .data = &prove_locking,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = &proc_dointvec,
367 },
368#endif
369#ifdef CONFIG_LOCK_STAT
370 {
371 .ctl_name = CTL_UNNUMBERED,
372 .procname = "lock_stat",
373 .data = &lock_stat,
374 .maxlen = sizeof(int),
375 .mode = 0644,
376 .proc_handler = &proc_dointvec,
377 },
77e54a1f 378#endif
1da177e4
LT
379 {
380 .ctl_name = KERN_PANIC,
381 .procname = "panic",
382 .data = &panic_timeout,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387 {
388 .ctl_name = KERN_CORE_USES_PID,
389 .procname = "core_uses_pid",
390 .data = &core_uses_pid,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
395 {
396 .ctl_name = KERN_CORE_PATTERN,
397 .procname = "core_pattern",
398 .data = core_pattern,
71ce92f3 399 .maxlen = CORENAME_MAX_SIZE,
1da177e4
LT
400 .mode = 0644,
401 .proc_handler = &proc_dostring,
402 .strategy = &sysctl_string,
403 },
34f5a398 404#ifdef CONFIG_PROC_SYSCTL
1da177e4 405 {
1da177e4
LT
406 .procname = "tainted",
407 .data = &tainted,
408 .maxlen = sizeof(int),
34f5a398
TT
409 .mode = 0644,
410 .proc_handler = &proc_dointvec_taint,
1da177e4 411 },
34f5a398 412#endif
9745512c
AV
413#ifdef CONFIG_LATENCYTOP
414 {
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421#endif
1da177e4
LT
422#ifdef CONFIG_BLK_DEV_INITRD
423 {
424 .ctl_name = KERN_REALROOTDEV,
425 .procname = "real-root-dev",
426 .data = &real_root_dev,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431#endif
45807a1d
IM
432 {
433 .ctl_name = CTL_UNNUMBERED,
434 .procname = "print-fatal-signals",
435 .data = &print_fatal_signals,
436 .maxlen = sizeof(int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
1da177e4
LT
440#ifdef __sparc__
441 {
442 .ctl_name = KERN_SPARC_REBOOT,
443 .procname = "reboot-cmd",
444 .data = reboot_command,
445 .maxlen = 256,
446 .mode = 0644,
447 .proc_handler = &proc_dostring,
448 .strategy = &sysctl_string,
449 },
450 {
451 .ctl_name = KERN_SPARC_STOP_A,
452 .procname = "stop-a",
453 .data = &stop_a_enabled,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458 {
459 .ctl_name = KERN_SPARC_SCONS_PWROFF,
460 .procname = "scons-poweroff",
461 .data = &scons_pwroff,
462 .maxlen = sizeof (int),
463 .mode = 0644,
464 .proc_handler = &proc_dointvec,
465 },
466#endif
467#ifdef __hppa__
468 {
469 .ctl_name = KERN_HPPA_PWRSW,
470 .procname = "soft-power",
471 .data = &pwrsw_enabled,
472 .maxlen = sizeof (int),
473 .mode = 0644,
474 .proc_handler = &proc_dointvec,
475 },
476 {
477 .ctl_name = KERN_HPPA_UNALIGNED,
478 .procname = "unaligned-trap",
479 .data = &unaligned_enabled,
480 .maxlen = sizeof (int),
481 .mode = 0644,
482 .proc_handler = &proc_dointvec,
483 },
484#endif
485 {
486 .ctl_name = KERN_CTLALTDEL,
487 .procname = "ctrl-alt-del",
488 .data = &C_A_D,
489 .maxlen = sizeof(int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
492 },
493 {
494 .ctl_name = KERN_PRINTK,
495 .procname = "printk",
496 .data = &console_loglevel,
497 .maxlen = 4*sizeof(int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501#ifdef CONFIG_KMOD
502 {
503 .ctl_name = KERN_MODPROBE,
504 .procname = "modprobe",
505 .data = &modprobe_path,
506 .maxlen = KMOD_PATH_LEN,
507 .mode = 0644,
508 .proc_handler = &proc_dostring,
509 .strategy = &sysctl_string,
510 },
511#endif
57ae2508 512#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
1da177e4
LT
513 {
514 .ctl_name = KERN_HOTPLUG,
515 .procname = "hotplug",
312c004d
KS
516 .data = &uevent_helper,
517 .maxlen = UEVENT_HELPER_PATH_LEN,
1da177e4
LT
518 .mode = 0644,
519 .proc_handler = &proc_dostring,
520 .strategy = &sysctl_string,
521 },
522#endif
523#ifdef CONFIG_CHR_DEV_SG
524 {
525 .ctl_name = KERN_SG_BIG_BUFF,
526 .procname = "sg-big-buff",
527 .data = &sg_big_buff,
528 .maxlen = sizeof (int),
529 .mode = 0444,
530 .proc_handler = &proc_dointvec,
531 },
532#endif
533#ifdef CONFIG_BSD_PROCESS_ACCT
534 {
535 .ctl_name = KERN_ACCT,
536 .procname = "acct",
537 .data = &acct_parm,
538 .maxlen = 3*sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec,
541 },
542#endif
1da177e4
LT
543#ifdef CONFIG_MAGIC_SYSRQ
544 {
545 .ctl_name = KERN_SYSRQ,
546 .procname = "sysrq",
5d6f647f 547 .data = &__sysrq_enabled,
1da177e4
LT
548 .maxlen = sizeof (int),
549 .mode = 0644,
550 .proc_handler = &proc_dointvec,
551 },
552#endif
d6f8ff73 553#ifdef CONFIG_PROC_SYSCTL
1da177e4 554 {
1da177e4 555 .procname = "cad_pid",
9ec52099 556 .data = NULL,
1da177e4
LT
557 .maxlen = sizeof (int),
558 .mode = 0600,
9ec52099 559 .proc_handler = &proc_do_cad_pid,
1da177e4 560 },
d6f8ff73 561#endif
1da177e4
LT
562 {
563 .ctl_name = KERN_MAX_THREADS,
564 .procname = "threads-max",
565 .data = &max_threads,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
569 },
570 {
571 .ctl_name = KERN_RANDOM,
572 .procname = "random",
573 .mode = 0555,
574 .child = random_table,
575 },
1da177e4
LT
576 {
577 .ctl_name = KERN_OVERFLOWUID,
578 .procname = "overflowuid",
579 .data = &overflowuid,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec_minmax,
583 .strategy = &sysctl_intvec,
584 .extra1 = &minolduid,
585 .extra2 = &maxolduid,
586 },
587 {
588 .ctl_name = KERN_OVERFLOWGID,
589 .procname = "overflowgid",
590 .data = &overflowgid,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = &sysctl_intvec,
595 .extra1 = &minolduid,
596 .extra2 = &maxolduid,
597 },
347a8dc3 598#ifdef CONFIG_S390
1da177e4
LT
599#ifdef CONFIG_MATHEMU
600 {
601 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
602 .procname = "ieee_emulation_warnings",
603 .data = &sysctl_ieee_emulation_warnings,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
607 },
608#endif
609#ifdef CONFIG_NO_IDLE_HZ
610 {
611 .ctl_name = KERN_HZ_TIMER,
612 .procname = "hz_timer",
613 .data = &sysctl_hz_timer,
614 .maxlen = sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
617 },
618#endif
619 {
620 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
621 .procname = "userprocess_debug",
622 .data = &sysctl_userprocess_debug,
623 .maxlen = sizeof(int),
624 .mode = 0644,
625 .proc_handler = &proc_dointvec,
626 },
627#endif
628 {
629 .ctl_name = KERN_PIDMAX,
630 .procname = "pid_max",
631 .data = &pid_max,
632 .maxlen = sizeof (int),
633 .mode = 0644,
634 .proc_handler = &proc_dointvec_minmax,
635 .strategy = sysctl_intvec,
636 .extra1 = &pid_max_min,
637 .extra2 = &pid_max_max,
638 },
639 {
640 .ctl_name = KERN_PANIC_ON_OOPS,
641 .procname = "panic_on_oops",
642 .data = &panic_on_oops,
643 .maxlen = sizeof(int),
644 .mode = 0644,
645 .proc_handler = &proc_dointvec,
646 },
647 {
648 .ctl_name = KERN_PRINTK_RATELIMIT,
649 .procname = "printk_ratelimit",
650 .data = &printk_ratelimit_jiffies,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec_jiffies,
654 .strategy = &sysctl_jiffies,
655 },
656 {
657 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
658 .procname = "printk_ratelimit_burst",
659 .data = &printk_ratelimit_burst,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
664 {
665 .ctl_name = KERN_NGROUPS_MAX,
666 .procname = "ngroups_max",
667 .data = &ngroups_max,
668 .maxlen = sizeof (int),
669 .mode = 0444,
670 .proc_handler = &proc_dointvec,
671 },
672#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
673 {
674 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
675 .procname = "unknown_nmi_panic",
676 .data = &unknown_nmi_panic,
677 .maxlen = sizeof (int),
678 .mode = 0644,
2fbe7b25 679 .proc_handler = &proc_dointvec,
1da177e4 680 },
407984f1 681 {
407984f1
DZ
682 .procname = "nmi_watchdog",
683 .data = &nmi_watchdog_enabled,
684 .maxlen = sizeof (int),
685 .mode = 0644,
686 .proc_handler = &proc_nmi_enabled,
1da177e4
LT
687 },
688#endif
689#if defined(CONFIG_X86)
8da5adda
DZ
690 {
691 .ctl_name = KERN_PANIC_ON_NMI,
692 .procname = "panic_on_unrecovered_nmi",
693 .data = &panic_on_unrecovered_nmi,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
697 },
1da177e4
LT
698 {
699 .ctl_name = KERN_BOOTLOADER_TYPE,
700 .procname = "bootloader_type",
701 .data = &bootloader_type,
702 .maxlen = sizeof (int),
703 .mode = 0444,
704 .proc_handler = &proc_dointvec,
705 },
0741f4d2
CE
706 {
707 .ctl_name = CTL_UNNUMBERED,
708 .procname = "kstack_depth_to_print",
709 .data = &kstack_depth_to_print,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
6e7c4025
IM
714 {
715 .ctl_name = CTL_UNNUMBERED,
716 .procname = "io_delay_type",
717 .data = &io_delay_type,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
1da177e4 722#endif
7a9166e3 723#if defined(CONFIG_MMU)
1da177e4
LT
724 {
725 .ctl_name = KERN_RANDOMIZE,
726 .procname = "randomize_va_space",
727 .data = &randomize_va_space,
728 .maxlen = sizeof(int),
729 .mode = 0644,
730 .proc_handler = &proc_dointvec,
731 },
7a9166e3 732#endif
0152fb37 733#if defined(CONFIG_S390) && defined(CONFIG_SMP)
951f22d5
MS
734 {
735 .ctl_name = KERN_SPIN_RETRY,
736 .procname = "spin_retry",
737 .data = &spin_retry,
738 .maxlen = sizeof (int),
739 .mode = 0644,
740 .proc_handler = &proc_dointvec,
741 },
c255d844 742#endif
673d5b43 743#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
c255d844 744 {
c255d844 745 .procname = "acpi_video_flags",
77afcf78 746 .data = &acpi_realmode_flags,
c255d844
PM
747 .maxlen = sizeof (unsigned long),
748 .mode = 0644,
7f99f06f 749 .proc_handler = &proc_doulongvec_minmax,
c255d844 750 },
d2b176ed
JS
751#endif
752#ifdef CONFIG_IA64
753 {
754 .ctl_name = KERN_IA64_UNALIGNED,
755 .procname = "ignore-unaligned-usertrap",
756 .data = &no_unaligned_warning,
757 .maxlen = sizeof (int),
758 .mode = 0644,
759 .proc_handler = &proc_dointvec,
760 },
bebfa101 761#endif
c4f3b63f
RT
762#ifdef CONFIG_DETECT_SOFTLOCKUP
763 {
764 .ctl_name = CTL_UNNUMBERED,
765 .procname = "softlockup_thresh",
766 .data = &softlockup_thresh,
90739081 767 .maxlen = sizeof(unsigned long),
c4f3b63f 768 .mode = 0644,
90739081 769 .proc_handler = &proc_doulongvec_minmax,
c4f3b63f
RT
770 .strategy = &sysctl_intvec,
771 .extra1 = &one,
772 .extra2 = &sixty,
773 },
82a1fcb9
IM
774 {
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_check_count",
777 .data = &sysctl_hung_task_check_count,
90739081 778 .maxlen = sizeof(unsigned long),
82a1fcb9 779 .mode = 0644,
90739081 780 .proc_handler = &proc_doulongvec_minmax,
82a1fcb9
IM
781 .strategy = &sysctl_intvec,
782 },
783 {
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "hung_task_timeout_secs",
786 .data = &sysctl_hung_task_timeout_secs,
90739081 787 .maxlen = sizeof(unsigned long),
82a1fcb9 788 .mode = 0644,
90739081 789 .proc_handler = &proc_doulongvec_minmax,
82a1fcb9
IM
790 .strategy = &sysctl_intvec,
791 },
792 {
793 .ctl_name = CTL_UNNUMBERED,
794 .procname = "hung_task_warnings",
795 .data = &sysctl_hung_task_warnings,
90739081 796 .maxlen = sizeof(unsigned long),
82a1fcb9 797 .mode = 0644,
90739081 798 .proc_handler = &proc_doulongvec_minmax,
82a1fcb9
IM
799 .strategy = &sysctl_intvec,
800 },
c4f3b63f 801#endif
bebfa101
AK
802#ifdef CONFIG_COMPAT
803 {
804 .ctl_name = KERN_COMPAT_LOG,
805 .procname = "compat-log",
806 .data = &compat_log,
807 .maxlen = sizeof (int),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
951f22d5 811#endif
23f78d4a
IM
812#ifdef CONFIG_RT_MUTEXES
813 {
814 .ctl_name = KERN_MAX_LOCK_DEPTH,
815 .procname = "max_lock_depth",
816 .data = &max_lock_depth,
817 .maxlen = sizeof(int),
818 .mode = 0644,
819 .proc_handler = &proc_dointvec,
820 },
821#endif
5096add8
KC
822#ifdef CONFIG_PROC_FS
823 {
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "maps_protect",
826 .data = &maps_protect,
827 .maxlen = sizeof(int),
828 .mode = 0644,
829 .proc_handler = &proc_dointvec,
830 },
831#endif
10a0a8d4
JF
832 {
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "poweroff_cmd",
835 .data = &poweroff_cmd,
836 .maxlen = POWEROFF_CMD_PATH_LEN,
837 .mode = 0644,
838 .proc_handler = &proc_dostring,
839 .strategy = &sysctl_string,
840 },
ed2c12f3
AM
841/*
842 * NOTE: do not add new entries to this table unless you have read
843 * Documentation/sysctl/ctl_unnumbered.txt
844 */
1da177e4
LT
845 { .ctl_name = 0 }
846};
847
d8217f07 848static struct ctl_table vm_table[] = {
1da177e4
LT
849 {
850 .ctl_name = VM_OVERCOMMIT_MEMORY,
851 .procname = "overcommit_memory",
852 .data = &sysctl_overcommit_memory,
853 .maxlen = sizeof(sysctl_overcommit_memory),
854 .mode = 0644,
855 .proc_handler = &proc_dointvec,
856 },
fadd8fbd
KH
857 {
858 .ctl_name = VM_PANIC_ON_OOM,
859 .procname = "panic_on_oom",
860 .data = &sysctl_panic_on_oom,
861 .maxlen = sizeof(sysctl_panic_on_oom),
862 .mode = 0644,
863 .proc_handler = &proc_dointvec,
864 },
fe071d7e
DR
865 {
866 .ctl_name = CTL_UNNUMBERED,
867 .procname = "oom_kill_allocating_task",
868 .data = &sysctl_oom_kill_allocating_task,
869 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
870 .mode = 0644,
871 .proc_handler = &proc_dointvec,
872 },
1da177e4
LT
873 {
874 .ctl_name = VM_OVERCOMMIT_RATIO,
875 .procname = "overcommit_ratio",
876 .data = &sysctl_overcommit_ratio,
877 .maxlen = sizeof(sysctl_overcommit_ratio),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
880 },
881 {
882 .ctl_name = VM_PAGE_CLUSTER,
883 .procname = "page-cluster",
884 .data = &page_cluster,
885 .maxlen = sizeof(int),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
888 },
889 {
890 .ctl_name = VM_DIRTY_BACKGROUND,
891 .procname = "dirty_background_ratio",
892 .data = &dirty_background_ratio,
893 .maxlen = sizeof(dirty_background_ratio),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec_minmax,
896 .strategy = &sysctl_intvec,
897 .extra1 = &zero,
898 .extra2 = &one_hundred,
899 },
900 {
901 .ctl_name = VM_DIRTY_RATIO,
902 .procname = "dirty_ratio",
903 .data = &vm_dirty_ratio,
904 .maxlen = sizeof(vm_dirty_ratio),
905 .mode = 0644,
04fbfdc1 906 .proc_handler = &dirty_ratio_handler,
1da177e4
LT
907 .strategy = &sysctl_intvec,
908 .extra1 = &zero,
909 .extra2 = &one_hundred,
910 },
911 {
1da177e4 912 .procname = "dirty_writeback_centisecs",
f6ef9438
BS
913 .data = &dirty_writeback_interval,
914 .maxlen = sizeof(dirty_writeback_interval),
1da177e4
LT
915 .mode = 0644,
916 .proc_handler = &dirty_writeback_centisecs_handler,
917 },
918 {
1da177e4 919 .procname = "dirty_expire_centisecs",
f6ef9438
BS
920 .data = &dirty_expire_interval,
921 .maxlen = sizeof(dirty_expire_interval),
1da177e4 922 .mode = 0644,
f6ef9438 923 .proc_handler = &proc_dointvec_userhz_jiffies,
1da177e4
LT
924 },
925 {
926 .ctl_name = VM_NR_PDFLUSH_THREADS,
927 .procname = "nr_pdflush_threads",
928 .data = &nr_pdflush_threads,
929 .maxlen = sizeof nr_pdflush_threads,
930 .mode = 0444 /* read-only*/,
931 .proc_handler = &proc_dointvec,
932 },
933 {
934 .ctl_name = VM_SWAPPINESS,
935 .procname = "swappiness",
936 .data = &vm_swappiness,
937 .maxlen = sizeof(vm_swappiness),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec_minmax,
940 .strategy = &sysctl_intvec,
941 .extra1 = &zero,
942 .extra2 = &one_hundred,
943 },
944#ifdef CONFIG_HUGETLB_PAGE
945 {
1da177e4
LT
946 .procname = "nr_hugepages",
947 .data = &max_huge_pages,
948 .maxlen = sizeof(unsigned long),
949 .mode = 0644,
950 .proc_handler = &hugetlb_sysctl_handler,
951 .extra1 = (void *)&hugetlb_zero,
952 .extra2 = (void *)&hugetlb_infinity,
953 },
954 {
955 .ctl_name = VM_HUGETLB_GROUP,
956 .procname = "hugetlb_shm_group",
957 .data = &sysctl_hugetlb_shm_group,
958 .maxlen = sizeof(gid_t),
959 .mode = 0644,
960 .proc_handler = &proc_dointvec,
961 },
396faf03
MG
962 {
963 .ctl_name = CTL_UNNUMBERED,
964 .procname = "hugepages_treat_as_movable",
965 .data = &hugepages_treat_as_movable,
966 .maxlen = sizeof(int),
967 .mode = 0644,
968 .proc_handler = &hugetlb_treat_movable_handler,
969 },
d1c3fb1f
NA
970 {
971 .ctl_name = CTL_UNNUMBERED,
972 .procname = "nr_overcommit_hugepages",
973 .data = &nr_overcommit_huge_pages,
974 .maxlen = sizeof(nr_overcommit_huge_pages),
975 .mode = 0644,
976 .proc_handler = &proc_doulongvec_minmax,
977 },
1da177e4
LT
978#endif
979 {
980 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
981 .procname = "lowmem_reserve_ratio",
982 .data = &sysctl_lowmem_reserve_ratio,
983 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
984 .mode = 0644,
985 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
986 .strategy = &sysctl_intvec,
987 },
9d0243bc
AM
988 {
989 .ctl_name = VM_DROP_PAGECACHE,
990 .procname = "drop_caches",
991 .data = &sysctl_drop_caches,
992 .maxlen = sizeof(int),
993 .mode = 0644,
994 .proc_handler = drop_caches_sysctl_handler,
995 .strategy = &sysctl_intvec,
996 },
1da177e4
LT
997 {
998 .ctl_name = VM_MIN_FREE_KBYTES,
999 .procname = "min_free_kbytes",
1000 .data = &min_free_kbytes,
1001 .maxlen = sizeof(min_free_kbytes),
1002 .mode = 0644,
1003 .proc_handler = &min_free_kbytes_sysctl_handler,
1004 .strategy = &sysctl_intvec,
1005 .extra1 = &zero,
1006 },
8ad4b1fb
RS
1007 {
1008 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1009 .procname = "percpu_pagelist_fraction",
1010 .data = &percpu_pagelist_fraction,
1011 .maxlen = sizeof(percpu_pagelist_fraction),
1012 .mode = 0644,
1013 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1014 .strategy = &sysctl_intvec,
1015 .extra1 = &min_percpu_pagelist_fract,
1016 },
1da177e4
LT
1017#ifdef CONFIG_MMU
1018 {
1019 .ctl_name = VM_MAX_MAP_COUNT,
1020 .procname = "max_map_count",
1021 .data = &sysctl_max_map_count,
1022 .maxlen = sizeof(sysctl_max_map_count),
1023 .mode = 0644,
1024 .proc_handler = &proc_dointvec
1025 },
1026#endif
1027 {
1028 .ctl_name = VM_LAPTOP_MODE,
1029 .procname = "laptop_mode",
1030 .data = &laptop_mode,
1031 .maxlen = sizeof(laptop_mode),
1032 .mode = 0644,
ed5b43f1
BS
1033 .proc_handler = &proc_dointvec_jiffies,
1034 .strategy = &sysctl_jiffies,
1da177e4
LT
1035 },
1036 {
1037 .ctl_name = VM_BLOCK_DUMP,
1038 .procname = "block_dump",
1039 .data = &block_dump,
1040 .maxlen = sizeof(block_dump),
1041 .mode = 0644,
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &zero,
1045 },
1046 {
1047 .ctl_name = VM_VFS_CACHE_PRESSURE,
1048 .procname = "vfs_cache_pressure",
1049 .data = &sysctl_vfs_cache_pressure,
1050 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1051 .mode = 0644,
1052 .proc_handler = &proc_dointvec,
1053 .strategy = &sysctl_intvec,
1054 .extra1 = &zero,
1055 },
1056#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1057 {
1058 .ctl_name = VM_LEGACY_VA_LAYOUT,
1059 .procname = "legacy_va_layout",
1060 .data = &sysctl_legacy_va_layout,
1061 .maxlen = sizeof(sysctl_legacy_va_layout),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
1064 .strategy = &sysctl_intvec,
1065 .extra1 = &zero,
1066 },
1067#endif
1743660b
CL
1068#ifdef CONFIG_NUMA
1069 {
1070 .ctl_name = VM_ZONE_RECLAIM_MODE,
1071 .procname = "zone_reclaim_mode",
1072 .data = &zone_reclaim_mode,
1073 .maxlen = sizeof(zone_reclaim_mode),
1074 .mode = 0644,
1075 .proc_handler = &proc_dointvec,
c84db23c
CL
1076 .strategy = &sysctl_intvec,
1077 .extra1 = &zero,
1743660b 1078 },
9614634f
CL
1079 {
1080 .ctl_name = VM_MIN_UNMAPPED,
1081 .procname = "min_unmapped_ratio",
1082 .data = &sysctl_min_unmapped_ratio,
1083 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1084 .mode = 0644,
1085 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1086 .strategy = &sysctl_intvec,
1087 .extra1 = &zero,
1088 .extra2 = &one_hundred,
1089 },
0ff38490
CL
1090 {
1091 .ctl_name = VM_MIN_SLAB,
1092 .procname = "min_slab_ratio",
1093 .data = &sysctl_min_slab_ratio,
1094 .maxlen = sizeof(sysctl_min_slab_ratio),
1095 .mode = 0644,
1096 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &zero,
1099 .extra2 = &one_hundred,
1100 },
e6e5494c 1101#endif
77461ab3
CL
1102#ifdef CONFIG_SMP
1103 {
1104 .ctl_name = CTL_UNNUMBERED,
1105 .procname = "stat_interval",
1106 .data = &sysctl_stat_interval,
1107 .maxlen = sizeof(sysctl_stat_interval),
1108 .mode = 0644,
1109 .proc_handler = &proc_dointvec_jiffies,
1110 .strategy = &sysctl_jiffies,
1111 },
1112#endif
ed032189
EP
1113#ifdef CONFIG_SECURITY
1114 {
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "mmap_min_addr",
1117 .data = &mmap_min_addr,
1118 .maxlen = sizeof(unsigned long),
1119 .mode = 0644,
1120 .proc_handler = &proc_doulongvec_minmax,
1121 },
8daec965 1122#endif
f0c0b2b8
KH
1123#ifdef CONFIG_NUMA
1124 {
1125 .ctl_name = CTL_UNNUMBERED,
1126 .procname = "numa_zonelist_order",
1127 .data = &numa_zonelist_order,
1128 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1129 .mode = 0644,
1130 .proc_handler = &numa_zonelist_order_handler,
1131 .strategy = &sysctl_string,
1132 },
1133#endif
2b8232ce 1134#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
5c36e657 1135 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
e6e5494c
IM
1136 {
1137 .ctl_name = VM_VDSO_ENABLED,
1138 .procname = "vdso_enabled",
1139 .data = &vdso_enabled,
1140 .maxlen = sizeof(vdso_enabled),
1141 .mode = 0644,
1142 .proc_handler = &proc_dointvec,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &zero,
1145 },
1da177e4 1146#endif
195cf453
BG
1147#ifdef CONFIG_HIGHMEM
1148 {
1149 .ctl_name = CTL_UNNUMBERED,
1150 .procname = "highmem_is_dirtyable",
1151 .data = &vm_highmem_is_dirtyable,
1152 .maxlen = sizeof(vm_highmem_is_dirtyable),
1153 .mode = 0644,
1154 .proc_handler = &proc_dointvec_minmax,
1155 .strategy = &sysctl_intvec,
1156 .extra1 = &zero,
1157 .extra2 = &one,
1158 },
1159#endif
2be7fe07
AM
1160/*
1161 * NOTE: do not add new entries to this table unless you have read
1162 * Documentation/sysctl/ctl_unnumbered.txt
1163 */
1da177e4
LT
1164 { .ctl_name = 0 }
1165};
1166
2abc26fc 1167#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
d8217f07 1168static struct ctl_table binfmt_misc_table[] = {
2abc26fc
EB
1169 { .ctl_name = 0 }
1170};
1171#endif
1172
d8217f07 1173static struct ctl_table fs_table[] = {
1da177e4
LT
1174 {
1175 .ctl_name = FS_NRINODE,
1176 .procname = "inode-nr",
1177 .data = &inodes_stat,
1178 .maxlen = 2*sizeof(int),
1179 .mode = 0444,
1180 .proc_handler = &proc_dointvec,
1181 },
1182 {
1183 .ctl_name = FS_STATINODE,
1184 .procname = "inode-state",
1185 .data = &inodes_stat,
1186 .maxlen = 7*sizeof(int),
1187 .mode = 0444,
1188 .proc_handler = &proc_dointvec,
1189 },
1190 {
1da177e4
LT
1191 .procname = "file-nr",
1192 .data = &files_stat,
1193 .maxlen = 3*sizeof(int),
1194 .mode = 0444,
529bf6be 1195 .proc_handler = &proc_nr_files,
1da177e4
LT
1196 },
1197 {
1198 .ctl_name = FS_MAXFILE,
1199 .procname = "file-max",
1200 .data = &files_stat.max_files,
1201 .maxlen = sizeof(int),
1202 .mode = 0644,
1203 .proc_handler = &proc_dointvec,
1204 },
9cfe015a
ED
1205 {
1206 .ctl_name = CTL_UNNUMBERED,
1207 .procname = "nr_open",
1208 .data = &sysctl_nr_open,
1209 .maxlen = sizeof(int),
1210 .mode = 0644,
1211 .proc_handler = &proc_dointvec,
1212 },
1da177e4
LT
1213 {
1214 .ctl_name = FS_DENTRY,
1215 .procname = "dentry-state",
1216 .data = &dentry_stat,
1217 .maxlen = 6*sizeof(int),
1218 .mode = 0444,
1219 .proc_handler = &proc_dointvec,
1220 },
1221 {
1222 .ctl_name = FS_OVERFLOWUID,
1223 .procname = "overflowuid",
1224 .data = &fs_overflowuid,
1225 .maxlen = sizeof(int),
1226 .mode = 0644,
1227 .proc_handler = &proc_dointvec_minmax,
1228 .strategy = &sysctl_intvec,
1229 .extra1 = &minolduid,
1230 .extra2 = &maxolduid,
1231 },
1232 {
1233 .ctl_name = FS_OVERFLOWGID,
1234 .procname = "overflowgid",
1235 .data = &fs_overflowgid,
1236 .maxlen = sizeof(int),
1237 .mode = 0644,
1238 .proc_handler = &proc_dointvec_minmax,
1239 .strategy = &sysctl_intvec,
1240 .extra1 = &minolduid,
1241 .extra2 = &maxolduid,
1242 },
1243 {
1244 .ctl_name = FS_LEASES,
1245 .procname = "leases-enable",
1246 .data = &leases_enable,
1247 .maxlen = sizeof(int),
1248 .mode = 0644,
1249 .proc_handler = &proc_dointvec,
1250 },
1251#ifdef CONFIG_DNOTIFY
1252 {
1253 .ctl_name = FS_DIR_NOTIFY,
1254 .procname = "dir-notify-enable",
1255 .data = &dir_notify_enable,
1256 .maxlen = sizeof(int),
1257 .mode = 0644,
1258 .proc_handler = &proc_dointvec,
1259 },
1260#endif
1261#ifdef CONFIG_MMU
1262 {
1263 .ctl_name = FS_LEASE_TIME,
1264 .procname = "lease-break-time",
1265 .data = &lease_break_time,
1266 .maxlen = sizeof(int),
1267 .mode = 0644,
76fdbb25
KH
1268 .proc_handler = &proc_dointvec_minmax,
1269 .strategy = &sysctl_intvec,
1270 .extra1 = &zero,
1271 .extra2 = &two,
1da177e4
LT
1272 },
1273 {
1da177e4
LT
1274 .procname = "aio-nr",
1275 .data = &aio_nr,
1276 .maxlen = sizeof(aio_nr),
1277 .mode = 0444,
d55b5fda 1278 .proc_handler = &proc_doulongvec_minmax,
1da177e4
LT
1279 },
1280 {
1da177e4
LT
1281 .procname = "aio-max-nr",
1282 .data = &aio_max_nr,
1283 .maxlen = sizeof(aio_max_nr),
1284 .mode = 0644,
d55b5fda 1285 .proc_handler = &proc_doulongvec_minmax,
1da177e4 1286 },
2d9048e2 1287#ifdef CONFIG_INOTIFY_USER
0399cb08
RL
1288 {
1289 .ctl_name = FS_INOTIFY,
1290 .procname = "inotify",
1291 .mode = 0555,
1292 .child = inotify_table,
1293 },
1294#endif
1da177e4 1295#endif
d6e71144
AC
1296 {
1297 .ctl_name = KERN_SETUID_DUMPABLE,
1298 .procname = "suid_dumpable",
1299 .data = &suid_dumpable,
1300 .maxlen = sizeof(int),
1301 .mode = 0644,
1302 .proc_handler = &proc_dointvec,
1303 },
2abc26fc
EB
1304#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1305 {
1306 .ctl_name = CTL_UNNUMBERED,
1307 .procname = "binfmt_misc",
1308 .mode = 0555,
1309 .child = binfmt_misc_table,
1310 },
1311#endif
2be7fe07
AM
1312/*
1313 * NOTE: do not add new entries to this table unless you have read
1314 * Documentation/sysctl/ctl_unnumbered.txt
2be7fe07 1315 */
1da177e4
LT
1316 { .ctl_name = 0 }
1317};
1318
d8217f07 1319static struct ctl_table debug_table[] = {
d0c3d534 1320#if defined(CONFIG_X86) || defined(CONFIG_PPC)
abd4f750
MAS
1321 {
1322 .ctl_name = CTL_UNNUMBERED,
1323 .procname = "exception-trace",
1324 .data = &show_unhandled_signals,
1325 .maxlen = sizeof(int),
1326 .mode = 0644,
1327 .proc_handler = proc_dointvec
1328 },
1329#endif
1da177e4
LT
1330 { .ctl_name = 0 }
1331};
1332
d8217f07 1333static struct ctl_table dev_table[] = {
1da177e4 1334 { .ctl_name = 0 }
0eeca283 1335};
1da177e4 1336
330d57fb
AV
1337static DEFINE_SPINLOCK(sysctl_lock);
1338
1339/* called under sysctl_lock */
1340static int use_table(struct ctl_table_header *p)
1341{
1342 if (unlikely(p->unregistering))
1343 return 0;
1344 p->used++;
1345 return 1;
1346}
1347
1348/* called under sysctl_lock */
1349static void unuse_table(struct ctl_table_header *p)
1350{
1351 if (!--p->used)
1352 if (unlikely(p->unregistering))
1353 complete(p->unregistering);
1354}
1355
1356/* called under sysctl_lock, will reacquire if has to wait */
1357static void start_unregistering(struct ctl_table_header *p)
1358{
1359 /*
1360 * if p->used is 0, nobody will ever touch that entry again;
1361 * we'll eliminate all paths to it before dropping sysctl_lock
1362 */
1363 if (unlikely(p->used)) {
1364 struct completion wait;
1365 init_completion(&wait);
1366 p->unregistering = &wait;
1367 spin_unlock(&sysctl_lock);
1368 wait_for_completion(&wait);
1369 spin_lock(&sysctl_lock);
1370 }
1371 /*
1372 * do not remove from the list until nobody holds it; walking the
1373 * list in do_sysctl() relies on that.
1374 */
1375 list_del_init(&p->ctl_entry);
1376}
1377
805b5d5e
EB
1378void sysctl_head_finish(struct ctl_table_header *head)
1379{
1380 if (!head)
1381 return;
1382 spin_lock(&sysctl_lock);
1383 unuse_table(head);
1384 spin_unlock(&sysctl_lock);
1385}
1386
e51b6ba0
EB
1387static struct list_head *
1388lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
805b5d5e 1389{
e51b6ba0
EB
1390 struct list_head *header_list;
1391 header_list = &root->header_list;
1392 if (root->lookup)
1393 header_list = root->lookup(root, namespaces);
1394 return header_list;
1395}
1396
1397struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1398 struct ctl_table_header *prev)
1399{
1400 struct ctl_table_root *root;
1401 struct list_head *header_list;
805b5d5e
EB
1402 struct ctl_table_header *head;
1403 struct list_head *tmp;
e51b6ba0 1404
805b5d5e
EB
1405 spin_lock(&sysctl_lock);
1406 if (prev) {
e51b6ba0 1407 head = prev;
805b5d5e
EB
1408 tmp = &prev->ctl_entry;
1409 unuse_table(prev);
1410 goto next;
1411 }
1412 tmp = &root_table_header.ctl_entry;
1413 for (;;) {
1414 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1415
1416 if (!use_table(head))
1417 goto next;
1418 spin_unlock(&sysctl_lock);
1419 return head;
1420 next:
e51b6ba0 1421 root = head->root;
805b5d5e 1422 tmp = tmp->next;
e51b6ba0
EB
1423 header_list = lookup_header_list(root, namespaces);
1424 if (tmp != header_list)
1425 continue;
1426
1427 do {
1428 root = list_entry(root->root_list.next,
1429 struct ctl_table_root, root_list);
1430 if (root == &sysctl_table_root)
1431 goto out;
1432 header_list = lookup_header_list(root, namespaces);
1433 } while (list_empty(header_list));
1434 tmp = header_list->next;
805b5d5e 1435 }
e51b6ba0 1436out:
805b5d5e
EB
1437 spin_unlock(&sysctl_lock);
1438 return NULL;
1439}
1440
e51b6ba0
EB
1441struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1442{
1443 return __sysctl_head_next(current->nsproxy, prev);
1444}
1445
1446void register_sysctl_root(struct ctl_table_root *root)
1447{
1448 spin_lock(&sysctl_lock);
1449 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1450 spin_unlock(&sysctl_lock);
1451}
1452
b89a8171 1453#ifdef CONFIG_SYSCTL_SYSCALL
1da177e4
LT
1454int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1455 void __user *newval, size_t newlen)
1456{
805b5d5e 1457 struct ctl_table_header *head;
330d57fb 1458 int error = -ENOTDIR;
1da177e4
LT
1459
1460 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1461 return -ENOTDIR;
1462 if (oldval) {
1463 int old_len;
1464 if (!oldlenp || get_user(old_len, oldlenp))
1465 return -EFAULT;
1466 }
330d57fb 1467
805b5d5e
EB
1468 for (head = sysctl_head_next(NULL); head;
1469 head = sysctl_head_next(head)) {
330d57fb 1470 error = parse_table(name, nlen, oldval, oldlenp,
1f29bcd7 1471 newval, newlen, head->ctl_table);
805b5d5e
EB
1472 if (error != -ENOTDIR) {
1473 sysctl_head_finish(head);
330d57fb 1474 break;
805b5d5e
EB
1475 }
1476 }
330d57fb 1477 return error;
1da177e4
LT
1478}
1479
1480asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1481{
1482 struct __sysctl_args tmp;
1483 int error;
1484
1485 if (copy_from_user(&tmp, args, sizeof(tmp)))
1486 return -EFAULT;
1487
7058cb02
EB
1488 error = deprecated_sysctl_warning(&tmp);
1489 if (error)
1490 goto out;
1491
1da177e4
LT
1492 lock_kernel();
1493 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1494 tmp.newval, tmp.newlen);
1495 unlock_kernel();
7058cb02 1496out:
1da177e4
LT
1497 return error;
1498}
b89a8171 1499#endif /* CONFIG_SYSCTL_SYSCALL */
1da177e4
LT
1500
1501/*
1ff007eb 1502 * sysctl_perm does NOT grant the superuser all rights automatically, because
1da177e4
LT
1503 * some sysctl variables are readonly even to root.
1504 */
1505
1506static int test_perm(int mode, int op)
1507{
1508 if (!current->euid)
1509 mode >>= 6;
1510 else if (in_egroup_p(0))
1511 mode >>= 3;
1512 if ((mode & op & 0007) == op)
1513 return 0;
1514 return -EACCES;
1515}
1516
d8217f07 1517int sysctl_perm(struct ctl_table *table, int op)
1da177e4
LT
1518{
1519 int error;
1520 error = security_sysctl(table, op);
1521 if (error)
1522 return error;
1523 return test_perm(table->mode, op);
1524}
1525
b89a8171 1526#ifdef CONFIG_SYSCTL_SYSCALL
1da177e4
LT
1527static int parse_table(int __user *name, int nlen,
1528 void __user *oldval, size_t __user *oldlenp,
1529 void __user *newval, size_t newlen,
d8217f07 1530 struct ctl_table *table)
1da177e4
LT
1531{
1532 int n;
1533repeat:
1534 if (!nlen)
1535 return -ENOTDIR;
1536 if (get_user(n, name))
1537 return -EFAULT;
d99f160a
EB
1538 for ( ; table->ctl_name || table->procname; table++) {
1539 if (!table->ctl_name)
1540 continue;
6703ddfc 1541 if (n == table->ctl_name) {
1da177e4
LT
1542 int error;
1543 if (table->child) {
1ff007eb 1544 if (sysctl_perm(table, 001))
1da177e4 1545 return -EPERM;
1da177e4
LT
1546 name++;
1547 nlen--;
1548 table = table->child;
1549 goto repeat;
1550 }
1551 error = do_sysctl_strategy(table, name, nlen,
1552 oldval, oldlenp,
1f29bcd7 1553 newval, newlen);
1da177e4
LT
1554 return error;
1555 }
1556 }
1557 return -ENOTDIR;
1558}
1559
1560/* Perform the actual read/write of a sysctl table entry. */
d8217f07 1561int do_sysctl_strategy (struct ctl_table *table,
1da177e4
LT
1562 int __user *name, int nlen,
1563 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 1564 void __user *newval, size_t newlen)
1da177e4
LT
1565{
1566 int op = 0, rc;
1da177e4
LT
1567
1568 if (oldval)
1569 op |= 004;
1570 if (newval)
1571 op |= 002;
1ff007eb 1572 if (sysctl_perm(table, op))
1da177e4
LT
1573 return -EPERM;
1574
1575 if (table->strategy) {
1576 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1f29bcd7 1577 newval, newlen);
1da177e4
LT
1578 if (rc < 0)
1579 return rc;
1580 if (rc > 0)
1581 return 0;
1582 }
1583
1584 /* If there is no strategy routine, or if the strategy returns
1585 * zero, proceed with automatic r/w */
1586 if (table->data && table->maxlen) {
49a0c458
EB
1587 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1588 newval, newlen);
1589 if (rc < 0)
1590 return rc;
1da177e4
LT
1591 }
1592 return 0;
1593}
b89a8171 1594#endif /* CONFIG_SYSCTL_SYSCALL */
1da177e4 1595
d912b0cc
EB
1596static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1597{
1598 for (; table->ctl_name || table->procname; table++) {
1599 table->parent = parent;
1600 if (table->child)
1601 sysctl_set_parent(table, table->child);
1602 }
1603}
1604
1605static __init int sysctl_init(void)
1606{
fc6cd25b 1607 int err;
d912b0cc 1608 sysctl_set_parent(NULL, root_table);
e51b6ba0 1609 err = sysctl_check_table(current->nsproxy, root_table);
d912b0cc
EB
1610 return 0;
1611}
1612
1613core_initcall(sysctl_init);
1614
1da177e4 1615/**
e51b6ba0
EB
1616 * __register_sysctl_paths - register a sysctl hierarchy
1617 * @root: List of sysctl headers to register on
1618 * @namespaces: Data to compute which lists of sysctl entries are visible
29e796fd 1619 * @path: The path to the directory the sysctl table is in.
1da177e4 1620 * @table: the top-level table structure
1da177e4
LT
1621 *
1622 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
29e796fd 1623 * array. A completely 0 filled entry terminates the table.
1da177e4 1624 *
d8217f07 1625 * The members of the &struct ctl_table structure are used as follows:
1da177e4
LT
1626 *
1627 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1628 * must be unique within that level of sysctl
1629 *
1630 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1631 * enter a sysctl file
1632 *
1633 * data - a pointer to data for use by proc_handler
1634 *
1635 * maxlen - the maximum size in bytes of the data
1636 *
1637 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1638 *
1639 * child - a pointer to the child sysctl table if this entry is a directory, or
1640 * %NULL.
1641 *
1642 * proc_handler - the text handler routine (described below)
1643 *
1644 * strategy - the strategy routine (described below)
1645 *
1646 * de - for internal use by the sysctl routines
1647 *
1648 * extra1, extra2 - extra pointers usable by the proc handler routines
1649 *
1650 * Leaf nodes in the sysctl tree will be represented by a single file
1651 * under /proc; non-leaf nodes will be represented by directories.
1652 *
1653 * sysctl(2) can automatically manage read and write requests through
1654 * the sysctl table. The data and maxlen fields of the ctl_table
1655 * struct enable minimal validation of the values being written to be
1656 * performed, and the mode field allows minimal authentication.
1657 *
1658 * More sophisticated management can be enabled by the provision of a
1659 * strategy routine with the table entry. This will be called before
1660 * any automatic read or write of the data is performed.
1661 *
1662 * The strategy routine may return
1663 *
1664 * < 0 - Error occurred (error is passed to user process)
1665 *
1666 * 0 - OK - proceed with automatic read or write.
1667 *
1668 * > 0 - OK - read or write has been done by the strategy routine, so
1669 * return immediately.
1670 *
1671 * There must be a proc_handler routine for any terminal nodes
1672 * mirrored under /proc/sys (non-terminals are handled by a built-in
1673 * directory handler). Several default handlers are available to
1674 * cover common cases -
1675 *
1676 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1677 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1678 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1679 *
1680 * It is the handler's job to read the input buffer from user memory
1681 * and process it. The handler should return 0 on success.
1682 *
1683 * This routine returns %NULL on a failure to register, and a pointer
1684 * to the table header on success.
1685 */
e51b6ba0
EB
1686struct ctl_table_header *__register_sysctl_paths(
1687 struct ctl_table_root *root,
1688 struct nsproxy *namespaces,
1689 const struct ctl_path *path, struct ctl_table *table)
1da177e4 1690{
e51b6ba0 1691 struct list_head *header_list;
29e796fd
EB
1692 struct ctl_table_header *header;
1693 struct ctl_table *new, **prevp;
1694 unsigned int n, npath;
1695
1696 /* Count the path components */
1697 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1698 ;
1699
1700 /*
1701 * For each path component, allocate a 2-element ctl_table array.
1702 * The first array element will be filled with the sysctl entry
1703 * for this, the second will be the sentinel (ctl_name == 0).
1704 *
1705 * We allocate everything in one go so that we don't have to
1706 * worry about freeing additional memory in unregister_sysctl_table.
1707 */
1708 header = kzalloc(sizeof(struct ctl_table_header) +
1709 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1710 if (!header)
1da177e4 1711 return NULL;
29e796fd
EB
1712
1713 new = (struct ctl_table *) (header + 1);
1714
1715 /* Now connect the dots */
1716 prevp = &header->ctl_table;
1717 for (n = 0; n < npath; ++n, ++path) {
1718 /* Copy the procname */
1719 new->procname = path->procname;
1720 new->ctl_name = path->ctl_name;
1721 new->mode = 0555;
1722
1723 *prevp = new;
1724 prevp = &new->child;
1725
1726 new += 2;
1727 }
1728 *prevp = table;
23eb06de 1729 header->ctl_table_arg = table;
29e796fd
EB
1730
1731 INIT_LIST_HEAD(&header->ctl_entry);
1732 header->used = 0;
1733 header->unregistering = NULL;
e51b6ba0 1734 header->root = root;
29e796fd 1735 sysctl_set_parent(NULL, header->ctl_table);
e51b6ba0 1736 if (sysctl_check_table(namespaces, header->ctl_table)) {
29e796fd 1737 kfree(header);
fc6cd25b
EB
1738 return NULL;
1739 }
330d57fb 1740 spin_lock(&sysctl_lock);
e51b6ba0
EB
1741 header_list = lookup_header_list(root, namespaces);
1742 list_add_tail(&header->ctl_entry, header_list);
330d57fb 1743 spin_unlock(&sysctl_lock);
29e796fd
EB
1744
1745 return header;
1746}
1747
e51b6ba0
EB
1748/**
1749 * register_sysctl_table_path - register a sysctl table hierarchy
1750 * @path: The path to the directory the sysctl table is in.
1751 * @table: the top-level table structure
1752 *
1753 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1754 * array. A completely 0 filled entry terminates the table.
1755 *
1756 * See __register_sysctl_paths for more details.
1757 */
1758struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1759 struct ctl_table *table)
1760{
1761 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1762 path, table);
1763}
1764
29e796fd
EB
1765/**
1766 * register_sysctl_table - register a sysctl table hierarchy
1767 * @table: the top-level table structure
1768 *
1769 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1770 * array. A completely 0 filled entry terminates the table.
1771 *
1772 * See register_sysctl_paths for more details.
1773 */
1774struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1775{
1776 static const struct ctl_path null_path[] = { {} };
1777
1778 return register_sysctl_paths(null_path, table);
1da177e4
LT
1779}
1780
1781/**
1782 * unregister_sysctl_table - unregister a sysctl table hierarchy
1783 * @header: the header returned from register_sysctl_table
1784 *
1785 * Unregisters the sysctl table and all children. proc entries may not
1786 * actually be removed until they are no longer used by anyone.
1787 */
1788void unregister_sysctl_table(struct ctl_table_header * header)
1789{
330d57fb 1790 might_sleep();
f1dad166
PE
1791
1792 if (header == NULL)
1793 return;
1794
330d57fb
AV
1795 spin_lock(&sysctl_lock);
1796 start_unregistering(header);
330d57fb 1797 spin_unlock(&sysctl_lock);
1da177e4
LT
1798 kfree(header);
1799}
1800
b89a8171 1801#else /* !CONFIG_SYSCTL */
d8217f07 1802struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
b89a8171
EB
1803{
1804 return NULL;
1805}
1806
29e796fd
EB
1807struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1808 struct ctl_table *table)
1809{
1810 return NULL;
1811}
1812
b89a8171
EB
1813void unregister_sysctl_table(struct ctl_table_header * table)
1814{
1815}
1816
1817#endif /* CONFIG_SYSCTL */
1818
1da177e4
LT
1819/*
1820 * /proc/sys support
1821 */
1822
b89a8171 1823#ifdef CONFIG_PROC_SYSCTL
1da177e4 1824
b1ba4ddd
AB
1825static int _proc_do_string(void* data, int maxlen, int write,
1826 struct file *filp, void __user *buffer,
1827 size_t *lenp, loff_t *ppos)
1da177e4
LT
1828{
1829 size_t len;
1830 char __user *p;
1831 char c;
8d060877
ON
1832
1833 if (!data || !maxlen || !*lenp) {
1da177e4
LT
1834 *lenp = 0;
1835 return 0;
1836 }
8d060877 1837
1da177e4
LT
1838 if (write) {
1839 len = 0;
1840 p = buffer;
1841 while (len < *lenp) {
1842 if (get_user(c, p++))
1843 return -EFAULT;
1844 if (c == 0 || c == '\n')
1845 break;
1846 len++;
1847 }
f5dd3d6f
SV
1848 if (len >= maxlen)
1849 len = maxlen-1;
1850 if(copy_from_user(data, buffer, len))
1da177e4 1851 return -EFAULT;
f5dd3d6f 1852 ((char *) data)[len] = 0;
1da177e4
LT
1853 *ppos += *lenp;
1854 } else {
f5dd3d6f
SV
1855 len = strlen(data);
1856 if (len > maxlen)
1857 len = maxlen;
8d060877
ON
1858
1859 if (*ppos > len) {
1860 *lenp = 0;
1861 return 0;
1862 }
1863
1864 data += *ppos;
1865 len -= *ppos;
1866
1da177e4
LT
1867 if (len > *lenp)
1868 len = *lenp;
1869 if (len)
f5dd3d6f 1870 if(copy_to_user(buffer, data, len))
1da177e4
LT
1871 return -EFAULT;
1872 if (len < *lenp) {
1873 if(put_user('\n', ((char __user *) buffer) + len))
1874 return -EFAULT;
1875 len++;
1876 }
1877 *lenp = len;
1878 *ppos += len;
1879 }
1880 return 0;
1881}
1882
f5dd3d6f
SV
1883/**
1884 * proc_dostring - read a string sysctl
1885 * @table: the sysctl table
1886 * @write: %TRUE if this is a write to the sysctl file
1887 * @filp: the file structure
1888 * @buffer: the user buffer
1889 * @lenp: the size of the user buffer
1890 * @ppos: file position
1891 *
1892 * Reads/writes a string from/to the user buffer. If the kernel
1893 * buffer provided is not large enough to hold the string, the
1894 * string is truncated. The copied string is %NULL-terminated.
1895 * If the string is being read by the user process, it is copied
1896 * and a newline '\n' is added. It is truncated if the buffer is
1897 * not large enough.
1898 *
1899 * Returns 0 on success.
1900 */
d8217f07 1901int proc_dostring(struct ctl_table *table, int write, struct file *filp,
f5dd3d6f
SV
1902 void __user *buffer, size_t *lenp, loff_t *ppos)
1903{
1904 return _proc_do_string(table->data, table->maxlen, write, filp,
1905 buffer, lenp, ppos);
1906}
1907
1da177e4
LT
1908
1909static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1910 int *valp,
1911 int write, void *data)
1912{
1913 if (write) {
1914 *valp = *negp ? -*lvalp : *lvalp;
1915 } else {
1916 int val = *valp;
1917 if (val < 0) {
1918 *negp = -1;
1919 *lvalp = (unsigned long)-val;
1920 } else {
1921 *negp = 0;
1922 *lvalp = (unsigned long)val;
1923 }
1924 }
1925 return 0;
1926}
1927
d8217f07 1928static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
fcfbd547
KK
1929 int write, struct file *filp, void __user *buffer,
1930 size_t *lenp, loff_t *ppos,
1da177e4
LT
1931 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1932 int write, void *data),
1933 void *data)
1934{
1935#define TMPBUFLEN 21
1936 int *i, vleft, first=1, neg, val;
1937 unsigned long lval;
1938 size_t left, len;
1939
1940 char buf[TMPBUFLEN], *p;
1941 char __user *s = buffer;
1942
fcfbd547 1943 if (!tbl_data || !table->maxlen || !*lenp ||
1da177e4
LT
1944 (*ppos && !write)) {
1945 *lenp = 0;
1946 return 0;
1947 }
1948
fcfbd547 1949 i = (int *) tbl_data;
1da177e4
LT
1950 vleft = table->maxlen / sizeof(*i);
1951 left = *lenp;
1952
1953 if (!conv)
1954 conv = do_proc_dointvec_conv;
1955
1956 for (; left && vleft--; i++, first=0) {
1957 if (write) {
1958 while (left) {
1959 char c;
1960 if (get_user(c, s))
1961 return -EFAULT;
1962 if (!isspace(c))
1963 break;
1964 left--;
1965 s++;
1966 }
1967 if (!left)
1968 break;
1969 neg = 0;
1970 len = left;
1971 if (len > sizeof(buf) - 1)
1972 len = sizeof(buf) - 1;
1973 if (copy_from_user(buf, s, len))
1974 return -EFAULT;
1975 buf[len] = 0;
1976 p = buf;
1977 if (*p == '-' && left > 1) {
1978 neg = 1;
bd9b0bac 1979 p++;
1da177e4
LT
1980 }
1981 if (*p < '0' || *p > '9')
1982 break;
1983
1984 lval = simple_strtoul(p, &p, 0);
1985
1986 len = p-buf;
1987 if ((len < left) && *p && !isspace(*p))
1988 break;
1989 if (neg)
1990 val = -val;
1991 s += len;
1992 left -= len;
1993
1994 if (conv(&neg, &lval, i, 1, data))
1995 break;
1996 } else {
1997 p = buf;
1998 if (!first)
1999 *p++ = '\t';
2000
2001 if (conv(&neg, &lval, i, 0, data))
2002 break;
2003
2004 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2005 len = strlen(buf);
2006 if (len > left)
2007 len = left;
2008 if(copy_to_user(s, buf, len))
2009 return -EFAULT;
2010 left -= len;
2011 s += len;
2012 }
2013 }
2014
2015 if (!write && !first && left) {
2016 if(put_user('\n', s))
2017 return -EFAULT;
2018 left--, s++;
2019 }
2020 if (write) {
2021 while (left) {
2022 char c;
2023 if (get_user(c, s++))
2024 return -EFAULT;
2025 if (!isspace(c))
2026 break;
2027 left--;
2028 }
2029 }
2030 if (write && first)
2031 return -EINVAL;
2032 *lenp -= left;
2033 *ppos += *lenp;
2034 return 0;
2035#undef TMPBUFLEN
2036}
2037
d8217f07 2038static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
fcfbd547
KK
2039 void __user *buffer, size_t *lenp, loff_t *ppos,
2040 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2041 int write, void *data),
2042 void *data)
2043{
2044 return __do_proc_dointvec(table->data, table, write, filp,
2045 buffer, lenp, ppos, conv, data);
2046}
2047
1da177e4
LT
2048/**
2049 * proc_dointvec - read a vector of integers
2050 * @table: the sysctl table
2051 * @write: %TRUE if this is a write to the sysctl file
2052 * @filp: the file structure
2053 * @buffer: the user buffer
2054 * @lenp: the size of the user buffer
2055 * @ppos: file position
2056 *
2057 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2058 * values from/to the user buffer, treated as an ASCII string.
2059 *
2060 * Returns 0 on success.
2061 */
d8217f07 2062int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2063 void __user *buffer, size_t *lenp, loff_t *ppos)
2064{
2065 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2066 NULL,NULL);
2067}
2068
2069#define OP_SET 0
2070#define OP_AND 1
34f5a398 2071#define OP_OR 2
1da177e4
LT
2072
2073static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2074 int *valp,
2075 int write, void *data)
2076{
2077 int op = *(int *)data;
2078 if (write) {
2079 int val = *negp ? -*lvalp : *lvalp;
2080 switch(op) {
2081 case OP_SET: *valp = val; break;
2082 case OP_AND: *valp &= val; break;
34f5a398 2083 case OP_OR: *valp |= val; break;
1da177e4
LT
2084 }
2085 } else {
2086 int val = *valp;
2087 if (val < 0) {
2088 *negp = -1;
2089 *lvalp = (unsigned long)-val;
2090 } else {
2091 *negp = 0;
2092 *lvalp = (unsigned long)val;
2093 }
2094 }
2095 return 0;
2096}
2097
34f5a398
TT
2098/*
2099 * Taint values can only be increased
2100 */
d8217f07 2101static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
34f5a398
TT
2102 void __user *buffer, size_t *lenp, loff_t *ppos)
2103{
2104 int op;
2105
91fcd412 2106 if (write && !capable(CAP_SYS_ADMIN))
34f5a398
TT
2107 return -EPERM;
2108
2109 op = OP_OR;
2110 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2111 do_proc_dointvec_bset_conv,&op);
2112}
2113
1da177e4
LT
2114struct do_proc_dointvec_minmax_conv_param {
2115 int *min;
2116 int *max;
2117};
2118
2119static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2120 int *valp,
2121 int write, void *data)
2122{
2123 struct do_proc_dointvec_minmax_conv_param *param = data;
2124 if (write) {
2125 int val = *negp ? -*lvalp : *lvalp;
2126 if ((param->min && *param->min > val) ||
2127 (param->max && *param->max < val))
2128 return -EINVAL;
2129 *valp = val;
2130 } else {
2131 int val = *valp;
2132 if (val < 0) {
2133 *negp = -1;
2134 *lvalp = (unsigned long)-val;
2135 } else {
2136 *negp = 0;
2137 *lvalp = (unsigned long)val;
2138 }
2139 }
2140 return 0;
2141}
2142
2143/**
2144 * proc_dointvec_minmax - read a vector of integers with min/max values
2145 * @table: the sysctl table
2146 * @write: %TRUE if this is a write to the sysctl file
2147 * @filp: the file structure
2148 * @buffer: the user buffer
2149 * @lenp: the size of the user buffer
2150 * @ppos: file position
2151 *
2152 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2153 * values from/to the user buffer, treated as an ASCII string.
2154 *
2155 * This routine will ensure the values are within the range specified by
2156 * table->extra1 (min) and table->extra2 (max).
2157 *
2158 * Returns 0 on success.
2159 */
d8217f07 2160int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2161 void __user *buffer, size_t *lenp, loff_t *ppos)
2162{
2163 struct do_proc_dointvec_minmax_conv_param param = {
2164 .min = (int *) table->extra1,
2165 .max = (int *) table->extra2,
2166 };
2167 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2168 do_proc_dointvec_minmax_conv, &param);
2169}
2170
d8217f07 2171static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1da177e4
LT
2172 struct file *filp,
2173 void __user *buffer,
2174 size_t *lenp, loff_t *ppos,
2175 unsigned long convmul,
2176 unsigned long convdiv)
2177{
2178#define TMPBUFLEN 21
2179 unsigned long *i, *min, *max, val;
2180 int vleft, first=1, neg;
2181 size_t len, left;
2182 char buf[TMPBUFLEN], *p;
2183 char __user *s = buffer;
2184
fcfbd547 2185 if (!data || !table->maxlen || !*lenp ||
1da177e4
LT
2186 (*ppos && !write)) {
2187 *lenp = 0;
2188 return 0;
2189 }
2190
fcfbd547 2191 i = (unsigned long *) data;
1da177e4
LT
2192 min = (unsigned long *) table->extra1;
2193 max = (unsigned long *) table->extra2;
2194 vleft = table->maxlen / sizeof(unsigned long);
2195 left = *lenp;
2196
2197 for (; left && vleft--; i++, min++, max++, first=0) {
2198 if (write) {
2199 while (left) {
2200 char c;
2201 if (get_user(c, s))
2202 return -EFAULT;
2203 if (!isspace(c))
2204 break;
2205 left--;
2206 s++;
2207 }
2208 if (!left)
2209 break;
2210 neg = 0;
2211 len = left;
2212 if (len > TMPBUFLEN-1)
2213 len = TMPBUFLEN-1;
2214 if (copy_from_user(buf, s, len))
2215 return -EFAULT;
2216 buf[len] = 0;
2217 p = buf;
2218 if (*p == '-' && left > 1) {
2219 neg = 1;
bd9b0bac 2220 p++;
1da177e4
LT
2221 }
2222 if (*p < '0' || *p > '9')
2223 break;
2224 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2225 len = p-buf;
2226 if ((len < left) && *p && !isspace(*p))
2227 break;
2228 if (neg)
2229 val = -val;
2230 s += len;
2231 left -= len;
2232
2233 if(neg)
2234 continue;
2235 if ((min && val < *min) || (max && val > *max))
2236 continue;
2237 *i = val;
2238 } else {
2239 p = buf;
2240 if (!first)
2241 *p++ = '\t';
2242 sprintf(p, "%lu", convdiv * (*i) / convmul);
2243 len = strlen(buf);
2244 if (len > left)
2245 len = left;
2246 if(copy_to_user(s, buf, len))
2247 return -EFAULT;
2248 left -= len;
2249 s += len;
2250 }
2251 }
2252
2253 if (!write && !first && left) {
2254 if(put_user('\n', s))
2255 return -EFAULT;
2256 left--, s++;
2257 }
2258 if (write) {
2259 while (left) {
2260 char c;
2261 if (get_user(c, s++))
2262 return -EFAULT;
2263 if (!isspace(c))
2264 break;
2265 left--;
2266 }
2267 }
2268 if (write && first)
2269 return -EINVAL;
2270 *lenp -= left;
2271 *ppos += *lenp;
2272 return 0;
2273#undef TMPBUFLEN
2274}
2275
d8217f07 2276static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
fcfbd547
KK
2277 struct file *filp,
2278 void __user *buffer,
2279 size_t *lenp, loff_t *ppos,
2280 unsigned long convmul,
2281 unsigned long convdiv)
2282{
2283 return __do_proc_doulongvec_minmax(table->data, table, write,
2284 filp, buffer, lenp, ppos, convmul, convdiv);
2285}
2286
1da177e4
LT
2287/**
2288 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2289 * @table: the sysctl table
2290 * @write: %TRUE if this is a write to the sysctl file
2291 * @filp: the file structure
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.
2298 *
2299 * This routine will ensure the values are within the range specified by
2300 * table->extra1 (min) and table->extra2 (max).
2301 *
2302 * Returns 0 on success.
2303 */
d8217f07 2304int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2306{
2307 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2308}
2309
2310/**
2311 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
2317 * @ppos: file position
2318 *
2319 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2320 * values from/to the user buffer, treated as an ASCII string. The values
2321 * are treated as milliseconds, and converted to jiffies when they are stored.
2322 *
2323 * This routine will ensure the values are within the range specified by
2324 * table->extra1 (min) and table->extra2 (max).
2325 *
2326 * Returns 0 on success.
2327 */
d8217f07 2328int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2329 struct file *filp,
2330 void __user *buffer,
2331 size_t *lenp, loff_t *ppos)
2332{
2333 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2334 lenp, ppos, HZ, 1000l);
2335}
2336
2337
2338static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2339 int *valp,
2340 int write, void *data)
2341{
2342 if (write) {
cba9f33d
BS
2343 if (*lvalp > LONG_MAX / HZ)
2344 return 1;
1da177e4
LT
2345 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2346 } else {
2347 int val = *valp;
2348 unsigned long lval;
2349 if (val < 0) {
2350 *negp = -1;
2351 lval = (unsigned long)-val;
2352 } else {
2353 *negp = 0;
2354 lval = (unsigned long)val;
2355 }
2356 *lvalp = lval / HZ;
2357 }
2358 return 0;
2359}
2360
2361static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2362 int *valp,
2363 int write, void *data)
2364{
2365 if (write) {
cba9f33d
BS
2366 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2367 return 1;
1da177e4
LT
2368 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2369 } else {
2370 int val = *valp;
2371 unsigned long lval;
2372 if (val < 0) {
2373 *negp = -1;
2374 lval = (unsigned long)-val;
2375 } else {
2376 *negp = 0;
2377 lval = (unsigned long)val;
2378 }
2379 *lvalp = jiffies_to_clock_t(lval);
2380 }
2381 return 0;
2382}
2383
2384static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2385 int *valp,
2386 int write, void *data)
2387{
2388 if (write) {
2389 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2390 } else {
2391 int val = *valp;
2392 unsigned long lval;
2393 if (val < 0) {
2394 *negp = -1;
2395 lval = (unsigned long)-val;
2396 } else {
2397 *negp = 0;
2398 lval = (unsigned long)val;
2399 }
2400 *lvalp = jiffies_to_msecs(lval);
2401 }
2402 return 0;
2403}
2404
2405/**
2406 * proc_dointvec_jiffies - read a vector of integers as seconds
2407 * @table: the sysctl table
2408 * @write: %TRUE if this is a write to the sysctl file
2409 * @filp: the file structure
2410 * @buffer: the user buffer
2411 * @lenp: the size of the user buffer
2412 * @ppos: file position
2413 *
2414 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2415 * values from/to the user buffer, treated as an ASCII string.
2416 * The values read are assumed to be in seconds, and are converted into
2417 * jiffies.
2418 *
2419 * Returns 0 on success.
2420 */
d8217f07 2421int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2422 void __user *buffer, size_t *lenp, loff_t *ppos)
2423{
2424 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2425 do_proc_dointvec_jiffies_conv,NULL);
2426}
2427
2428/**
2429 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2430 * @table: the sysctl table
2431 * @write: %TRUE if this is a write to the sysctl file
2432 * @filp: the file structure
2433 * @buffer: the user buffer
2434 * @lenp: the size of the user buffer
1e5d5331 2435 * @ppos: pointer to the file position
1da177e4
LT
2436 *
2437 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2438 * values from/to the user buffer, treated as an ASCII string.
2439 * The values read are assumed to be in 1/USER_HZ seconds, and
2440 * are converted into jiffies.
2441 *
2442 * Returns 0 on success.
2443 */
d8217f07 2444int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2446{
2447 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2448 do_proc_dointvec_userhz_jiffies_conv,NULL);
2449}
2450
2451/**
2452 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2453 * @table: the sysctl table
2454 * @write: %TRUE if this is a write to the sysctl file
2455 * @filp: the file structure
2456 * @buffer: the user buffer
2457 * @lenp: the size of the user buffer
67be2dd1
MW
2458 * @ppos: file position
2459 * @ppos: the current position in the file
1da177e4
LT
2460 *
2461 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2462 * values from/to the user buffer, treated as an ASCII string.
2463 * The values read are assumed to be in 1/1000 seconds, and
2464 * are converted into jiffies.
2465 *
2466 * Returns 0 on success.
2467 */
d8217f07 2468int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2469 void __user *buffer, size_t *lenp, loff_t *ppos)
2470{
2471 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2472 do_proc_dointvec_ms_jiffies_conv, NULL);
2473}
2474
d8217f07 2475static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
9ec52099
CLG
2476 void __user *buffer, size_t *lenp, loff_t *ppos)
2477{
2478 struct pid *new_pid;
2479 pid_t tmp;
2480 int r;
2481
b488893a 2482 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
9ec52099
CLG
2483
2484 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2485 lenp, ppos, NULL, NULL);
2486 if (r || !write)
2487 return r;
2488
2489 new_pid = find_get_pid(tmp);
2490 if (!new_pid)
2491 return -ESRCH;
2492
2493 put_pid(xchg(&cad_pid, new_pid));
2494 return 0;
2495}
2496
1da177e4
LT
2497#else /* CONFIG_PROC_FS */
2498
d8217f07 2499int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2500 void __user *buffer, size_t *lenp, loff_t *ppos)
2501{
2502 return -ENOSYS;
2503}
2504
d8217f07 2505int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1da177e4 2506 void __user *buffer, size_t *lenp, loff_t *ppos)
1da177e4
LT
2507{
2508 return -ENOSYS;
2509}
2510
d8217f07 2511int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2512 void __user *buffer, size_t *lenp, loff_t *ppos)
2513{
2514 return -ENOSYS;
2515}
2516
d8217f07 2517int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2518 void __user *buffer, size_t *lenp, loff_t *ppos)
2519{
2520 return -ENOSYS;
2521}
2522
d8217f07 2523int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2524 void __user *buffer, size_t *lenp, loff_t *ppos)
2525{
2526 return -ENOSYS;
2527}
2528
d8217f07 2529int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2530 void __user *buffer, size_t *lenp, loff_t *ppos)
2531{
2532 return -ENOSYS;
2533}
2534
d8217f07 2535int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
1da177e4
LT
2536 void __user *buffer, size_t *lenp, loff_t *ppos)
2537{
2538 return -ENOSYS;
2539}
2540
d8217f07 2541int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1da177e4
LT
2542 struct file *filp,
2543 void __user *buffer,
2544 size_t *lenp, loff_t *ppos)
2545{
2546 return -ENOSYS;
2547}
2548
2549
2550#endif /* CONFIG_PROC_FS */
2551
2552
b89a8171 2553#ifdef CONFIG_SYSCTL_SYSCALL
1da177e4
LT
2554/*
2555 * General sysctl support routines
2556 */
2557
49a0c458
EB
2558/* The generic sysctl data routine (used if no strategy routine supplied) */
2559int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2560 void __user *oldval, size_t __user *oldlenp,
2561 void __user *newval, size_t newlen)
2562{
2563 size_t len;
2564
2565 /* Get out of I don't have a variable */
2566 if (!table->data || !table->maxlen)
2567 return -ENOTDIR;
2568
2569 if (oldval && oldlenp) {
2570 if (get_user(len, oldlenp))
2571 return -EFAULT;
2572 if (len) {
2573 if (len > table->maxlen)
2574 len = table->maxlen;
2575 if (copy_to_user(oldval, table->data, len))
2576 return -EFAULT;
2577 if (put_user(len, oldlenp))
2578 return -EFAULT;
2579 }
2580 }
2581
2582 if (newval && newlen) {
2583 if (newlen > table->maxlen)
2584 newlen = table->maxlen;
2585
2586 if (copy_from_user(table->data, newval, newlen))
2587 return -EFAULT;
2588 }
2589 return 1;
2590}
2591
1da177e4 2592/* The generic string strategy routine: */
d8217f07 2593int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2594 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2595 void __user *newval, size_t newlen)
1da177e4 2596{
1da177e4
LT
2597 if (!table->data || !table->maxlen)
2598 return -ENOTDIR;
2599
2600 if (oldval && oldlenp) {
de9e007d
LT
2601 size_t bufsize;
2602 if (get_user(bufsize, oldlenp))
1da177e4 2603 return -EFAULT;
de9e007d
LT
2604 if (bufsize) {
2605 size_t len = strlen(table->data), copied;
2606
2607 /* This shouldn't trigger for a well-formed sysctl */
2608 if (len > table->maxlen)
1da177e4 2609 len = table->maxlen;
de9e007d
LT
2610
2611 /* Copy up to a max of bufsize-1 bytes of the string */
2612 copied = (len >= bufsize) ? bufsize - 1 : len;
2613
2614 if (copy_to_user(oldval, table->data, copied) ||
2615 put_user(0, (char __user *)(oldval + copied)))
1da177e4 2616 return -EFAULT;
de9e007d 2617 if (put_user(len, oldlenp))
1da177e4
LT
2618 return -EFAULT;
2619 }
2620 }
2621 if (newval && newlen) {
de9e007d 2622 size_t len = newlen;
1da177e4
LT
2623 if (len > table->maxlen)
2624 len = table->maxlen;
2625 if(copy_from_user(table->data, newval, len))
2626 return -EFAULT;
2627 if (len == table->maxlen)
2628 len--;
2629 ((char *) table->data)[len] = 0;
2630 }
82c9df82 2631 return 1;
1da177e4
LT
2632}
2633
2634/*
2635 * This function makes sure that all of the integers in the vector
2636 * are between the minimum and maximum values given in the arrays
2637 * table->extra1 and table->extra2, respectively.
2638 */
d8217f07 2639int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2640 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2641 void __user *newval, size_t newlen)
1da177e4
LT
2642{
2643
2644 if (newval && newlen) {
2645 int __user *vec = (int __user *) newval;
2646 int *min = (int *) table->extra1;
2647 int *max = (int *) table->extra2;
2648 size_t length;
2649 int i;
2650
2651 if (newlen % sizeof(int) != 0)
2652 return -EINVAL;
2653
2654 if (!table->extra1 && !table->extra2)
2655 return 0;
2656
2657 if (newlen > table->maxlen)
2658 newlen = table->maxlen;
2659 length = newlen / sizeof(int);
2660
2661 for (i = 0; i < length; i++) {
2662 int value;
2663 if (get_user(value, vec + i))
2664 return -EFAULT;
2665 if (min && value < min[i])
2666 return -EINVAL;
2667 if (max && value > max[i])
2668 return -EINVAL;
2669 }
2670 }
2671 return 0;
2672}
2673
2674/* Strategy function to convert jiffies to seconds */
d8217f07 2675int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2676 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2677 void __user *newval, size_t newlen)
1da177e4 2678{
3ee75ac3 2679 if (oldval && oldlenp) {
1da177e4 2680 size_t olen;
3ee75ac3
AD
2681
2682 if (get_user(olen, oldlenp))
2683 return -EFAULT;
2684 if (olen) {
2685 int val;
2686
2687 if (olen < sizeof(int))
2688 return -EINVAL;
2689
2690 val = *(int *)(table->data) / HZ;
2691 if (put_user(val, (int __user *)oldval))
2692 return -EFAULT;
2693 if (put_user(sizeof(int), oldlenp))
1da177e4 2694 return -EFAULT;
1da177e4 2695 }
1da177e4
LT
2696 }
2697 if (newval && newlen) {
2698 int new;
2699 if (newlen != sizeof(int))
2700 return -EINVAL;
2701 if (get_user(new, (int __user *)newval))
2702 return -EFAULT;
2703 *(int *)(table->data) = new*HZ;
2704 }
2705 return 1;
2706}
2707
2708/* Strategy function to convert jiffies to seconds */
d8217f07 2709int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2710 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2711 void __user *newval, size_t newlen)
1da177e4 2712{
3ee75ac3 2713 if (oldval && oldlenp) {
1da177e4 2714 size_t olen;
3ee75ac3
AD
2715
2716 if (get_user(olen, oldlenp))
2717 return -EFAULT;
2718 if (olen) {
2719 int val;
2720
2721 if (olen < sizeof(int))
2722 return -EINVAL;
2723
2724 val = jiffies_to_msecs(*(int *)(table->data));
2725 if (put_user(val, (int __user *)oldval))
2726 return -EFAULT;
2727 if (put_user(sizeof(int), oldlenp))
1da177e4 2728 return -EFAULT;
1da177e4 2729 }
1da177e4
LT
2730 }
2731 if (newval && newlen) {
2732 int new;
2733 if (newlen != sizeof(int))
2734 return -EINVAL;
2735 if (get_user(new, (int __user *)newval))
2736 return -EFAULT;
2737 *(int *)(table->data) = msecs_to_jiffies(new);
2738 }
2739 return 1;
2740}
2741
c4b8b769 2742
c4b8b769 2743
b89a8171 2744#else /* CONFIG_SYSCTL_SYSCALL */
1da177e4
LT
2745
2746
2747asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2748{
0e009be8 2749 struct __sysctl_args tmp;
7058cb02 2750 int error;
0e009be8 2751
0e009be8
EB
2752 if (copy_from_user(&tmp, args, sizeof(tmp)))
2753 return -EFAULT;
0e009be8 2754
7058cb02 2755 error = deprecated_sysctl_warning(&tmp);
b89a8171 2756
7058cb02
EB
2757 /* If no error reading the parameters then just -ENOSYS ... */
2758 if (!error)
2759 error = -ENOSYS;
2760
2761 return error;
1da177e4
LT
2762}
2763
49a0c458
EB
2764int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2765 void __user *oldval, size_t __user *oldlenp,
2766 void __user *newval, size_t newlen)
2767{
2768 return -ENOSYS;
2769}
2770
d8217f07 2771int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2772 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2773 void __user *newval, size_t newlen)
1da177e4
LT
2774{
2775 return -ENOSYS;
2776}
2777
d8217f07 2778int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2779 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2780 void __user *newval, size_t newlen)
1da177e4
LT
2781{
2782 return -ENOSYS;
2783}
2784
d8217f07 2785int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2786 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2787 void __user *newval, size_t newlen)
1da177e4
LT
2788{
2789 return -ENOSYS;
2790}
2791
d8217f07 2792int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
1da177e4 2793 void __user *oldval, size_t __user *oldlenp,
1f29bcd7 2794 void __user *newval, size_t newlen)
1da177e4
LT
2795{
2796 return -ENOSYS;
2797}
2798
b89a8171 2799#endif /* CONFIG_SYSCTL_SYSCALL */
1da177e4 2800
7058cb02
EB
2801static int deprecated_sysctl_warning(struct __sysctl_args *args)
2802{
2803 static int msg_count;
2804 int name[CTL_MAXNAME];
2805 int i;
2806
6fc48af8
TH
2807 /* Check args->nlen. */
2808 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2809 return -ENOTDIR;
2810
7058cb02
EB
2811 /* Read in the sysctl name for better debug message logging */
2812 for (i = 0; i < args->nlen; i++)
2813 if (get_user(name[i], args->name + i))
2814 return -EFAULT;
2815
2816 /* Ignore accesses to kernel.version */
2817 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2818 return 0;
2819
2820 if (msg_count < 5) {
2821 msg_count++;
2822 printk(KERN_INFO
2823 "warning: process `%s' used the deprecated sysctl "
2824 "system call with ", current->comm);
2825 for (i = 0; i < args->nlen; i++)
2826 printk("%d.", name[i]);
2827 printk("\n");
2828 }
2829 return 0;
2830}
2831
1da177e4
LT
2832/*
2833 * No sense putting this after each symbol definition, twice,
2834 * exception granted :-)
2835 */
2836EXPORT_SYMBOL(proc_dointvec);
2837EXPORT_SYMBOL(proc_dointvec_jiffies);
2838EXPORT_SYMBOL(proc_dointvec_minmax);
2839EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2840EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2841EXPORT_SYMBOL(proc_dostring);
2842EXPORT_SYMBOL(proc_doulongvec_minmax);
2843EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2844EXPORT_SYMBOL(register_sysctl_table);
29e796fd 2845EXPORT_SYMBOL(register_sysctl_paths);
1da177e4
LT
2846EXPORT_SYMBOL(sysctl_intvec);
2847EXPORT_SYMBOL(sysctl_jiffies);
2848EXPORT_SYMBOL(sysctl_ms_jiffies);
2849EXPORT_SYMBOL(sysctl_string);
49a0c458 2850EXPORT_SYMBOL(sysctl_data);
1da177e4 2851EXPORT_SYMBOL(unregister_sysctl_table);