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