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