]>
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 | ||
2abc26fc EB |
884 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
885 | static ctl_table binfmt_misc_table[] = { | |
886 | { .ctl_name = 0 } | |
887 | }; | |
888 | #endif | |
889 | ||
1da177e4 LT |
890 | static ctl_table fs_table[] = { |
891 | { | |
892 | .ctl_name = FS_NRINODE, | |
893 | .procname = "inode-nr", | |
894 | .data = &inodes_stat, | |
895 | .maxlen = 2*sizeof(int), | |
896 | .mode = 0444, | |
897 | .proc_handler = &proc_dointvec, | |
898 | }, | |
899 | { | |
900 | .ctl_name = FS_STATINODE, | |
901 | .procname = "inode-state", | |
902 | .data = &inodes_stat, | |
903 | .maxlen = 7*sizeof(int), | |
904 | .mode = 0444, | |
905 | .proc_handler = &proc_dointvec, | |
906 | }, | |
907 | { | |
908 | .ctl_name = FS_NRFILE, | |
909 | .procname = "file-nr", | |
910 | .data = &files_stat, | |
911 | .maxlen = 3*sizeof(int), | |
912 | .mode = 0444, | |
529bf6be | 913 | .proc_handler = &proc_nr_files, |
1da177e4 LT |
914 | }, |
915 | { | |
916 | .ctl_name = FS_MAXFILE, | |
917 | .procname = "file-max", | |
918 | .data = &files_stat.max_files, | |
919 | .maxlen = sizeof(int), | |
920 | .mode = 0644, | |
921 | .proc_handler = &proc_dointvec, | |
922 | }, | |
923 | { | |
924 | .ctl_name = FS_DENTRY, | |
925 | .procname = "dentry-state", | |
926 | .data = &dentry_stat, | |
927 | .maxlen = 6*sizeof(int), | |
928 | .mode = 0444, | |
929 | .proc_handler = &proc_dointvec, | |
930 | }, | |
931 | { | |
932 | .ctl_name = FS_OVERFLOWUID, | |
933 | .procname = "overflowuid", | |
934 | .data = &fs_overflowuid, | |
935 | .maxlen = sizeof(int), | |
936 | .mode = 0644, | |
937 | .proc_handler = &proc_dointvec_minmax, | |
938 | .strategy = &sysctl_intvec, | |
939 | .extra1 = &minolduid, | |
940 | .extra2 = &maxolduid, | |
941 | }, | |
942 | { | |
943 | .ctl_name = FS_OVERFLOWGID, | |
944 | .procname = "overflowgid", | |
945 | .data = &fs_overflowgid, | |
946 | .maxlen = sizeof(int), | |
947 | .mode = 0644, | |
948 | .proc_handler = &proc_dointvec_minmax, | |
949 | .strategy = &sysctl_intvec, | |
950 | .extra1 = &minolduid, | |
951 | .extra2 = &maxolduid, | |
952 | }, | |
953 | { | |
954 | .ctl_name = FS_LEASES, | |
955 | .procname = "leases-enable", | |
956 | .data = &leases_enable, | |
957 | .maxlen = sizeof(int), | |
958 | .mode = 0644, | |
959 | .proc_handler = &proc_dointvec, | |
960 | }, | |
961 | #ifdef CONFIG_DNOTIFY | |
962 | { | |
963 | .ctl_name = FS_DIR_NOTIFY, | |
964 | .procname = "dir-notify-enable", | |
965 | .data = &dir_notify_enable, | |
966 | .maxlen = sizeof(int), | |
967 | .mode = 0644, | |
968 | .proc_handler = &proc_dointvec, | |
969 | }, | |
970 | #endif | |
971 | #ifdef CONFIG_MMU | |
972 | { | |
973 | .ctl_name = FS_LEASE_TIME, | |
974 | .procname = "lease-break-time", | |
975 | .data = &lease_break_time, | |
976 | .maxlen = sizeof(int), | |
977 | .mode = 0644, | |
978 | .proc_handler = &proc_dointvec, | |
979 | }, | |
980 | { | |
981 | .ctl_name = FS_AIO_NR, | |
982 | .procname = "aio-nr", | |
983 | .data = &aio_nr, | |
984 | .maxlen = sizeof(aio_nr), | |
985 | .mode = 0444, | |
d55b5fda | 986 | .proc_handler = &proc_doulongvec_minmax, |
1da177e4 LT |
987 | }, |
988 | { | |
989 | .ctl_name = FS_AIO_MAX_NR, | |
990 | .procname = "aio-max-nr", | |
991 | .data = &aio_max_nr, | |
992 | .maxlen = sizeof(aio_max_nr), | |
993 | .mode = 0644, | |
d55b5fda | 994 | .proc_handler = &proc_doulongvec_minmax, |
1da177e4 | 995 | }, |
2d9048e2 | 996 | #ifdef CONFIG_INOTIFY_USER |
0399cb08 RL |
997 | { |
998 | .ctl_name = FS_INOTIFY, | |
999 | .procname = "inotify", | |
1000 | .mode = 0555, | |
1001 | .child = inotify_table, | |
1002 | }, | |
1003 | #endif | |
1da177e4 | 1004 | #endif |
d6e71144 AC |
1005 | { |
1006 | .ctl_name = KERN_SETUID_DUMPABLE, | |
1007 | .procname = "suid_dumpable", | |
1008 | .data = &suid_dumpable, | |
1009 | .maxlen = sizeof(int), | |
1010 | .mode = 0644, | |
1011 | .proc_handler = &proc_dointvec, | |
1012 | }, | |
2abc26fc EB |
1013 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
1014 | { | |
1015 | .ctl_name = CTL_UNNUMBERED, | |
1016 | .procname = "binfmt_misc", | |
1017 | .mode = 0555, | |
1018 | .child = binfmt_misc_table, | |
1019 | }, | |
1020 | #endif | |
1da177e4 LT |
1021 | { .ctl_name = 0 } |
1022 | }; | |
1023 | ||
1024 | static ctl_table debug_table[] = { | |
1025 | { .ctl_name = 0 } | |
1026 | }; | |
1027 | ||
1028 | static ctl_table dev_table[] = { | |
1029 | { .ctl_name = 0 } | |
0eeca283 | 1030 | }; |
1da177e4 | 1031 | |
330d57fb AV |
1032 | static DEFINE_SPINLOCK(sysctl_lock); |
1033 | ||
1034 | /* called under sysctl_lock */ | |
1035 | static int use_table(struct ctl_table_header *p) | |
1036 | { | |
1037 | if (unlikely(p->unregistering)) | |
1038 | return 0; | |
1039 | p->used++; | |
1040 | return 1; | |
1041 | } | |
1042 | ||
1043 | /* called under sysctl_lock */ | |
1044 | static void unuse_table(struct ctl_table_header *p) | |
1045 | { | |
1046 | if (!--p->used) | |
1047 | if (unlikely(p->unregistering)) | |
1048 | complete(p->unregistering); | |
1049 | } | |
1050 | ||
1051 | /* called under sysctl_lock, will reacquire if has to wait */ | |
1052 | static void start_unregistering(struct ctl_table_header *p) | |
1053 | { | |
1054 | /* | |
1055 | * if p->used is 0, nobody will ever touch that entry again; | |
1056 | * we'll eliminate all paths to it before dropping sysctl_lock | |
1057 | */ | |
1058 | if (unlikely(p->used)) { | |
1059 | struct completion wait; | |
1060 | init_completion(&wait); | |
1061 | p->unregistering = &wait; | |
1062 | spin_unlock(&sysctl_lock); | |
1063 | wait_for_completion(&wait); | |
1064 | spin_lock(&sysctl_lock); | |
1065 | } | |
1066 | /* | |
1067 | * do not remove from the list until nobody holds it; walking the | |
1068 | * list in do_sysctl() relies on that. | |
1069 | */ | |
1070 | list_del_init(&p->ctl_entry); | |
1071 | } | |
1072 | ||
1da177e4 LT |
1073 | void __init sysctl_init(void) |
1074 | { | |
b89a8171 | 1075 | #ifdef CONFIG_PROC_SYSCTL |
330d57fb | 1076 | register_proc_table(root_table, proc_sys_root, &root_table_header); |
1da177e4 LT |
1077 | #endif |
1078 | } | |
1079 | ||
b89a8171 | 1080 | #ifdef CONFIG_SYSCTL_SYSCALL |
1da177e4 LT |
1081 | int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, |
1082 | void __user *newval, size_t newlen) | |
1083 | { | |
1084 | struct list_head *tmp; | |
330d57fb | 1085 | int error = -ENOTDIR; |
1da177e4 LT |
1086 | |
1087 | if (nlen <= 0 || nlen >= CTL_MAXNAME) | |
1088 | return -ENOTDIR; | |
1089 | if (oldval) { | |
1090 | int old_len; | |
1091 | if (!oldlenp || get_user(old_len, oldlenp)) | |
1092 | return -EFAULT; | |
1093 | } | |
330d57fb | 1094 | spin_lock(&sysctl_lock); |
1da177e4 LT |
1095 | tmp = &root_table_header.ctl_entry; |
1096 | do { | |
1097 | struct ctl_table_header *head = | |
1098 | list_entry(tmp, struct ctl_table_header, ctl_entry); | |
330d57fb AV |
1099 | |
1100 | if (!use_table(head)) | |
1101 | continue; | |
1102 | ||
1103 | spin_unlock(&sysctl_lock); | |
1104 | ||
1105 | error = parse_table(name, nlen, oldval, oldlenp, | |
1f29bcd7 | 1106 | newval, newlen, head->ctl_table); |
330d57fb AV |
1107 | |
1108 | spin_lock(&sysctl_lock); | |
1109 | unuse_table(head); | |
1da177e4 | 1110 | if (error != -ENOTDIR) |
330d57fb AV |
1111 | break; |
1112 | } while ((tmp = tmp->next) != &root_table_header.ctl_entry); | |
1113 | spin_unlock(&sysctl_lock); | |
1114 | return error; | |
1da177e4 LT |
1115 | } |
1116 | ||
1117 | asmlinkage long sys_sysctl(struct __sysctl_args __user *args) | |
1118 | { | |
1119 | struct __sysctl_args tmp; | |
1120 | int error; | |
1121 | ||
1122 | if (copy_from_user(&tmp, args, sizeof(tmp))) | |
1123 | return -EFAULT; | |
1124 | ||
1125 | lock_kernel(); | |
1126 | error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, | |
1127 | tmp.newval, tmp.newlen); | |
1128 | unlock_kernel(); | |
1129 | return error; | |
1130 | } | |
b89a8171 | 1131 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 LT |
1132 | |
1133 | /* | |
1134 | * ctl_perm does NOT grant the superuser all rights automatically, because | |
1135 | * some sysctl variables are readonly even to root. | |
1136 | */ | |
1137 | ||
1138 | static int test_perm(int mode, int op) | |
1139 | { | |
1140 | if (!current->euid) | |
1141 | mode >>= 6; | |
1142 | else if (in_egroup_p(0)) | |
1143 | mode >>= 3; | |
1144 | if ((mode & op & 0007) == op) | |
1145 | return 0; | |
1146 | return -EACCES; | |
1147 | } | |
1148 | ||
1149 | static inline int ctl_perm(ctl_table *table, int op) | |
1150 | { | |
1151 | int error; | |
1152 | error = security_sysctl(table, op); | |
1153 | if (error) | |
1154 | return error; | |
1155 | return test_perm(table->mode, op); | |
1156 | } | |
1157 | ||
b89a8171 | 1158 | #ifdef CONFIG_SYSCTL_SYSCALL |
1da177e4 LT |
1159 | static int parse_table(int __user *name, int nlen, |
1160 | void __user *oldval, size_t __user *oldlenp, | |
1161 | void __user *newval, size_t newlen, | |
1f29bcd7 | 1162 | ctl_table *table) |
1da177e4 LT |
1163 | { |
1164 | int n; | |
1165 | repeat: | |
1166 | if (!nlen) | |
1167 | return -ENOTDIR; | |
1168 | if (get_user(n, name)) | |
1169 | return -EFAULT; | |
d99f160a EB |
1170 | for ( ; table->ctl_name || table->procname; table++) { |
1171 | if (!table->ctl_name) | |
1172 | continue; | |
6703ddfc | 1173 | if (n == table->ctl_name) { |
1da177e4 LT |
1174 | int error; |
1175 | if (table->child) { | |
1176 | if (ctl_perm(table, 001)) | |
1177 | return -EPERM; | |
1178 | if (table->strategy) { | |
1179 | error = table->strategy( | |
1180 | table, name, nlen, | |
1181 | oldval, oldlenp, | |
1f29bcd7 | 1182 | newval, newlen); |
1da177e4 LT |
1183 | if (error) |
1184 | return error; | |
1185 | } | |
1186 | name++; | |
1187 | nlen--; | |
1188 | table = table->child; | |
1189 | goto repeat; | |
1190 | } | |
1191 | error = do_sysctl_strategy(table, name, nlen, | |
1192 | oldval, oldlenp, | |
1f29bcd7 | 1193 | newval, newlen); |
1da177e4 LT |
1194 | return error; |
1195 | } | |
1196 | } | |
1197 | return -ENOTDIR; | |
1198 | } | |
1199 | ||
1200 | /* Perform the actual read/write of a sysctl table entry. */ | |
1201 | int do_sysctl_strategy (ctl_table *table, | |
1202 | int __user *name, int nlen, | |
1203 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 1204 | void __user *newval, size_t newlen) |
1da177e4 LT |
1205 | { |
1206 | int op = 0, rc; | |
1207 | size_t len; | |
1208 | ||
1209 | if (oldval) | |
1210 | op |= 004; | |
1211 | if (newval) | |
1212 | op |= 002; | |
1213 | if (ctl_perm(table, op)) | |
1214 | return -EPERM; | |
1215 | ||
1216 | if (table->strategy) { | |
1217 | rc = table->strategy(table, name, nlen, oldval, oldlenp, | |
1f29bcd7 | 1218 | newval, newlen); |
1da177e4 LT |
1219 | if (rc < 0) |
1220 | return rc; | |
1221 | if (rc > 0) | |
1222 | return 0; | |
1223 | } | |
1224 | ||
1225 | /* If there is no strategy routine, or if the strategy returns | |
1226 | * zero, proceed with automatic r/w */ | |
1227 | if (table->data && table->maxlen) { | |
1228 | if (oldval && oldlenp) { | |
1229 | if (get_user(len, oldlenp)) | |
1230 | return -EFAULT; | |
1231 | if (len) { | |
1232 | if (len > table->maxlen) | |
1233 | len = table->maxlen; | |
1234 | if(copy_to_user(oldval, table->data, len)) | |
1235 | return -EFAULT; | |
1236 | if(put_user(len, oldlenp)) | |
1237 | return -EFAULT; | |
1238 | } | |
1239 | } | |
1240 | if (newval && newlen) { | |
1241 | len = newlen; | |
1242 | if (len > table->maxlen) | |
1243 | len = table->maxlen; | |
1244 | if(copy_from_user(table->data, newval, len)) | |
1245 | return -EFAULT; | |
1246 | } | |
1247 | } | |
1248 | return 0; | |
1249 | } | |
b89a8171 | 1250 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 LT |
1251 | |
1252 | /** | |
1253 | * register_sysctl_table - register a sysctl hierarchy | |
1254 | * @table: the top-level table structure | |
1255 | * @insert_at_head: whether the entry should be inserted in front or at the end | |
1256 | * | |
1257 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
1258 | * array. An entry with a ctl_name of 0 terminates the table. | |
1259 | * | |
1260 | * The members of the &ctl_table structure are used as follows: | |
1261 | * | |
1262 | * ctl_name - This is the numeric sysctl value used by sysctl(2). The number | |
1263 | * must be unique within that level of sysctl | |
1264 | * | |
1265 | * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not | |
1266 | * enter a sysctl file | |
1267 | * | |
1268 | * data - a pointer to data for use by proc_handler | |
1269 | * | |
1270 | * maxlen - the maximum size in bytes of the data | |
1271 | * | |
1272 | * mode - the file permissions for the /proc/sys file, and for sysctl(2) | |
1273 | * | |
1274 | * child - a pointer to the child sysctl table if this entry is a directory, or | |
1275 | * %NULL. | |
1276 | * | |
1277 | * proc_handler - the text handler routine (described below) | |
1278 | * | |
1279 | * strategy - the strategy routine (described below) | |
1280 | * | |
1281 | * de - for internal use by the sysctl routines | |
1282 | * | |
1283 | * extra1, extra2 - extra pointers usable by the proc handler routines | |
1284 | * | |
1285 | * Leaf nodes in the sysctl tree will be represented by a single file | |
1286 | * under /proc; non-leaf nodes will be represented by directories. | |
1287 | * | |
1288 | * sysctl(2) can automatically manage read and write requests through | |
1289 | * the sysctl table. The data and maxlen fields of the ctl_table | |
1290 | * struct enable minimal validation of the values being written to be | |
1291 | * performed, and the mode field allows minimal authentication. | |
1292 | * | |
1293 | * More sophisticated management can be enabled by the provision of a | |
1294 | * strategy routine with the table entry. This will be called before | |
1295 | * any automatic read or write of the data is performed. | |
1296 | * | |
1297 | * The strategy routine may return | |
1298 | * | |
1299 | * < 0 - Error occurred (error is passed to user process) | |
1300 | * | |
1301 | * 0 - OK - proceed with automatic read or write. | |
1302 | * | |
1303 | * > 0 - OK - read or write has been done by the strategy routine, so | |
1304 | * return immediately. | |
1305 | * | |
1306 | * There must be a proc_handler routine for any terminal nodes | |
1307 | * mirrored under /proc/sys (non-terminals are handled by a built-in | |
1308 | * directory handler). Several default handlers are available to | |
1309 | * cover common cases - | |
1310 | * | |
1311 | * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), | |
1312 | * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), | |
1313 | * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() | |
1314 | * | |
1315 | * It is the handler's job to read the input buffer from user memory | |
1316 | * and process it. The handler should return 0 on success. | |
1317 | * | |
1318 | * This routine returns %NULL on a failure to register, and a pointer | |
1319 | * to the table header on success. | |
1320 | */ | |
1321 | struct ctl_table_header *register_sysctl_table(ctl_table * table, | |
1322 | int insert_at_head) | |
1323 | { | |
1324 | struct ctl_table_header *tmp; | |
1325 | tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL); | |
1326 | if (!tmp) | |
1327 | return NULL; | |
1328 | tmp->ctl_table = table; | |
1329 | INIT_LIST_HEAD(&tmp->ctl_entry); | |
330d57fb AV |
1330 | tmp->used = 0; |
1331 | tmp->unregistering = NULL; | |
1332 | spin_lock(&sysctl_lock); | |
1da177e4 LT |
1333 | if (insert_at_head) |
1334 | list_add(&tmp->ctl_entry, &root_table_header.ctl_entry); | |
1335 | else | |
1336 | list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry); | |
330d57fb | 1337 | spin_unlock(&sysctl_lock); |
b89a8171 | 1338 | #ifdef CONFIG_PROC_SYSCTL |
330d57fb | 1339 | register_proc_table(table, proc_sys_root, tmp); |
1da177e4 LT |
1340 | #endif |
1341 | return tmp; | |
1342 | } | |
1343 | ||
1344 | /** | |
1345 | * unregister_sysctl_table - unregister a sysctl table hierarchy | |
1346 | * @header: the header returned from register_sysctl_table | |
1347 | * | |
1348 | * Unregisters the sysctl table and all children. proc entries may not | |
1349 | * actually be removed until they are no longer used by anyone. | |
1350 | */ | |
1351 | void unregister_sysctl_table(struct ctl_table_header * header) | |
1352 | { | |
330d57fb AV |
1353 | might_sleep(); |
1354 | spin_lock(&sysctl_lock); | |
1355 | start_unregistering(header); | |
b89a8171 | 1356 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 LT |
1357 | unregister_proc_table(header->ctl_table, proc_sys_root); |
1358 | #endif | |
330d57fb | 1359 | spin_unlock(&sysctl_lock); |
1da177e4 LT |
1360 | kfree(header); |
1361 | } | |
1362 | ||
b89a8171 EB |
1363 | #else /* !CONFIG_SYSCTL */ |
1364 | struct ctl_table_header * register_sysctl_table(ctl_table * table, | |
1365 | int insert_at_head) | |
1366 | { | |
1367 | return NULL; | |
1368 | } | |
1369 | ||
1370 | void unregister_sysctl_table(struct ctl_table_header * table) | |
1371 | { | |
1372 | } | |
1373 | ||
1374 | #endif /* CONFIG_SYSCTL */ | |
1375 | ||
1da177e4 LT |
1376 | /* |
1377 | * /proc/sys support | |
1378 | */ | |
1379 | ||
b89a8171 | 1380 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 LT |
1381 | |
1382 | /* Scan the sysctl entries in table and add them all into /proc */ | |
330d57fb | 1383 | static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set) |
1da177e4 LT |
1384 | { |
1385 | struct proc_dir_entry *de; | |
1386 | int len; | |
1387 | mode_t mode; | |
1388 | ||
d99f160a | 1389 | for (; table->ctl_name || table->procname; table++) { |
1da177e4 LT |
1390 | /* Can't do anything without a proc name. */ |
1391 | if (!table->procname) | |
1392 | continue; | |
1393 | /* Maybe we can't do anything with it... */ | |
1394 | if (!table->proc_handler && !table->child) { | |
1395 | printk(KERN_WARNING "SYSCTL: Can't register %s\n", | |
1396 | table->procname); | |
1397 | continue; | |
1398 | } | |
1399 | ||
1400 | len = strlen(table->procname); | |
1401 | mode = table->mode; | |
1402 | ||
1403 | de = NULL; | |
1404 | if (table->proc_handler) | |
1405 | mode |= S_IFREG; | |
1406 | else { | |
1407 | mode |= S_IFDIR; | |
1408 | for (de = root->subdir; de; de = de->next) { | |
1409 | if (proc_match(len, table->procname, de)) | |
1410 | break; | |
1411 | } | |
1412 | /* If the subdir exists already, de is non-NULL */ | |
1413 | } | |
1414 | ||
1415 | if (!de) { | |
1416 | de = create_proc_entry(table->procname, mode, root); | |
1417 | if (!de) | |
1418 | continue; | |
330d57fb | 1419 | de->set = set; |
1da177e4 LT |
1420 | de->data = (void *) table; |
1421 | if (table->proc_handler) | |
1422 | de->proc_fops = &proc_sys_file_operations; | |
1423 | } | |
1424 | table->de = de; | |
1425 | if (de->mode & S_IFDIR) | |
330d57fb | 1426 | register_proc_table(table->child, de, set); |
1da177e4 LT |
1427 | } |
1428 | } | |
1429 | ||
1430 | /* | |
1431 | * Unregister a /proc sysctl table and any subdirectories. | |
1432 | */ | |
1433 | static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root) | |
1434 | { | |
1435 | struct proc_dir_entry *de; | |
d99f160a | 1436 | for (; table->ctl_name || table->procname; table++) { |
1da177e4 LT |
1437 | if (!(de = table->de)) |
1438 | continue; | |
1439 | if (de->mode & S_IFDIR) { | |
1440 | if (!table->child) { | |
1441 | printk (KERN_ALERT "Help - malformed sysctl tree on free\n"); | |
1442 | continue; | |
1443 | } | |
1444 | unregister_proc_table(table->child, de); | |
1445 | ||
1446 | /* Don't unregister directories which still have entries.. */ | |
1447 | if (de->subdir) | |
1448 | continue; | |
1449 | } | |
1450 | ||
330d57fb AV |
1451 | /* |
1452 | * In any case, mark the entry as goner; we'll keep it | |
1453 | * around if it's busy, but we'll know to do nothing with | |
1454 | * its fields. We are under sysctl_lock here. | |
1455 | */ | |
1456 | de->data = NULL; | |
1457 | ||
1da177e4 LT |
1458 | /* Don't unregister proc entries that are still being used.. */ |
1459 | if (atomic_read(&de->count)) | |
1460 | continue; | |
1461 | ||
1462 | table->de = NULL; | |
1463 | remove_proc_entry(table->procname, root); | |
1464 | } | |
1465 | } | |
1466 | ||
1467 | static ssize_t do_rw_proc(int write, struct file * file, char __user * buf, | |
1468 | size_t count, loff_t *ppos) | |
1469 | { | |
1470 | int op; | |
f3a43f3f | 1471 | struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode); |
1da177e4 LT |
1472 | struct ctl_table *table; |
1473 | size_t res; | |
330d57fb | 1474 | ssize_t error = -ENOTDIR; |
1da177e4 | 1475 | |
330d57fb AV |
1476 | spin_lock(&sysctl_lock); |
1477 | if (de && de->data && use_table(de->set)) { | |
1478 | /* | |
1479 | * at that point we know that sysctl was not unregistered | |
1480 | * and won't be until we finish | |
1481 | */ | |
1482 | spin_unlock(&sysctl_lock); | |
1483 | table = (struct ctl_table *) de->data; | |
1484 | if (!table || !table->proc_handler) | |
1485 | goto out; | |
1486 | error = -EPERM; | |
1487 | op = (write ? 002 : 004); | |
1488 | if (ctl_perm(table, op)) | |
1489 | goto out; | |
1490 | ||
1491 | /* careful: calling conventions are nasty here */ | |
1492 | res = count; | |
1493 | error = (*table->proc_handler)(table, write, file, | |
1494 | buf, &res, ppos); | |
1495 | if (!error) | |
1496 | error = res; | |
1497 | out: | |
1498 | spin_lock(&sysctl_lock); | |
1499 | unuse_table(de->set); | |
1500 | } | |
1501 | spin_unlock(&sysctl_lock); | |
1502 | return error; | |
1da177e4 LT |
1503 | } |
1504 | ||
1505 | static int proc_opensys(struct inode *inode, struct file *file) | |
1506 | { | |
1507 | if (file->f_mode & FMODE_WRITE) { | |
1508 | /* | |
1509 | * sysctl entries that are not writable, | |
1510 | * are _NOT_ writable, capabilities or not. | |
1511 | */ | |
1512 | if (!(inode->i_mode & S_IWUSR)) | |
1513 | return -EPERM; | |
1514 | } | |
1515 | ||
1516 | return 0; | |
1517 | } | |
1518 | ||
1519 | static ssize_t proc_readsys(struct file * file, char __user * buf, | |
1520 | size_t count, loff_t *ppos) | |
1521 | { | |
1522 | return do_rw_proc(0, file, buf, count, ppos); | |
1523 | } | |
1524 | ||
1525 | static ssize_t proc_writesys(struct file * file, const char __user * buf, | |
1526 | size_t count, loff_t *ppos) | |
1527 | { | |
1528 | return do_rw_proc(1, file, (char __user *) buf, count, ppos); | |
1529 | } | |
1530 | ||
b1ba4ddd AB |
1531 | static int _proc_do_string(void* data, int maxlen, int write, |
1532 | struct file *filp, void __user *buffer, | |
1533 | size_t *lenp, loff_t *ppos) | |
1da177e4 LT |
1534 | { |
1535 | size_t len; | |
1536 | char __user *p; | |
1537 | char c; | |
8d060877 ON |
1538 | |
1539 | if (!data || !maxlen || !*lenp) { | |
1da177e4 LT |
1540 | *lenp = 0; |
1541 | return 0; | |
1542 | } | |
8d060877 | 1543 | |
1da177e4 LT |
1544 | if (write) { |
1545 | len = 0; | |
1546 | p = buffer; | |
1547 | while (len < *lenp) { | |
1548 | if (get_user(c, p++)) | |
1549 | return -EFAULT; | |
1550 | if (c == 0 || c == '\n') | |
1551 | break; | |
1552 | len++; | |
1553 | } | |
f5dd3d6f SV |
1554 | if (len >= maxlen) |
1555 | len = maxlen-1; | |
1556 | if(copy_from_user(data, buffer, len)) | |
1da177e4 | 1557 | return -EFAULT; |
f5dd3d6f | 1558 | ((char *) data)[len] = 0; |
1da177e4 LT |
1559 | *ppos += *lenp; |
1560 | } else { | |
f5dd3d6f SV |
1561 | len = strlen(data); |
1562 | if (len > maxlen) | |
1563 | len = maxlen; | |
8d060877 ON |
1564 | |
1565 | if (*ppos > len) { | |
1566 | *lenp = 0; | |
1567 | return 0; | |
1568 | } | |
1569 | ||
1570 | data += *ppos; | |
1571 | len -= *ppos; | |
1572 | ||
1da177e4 LT |
1573 | if (len > *lenp) |
1574 | len = *lenp; | |
1575 | if (len) | |
f5dd3d6f | 1576 | if(copy_to_user(buffer, data, len)) |
1da177e4 LT |
1577 | return -EFAULT; |
1578 | if (len < *lenp) { | |
1579 | if(put_user('\n', ((char __user *) buffer) + len)) | |
1580 | return -EFAULT; | |
1581 | len++; | |
1582 | } | |
1583 | *lenp = len; | |
1584 | *ppos += len; | |
1585 | } | |
1586 | return 0; | |
1587 | } | |
1588 | ||
f5dd3d6f SV |
1589 | /** |
1590 | * proc_dostring - read a string sysctl | |
1591 | * @table: the sysctl table | |
1592 | * @write: %TRUE if this is a write to the sysctl file | |
1593 | * @filp: the file structure | |
1594 | * @buffer: the user buffer | |
1595 | * @lenp: the size of the user buffer | |
1596 | * @ppos: file position | |
1597 | * | |
1598 | * Reads/writes a string from/to the user buffer. If the kernel | |
1599 | * buffer provided is not large enough to hold the string, the | |
1600 | * string is truncated. The copied string is %NULL-terminated. | |
1601 | * If the string is being read by the user process, it is copied | |
1602 | * and a newline '\n' is added. It is truncated if the buffer is | |
1603 | * not large enough. | |
1604 | * | |
1605 | * Returns 0 on success. | |
1606 | */ | |
1607 | int proc_dostring(ctl_table *table, int write, struct file *filp, | |
1608 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
1609 | { | |
1610 | return _proc_do_string(table->data, table->maxlen, write, filp, | |
1611 | buffer, lenp, ppos); | |
1612 | } | |
1613 | ||
1da177e4 LT |
1614 | |
1615 | static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, | |
1616 | int *valp, | |
1617 | int write, void *data) | |
1618 | { | |
1619 | if (write) { | |
1620 | *valp = *negp ? -*lvalp : *lvalp; | |
1621 | } else { | |
1622 | int val = *valp; | |
1623 | if (val < 0) { | |
1624 | *negp = -1; | |
1625 | *lvalp = (unsigned long)-val; | |
1626 | } else { | |
1627 | *negp = 0; | |
1628 | *lvalp = (unsigned long)val; | |
1629 | } | |
1630 | } | |
1631 | return 0; | |
1632 | } | |
1633 | ||
fcfbd547 KK |
1634 | static int __do_proc_dointvec(void *tbl_data, ctl_table *table, |
1635 | int write, struct file *filp, void __user *buffer, | |
1636 | size_t *lenp, loff_t *ppos, | |
1da177e4 LT |
1637 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, |
1638 | int write, void *data), | |
1639 | void *data) | |
1640 | { | |
1641 | #define TMPBUFLEN 21 | |
1642 | int *i, vleft, first=1, neg, val; | |
1643 | unsigned long lval; | |
1644 | size_t left, len; | |
1645 | ||
1646 | char buf[TMPBUFLEN], *p; | |
1647 | char __user *s = buffer; | |
1648 | ||
fcfbd547 | 1649 | if (!tbl_data || !table->maxlen || !*lenp || |
1da177e4 LT |
1650 | (*ppos && !write)) { |
1651 | *lenp = 0; | |
1652 | return 0; | |
1653 | } | |
1654 | ||
fcfbd547 | 1655 | i = (int *) tbl_data; |
1da177e4 LT |
1656 | vleft = table->maxlen / sizeof(*i); |
1657 | left = *lenp; | |
1658 | ||
1659 | if (!conv) | |
1660 | conv = do_proc_dointvec_conv; | |
1661 | ||
1662 | for (; left && vleft--; i++, first=0) { | |
1663 | if (write) { | |
1664 | while (left) { | |
1665 | char c; | |
1666 | if (get_user(c, s)) | |
1667 | return -EFAULT; | |
1668 | if (!isspace(c)) | |
1669 | break; | |
1670 | left--; | |
1671 | s++; | |
1672 | } | |
1673 | if (!left) | |
1674 | break; | |
1675 | neg = 0; | |
1676 | len = left; | |
1677 | if (len > sizeof(buf) - 1) | |
1678 | len = sizeof(buf) - 1; | |
1679 | if (copy_from_user(buf, s, len)) | |
1680 | return -EFAULT; | |
1681 | buf[len] = 0; | |
1682 | p = buf; | |
1683 | if (*p == '-' && left > 1) { | |
1684 | neg = 1; | |
bd9b0bac | 1685 | p++; |
1da177e4 LT |
1686 | } |
1687 | if (*p < '0' || *p > '9') | |
1688 | break; | |
1689 | ||
1690 | lval = simple_strtoul(p, &p, 0); | |
1691 | ||
1692 | len = p-buf; | |
1693 | if ((len < left) && *p && !isspace(*p)) | |
1694 | break; | |
1695 | if (neg) | |
1696 | val = -val; | |
1697 | s += len; | |
1698 | left -= len; | |
1699 | ||
1700 | if (conv(&neg, &lval, i, 1, data)) | |
1701 | break; | |
1702 | } else { | |
1703 | p = buf; | |
1704 | if (!first) | |
1705 | *p++ = '\t'; | |
1706 | ||
1707 | if (conv(&neg, &lval, i, 0, data)) | |
1708 | break; | |
1709 | ||
1710 | sprintf(p, "%s%lu", neg ? "-" : "", lval); | |
1711 | len = strlen(buf); | |
1712 | if (len > left) | |
1713 | len = left; | |
1714 | if(copy_to_user(s, buf, len)) | |
1715 | return -EFAULT; | |
1716 | left -= len; | |
1717 | s += len; | |
1718 | } | |
1719 | } | |
1720 | ||
1721 | if (!write && !first && left) { | |
1722 | if(put_user('\n', s)) | |
1723 | return -EFAULT; | |
1724 | left--, s++; | |
1725 | } | |
1726 | if (write) { | |
1727 | while (left) { | |
1728 | char c; | |
1729 | if (get_user(c, s++)) | |
1730 | return -EFAULT; | |
1731 | if (!isspace(c)) | |
1732 | break; | |
1733 | left--; | |
1734 | } | |
1735 | } | |
1736 | if (write && first) | |
1737 | return -EINVAL; | |
1738 | *lenp -= left; | |
1739 | *ppos += *lenp; | |
1740 | return 0; | |
1741 | #undef TMPBUFLEN | |
1742 | } | |
1743 | ||
fcfbd547 KK |
1744 | static int do_proc_dointvec(ctl_table *table, int write, struct file *filp, |
1745 | void __user *buffer, size_t *lenp, loff_t *ppos, | |
1746 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, | |
1747 | int write, void *data), | |
1748 | void *data) | |
1749 | { | |
1750 | return __do_proc_dointvec(table->data, table, write, filp, | |
1751 | buffer, lenp, ppos, conv, data); | |
1752 | } | |
1753 | ||
1da177e4 LT |
1754 | /** |
1755 | * proc_dointvec - read a vector of integers | |
1756 | * @table: the sysctl table | |
1757 | * @write: %TRUE if this is a write to the sysctl file | |
1758 | * @filp: the file structure | |
1759 | * @buffer: the user buffer | |
1760 | * @lenp: the size of the user buffer | |
1761 | * @ppos: file position | |
1762 | * | |
1763 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
1764 | * values from/to the user buffer, treated as an ASCII string. | |
1765 | * | |
1766 | * Returns 0 on success. | |
1767 | */ | |
1768 | int proc_dointvec(ctl_table *table, int write, struct file *filp, | |
1769 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
1770 | { | |
1771 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
1772 | NULL,NULL); | |
1773 | } | |
1774 | ||
1775 | #define OP_SET 0 | |
1776 | #define OP_AND 1 | |
34f5a398 | 1777 | #define OP_OR 2 |
1da177e4 LT |
1778 | |
1779 | static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp, | |
1780 | int *valp, | |
1781 | int write, void *data) | |
1782 | { | |
1783 | int op = *(int *)data; | |
1784 | if (write) { | |
1785 | int val = *negp ? -*lvalp : *lvalp; | |
1786 | switch(op) { | |
1787 | case OP_SET: *valp = val; break; | |
1788 | case OP_AND: *valp &= val; break; | |
34f5a398 | 1789 | case OP_OR: *valp |= val; break; |
1da177e4 LT |
1790 | } |
1791 | } else { | |
1792 | int val = *valp; | |
1793 | if (val < 0) { | |
1794 | *negp = -1; | |
1795 | *lvalp = (unsigned long)-val; | |
1796 | } else { | |
1797 | *negp = 0; | |
1798 | *lvalp = (unsigned long)val; | |
1799 | } | |
1800 | } | |
1801 | return 0; | |
1802 | } | |
1803 | ||
1804 | /* | |
1805 | * init may raise the set. | |
1806 | */ | |
1807 | ||
1808 | int proc_dointvec_bset(ctl_table *table, int write, struct file *filp, | |
1809 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
1810 | { | |
1811 | int op; | |
1812 | ||
6ff1b442 | 1813 | if (write && !capable(CAP_SYS_MODULE)) { |
1da177e4 LT |
1814 | return -EPERM; |
1815 | } | |
1816 | ||
f400e198 | 1817 | op = is_init(current) ? OP_SET : OP_AND; |
1da177e4 LT |
1818 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, |
1819 | do_proc_dointvec_bset_conv,&op); | |
1820 | } | |
1821 | ||
34f5a398 TT |
1822 | /* |
1823 | * Taint values can only be increased | |
1824 | */ | |
1825 | static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp, | |
1826 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
1827 | { | |
1828 | int op; | |
1829 | ||
1830 | if (!capable(CAP_SYS_ADMIN)) | |
1831 | return -EPERM; | |
1832 | ||
1833 | op = OP_OR; | |
1834 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
1835 | do_proc_dointvec_bset_conv,&op); | |
1836 | } | |
1837 | ||
1da177e4 LT |
1838 | struct do_proc_dointvec_minmax_conv_param { |
1839 | int *min; | |
1840 | int *max; | |
1841 | }; | |
1842 | ||
1843 | static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, | |
1844 | int *valp, | |
1845 | int write, void *data) | |
1846 | { | |
1847 | struct do_proc_dointvec_minmax_conv_param *param = data; | |
1848 | if (write) { | |
1849 | int val = *negp ? -*lvalp : *lvalp; | |
1850 | if ((param->min && *param->min > val) || | |
1851 | (param->max && *param->max < val)) | |
1852 | return -EINVAL; | |
1853 | *valp = val; | |
1854 | } else { | |
1855 | int val = *valp; | |
1856 | if (val < 0) { | |
1857 | *negp = -1; | |
1858 | *lvalp = (unsigned long)-val; | |
1859 | } else { | |
1860 | *negp = 0; | |
1861 | *lvalp = (unsigned long)val; | |
1862 | } | |
1863 | } | |
1864 | return 0; | |
1865 | } | |
1866 | ||
1867 | /** | |
1868 | * proc_dointvec_minmax - read a vector of integers with min/max values | |
1869 | * @table: the sysctl table | |
1870 | * @write: %TRUE if this is a write to the sysctl file | |
1871 | * @filp: the file structure | |
1872 | * @buffer: the user buffer | |
1873 | * @lenp: the size of the user buffer | |
1874 | * @ppos: file position | |
1875 | * | |
1876 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
1877 | * values from/to the user buffer, treated as an ASCII string. | |
1878 | * | |
1879 | * This routine will ensure the values are within the range specified by | |
1880 | * table->extra1 (min) and table->extra2 (max). | |
1881 | * | |
1882 | * Returns 0 on success. | |
1883 | */ | |
1884 | int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp, | |
1885 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
1886 | { | |
1887 | struct do_proc_dointvec_minmax_conv_param param = { | |
1888 | .min = (int *) table->extra1, | |
1889 | .max = (int *) table->extra2, | |
1890 | }; | |
1891 | return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, | |
1892 | do_proc_dointvec_minmax_conv, ¶m); | |
1893 | } | |
1894 | ||
fcfbd547 | 1895 | static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write, |
1da177e4 LT |
1896 | struct file *filp, |
1897 | void __user *buffer, | |
1898 | size_t *lenp, loff_t *ppos, | |
1899 | unsigned long convmul, | |
1900 | unsigned long convdiv) | |
1901 | { | |
1902 | #define TMPBUFLEN 21 | |
1903 | unsigned long *i, *min, *max, val; | |
1904 | int vleft, first=1, neg; | |
1905 | size_t len, left; | |
1906 | char buf[TMPBUFLEN], *p; | |
1907 | char __user *s = buffer; | |
1908 | ||
fcfbd547 | 1909 | if (!data || !table->maxlen || !*lenp || |
1da177e4 LT |
1910 | (*ppos && !write)) { |
1911 | *lenp = 0; | |
1912 | return 0; | |
1913 | } | |
1914 | ||
fcfbd547 | 1915 | i = (unsigned long *) data; |
1da177e4 LT |
1916 | min = (unsigned long *) table->extra1; |
1917 | max = (unsigned long *) table->extra2; | |
1918 | vleft = table->maxlen / sizeof(unsigned long); | |
1919 | left = *lenp; | |
1920 | ||
1921 | for (; left && vleft--; i++, min++, max++, first=0) { | |
1922 | if (write) { | |
1923 | while (left) { | |
1924 | char c; | |
1925 | if (get_user(c, s)) | |
1926 | return -EFAULT; | |
1927 | if (!isspace(c)) | |
1928 | break; | |
1929 | left--; | |
1930 | s++; | |
1931 | } | |
1932 | if (!left) | |
1933 | break; | |
1934 | neg = 0; | |
1935 | len = left; | |
1936 | if (len > TMPBUFLEN-1) | |
1937 | len = TMPBUFLEN-1; | |
1938 | if (copy_from_user(buf, s, len)) | |
1939 | return -EFAULT; | |
1940 | buf[len] = 0; | |
1941 | p = buf; | |
1942 | if (*p == '-' && left > 1) { | |
1943 | neg = 1; | |
bd9b0bac | 1944 | p++; |
1da177e4 LT |
1945 | } |
1946 | if (*p < '0' || *p > '9') | |
1947 | break; | |
1948 | val = simple_strtoul(p, &p, 0) * convmul / convdiv ; | |
1949 | len = p-buf; | |
1950 | if ((len < left) && *p && !isspace(*p)) | |
1951 | break; | |
1952 | if (neg) | |
1953 | val = -val; | |
1954 | s += len; | |
1955 | left -= len; | |
1956 | ||
1957 | if(neg) | |
1958 | continue; | |
1959 | if ((min && val < *min) || (max && val > *max)) | |
1960 | continue; | |
1961 | *i = val; | |
1962 | } else { | |
1963 | p = buf; | |
1964 | if (!first) | |
1965 | *p++ = '\t'; | |
1966 | sprintf(p, "%lu", convdiv * (*i) / convmul); | |
1967 | len = strlen(buf); | |
1968 | if (len > left) | |
1969 | len = left; | |
1970 | if(copy_to_user(s, buf, len)) | |
1971 | return -EFAULT; | |
1972 | left -= len; | |
1973 | s += len; | |
1974 | } | |
1975 | } | |
1976 | ||
1977 | if (!write && !first && left) { | |
1978 | if(put_user('\n', s)) | |
1979 | return -EFAULT; | |
1980 | left--, s++; | |
1981 | } | |
1982 | if (write) { | |
1983 | while (left) { | |
1984 | char c; | |
1985 | if (get_user(c, s++)) | |
1986 | return -EFAULT; | |
1987 | if (!isspace(c)) | |
1988 | break; | |
1989 | left--; | |
1990 | } | |
1991 | } | |
1992 | if (write && first) | |
1993 | return -EINVAL; | |
1994 | *lenp -= left; | |
1995 | *ppos += *lenp; | |
1996 | return 0; | |
1997 | #undef TMPBUFLEN | |
1998 | } | |
1999 | ||
fcfbd547 KK |
2000 | static int do_proc_doulongvec_minmax(ctl_table *table, int write, |
2001 | struct file *filp, | |
2002 | void __user *buffer, | |
2003 | size_t *lenp, loff_t *ppos, | |
2004 | unsigned long convmul, | |
2005 | unsigned long convdiv) | |
2006 | { | |
2007 | return __do_proc_doulongvec_minmax(table->data, table, write, | |
2008 | filp, buffer, lenp, ppos, convmul, convdiv); | |
2009 | } | |
2010 | ||
1da177e4 LT |
2011 | /** |
2012 | * proc_doulongvec_minmax - read a vector of long integers with min/max values | |
2013 | * @table: the sysctl table | |
2014 | * @write: %TRUE if this is a write to the sysctl file | |
2015 | * @filp: the file structure | |
2016 | * @buffer: the user buffer | |
2017 | * @lenp: the size of the user buffer | |
2018 | * @ppos: file position | |
2019 | * | |
2020 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
2021 | * values from/to the user buffer, treated as an ASCII string. | |
2022 | * | |
2023 | * This routine will ensure the values are within the range specified by | |
2024 | * table->extra1 (min) and table->extra2 (max). | |
2025 | * | |
2026 | * Returns 0 on success. | |
2027 | */ | |
2028 | int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp, | |
2029 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2030 | { | |
2031 | return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); | |
2032 | } | |
2033 | ||
2034 | /** | |
2035 | * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values | |
2036 | * @table: the sysctl table | |
2037 | * @write: %TRUE if this is a write to the sysctl file | |
2038 | * @filp: the file structure | |
2039 | * @buffer: the user buffer | |
2040 | * @lenp: the size of the user buffer | |
2041 | * @ppos: file position | |
2042 | * | |
2043 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
2044 | * values from/to the user buffer, treated as an ASCII string. The values | |
2045 | * are treated as milliseconds, and converted to jiffies when they are stored. | |
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_ms_jiffies_minmax(ctl_table *table, int write, | |
2053 | struct file *filp, | |
2054 | void __user *buffer, | |
2055 | size_t *lenp, loff_t *ppos) | |
2056 | { | |
2057 | return do_proc_doulongvec_minmax(table, write, filp, buffer, | |
2058 | lenp, ppos, HZ, 1000l); | |
2059 | } | |
2060 | ||
2061 | ||
2062 | static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, | |
2063 | int *valp, | |
2064 | int write, void *data) | |
2065 | { | |
2066 | if (write) { | |
cba9f33d BS |
2067 | if (*lvalp > LONG_MAX / HZ) |
2068 | return 1; | |
1da177e4 LT |
2069 | *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); |
2070 | } else { | |
2071 | int val = *valp; | |
2072 | unsigned long lval; | |
2073 | if (val < 0) { | |
2074 | *negp = -1; | |
2075 | lval = (unsigned long)-val; | |
2076 | } else { | |
2077 | *negp = 0; | |
2078 | lval = (unsigned long)val; | |
2079 | } | |
2080 | *lvalp = lval / HZ; | |
2081 | } | |
2082 | return 0; | |
2083 | } | |
2084 | ||
2085 | static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, | |
2086 | int *valp, | |
2087 | int write, void *data) | |
2088 | { | |
2089 | if (write) { | |
cba9f33d BS |
2090 | if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) |
2091 | return 1; | |
1da177e4 LT |
2092 | *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); |
2093 | } else { | |
2094 | int val = *valp; | |
2095 | unsigned long lval; | |
2096 | if (val < 0) { | |
2097 | *negp = -1; | |
2098 | lval = (unsigned long)-val; | |
2099 | } else { | |
2100 | *negp = 0; | |
2101 | lval = (unsigned long)val; | |
2102 | } | |
2103 | *lvalp = jiffies_to_clock_t(lval); | |
2104 | } | |
2105 | return 0; | |
2106 | } | |
2107 | ||
2108 | static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, | |
2109 | int *valp, | |
2110 | int write, void *data) | |
2111 | { | |
2112 | if (write) { | |
2113 | *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); | |
2114 | } else { | |
2115 | int val = *valp; | |
2116 | unsigned long lval; | |
2117 | if (val < 0) { | |
2118 | *negp = -1; | |
2119 | lval = (unsigned long)-val; | |
2120 | } else { | |
2121 | *negp = 0; | |
2122 | lval = (unsigned long)val; | |
2123 | } | |
2124 | *lvalp = jiffies_to_msecs(lval); | |
2125 | } | |
2126 | return 0; | |
2127 | } | |
2128 | ||
2129 | /** | |
2130 | * proc_dointvec_jiffies - read a vector of integers as seconds | |
2131 | * @table: the sysctl table | |
2132 | * @write: %TRUE if this is a write to the sysctl file | |
2133 | * @filp: the file structure | |
2134 | * @buffer: the user buffer | |
2135 | * @lenp: the size of the user buffer | |
2136 | * @ppos: file position | |
2137 | * | |
2138 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2139 | * values from/to the user buffer, treated as an ASCII string. | |
2140 | * The values read are assumed to be in seconds, and are converted into | |
2141 | * jiffies. | |
2142 | * | |
2143 | * Returns 0 on success. | |
2144 | */ | |
2145 | int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp, | |
2146 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2147 | { | |
2148 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
2149 | do_proc_dointvec_jiffies_conv,NULL); | |
2150 | } | |
2151 | ||
2152 | /** | |
2153 | * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds | |
2154 | * @table: the sysctl table | |
2155 | * @write: %TRUE if this is a write to the sysctl file | |
2156 | * @filp: the file structure | |
2157 | * @buffer: the user buffer | |
2158 | * @lenp: the size of the user buffer | |
1e5d5331 | 2159 | * @ppos: pointer to the file position |
1da177e4 LT |
2160 | * |
2161 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2162 | * values from/to the user buffer, treated as an ASCII string. | |
2163 | * The values read are assumed to be in 1/USER_HZ seconds, and | |
2164 | * are converted into jiffies. | |
2165 | * | |
2166 | * Returns 0 on success. | |
2167 | */ | |
2168 | int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp, | |
2169 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2170 | { | |
2171 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
2172 | do_proc_dointvec_userhz_jiffies_conv,NULL); | |
2173 | } | |
2174 | ||
2175 | /** | |
2176 | * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds | |
2177 | * @table: the sysctl table | |
2178 | * @write: %TRUE if this is a write to the sysctl file | |
2179 | * @filp: the file structure | |
2180 | * @buffer: the user buffer | |
2181 | * @lenp: the size of the user buffer | |
67be2dd1 MW |
2182 | * @ppos: file position |
2183 | * @ppos: the current position in the file | |
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/1000 seconds, and | |
2188 | * are converted into jiffies. | |
2189 | * | |
2190 | * Returns 0 on success. | |
2191 | */ | |
2192 | int proc_dointvec_ms_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_ms_jiffies_conv, NULL); | |
2197 | } | |
2198 | ||
9ec52099 CLG |
2199 | static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp, |
2200 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2201 | { | |
2202 | struct pid *new_pid; | |
2203 | pid_t tmp; | |
2204 | int r; | |
2205 | ||
2206 | tmp = pid_nr(cad_pid); | |
2207 | ||
2208 | r = __do_proc_dointvec(&tmp, table, write, filp, buffer, | |
2209 | lenp, ppos, NULL, NULL); | |
2210 | if (r || !write) | |
2211 | return r; | |
2212 | ||
2213 | new_pid = find_get_pid(tmp); | |
2214 | if (!new_pid) | |
2215 | return -ESRCH; | |
2216 | ||
2217 | put_pid(xchg(&cad_pid, new_pid)); | |
2218 | return 0; | |
2219 | } | |
2220 | ||
1da177e4 LT |
2221 | #else /* CONFIG_PROC_FS */ |
2222 | ||
2223 | int proc_dostring(ctl_table *table, int write, struct file *filp, | |
2224 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2225 | { | |
2226 | return -ENOSYS; | |
2227 | } | |
2228 | ||
1da177e4 LT |
2229 | int proc_dointvec(ctl_table *table, int write, struct file *filp, |
2230 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2231 | { | |
2232 | return -ENOSYS; | |
2233 | } | |
2234 | ||
2235 | int proc_dointvec_bset(ctl_table *table, int write, struct file *filp, | |
2236 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2237 | { | |
2238 | return -ENOSYS; | |
2239 | } | |
2240 | ||
2241 | int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp, | |
2242 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2243 | { | |
2244 | return -ENOSYS; | |
2245 | } | |
2246 | ||
2247 | int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp, | |
2248 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2249 | { | |
2250 | return -ENOSYS; | |
2251 | } | |
2252 | ||
2253 | int proc_dointvec_userhz_jiffies(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_ms_jiffies(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_doulongvec_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_doulongvec_ms_jiffies_minmax(ctl_table *table, int write, | |
2272 | struct file *filp, | |
2273 | void __user *buffer, | |
2274 | size_t *lenp, loff_t *ppos) | |
2275 | { | |
2276 | return -ENOSYS; | |
2277 | } | |
2278 | ||
2279 | ||
2280 | #endif /* CONFIG_PROC_FS */ | |
2281 | ||
2282 | ||
b89a8171 | 2283 | #ifdef CONFIG_SYSCTL_SYSCALL |
1da177e4 LT |
2284 | /* |
2285 | * General sysctl support routines | |
2286 | */ | |
2287 | ||
2288 | /* The generic string strategy routine: */ | |
2289 | int sysctl_string(ctl_table *table, int __user *name, int nlen, | |
2290 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 2291 | void __user *newval, size_t newlen) |
1da177e4 | 2292 | { |
1da177e4 LT |
2293 | if (!table->data || !table->maxlen) |
2294 | return -ENOTDIR; | |
2295 | ||
2296 | if (oldval && oldlenp) { | |
de9e007d LT |
2297 | size_t bufsize; |
2298 | if (get_user(bufsize, oldlenp)) | |
1da177e4 | 2299 | return -EFAULT; |
de9e007d LT |
2300 | if (bufsize) { |
2301 | size_t len = strlen(table->data), copied; | |
2302 | ||
2303 | /* This shouldn't trigger for a well-formed sysctl */ | |
2304 | if (len > table->maxlen) | |
1da177e4 | 2305 | len = table->maxlen; |
de9e007d LT |
2306 | |
2307 | /* Copy up to a max of bufsize-1 bytes of the string */ | |
2308 | copied = (len >= bufsize) ? bufsize - 1 : len; | |
2309 | ||
2310 | if (copy_to_user(oldval, table->data, copied) || | |
2311 | put_user(0, (char __user *)(oldval + copied))) | |
1da177e4 | 2312 | return -EFAULT; |
de9e007d | 2313 | if (put_user(len, oldlenp)) |
1da177e4 LT |
2314 | return -EFAULT; |
2315 | } | |
2316 | } | |
2317 | if (newval && newlen) { | |
de9e007d | 2318 | size_t len = newlen; |
1da177e4 LT |
2319 | if (len > table->maxlen) |
2320 | len = table->maxlen; | |
2321 | if(copy_from_user(table->data, newval, len)) | |
2322 | return -EFAULT; | |
2323 | if (len == table->maxlen) | |
2324 | len--; | |
2325 | ((char *) table->data)[len] = 0; | |
2326 | } | |
82c9df82 | 2327 | return 1; |
1da177e4 LT |
2328 | } |
2329 | ||
2330 | /* | |
2331 | * This function makes sure that all of the integers in the vector | |
2332 | * are between the minimum and maximum values given in the arrays | |
2333 | * table->extra1 and table->extra2, respectively. | |
2334 | */ | |
2335 | int sysctl_intvec(ctl_table *table, int __user *name, int nlen, | |
2336 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 2337 | void __user *newval, size_t newlen) |
1da177e4 LT |
2338 | { |
2339 | ||
2340 | if (newval && newlen) { | |
2341 | int __user *vec = (int __user *) newval; | |
2342 | int *min = (int *) table->extra1; | |
2343 | int *max = (int *) table->extra2; | |
2344 | size_t length; | |
2345 | int i; | |
2346 | ||
2347 | if (newlen % sizeof(int) != 0) | |
2348 | return -EINVAL; | |
2349 | ||
2350 | if (!table->extra1 && !table->extra2) | |
2351 | return 0; | |
2352 | ||
2353 | if (newlen > table->maxlen) | |
2354 | newlen = table->maxlen; | |
2355 | length = newlen / sizeof(int); | |
2356 | ||
2357 | for (i = 0; i < length; i++) { | |
2358 | int value; | |
2359 | if (get_user(value, vec + i)) | |
2360 | return -EFAULT; | |
2361 | if (min && value < min[i]) | |
2362 | return -EINVAL; | |
2363 | if (max && value > max[i]) | |
2364 | return -EINVAL; | |
2365 | } | |
2366 | } | |
2367 | return 0; | |
2368 | } | |
2369 | ||
2370 | /* Strategy function to convert jiffies to seconds */ | |
2371 | int sysctl_jiffies(ctl_table *table, int __user *name, int nlen, | |
2372 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 2373 | void __user *newval, size_t newlen) |
1da177e4 | 2374 | { |
3ee75ac3 | 2375 | if (oldval && oldlenp) { |
1da177e4 | 2376 | size_t olen; |
3ee75ac3 AD |
2377 | |
2378 | if (get_user(olen, oldlenp)) | |
2379 | return -EFAULT; | |
2380 | if (olen) { | |
2381 | int val; | |
2382 | ||
2383 | if (olen < sizeof(int)) | |
2384 | return -EINVAL; | |
2385 | ||
2386 | val = *(int *)(table->data) / HZ; | |
2387 | if (put_user(val, (int __user *)oldval)) | |
2388 | return -EFAULT; | |
2389 | if (put_user(sizeof(int), oldlenp)) | |
1da177e4 | 2390 | return -EFAULT; |
1da177e4 | 2391 | } |
1da177e4 LT |
2392 | } |
2393 | if (newval && newlen) { | |
2394 | int new; | |
2395 | if (newlen != sizeof(int)) | |
2396 | return -EINVAL; | |
2397 | if (get_user(new, (int __user *)newval)) | |
2398 | return -EFAULT; | |
2399 | *(int *)(table->data) = new*HZ; | |
2400 | } | |
2401 | return 1; | |
2402 | } | |
2403 | ||
2404 | /* Strategy function to convert jiffies to seconds */ | |
2405 | int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen, | |
2406 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 2407 | void __user *newval, size_t newlen) |
1da177e4 | 2408 | { |
3ee75ac3 | 2409 | if (oldval && oldlenp) { |
1da177e4 | 2410 | size_t olen; |
3ee75ac3 AD |
2411 | |
2412 | if (get_user(olen, oldlenp)) | |
2413 | return -EFAULT; | |
2414 | if (olen) { | |
2415 | int val; | |
2416 | ||
2417 | if (olen < sizeof(int)) | |
2418 | return -EINVAL; | |
2419 | ||
2420 | val = jiffies_to_msecs(*(int *)(table->data)); | |
2421 | if (put_user(val, (int __user *)oldval)) | |
2422 | return -EFAULT; | |
2423 | if (put_user(sizeof(int), oldlenp)) | |
1da177e4 | 2424 | return -EFAULT; |
1da177e4 | 2425 | } |
1da177e4 LT |
2426 | } |
2427 | if (newval && newlen) { | |
2428 | int new; | |
2429 | if (newlen != sizeof(int)) | |
2430 | return -EINVAL; | |
2431 | if (get_user(new, (int __user *)newval)) | |
2432 | return -EFAULT; | |
2433 | *(int *)(table->data) = msecs_to_jiffies(new); | |
2434 | } | |
2435 | return 1; | |
2436 | } | |
2437 | ||
c4b8b769 | 2438 | |
c4b8b769 | 2439 | |
b89a8171 | 2440 | #else /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 LT |
2441 | |
2442 | ||
2443 | asmlinkage long sys_sysctl(struct __sysctl_args __user *args) | |
2444 | { | |
b89a8171 | 2445 | static int msg_count; |
0e009be8 EB |
2446 | struct __sysctl_args tmp; |
2447 | int name[CTL_MAXNAME]; | |
2448 | int i; | |
2449 | ||
2450 | /* Read in the sysctl name for better debug message logging */ | |
2451 | if (copy_from_user(&tmp, args, sizeof(tmp))) | |
2452 | return -EFAULT; | |
2453 | if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME) | |
2454 | return -ENOTDIR; | |
2455 | for (i = 0; i < tmp.nlen; i++) | |
2456 | if (get_user(name[i], tmp.name + i)) | |
2457 | return -EFAULT; | |
2458 | ||
2459 | /* Ignore accesses to kernel.version */ | |
2460 | if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) | |
2461 | goto out; | |
b89a8171 EB |
2462 | |
2463 | if (msg_count < 5) { | |
2464 | msg_count++; | |
2465 | printk(KERN_INFO | |
2466 | "warning: process `%s' used the removed sysctl " | |
0e009be8 EB |
2467 | "system call with ", current->comm); |
2468 | for (i = 0; i < tmp.nlen; i++) | |
2469 | printk("%d.", name[i]); | |
2470 | printk("\n"); | |
b89a8171 | 2471 | } |
0e009be8 | 2472 | out: |
1da177e4 LT |
2473 | return -ENOSYS; |
2474 | } | |
2475 | ||
2476 | int sysctl_string(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_intvec(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 | ||
2490 | int sysctl_jiffies(ctl_table *table, int __user *name, int nlen, | |
2491 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 2492 | void __user *newval, size_t newlen) |
1da177e4 LT |
2493 | { |
2494 | return -ENOSYS; | |
2495 | } | |
2496 | ||
2497 | int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen, | |
2498 | void __user *oldval, size_t __user *oldlenp, | |
1f29bcd7 | 2499 | void __user *newval, size_t newlen) |
1da177e4 LT |
2500 | { |
2501 | return -ENOSYS; | |
2502 | } | |
2503 | ||
b89a8171 | 2504 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 LT |
2505 | |
2506 | /* | |
2507 | * No sense putting this after each symbol definition, twice, | |
2508 | * exception granted :-) | |
2509 | */ | |
2510 | EXPORT_SYMBOL(proc_dointvec); | |
2511 | EXPORT_SYMBOL(proc_dointvec_jiffies); | |
2512 | EXPORT_SYMBOL(proc_dointvec_minmax); | |
2513 | EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); | |
2514 | EXPORT_SYMBOL(proc_dointvec_ms_jiffies); | |
2515 | EXPORT_SYMBOL(proc_dostring); | |
2516 | EXPORT_SYMBOL(proc_doulongvec_minmax); | |
2517 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); | |
2518 | EXPORT_SYMBOL(register_sysctl_table); | |
2519 | EXPORT_SYMBOL(sysctl_intvec); | |
2520 | EXPORT_SYMBOL(sysctl_jiffies); | |
2521 | EXPORT_SYMBOL(sysctl_ms_jiffies); | |
2522 | EXPORT_SYMBOL(sysctl_string); | |
2523 | EXPORT_SYMBOL(unregister_sysctl_table); |