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