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