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