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