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