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, | |
58687acb DZ |
733 | .proc_handler = proc_dowatchdog_enabled, |
734 | }, | |
735 | { | |
736 | .procname = "watchdog_thresh", | |
737 | .data = &softlockup_thresh, | |
738 | .maxlen = sizeof(int), | |
739 | .mode = 0644, | |
740 | .proc_handler = proc_dowatchdog_thresh, | |
741 | .extra1 = &neg_one, | |
742 | .extra2 = &sixty, | |
504d7cf1 | 743 | }, |
2508ce18 DZ |
744 | { |
745 | .procname = "softlockup_panic", | |
746 | .data = &softlockup_panic, | |
747 | .maxlen = sizeof(int), | |
748 | .mode = 0644, | |
749 | .proc_handler = proc_dointvec_minmax, | |
750 | .extra1 = &zero, | |
751 | .extra2 = &one, | |
752 | }, | |
5dc30558 DZ |
753 | { |
754 | .procname = "nmi_watchdog", | |
755 | .data = &watchdog_enabled, | |
756 | .maxlen = sizeof (int), | |
757 | .mode = 0644, | |
758 | .proc_handler = proc_dowatchdog_enabled, | |
759 | }, | |
760 | #endif | |
761 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) | |
762 | { | |
763 | .procname = "unknown_nmi_panic", | |
764 | .data = &unknown_nmi_panic, | |
765 | .maxlen = sizeof (int), | |
766 | .mode = 0644, | |
767 | .proc_handler = proc_dointvec, | |
768 | }, | |
504d7cf1 | 769 | #endif |
1da177e4 | 770 | #if defined(CONFIG_X86) |
8da5adda | 771 | { |
8da5adda DZ |
772 | .procname = "panic_on_unrecovered_nmi", |
773 | .data = &panic_on_unrecovered_nmi, | |
774 | .maxlen = sizeof(int), | |
775 | .mode = 0644, | |
6d456111 | 776 | .proc_handler = proc_dointvec, |
8da5adda | 777 | }, |
5211a242 | 778 | { |
5211a242 KG |
779 | .procname = "panic_on_io_nmi", |
780 | .data = &panic_on_io_nmi, | |
781 | .maxlen = sizeof(int), | |
782 | .mode = 0644, | |
6d456111 | 783 | .proc_handler = proc_dointvec, |
5211a242 | 784 | }, |
1da177e4 | 785 | { |
1da177e4 LT |
786 | .procname = "bootloader_type", |
787 | .data = &bootloader_type, | |
788 | .maxlen = sizeof (int), | |
789 | .mode = 0444, | |
6d456111 | 790 | .proc_handler = proc_dointvec, |
1da177e4 | 791 | }, |
5031296c | 792 | { |
5031296c PA |
793 | .procname = "bootloader_version", |
794 | .data = &bootloader_version, | |
795 | .maxlen = sizeof (int), | |
796 | .mode = 0444, | |
6d456111 | 797 | .proc_handler = proc_dointvec, |
5031296c | 798 | }, |
0741f4d2 | 799 | { |
0741f4d2 CE |
800 | .procname = "kstack_depth_to_print", |
801 | .data = &kstack_depth_to_print, | |
802 | .maxlen = sizeof(int), | |
803 | .mode = 0644, | |
6d456111 | 804 | .proc_handler = proc_dointvec, |
0741f4d2 | 805 | }, |
6e7c4025 | 806 | { |
6e7c4025 IM |
807 | .procname = "io_delay_type", |
808 | .data = &io_delay_type, | |
809 | .maxlen = sizeof(int), | |
810 | .mode = 0644, | |
6d456111 | 811 | .proc_handler = proc_dointvec, |
6e7c4025 | 812 | }, |
1da177e4 | 813 | #endif |
7a9166e3 | 814 | #if defined(CONFIG_MMU) |
1da177e4 | 815 | { |
1da177e4 LT |
816 | .procname = "randomize_va_space", |
817 | .data = &randomize_va_space, | |
818 | .maxlen = sizeof(int), | |
819 | .mode = 0644, | |
6d456111 | 820 | .proc_handler = proc_dointvec, |
1da177e4 | 821 | }, |
7a9166e3 | 822 | #endif |
0152fb37 | 823 | #if defined(CONFIG_S390) && defined(CONFIG_SMP) |
951f22d5 | 824 | { |
951f22d5 MS |
825 | .procname = "spin_retry", |
826 | .data = &spin_retry, | |
827 | .maxlen = sizeof (int), | |
828 | .mode = 0644, | |
6d456111 | 829 | .proc_handler = proc_dointvec, |
951f22d5 | 830 | }, |
c255d844 | 831 | #endif |
673d5b43 | 832 | #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) |
c255d844 | 833 | { |
c255d844 | 834 | .procname = "acpi_video_flags", |
77afcf78 | 835 | .data = &acpi_realmode_flags, |
c255d844 PM |
836 | .maxlen = sizeof (unsigned long), |
837 | .mode = 0644, | |
6d456111 | 838 | .proc_handler = proc_doulongvec_minmax, |
c255d844 | 839 | }, |
d2b176ed JS |
840 | #endif |
841 | #ifdef CONFIG_IA64 | |
842 | { | |
d2b176ed JS |
843 | .procname = "ignore-unaligned-usertrap", |
844 | .data = &no_unaligned_warning, | |
845 | .maxlen = sizeof (int), | |
846 | .mode = 0644, | |
6d456111 | 847 | .proc_handler = proc_dointvec, |
d2b176ed | 848 | }, |
88fc241f | 849 | { |
88fc241f DC |
850 | .procname = "unaligned-dump-stack", |
851 | .data = &unaligned_dump_stack, | |
852 | .maxlen = sizeof (int), | |
853 | .mode = 0644, | |
6d456111 | 854 | .proc_handler = proc_dointvec, |
88fc241f | 855 | }, |
bebfa101 | 856 | #endif |
e162b39a MSB |
857 | #ifdef CONFIG_DETECT_HUNG_TASK |
858 | { | |
e162b39a MSB |
859 | .procname = "hung_task_panic", |
860 | .data = &sysctl_hung_task_panic, | |
861 | .maxlen = sizeof(int), | |
862 | .mode = 0644, | |
6d456111 | 863 | .proc_handler = proc_dointvec_minmax, |
e162b39a MSB |
864 | .extra1 = &zero, |
865 | .extra2 = &one, | |
866 | }, | |
82a1fcb9 | 867 | { |
82a1fcb9 IM |
868 | .procname = "hung_task_check_count", |
869 | .data = &sysctl_hung_task_check_count, | |
90739081 | 870 | .maxlen = sizeof(unsigned long), |
82a1fcb9 | 871 | .mode = 0644, |
6d456111 | 872 | .proc_handler = proc_doulongvec_minmax, |
82a1fcb9 IM |
873 | }, |
874 | { | |
82a1fcb9 IM |
875 | .procname = "hung_task_timeout_secs", |
876 | .data = &sysctl_hung_task_timeout_secs, | |
90739081 | 877 | .maxlen = sizeof(unsigned long), |
82a1fcb9 | 878 | .mode = 0644, |
6d456111 | 879 | .proc_handler = proc_dohung_task_timeout_secs, |
82a1fcb9 IM |
880 | }, |
881 | { | |
82a1fcb9 IM |
882 | .procname = "hung_task_warnings", |
883 | .data = &sysctl_hung_task_warnings, | |
90739081 | 884 | .maxlen = sizeof(unsigned long), |
82a1fcb9 | 885 | .mode = 0644, |
6d456111 | 886 | .proc_handler = proc_doulongvec_minmax, |
82a1fcb9 | 887 | }, |
c4f3b63f | 888 | #endif |
bebfa101 AK |
889 | #ifdef CONFIG_COMPAT |
890 | { | |
bebfa101 AK |
891 | .procname = "compat-log", |
892 | .data = &compat_log, | |
893 | .maxlen = sizeof (int), | |
894 | .mode = 0644, | |
6d456111 | 895 | .proc_handler = proc_dointvec, |
bebfa101 | 896 | }, |
951f22d5 | 897 | #endif |
23f78d4a IM |
898 | #ifdef CONFIG_RT_MUTEXES |
899 | { | |
23f78d4a IM |
900 | .procname = "max_lock_depth", |
901 | .data = &max_lock_depth, | |
902 | .maxlen = sizeof(int), | |
903 | .mode = 0644, | |
6d456111 | 904 | .proc_handler = proc_dointvec, |
23f78d4a | 905 | }, |
5096add8 | 906 | #endif |
10a0a8d4 | 907 | { |
10a0a8d4 JF |
908 | .procname = "poweroff_cmd", |
909 | .data = &poweroff_cmd, | |
910 | .maxlen = POWEROFF_CMD_PATH_LEN, | |
911 | .mode = 0644, | |
6d456111 | 912 | .proc_handler = proc_dostring, |
10a0a8d4 | 913 | }, |
0b77f5bf DH |
914 | #ifdef CONFIG_KEYS |
915 | { | |
0b77f5bf DH |
916 | .procname = "keys", |
917 | .mode = 0555, | |
918 | .child = key_sysctls, | |
919 | }, | |
920 | #endif | |
31a72bce PM |
921 | #ifdef CONFIG_RCU_TORTURE_TEST |
922 | { | |
31a72bce PM |
923 | .procname = "rcutorture_runnable", |
924 | .data = &rcutorture_runnable, | |
925 | .maxlen = sizeof(int), | |
926 | .mode = 0644, | |
6d456111 | 927 | .proc_handler = proc_dointvec, |
31a72bce PM |
928 | }, |
929 | #endif | |
cdd6c482 | 930 | #ifdef CONFIG_PERF_EVENTS |
1ccd1549 | 931 | { |
cdd6c482 IM |
932 | .procname = "perf_event_paranoid", |
933 | .data = &sysctl_perf_event_paranoid, | |
934 | .maxlen = sizeof(sysctl_perf_event_paranoid), | |
1ccd1549 | 935 | .mode = 0644, |
6d456111 | 936 | .proc_handler = proc_dointvec, |
1ccd1549 | 937 | }, |
c5078f78 | 938 | { |
cdd6c482 IM |
939 | .procname = "perf_event_mlock_kb", |
940 | .data = &sysctl_perf_event_mlock, | |
941 | .maxlen = sizeof(sysctl_perf_event_mlock), | |
c5078f78 | 942 | .mode = 0644, |
6d456111 | 943 | .proc_handler = proc_dointvec, |
c5078f78 | 944 | }, |
a78ac325 | 945 | { |
cdd6c482 IM |
946 | .procname = "perf_event_max_sample_rate", |
947 | .data = &sysctl_perf_event_sample_rate, | |
948 | .maxlen = sizeof(sysctl_perf_event_sample_rate), | |
a78ac325 | 949 | .mode = 0644, |
163ec435 | 950 | .proc_handler = perf_proc_update_handler, |
a78ac325 | 951 | }, |
1ccd1549 | 952 | #endif |
dfec072e VN |
953 | #ifdef CONFIG_KMEMCHECK |
954 | { | |
dfec072e VN |
955 | .procname = "kmemcheck", |
956 | .data = &kmemcheck_enabled, | |
957 | .maxlen = sizeof(int), | |
958 | .mode = 0644, | |
6d456111 | 959 | .proc_handler = proc_dointvec, |
dfec072e VN |
960 | }, |
961 | #endif | |
cb684b5b | 962 | #ifdef CONFIG_BLOCK |
5e605b64 | 963 | { |
5e605b64 JA |
964 | .procname = "blk_iopoll", |
965 | .data = &blk_iopoll_enabled, | |
966 | .maxlen = sizeof(int), | |
967 | .mode = 0644, | |
6d456111 | 968 | .proc_handler = proc_dointvec, |
5e605b64 | 969 | }, |
cb684b5b | 970 | #endif |
6fce56ec | 971 | { } |
1da177e4 LT |
972 | }; |
973 | ||
d8217f07 | 974 | static struct ctl_table vm_table[] = { |
1da177e4 | 975 | { |
1da177e4 LT |
976 | .procname = "overcommit_memory", |
977 | .data = &sysctl_overcommit_memory, | |
978 | .maxlen = sizeof(sysctl_overcommit_memory), | |
979 | .mode = 0644, | |
cb16e95f PH |
980 | .proc_handler = proc_dointvec_minmax, |
981 | .extra1 = &zero, | |
982 | .extra2 = &two, | |
1da177e4 | 983 | }, |
fadd8fbd | 984 | { |
fadd8fbd KH |
985 | .procname = "panic_on_oom", |
986 | .data = &sysctl_panic_on_oom, | |
987 | .maxlen = sizeof(sysctl_panic_on_oom), | |
988 | .mode = 0644, | |
cb16e95f PH |
989 | .proc_handler = proc_dointvec_minmax, |
990 | .extra1 = &zero, | |
991 | .extra2 = &two, | |
fadd8fbd | 992 | }, |
fe071d7e | 993 | { |
fe071d7e DR |
994 | .procname = "oom_kill_allocating_task", |
995 | .data = &sysctl_oom_kill_allocating_task, | |
996 | .maxlen = sizeof(sysctl_oom_kill_allocating_task), | |
997 | .mode = 0644, | |
6d456111 | 998 | .proc_handler = proc_dointvec, |
fe071d7e | 999 | }, |
fef1bdd6 | 1000 | { |
fef1bdd6 DR |
1001 | .procname = "oom_dump_tasks", |
1002 | .data = &sysctl_oom_dump_tasks, | |
1003 | .maxlen = sizeof(sysctl_oom_dump_tasks), | |
1004 | .mode = 0644, | |
6d456111 | 1005 | .proc_handler = proc_dointvec, |
fef1bdd6 | 1006 | }, |
1da177e4 | 1007 | { |
1da177e4 LT |
1008 | .procname = "overcommit_ratio", |
1009 | .data = &sysctl_overcommit_ratio, | |
1010 | .maxlen = sizeof(sysctl_overcommit_ratio), | |
1011 | .mode = 0644, | |
6d456111 | 1012 | .proc_handler = proc_dointvec, |
1da177e4 LT |
1013 | }, |
1014 | { | |
1da177e4 LT |
1015 | .procname = "page-cluster", |
1016 | .data = &page_cluster, | |
1017 | .maxlen = sizeof(int), | |
1018 | .mode = 0644, | |
cb16e95f PH |
1019 | .proc_handler = proc_dointvec_minmax, |
1020 | .extra1 = &zero, | |
1da177e4 LT |
1021 | }, |
1022 | { | |
1da177e4 LT |
1023 | .procname = "dirty_background_ratio", |
1024 | .data = &dirty_background_ratio, | |
1025 | .maxlen = sizeof(dirty_background_ratio), | |
1026 | .mode = 0644, | |
6d456111 | 1027 | .proc_handler = dirty_background_ratio_handler, |
1da177e4 LT |
1028 | .extra1 = &zero, |
1029 | .extra2 = &one_hundred, | |
1030 | }, | |
2da02997 | 1031 | { |
2da02997 DR |
1032 | .procname = "dirty_background_bytes", |
1033 | .data = &dirty_background_bytes, | |
1034 | .maxlen = sizeof(dirty_background_bytes), | |
1035 | .mode = 0644, | |
6d456111 | 1036 | .proc_handler = dirty_background_bytes_handler, |
fc3501d4 | 1037 | .extra1 = &one_ul, |
2da02997 | 1038 | }, |
1da177e4 | 1039 | { |
1da177e4 LT |
1040 | .procname = "dirty_ratio", |
1041 | .data = &vm_dirty_ratio, | |
1042 | .maxlen = sizeof(vm_dirty_ratio), | |
1043 | .mode = 0644, | |
6d456111 | 1044 | .proc_handler = dirty_ratio_handler, |
1da177e4 LT |
1045 | .extra1 = &zero, |
1046 | .extra2 = &one_hundred, | |
1047 | }, | |
2da02997 | 1048 | { |
2da02997 DR |
1049 | .procname = "dirty_bytes", |
1050 | .data = &vm_dirty_bytes, | |
1051 | .maxlen = sizeof(vm_dirty_bytes), | |
1052 | .mode = 0644, | |
6d456111 | 1053 | .proc_handler = dirty_bytes_handler, |
9e4a5bda | 1054 | .extra1 = &dirty_bytes_min, |
2da02997 | 1055 | }, |
1da177e4 | 1056 | { |
1da177e4 | 1057 | .procname = "dirty_writeback_centisecs", |
f6ef9438 BS |
1058 | .data = &dirty_writeback_interval, |
1059 | .maxlen = sizeof(dirty_writeback_interval), | |
1da177e4 | 1060 | .mode = 0644, |
6d456111 | 1061 | .proc_handler = dirty_writeback_centisecs_handler, |
1da177e4 LT |
1062 | }, |
1063 | { | |
1da177e4 | 1064 | .procname = "dirty_expire_centisecs", |
f6ef9438 BS |
1065 | .data = &dirty_expire_interval, |
1066 | .maxlen = sizeof(dirty_expire_interval), | |
1da177e4 | 1067 | .mode = 0644, |
cb16e95f PH |
1068 | .proc_handler = proc_dointvec_minmax, |
1069 | .extra1 = &zero, | |
1da177e4 LT |
1070 | }, |
1071 | { | |
1da177e4 LT |
1072 | .procname = "nr_pdflush_threads", |
1073 | .data = &nr_pdflush_threads, | |
1074 | .maxlen = sizeof nr_pdflush_threads, | |
1075 | .mode = 0444 /* read-only*/, | |
6d456111 | 1076 | .proc_handler = proc_dointvec, |
1da177e4 LT |
1077 | }, |
1078 | { | |
1da177e4 LT |
1079 | .procname = "swappiness", |
1080 | .data = &vm_swappiness, | |
1081 | .maxlen = sizeof(vm_swappiness), | |
1082 | .mode = 0644, | |
6d456111 | 1083 | .proc_handler = proc_dointvec_minmax, |
1da177e4 LT |
1084 | .extra1 = &zero, |
1085 | .extra2 = &one_hundred, | |
1086 | }, | |
1087 | #ifdef CONFIG_HUGETLB_PAGE | |
06808b08 | 1088 | { |
1da177e4 | 1089 | .procname = "nr_hugepages", |
e5ff2159 | 1090 | .data = NULL, |
1da177e4 LT |
1091 | .maxlen = sizeof(unsigned long), |
1092 | .mode = 0644, | |
6d456111 | 1093 | .proc_handler = hugetlb_sysctl_handler, |
1da177e4 LT |
1094 | .extra1 = (void *)&hugetlb_zero, |
1095 | .extra2 = (void *)&hugetlb_infinity, | |
06808b08 LS |
1096 | }, |
1097 | #ifdef CONFIG_NUMA | |
1098 | { | |
1099 | .procname = "nr_hugepages_mempolicy", | |
1100 | .data = NULL, | |
1101 | .maxlen = sizeof(unsigned long), | |
1102 | .mode = 0644, | |
1103 | .proc_handler = &hugetlb_mempolicy_sysctl_handler, | |
1104 | .extra1 = (void *)&hugetlb_zero, | |
1105 | .extra2 = (void *)&hugetlb_infinity, | |
1106 | }, | |
1107 | #endif | |
1da177e4 | 1108 | { |
1da177e4 LT |
1109 | .procname = "hugetlb_shm_group", |
1110 | .data = &sysctl_hugetlb_shm_group, | |
1111 | .maxlen = sizeof(gid_t), | |
1112 | .mode = 0644, | |
6d456111 | 1113 | .proc_handler = proc_dointvec, |
1da177e4 | 1114 | }, |
396faf03 | 1115 | { |
396faf03 MG |
1116 | .procname = "hugepages_treat_as_movable", |
1117 | .data = &hugepages_treat_as_movable, | |
1118 | .maxlen = sizeof(int), | |
1119 | .mode = 0644, | |
6d456111 | 1120 | .proc_handler = hugetlb_treat_movable_handler, |
396faf03 | 1121 | }, |
d1c3fb1f | 1122 | { |
d1c3fb1f | 1123 | .procname = "nr_overcommit_hugepages", |
e5ff2159 AK |
1124 | .data = NULL, |
1125 | .maxlen = sizeof(unsigned long), | |
d1c3fb1f | 1126 | .mode = 0644, |
6d456111 | 1127 | .proc_handler = hugetlb_overcommit_handler, |
e5ff2159 AK |
1128 | .extra1 = (void *)&hugetlb_zero, |
1129 | .extra2 = (void *)&hugetlb_infinity, | |
d1c3fb1f | 1130 | }, |
1da177e4 LT |
1131 | #endif |
1132 | { | |
1da177e4 LT |
1133 | .procname = "lowmem_reserve_ratio", |
1134 | .data = &sysctl_lowmem_reserve_ratio, | |
1135 | .maxlen = sizeof(sysctl_lowmem_reserve_ratio), | |
1136 | .mode = 0644, | |
6d456111 | 1137 | .proc_handler = lowmem_reserve_ratio_sysctl_handler, |
1da177e4 | 1138 | }, |
9d0243bc | 1139 | { |
9d0243bc AM |
1140 | .procname = "drop_caches", |
1141 | .data = &sysctl_drop_caches, | |
1142 | .maxlen = sizeof(int), | |
1143 | .mode = 0644, | |
1144 | .proc_handler = drop_caches_sysctl_handler, | |
cb16e95f PH |
1145 | .extra1 = &one, |
1146 | .extra2 = &three, | |
9d0243bc | 1147 | }, |
76ab0f53 MG |
1148 | #ifdef CONFIG_COMPACTION |
1149 | { | |
1150 | .procname = "compact_memory", | |
1151 | .data = &sysctl_compact_memory, | |
1152 | .maxlen = sizeof(int), | |
1153 | .mode = 0200, | |
1154 | .proc_handler = sysctl_compaction_handler, | |
1155 | }, | |
5e771905 MG |
1156 | { |
1157 | .procname = "extfrag_threshold", | |
1158 | .data = &sysctl_extfrag_threshold, | |
1159 | .maxlen = sizeof(int), | |
1160 | .mode = 0644, | |
1161 | .proc_handler = sysctl_extfrag_handler, | |
1162 | .extra1 = &min_extfrag_threshold, | |
1163 | .extra2 = &max_extfrag_threshold, | |
1164 | }, | |
1165 | ||
76ab0f53 | 1166 | #endif /* CONFIG_COMPACTION */ |
1da177e4 | 1167 | { |
1da177e4 LT |
1168 | .procname = "min_free_kbytes", |
1169 | .data = &min_free_kbytes, | |
1170 | .maxlen = sizeof(min_free_kbytes), | |
1171 | .mode = 0644, | |
6d456111 | 1172 | .proc_handler = min_free_kbytes_sysctl_handler, |
1da177e4 LT |
1173 | .extra1 = &zero, |
1174 | }, | |
8ad4b1fb | 1175 | { |
8ad4b1fb RS |
1176 | .procname = "percpu_pagelist_fraction", |
1177 | .data = &percpu_pagelist_fraction, | |
1178 | .maxlen = sizeof(percpu_pagelist_fraction), | |
1179 | .mode = 0644, | |
6d456111 | 1180 | .proc_handler = percpu_pagelist_fraction_sysctl_handler, |
8ad4b1fb RS |
1181 | .extra1 = &min_percpu_pagelist_fract, |
1182 | }, | |
1da177e4 LT |
1183 | #ifdef CONFIG_MMU |
1184 | { | |
1da177e4 LT |
1185 | .procname = "max_map_count", |
1186 | .data = &sysctl_max_map_count, | |
1187 | .maxlen = sizeof(sysctl_max_map_count), | |
1188 | .mode = 0644, | |
3e26120c | 1189 | .proc_handler = proc_dointvec_minmax, |
70da2340 | 1190 | .extra1 = &zero, |
1da177e4 | 1191 | }, |
dd8632a1 PM |
1192 | #else |
1193 | { | |
dd8632a1 PM |
1194 | .procname = "nr_trim_pages", |
1195 | .data = &sysctl_nr_trim_pages, | |
1196 | .maxlen = sizeof(sysctl_nr_trim_pages), | |
1197 | .mode = 0644, | |
6d456111 | 1198 | .proc_handler = proc_dointvec_minmax, |
dd8632a1 PM |
1199 | .extra1 = &zero, |
1200 | }, | |
1da177e4 LT |
1201 | #endif |
1202 | { | |
1da177e4 LT |
1203 | .procname = "laptop_mode", |
1204 | .data = &laptop_mode, | |
1205 | .maxlen = sizeof(laptop_mode), | |
1206 | .mode = 0644, | |
6d456111 | 1207 | .proc_handler = proc_dointvec_jiffies, |
1da177e4 LT |
1208 | }, |
1209 | { | |
1da177e4 LT |
1210 | .procname = "block_dump", |
1211 | .data = &block_dump, | |
1212 | .maxlen = sizeof(block_dump), | |
1213 | .mode = 0644, | |
6d456111 | 1214 | .proc_handler = proc_dointvec, |
1da177e4 LT |
1215 | .extra1 = &zero, |
1216 | }, | |
1217 | { | |
1da177e4 LT |
1218 | .procname = "vfs_cache_pressure", |
1219 | .data = &sysctl_vfs_cache_pressure, | |
1220 | .maxlen = sizeof(sysctl_vfs_cache_pressure), | |
1221 | .mode = 0644, | |
6d456111 | 1222 | .proc_handler = proc_dointvec, |
1da177e4 LT |
1223 | .extra1 = &zero, |
1224 | }, | |
1225 | #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT | |
1226 | { | |
1da177e4 LT |
1227 | .procname = "legacy_va_layout", |
1228 | .data = &sysctl_legacy_va_layout, | |
1229 | .maxlen = sizeof(sysctl_legacy_va_layout), | |
1230 | .mode = 0644, | |
6d456111 | 1231 | .proc_handler = proc_dointvec, |
1da177e4 LT |
1232 | .extra1 = &zero, |
1233 | }, | |
1234 | #endif | |
1743660b CL |
1235 | #ifdef CONFIG_NUMA |
1236 | { | |
1743660b CL |
1237 | .procname = "zone_reclaim_mode", |
1238 | .data = &zone_reclaim_mode, | |
1239 | .maxlen = sizeof(zone_reclaim_mode), | |
1240 | .mode = 0644, | |
6d456111 | 1241 | .proc_handler = proc_dointvec, |
c84db23c | 1242 | .extra1 = &zero, |
1743660b | 1243 | }, |
9614634f | 1244 | { |
9614634f CL |
1245 | .procname = "min_unmapped_ratio", |
1246 | .data = &sysctl_min_unmapped_ratio, | |
1247 | .maxlen = sizeof(sysctl_min_unmapped_ratio), | |
1248 | .mode = 0644, | |
6d456111 | 1249 | .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, |
9614634f CL |
1250 | .extra1 = &zero, |
1251 | .extra2 = &one_hundred, | |
1252 | }, | |
0ff38490 | 1253 | { |
0ff38490 CL |
1254 | .procname = "min_slab_ratio", |
1255 | .data = &sysctl_min_slab_ratio, | |
1256 | .maxlen = sizeof(sysctl_min_slab_ratio), | |
1257 | .mode = 0644, | |
6d456111 | 1258 | .proc_handler = sysctl_min_slab_ratio_sysctl_handler, |
0ff38490 CL |
1259 | .extra1 = &zero, |
1260 | .extra2 = &one_hundred, | |
1261 | }, | |
e6e5494c | 1262 | #endif |
77461ab3 CL |
1263 | #ifdef CONFIG_SMP |
1264 | { | |
77461ab3 CL |
1265 | .procname = "stat_interval", |
1266 | .data = &sysctl_stat_interval, | |
1267 | .maxlen = sizeof(sysctl_stat_interval), | |
1268 | .mode = 0644, | |
6d456111 | 1269 | .proc_handler = proc_dointvec_jiffies, |
77461ab3 CL |
1270 | }, |
1271 | #endif | |
6e141546 | 1272 | #ifdef CONFIG_MMU |
ed032189 | 1273 | { |
ed032189 | 1274 | .procname = "mmap_min_addr", |
788084ab EP |
1275 | .data = &dac_mmap_min_addr, |
1276 | .maxlen = sizeof(unsigned long), | |
ed032189 | 1277 | .mode = 0644, |
6d456111 | 1278 | .proc_handler = mmap_min_addr_handler, |
ed032189 | 1279 | }, |
6e141546 | 1280 | #endif |
f0c0b2b8 KH |
1281 | #ifdef CONFIG_NUMA |
1282 | { | |
f0c0b2b8 KH |
1283 | .procname = "numa_zonelist_order", |
1284 | .data = &numa_zonelist_order, | |
1285 | .maxlen = NUMA_ZONELIST_ORDER_LEN, | |
1286 | .mode = 0644, | |
6d456111 | 1287 | .proc_handler = numa_zonelist_order_handler, |
f0c0b2b8 KH |
1288 | }, |
1289 | #endif | |
2b8232ce | 1290 | #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ |
5c36e657 | 1291 | (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) |
e6e5494c | 1292 | { |
e6e5494c IM |
1293 | .procname = "vdso_enabled", |
1294 | .data = &vdso_enabled, | |
1295 | .maxlen = sizeof(vdso_enabled), | |
1296 | .mode = 0644, | |
6d456111 | 1297 | .proc_handler = proc_dointvec, |
e6e5494c IM |
1298 | .extra1 = &zero, |
1299 | }, | |
1da177e4 | 1300 | #endif |
195cf453 BG |
1301 | #ifdef CONFIG_HIGHMEM |
1302 | { | |
195cf453 BG |
1303 | .procname = "highmem_is_dirtyable", |
1304 | .data = &vm_highmem_is_dirtyable, | |
1305 | .maxlen = sizeof(vm_highmem_is_dirtyable), | |
1306 | .mode = 0644, | |
6d456111 | 1307 | .proc_handler = proc_dointvec_minmax, |
195cf453 BG |
1308 | .extra1 = &zero, |
1309 | .extra2 = &one, | |
1310 | }, | |
1311 | #endif | |
4be6f6bb | 1312 | { |
4be6f6bb PZ |
1313 | .procname = "scan_unevictable_pages", |
1314 | .data = &scan_unevictable_pages, | |
1315 | .maxlen = sizeof(scan_unevictable_pages), | |
1316 | .mode = 0644, | |
6d456111 | 1317 | .proc_handler = scan_unevictable_handler, |
4be6f6bb | 1318 | }, |
6a46079c AK |
1319 | #ifdef CONFIG_MEMORY_FAILURE |
1320 | { | |
6a46079c AK |
1321 | .procname = "memory_failure_early_kill", |
1322 | .data = &sysctl_memory_failure_early_kill, | |
1323 | .maxlen = sizeof(sysctl_memory_failure_early_kill), | |
1324 | .mode = 0644, | |
6d456111 | 1325 | .proc_handler = proc_dointvec_minmax, |
6a46079c AK |
1326 | .extra1 = &zero, |
1327 | .extra2 = &one, | |
1328 | }, | |
1329 | { | |
6a46079c AK |
1330 | .procname = "memory_failure_recovery", |
1331 | .data = &sysctl_memory_failure_recovery, | |
1332 | .maxlen = sizeof(sysctl_memory_failure_recovery), | |
1333 | .mode = 0644, | |
6d456111 | 1334 | .proc_handler = proc_dointvec_minmax, |
6a46079c AK |
1335 | .extra1 = &zero, |
1336 | .extra2 = &one, | |
1337 | }, | |
1338 | #endif | |
6fce56ec | 1339 | { } |
1da177e4 LT |
1340 | }; |
1341 | ||
2abc26fc | 1342 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
d8217f07 | 1343 | static struct ctl_table binfmt_misc_table[] = { |
6fce56ec | 1344 | { } |
2abc26fc EB |
1345 | }; |
1346 | #endif | |
1347 | ||
d8217f07 | 1348 | static struct ctl_table fs_table[] = { |
1da177e4 | 1349 | { |
1da177e4 LT |
1350 | .procname = "inode-nr", |
1351 | .data = &inodes_stat, | |
1352 | .maxlen = 2*sizeof(int), | |
1353 | .mode = 0444, | |
cffbc8aa | 1354 | .proc_handler = proc_nr_inodes, |
1da177e4 LT |
1355 | }, |
1356 | { | |
1da177e4 LT |
1357 | .procname = "inode-state", |
1358 | .data = &inodes_stat, | |
1359 | .maxlen = 7*sizeof(int), | |
1360 | .mode = 0444, | |
cffbc8aa | 1361 | .proc_handler = proc_nr_inodes, |
1da177e4 LT |
1362 | }, |
1363 | { | |
1da177e4 LT |
1364 | .procname = "file-nr", |
1365 | .data = &files_stat, | |
518de9b3 | 1366 | .maxlen = sizeof(files_stat), |
1da177e4 | 1367 | .mode = 0444, |
6d456111 | 1368 | .proc_handler = proc_nr_files, |
1da177e4 LT |
1369 | }, |
1370 | { | |
1da177e4 LT |
1371 | .procname = "file-max", |
1372 | .data = &files_stat.max_files, | |
518de9b3 | 1373 | .maxlen = sizeof(files_stat.max_files), |
1da177e4 | 1374 | .mode = 0644, |
518de9b3 | 1375 | .proc_handler = proc_doulongvec_minmax, |
1da177e4 | 1376 | }, |
9cfe015a | 1377 | { |
9cfe015a ED |
1378 | .procname = "nr_open", |
1379 | .data = &sysctl_nr_open, | |
1380 | .maxlen = sizeof(int), | |
1381 | .mode = 0644, | |
6d456111 | 1382 | .proc_handler = proc_dointvec_minmax, |
eceea0b3 AV |
1383 | .extra1 = &sysctl_nr_open_min, |
1384 | .extra2 = &sysctl_nr_open_max, | |
9cfe015a | 1385 | }, |
1da177e4 | 1386 | { |
1da177e4 LT |
1387 | .procname = "dentry-state", |
1388 | .data = &dentry_stat, | |
1389 | .maxlen = 6*sizeof(int), | |
1390 | .mode = 0444, | |
312d3ca8 | 1391 | .proc_handler = proc_nr_dentry, |
1da177e4 LT |
1392 | }, |
1393 | { | |
1da177e4 LT |
1394 | .procname = "overflowuid", |
1395 | .data = &fs_overflowuid, | |
1396 | .maxlen = sizeof(int), | |
1397 | .mode = 0644, | |
6d456111 | 1398 | .proc_handler = proc_dointvec_minmax, |
1da177e4 LT |
1399 | .extra1 = &minolduid, |
1400 | .extra2 = &maxolduid, | |
1401 | }, | |
1402 | { | |
1da177e4 LT |
1403 | .procname = "overflowgid", |
1404 | .data = &fs_overflowgid, | |
1405 | .maxlen = sizeof(int), | |
1406 | .mode = 0644, | |
6d456111 | 1407 | .proc_handler = proc_dointvec_minmax, |
1da177e4 LT |
1408 | .extra1 = &minolduid, |
1409 | .extra2 = &maxolduid, | |
1410 | }, | |
bfcd17a6 | 1411 | #ifdef CONFIG_FILE_LOCKING |
1da177e4 | 1412 | { |
1da177e4 LT |
1413 | .procname = "leases-enable", |
1414 | .data = &leases_enable, | |
1415 | .maxlen = sizeof(int), | |
1416 | .mode = 0644, | |
6d456111 | 1417 | .proc_handler = proc_dointvec, |
1da177e4 | 1418 | }, |
bfcd17a6 | 1419 | #endif |
1da177e4 LT |
1420 | #ifdef CONFIG_DNOTIFY |
1421 | { | |
1da177e4 LT |
1422 | .procname = "dir-notify-enable", |
1423 | .data = &dir_notify_enable, | |
1424 | .maxlen = sizeof(int), | |
1425 | .mode = 0644, | |
6d456111 | 1426 | .proc_handler = proc_dointvec, |
1da177e4 LT |
1427 | }, |
1428 | #endif | |
1429 | #ifdef CONFIG_MMU | |
bfcd17a6 | 1430 | #ifdef CONFIG_FILE_LOCKING |
1da177e4 | 1431 | { |
1da177e4 LT |
1432 | .procname = "lease-break-time", |
1433 | .data = &lease_break_time, | |
1434 | .maxlen = sizeof(int), | |
1435 | .mode = 0644, | |
6d456111 | 1436 | .proc_handler = proc_dointvec, |
1da177e4 | 1437 | }, |
bfcd17a6 | 1438 | #endif |
ebf3f09c | 1439 | #ifdef CONFIG_AIO |
1da177e4 | 1440 | { |
1da177e4 LT |
1441 | .procname = "aio-nr", |
1442 | .data = &aio_nr, | |
1443 | .maxlen = sizeof(aio_nr), | |
1444 | .mode = 0444, | |
6d456111 | 1445 | .proc_handler = proc_doulongvec_minmax, |
1da177e4 LT |
1446 | }, |
1447 | { | |
1da177e4 LT |
1448 | .procname = "aio-max-nr", |
1449 | .data = &aio_max_nr, | |
1450 | .maxlen = sizeof(aio_max_nr), | |
1451 | .mode = 0644, | |
6d456111 | 1452 | .proc_handler = proc_doulongvec_minmax, |
1da177e4 | 1453 | }, |
ebf3f09c | 1454 | #endif /* CONFIG_AIO */ |
2d9048e2 | 1455 | #ifdef CONFIG_INOTIFY_USER |
0399cb08 | 1456 | { |
0399cb08 RL |
1457 | .procname = "inotify", |
1458 | .mode = 0555, | |
1459 | .child = inotify_table, | |
1460 | }, | |
1461 | #endif | |
7ef9964e DL |
1462 | #ifdef CONFIG_EPOLL |
1463 | { | |
1464 | .procname = "epoll", | |
1465 | .mode = 0555, | |
1466 | .child = epoll_table, | |
1467 | }, | |
1468 | #endif | |
1da177e4 | 1469 | #endif |
d6e71144 | 1470 | { |
d6e71144 AC |
1471 | .procname = "suid_dumpable", |
1472 | .data = &suid_dumpable, | |
1473 | .maxlen = sizeof(int), | |
1474 | .mode = 0644, | |
6d456111 | 1475 | .proc_handler = proc_dointvec_minmax, |
8e654fba MW |
1476 | .extra1 = &zero, |
1477 | .extra2 = &two, | |
d6e71144 | 1478 | }, |
2abc26fc EB |
1479 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
1480 | { | |
2abc26fc EB |
1481 | .procname = "binfmt_misc", |
1482 | .mode = 0555, | |
1483 | .child = binfmt_misc_table, | |
1484 | }, | |
1485 | #endif | |
b492e95b | 1486 | { |
ff9da691 JA |
1487 | .procname = "pipe-max-size", |
1488 | .data = &pipe_max_size, | |
b492e95b JA |
1489 | .maxlen = sizeof(int), |
1490 | .mode = 0644, | |
ff9da691 JA |
1491 | .proc_handler = &pipe_proc_fn, |
1492 | .extra1 = &pipe_min_size, | |
b492e95b | 1493 | }, |
6fce56ec | 1494 | { } |
1da177e4 LT |
1495 | }; |
1496 | ||
d8217f07 | 1497 | static struct ctl_table debug_table[] = { |
ab3c68ee HC |
1498 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \ |
1499 | defined(CONFIG_S390) | |
abd4f750 | 1500 | { |
abd4f750 MAS |
1501 | .procname = "exception-trace", |
1502 | .data = &show_unhandled_signals, | |
1503 | .maxlen = sizeof(int), | |
1504 | .mode = 0644, | |
1505 | .proc_handler = proc_dointvec | |
1506 | }, | |
b2be84df MH |
1507 | #endif |
1508 | #if defined(CONFIG_OPTPROBES) | |
1509 | { | |
1510 | .procname = "kprobes-optimization", | |
1511 | .data = &sysctl_kprobes_optimization, | |
1512 | .maxlen = sizeof(int), | |
1513 | .mode = 0644, | |
1514 | .proc_handler = proc_kprobes_optimization_handler, | |
1515 | .extra1 = &zero, | |
1516 | .extra2 = &one, | |
1517 | }, | |
abd4f750 | 1518 | #endif |
6fce56ec | 1519 | { } |
1da177e4 LT |
1520 | }; |
1521 | ||
d8217f07 | 1522 | static struct ctl_table dev_table[] = { |
6fce56ec | 1523 | { } |
0eeca283 | 1524 | }; |
1da177e4 | 1525 | |
330d57fb AV |
1526 | static DEFINE_SPINLOCK(sysctl_lock); |
1527 | ||
1528 | /* called under sysctl_lock */ | |
1529 | static int use_table(struct ctl_table_header *p) | |
1530 | { | |
1531 | if (unlikely(p->unregistering)) | |
1532 | return 0; | |
1533 | p->used++; | |
1534 | return 1; | |
1535 | } | |
1536 | ||
1537 | /* called under sysctl_lock */ | |
1538 | static void unuse_table(struct ctl_table_header *p) | |
1539 | { | |
1540 | if (!--p->used) | |
1541 | if (unlikely(p->unregistering)) | |
1542 | complete(p->unregistering); | |
1543 | } | |
1544 | ||
1545 | /* called under sysctl_lock, will reacquire if has to wait */ | |
1546 | static void start_unregistering(struct ctl_table_header *p) | |
1547 | { | |
1548 | /* | |
1549 | * if p->used is 0, nobody will ever touch that entry again; | |
1550 | * we'll eliminate all paths to it before dropping sysctl_lock | |
1551 | */ | |
1552 | if (unlikely(p->used)) { | |
1553 | struct completion wait; | |
1554 | init_completion(&wait); | |
1555 | p->unregistering = &wait; | |
1556 | spin_unlock(&sysctl_lock); | |
1557 | wait_for_completion(&wait); | |
1558 | spin_lock(&sysctl_lock); | |
f7e6ced4 AV |
1559 | } else { |
1560 | /* anything non-NULL; we'll never dereference it */ | |
1561 | p->unregistering = ERR_PTR(-EINVAL); | |
330d57fb AV |
1562 | } |
1563 | /* | |
1564 | * do not remove from the list until nobody holds it; walking the | |
1565 | * list in do_sysctl() relies on that. | |
1566 | */ | |
1567 | list_del_init(&p->ctl_entry); | |
1568 | } | |
1569 | ||
f7e6ced4 AV |
1570 | void sysctl_head_get(struct ctl_table_header *head) |
1571 | { | |
1572 | spin_lock(&sysctl_lock); | |
1573 | head->count++; | |
1574 | spin_unlock(&sysctl_lock); | |
1575 | } | |
1576 | ||
dfef6dcd AV |
1577 | static void free_head(struct rcu_head *rcu) |
1578 | { | |
1579 | kfree(container_of(rcu, struct ctl_table_header, rcu)); | |
1580 | } | |
1581 | ||
f7e6ced4 AV |
1582 | void sysctl_head_put(struct ctl_table_header *head) |
1583 | { | |
1584 | spin_lock(&sysctl_lock); | |
1585 | if (!--head->count) | |
dfef6dcd | 1586 | call_rcu(&head->rcu, free_head); |
f7e6ced4 AV |
1587 | spin_unlock(&sysctl_lock); |
1588 | } | |
1589 | ||
1590 | struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) | |
1591 | { | |
1592 | if (!head) | |
1593 | BUG(); | |
1594 | spin_lock(&sysctl_lock); | |
1595 | if (!use_table(head)) | |
1596 | head = ERR_PTR(-ENOENT); | |
1597 | spin_unlock(&sysctl_lock); | |
1598 | return head; | |
1599 | } | |
1600 | ||
805b5d5e EB |
1601 | void sysctl_head_finish(struct ctl_table_header *head) |
1602 | { | |
1603 | if (!head) | |
1604 | return; | |
1605 | spin_lock(&sysctl_lock); | |
1606 | unuse_table(head); | |
1607 | spin_unlock(&sysctl_lock); | |
1608 | } | |
1609 | ||
73455092 AV |
1610 | static struct ctl_table_set * |
1611 | lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) | |
1612 | { | |
1613 | struct ctl_table_set *set = &root->default_set; | |
1614 | if (root->lookup) | |
1615 | set = root->lookup(root, namespaces); | |
1616 | return set; | |
1617 | } | |
1618 | ||
e51b6ba0 EB |
1619 | static struct list_head * |
1620 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) | |
805b5d5e | 1621 | { |
73455092 AV |
1622 | struct ctl_table_set *set = lookup_header_set(root, namespaces); |
1623 | return &set->list; | |
e51b6ba0 EB |
1624 | } |
1625 | ||
1626 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, | |
1627 | struct ctl_table_header *prev) | |
1628 | { | |
1629 | struct ctl_table_root *root; | |
1630 | struct list_head *header_list; | |
805b5d5e EB |
1631 | struct ctl_table_header *head; |
1632 | struct list_head *tmp; | |
e51b6ba0 | 1633 | |
805b5d5e EB |
1634 | spin_lock(&sysctl_lock); |
1635 | if (prev) { | |
e51b6ba0 | 1636 | head = prev; |
805b5d5e EB |
1637 | tmp = &prev->ctl_entry; |
1638 | unuse_table(prev); | |
1639 | goto next; | |
1640 | } | |
1641 | tmp = &root_table_header.ctl_entry; | |
1642 | for (;;) { | |
1643 | head = list_entry(tmp, struct ctl_table_header, ctl_entry); | |
1644 | ||
1645 | if (!use_table(head)) | |
1646 | goto next; | |
1647 | spin_unlock(&sysctl_lock); | |
1648 | return head; | |
1649 | next: | |
e51b6ba0 | 1650 | root = head->root; |
805b5d5e | 1651 | tmp = tmp->next; |
e51b6ba0 EB |
1652 | header_list = lookup_header_list(root, namespaces); |
1653 | if (tmp != header_list) | |
1654 | continue; | |
1655 | ||
1656 | do { | |
1657 | root = list_entry(root->root_list.next, | |
1658 | struct ctl_table_root, root_list); | |
1659 | if (root == &sysctl_table_root) | |
1660 | goto out; | |
1661 | header_list = lookup_header_list(root, namespaces); | |
1662 | } while (list_empty(header_list)); | |
1663 | tmp = header_list->next; | |
805b5d5e | 1664 | } |
e51b6ba0 | 1665 | out: |
805b5d5e EB |
1666 | spin_unlock(&sysctl_lock); |
1667 | return NULL; | |
1668 | } | |
1669 | ||
e51b6ba0 EB |
1670 | struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) |
1671 | { | |
1672 | return __sysctl_head_next(current->nsproxy, prev); | |
1673 | } | |
1674 | ||
1675 | void register_sysctl_root(struct ctl_table_root *root) | |
1676 | { | |
1677 | spin_lock(&sysctl_lock); | |
1678 | list_add_tail(&root->root_list, &sysctl_table_root.root_list); | |
1679 | spin_unlock(&sysctl_lock); | |
1680 | } | |
1681 | ||
1da177e4 | 1682 | /* |
1ff007eb | 1683 | * sysctl_perm does NOT grant the superuser all rights automatically, because |
1da177e4 LT |
1684 | * some sysctl variables are readonly even to root. |
1685 | */ | |
1686 | ||
1687 | static int test_perm(int mode, int op) | |
1688 | { | |
76aac0e9 | 1689 | if (!current_euid()) |
1da177e4 LT |
1690 | mode >>= 6; |
1691 | else if (in_egroup_p(0)) | |
1692 | mode >>= 3; | |
e6305c43 | 1693 | if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) |
1da177e4 LT |
1694 | return 0; |
1695 | return -EACCES; | |
1696 | } | |
1697 | ||
d7321cd6 | 1698 | int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) |
1da177e4 | 1699 | { |
d7321cd6 PE |
1700 | int mode; |
1701 | ||
d7321cd6 PE |
1702 | if (root->permissions) |
1703 | mode = root->permissions(root, current->nsproxy, table); | |
1704 | else | |
1705 | mode = table->mode; | |
1706 | ||
1707 | return test_perm(mode, op); | |
1da177e4 LT |
1708 | } |
1709 | ||
d912b0cc EB |
1710 | static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) |
1711 | { | |
2315ffa0 | 1712 | for (; table->procname; table++) { |
d912b0cc EB |
1713 | table->parent = parent; |
1714 | if (table->child) | |
1715 | sysctl_set_parent(table, table->child); | |
1716 | } | |
1717 | } | |
1718 | ||
1719 | static __init int sysctl_init(void) | |
1720 | { | |
1721 | sysctl_set_parent(NULL, root_table); | |
88f458e4 | 1722 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
b3bd3de6 | 1723 | sysctl_check_table(current->nsproxy, root_table); |
88f458e4 | 1724 | #endif |
d912b0cc EB |
1725 | return 0; |
1726 | } | |
1727 | ||
1728 | core_initcall(sysctl_init); | |
1729 | ||
bfbcf034 AV |
1730 | static struct ctl_table *is_branch_in(struct ctl_table *branch, |
1731 | struct ctl_table *table) | |
ae7edecc AV |
1732 | { |
1733 | struct ctl_table *p; | |
1734 | const char *s = branch->procname; | |
1735 | ||
1736 | /* branch should have named subdirectory as its first element */ | |
1737 | if (!s || !branch->child) | |
bfbcf034 | 1738 | return NULL; |
ae7edecc AV |
1739 | |
1740 | /* ... and nothing else */ | |
2315ffa0 | 1741 | if (branch[1].procname) |
bfbcf034 | 1742 | return NULL; |
ae7edecc AV |
1743 | |
1744 | /* table should contain subdirectory with the same name */ | |
2315ffa0 | 1745 | for (p = table; p->procname; p++) { |
ae7edecc AV |
1746 | if (!p->child) |
1747 | continue; | |
1748 | if (p->procname && strcmp(p->procname, s) == 0) | |
bfbcf034 | 1749 | return p; |
ae7edecc | 1750 | } |
bfbcf034 | 1751 | return NULL; |
ae7edecc AV |
1752 | } |
1753 | ||
1754 | /* see if attaching q to p would be an improvement */ | |
1755 | static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) | |
1756 | { | |
1757 | struct ctl_table *to = p->ctl_table, *by = q->ctl_table; | |
bfbcf034 | 1758 | struct ctl_table *next; |
ae7edecc AV |
1759 | int is_better = 0; |
1760 | int not_in_parent = !p->attached_by; | |
1761 | ||
bfbcf034 | 1762 | while ((next = is_branch_in(by, to)) != NULL) { |
ae7edecc AV |
1763 | if (by == q->attached_by) |
1764 | is_better = 1; | |
1765 | if (to == p->attached_by) | |
1766 | not_in_parent = 1; | |
1767 | by = by->child; | |
bfbcf034 | 1768 | to = next->child; |
ae7edecc AV |
1769 | } |
1770 | ||
1771 | if (is_better && not_in_parent) { | |
1772 | q->attached_by = by; | |
1773 | q->attached_to = to; | |
1774 | q->parent = p; | |
1775 | } | |
1776 | } | |
1777 | ||
1da177e4 | 1778 | /** |
e51b6ba0 EB |
1779 | * __register_sysctl_paths - register a sysctl hierarchy |
1780 | * @root: List of sysctl headers to register on | |
1781 | * @namespaces: Data to compute which lists of sysctl entries are visible | |
29e796fd | 1782 | * @path: The path to the directory the sysctl table is in. |
1da177e4 | 1783 | * @table: the top-level table structure |
1da177e4 LT |
1784 | * |
1785 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
29e796fd | 1786 | * array. A completely 0 filled entry terminates the table. |
1da177e4 | 1787 | * |
d8217f07 | 1788 | * The members of the &struct ctl_table structure are used as follows: |
1da177e4 | 1789 | * |
1da177e4 LT |
1790 | * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not |
1791 | * enter a sysctl file | |
1792 | * | |
1793 | * data - a pointer to data for use by proc_handler | |
1794 | * | |
1795 | * maxlen - the maximum size in bytes of the data | |
1796 | * | |
1797 | * mode - the file permissions for the /proc/sys file, and for sysctl(2) | |
1798 | * | |
1799 | * child - a pointer to the child sysctl table if this entry is a directory, or | |
1800 | * %NULL. | |
1801 | * | |
1802 | * proc_handler - the text handler routine (described below) | |
1803 | * | |
1da177e4 LT |
1804 | * de - for internal use by the sysctl routines |
1805 | * | |
1806 | * extra1, extra2 - extra pointers usable by the proc handler routines | |
1807 | * | |
1808 | * Leaf nodes in the sysctl tree will be represented by a single file | |
1809 | * under /proc; non-leaf nodes will be represented by directories. | |
1810 | * | |
1811 | * sysctl(2) can automatically manage read and write requests through | |
1812 | * the sysctl table. The data and maxlen fields of the ctl_table | |
1813 | * struct enable minimal validation of the values being written to be | |
1814 | * performed, and the mode field allows minimal authentication. | |
1815 | * | |
1da177e4 LT |
1816 | * There must be a proc_handler routine for any terminal nodes |
1817 | * mirrored under /proc/sys (non-terminals are handled by a built-in | |
1818 | * directory handler). Several default handlers are available to | |
1819 | * cover common cases - | |
1820 | * | |
1821 | * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), | |
1822 | * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), | |
1823 | * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() | |
1824 | * | |
1825 | * It is the handler's job to read the input buffer from user memory | |
1826 | * and process it. The handler should return 0 on success. | |
1827 | * | |
1828 | * This routine returns %NULL on a failure to register, and a pointer | |
1829 | * to the table header on success. | |
1830 | */ | |
e51b6ba0 EB |
1831 | struct ctl_table_header *__register_sysctl_paths( |
1832 | struct ctl_table_root *root, | |
1833 | struct nsproxy *namespaces, | |
1834 | const struct ctl_path *path, struct ctl_table *table) | |
1da177e4 | 1835 | { |
29e796fd EB |
1836 | struct ctl_table_header *header; |
1837 | struct ctl_table *new, **prevp; | |
1838 | unsigned int n, npath; | |
ae7edecc | 1839 | struct ctl_table_set *set; |
29e796fd EB |
1840 | |
1841 | /* Count the path components */ | |
2315ffa0 | 1842 | for (npath = 0; path[npath].procname; ++npath) |
29e796fd EB |
1843 | ; |
1844 | ||
1845 | /* | |
1846 | * For each path component, allocate a 2-element ctl_table array. | |
1847 | * The first array element will be filled with the sysctl entry | |
2315ffa0 | 1848 | * for this, the second will be the sentinel (procname == 0). |
29e796fd EB |
1849 | * |
1850 | * We allocate everything in one go so that we don't have to | |
1851 | * worry about freeing additional memory in unregister_sysctl_table. | |
1852 | */ | |
1853 | header = kzalloc(sizeof(struct ctl_table_header) + | |
1854 | (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); | |
1855 | if (!header) | |
1da177e4 | 1856 | return NULL; |
29e796fd EB |
1857 | |
1858 | new = (struct ctl_table *) (header + 1); | |
1859 | ||
1860 | /* Now connect the dots */ | |
1861 | prevp = &header->ctl_table; | |
1862 | for (n = 0; n < npath; ++n, ++path) { | |
1863 | /* Copy the procname */ | |
1864 | new->procname = path->procname; | |
29e796fd EB |
1865 | new->mode = 0555; |
1866 | ||
1867 | *prevp = new; | |
1868 | prevp = &new->child; | |
1869 | ||
1870 | new += 2; | |
1871 | } | |
1872 | *prevp = table; | |
23eb06de | 1873 | header->ctl_table_arg = table; |
29e796fd EB |
1874 | |
1875 | INIT_LIST_HEAD(&header->ctl_entry); | |
1876 | header->used = 0; | |
1877 | header->unregistering = NULL; | |
e51b6ba0 | 1878 | header->root = root; |
29e796fd | 1879 | sysctl_set_parent(NULL, header->ctl_table); |
f7e6ced4 | 1880 | header->count = 1; |
88f458e4 | 1881 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
e51b6ba0 | 1882 | if (sysctl_check_table(namespaces, header->ctl_table)) { |
29e796fd | 1883 | kfree(header); |
fc6cd25b EB |
1884 | return NULL; |
1885 | } | |
88f458e4 | 1886 | #endif |
330d57fb | 1887 | spin_lock(&sysctl_lock); |
73455092 | 1888 | header->set = lookup_header_set(root, namespaces); |
ae7edecc AV |
1889 | header->attached_by = header->ctl_table; |
1890 | header->attached_to = root_table; | |
1891 | header->parent = &root_table_header; | |
1892 | for (set = header->set; set; set = set->parent) { | |
1893 | struct ctl_table_header *p; | |
1894 | list_for_each_entry(p, &set->list, ctl_entry) { | |
1895 | if (p->unregistering) | |
1896 | continue; | |
1897 | try_attach(p, header); | |
1898 | } | |
1899 | } | |
1900 | header->parent->count++; | |
73455092 | 1901 | list_add_tail(&header->ctl_entry, &header->set->list); |
330d57fb | 1902 | spin_unlock(&sysctl_lock); |
29e796fd EB |
1903 | |
1904 | return header; | |
1905 | } | |
1906 | ||
e51b6ba0 EB |
1907 | /** |
1908 | * register_sysctl_table_path - register a sysctl table hierarchy | |
1909 | * @path: The path to the directory the sysctl table is in. | |
1910 | * @table: the top-level table structure | |
1911 | * | |
1912 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
1913 | * array. A completely 0 filled entry terminates the table. | |
1914 | * | |
1915 | * See __register_sysctl_paths for more details. | |
1916 | */ | |
1917 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, | |
1918 | struct ctl_table *table) | |
1919 | { | |
1920 | return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, | |
1921 | path, table); | |
1922 | } | |
1923 | ||
29e796fd EB |
1924 | /** |
1925 | * register_sysctl_table - register a sysctl table hierarchy | |
1926 | * @table: the top-level table structure | |
1927 | * | |
1928 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
1929 | * array. A completely 0 filled entry terminates the table. | |
1930 | * | |
1931 | * See register_sysctl_paths for more details. | |
1932 | */ | |
1933 | struct ctl_table_header *register_sysctl_table(struct ctl_table *table) | |
1934 | { | |
1935 | static const struct ctl_path null_path[] = { {} }; | |
1936 | ||
1937 | return register_sysctl_paths(null_path, table); | |
1da177e4 LT |
1938 | } |
1939 | ||
1940 | /** | |
1941 | * unregister_sysctl_table - unregister a sysctl table hierarchy | |
1942 | * @header: the header returned from register_sysctl_table | |
1943 | * | |
1944 | * Unregisters the sysctl table and all children. proc entries may not | |
1945 | * actually be removed until they are no longer used by anyone. | |
1946 | */ | |
1947 | void unregister_sysctl_table(struct ctl_table_header * header) | |
1948 | { | |
330d57fb | 1949 | might_sleep(); |
f1dad166 PE |
1950 | |
1951 | if (header == NULL) | |
1952 | return; | |
1953 | ||
330d57fb AV |
1954 | spin_lock(&sysctl_lock); |
1955 | start_unregistering(header); | |
ae7edecc AV |
1956 | if (!--header->parent->count) { |
1957 | WARN_ON(1); | |
dfef6dcd | 1958 | call_rcu(&header->parent->rcu, free_head); |
ae7edecc | 1959 | } |
f7e6ced4 | 1960 | if (!--header->count) |
dfef6dcd | 1961 | call_rcu(&header->rcu, free_head); |
330d57fb | 1962 | spin_unlock(&sysctl_lock); |
1da177e4 LT |
1963 | } |
1964 | ||
9043476f AV |
1965 | int sysctl_is_seen(struct ctl_table_header *p) |
1966 | { | |
1967 | struct ctl_table_set *set = p->set; | |
1968 | int res; | |
1969 | spin_lock(&sysctl_lock); | |
1970 | if (p->unregistering) | |
1971 | res = 0; | |
1972 | else if (!set->is_seen) | |
1973 | res = 1; | |
1974 | else | |
1975 | res = set->is_seen(set); | |
1976 | spin_unlock(&sysctl_lock); | |
1977 | return res; | |
1978 | } | |
1979 | ||
73455092 AV |
1980 | void setup_sysctl_set(struct ctl_table_set *p, |
1981 | struct ctl_table_set *parent, | |
1982 | int (*is_seen)(struct ctl_table_set *)) | |
1983 | { | |
1984 | INIT_LIST_HEAD(&p->list); | |
1985 | p->parent = parent ? parent : &sysctl_table_root.default_set; | |
1986 | p->is_seen = is_seen; | |
1987 | } | |
1988 | ||
b89a8171 | 1989 | #else /* !CONFIG_SYSCTL */ |
d8217f07 | 1990 | struct ctl_table_header *register_sysctl_table(struct ctl_table * table) |
b89a8171 EB |
1991 | { |
1992 | return NULL; | |
1993 | } | |
1994 | ||
29e796fd EB |
1995 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, |
1996 | struct ctl_table *table) | |
1997 | { | |
1998 | return NULL; | |
1999 | } | |
2000 | ||
b89a8171 EB |
2001 | void unregister_sysctl_table(struct ctl_table_header * table) |
2002 | { | |
2003 | } | |
2004 | ||
73455092 AV |
2005 | void setup_sysctl_set(struct ctl_table_set *p, |
2006 | struct ctl_table_set *parent, | |
2007 | int (*is_seen)(struct ctl_table_set *)) | |
2008 | { | |
2009 | } | |
2010 | ||
f7e6ced4 AV |
2011 | void sysctl_head_put(struct ctl_table_header *head) |
2012 | { | |
2013 | } | |
2014 | ||
b89a8171 EB |
2015 | #endif /* CONFIG_SYSCTL */ |
2016 | ||
1da177e4 LT |
2017 | /* |
2018 | * /proc/sys support | |
2019 | */ | |
2020 | ||
b89a8171 | 2021 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 | 2022 | |
b1ba4ddd | 2023 | static int _proc_do_string(void* data, int maxlen, int write, |
8d65af78 | 2024 | void __user *buffer, |
b1ba4ddd | 2025 | size_t *lenp, loff_t *ppos) |
1da177e4 LT |
2026 | { |
2027 | size_t len; | |
2028 | char __user *p; | |
2029 | char c; | |
8d060877 ON |
2030 | |
2031 | if (!data || !maxlen || !*lenp) { | |
1da177e4 LT |
2032 | *lenp = 0; |
2033 | return 0; | |
2034 | } | |
8d060877 | 2035 | |
1da177e4 LT |
2036 | if (write) { |
2037 | len = 0; | |
2038 | p = buffer; | |
2039 | while (len < *lenp) { | |
2040 | if (get_user(c, p++)) | |
2041 | return -EFAULT; | |
2042 | if (c == 0 || c == '\n') | |
2043 | break; | |
2044 | len++; | |
2045 | } | |
f5dd3d6f SV |
2046 | if (len >= maxlen) |
2047 | len = maxlen-1; | |
2048 | if(copy_from_user(data, buffer, len)) | |
1da177e4 | 2049 | return -EFAULT; |
f5dd3d6f | 2050 | ((char *) data)[len] = 0; |
1da177e4 LT |
2051 | *ppos += *lenp; |
2052 | } else { | |
f5dd3d6f SV |
2053 | len = strlen(data); |
2054 | if (len > maxlen) | |
2055 | len = maxlen; | |
8d060877 ON |
2056 | |
2057 | if (*ppos > len) { | |
2058 | *lenp = 0; | |
2059 | return 0; | |
2060 | } | |
2061 | ||
2062 | data += *ppos; | |
2063 | len -= *ppos; | |
2064 | ||
1da177e4 LT |
2065 | if (len > *lenp) |
2066 | len = *lenp; | |
2067 | if (len) | |
f5dd3d6f | 2068 | if(copy_to_user(buffer, data, len)) |
1da177e4 LT |
2069 | return -EFAULT; |
2070 | if (len < *lenp) { | |
2071 | if(put_user('\n', ((char __user *) buffer) + len)) | |
2072 | return -EFAULT; | |
2073 | len++; | |
2074 | } | |
2075 | *lenp = len; | |
2076 | *ppos += len; | |
2077 | } | |
2078 | return 0; | |
2079 | } | |
2080 | ||
f5dd3d6f SV |
2081 | /** |
2082 | * proc_dostring - read a string sysctl | |
2083 | * @table: the sysctl table | |
2084 | * @write: %TRUE if this is a write to the sysctl file | |
f5dd3d6f SV |
2085 | * @buffer: the user buffer |
2086 | * @lenp: the size of the user buffer | |
2087 | * @ppos: file position | |
2088 | * | |
2089 | * Reads/writes a string from/to the user buffer. If the kernel | |
2090 | * buffer provided is not large enough to hold the string, the | |
2091 | * string is truncated. The copied string is %NULL-terminated. | |
2092 | * If the string is being read by the user process, it is copied | |
2093 | * and a newline '\n' is added. It is truncated if the buffer is | |
2094 | * not large enough. | |
2095 | * | |
2096 | * Returns 0 on success. | |
2097 | */ | |
8d65af78 | 2098 | int proc_dostring(struct ctl_table *table, int write, |
f5dd3d6f SV |
2099 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2100 | { | |
8d65af78 | 2101 | return _proc_do_string(table->data, table->maxlen, write, |
f5dd3d6f SV |
2102 | buffer, lenp, ppos); |
2103 | } | |
2104 | ||
00b7c339 AW |
2105 | static size_t proc_skip_spaces(char **buf) |
2106 | { | |
2107 | size_t ret; | |
2108 | char *tmp = skip_spaces(*buf); | |
2109 | ret = tmp - *buf; | |
2110 | *buf = tmp; | |
2111 | return ret; | |
2112 | } | |
2113 | ||
9f977fb7 OP |
2114 | static void proc_skip_char(char **buf, size_t *size, const char v) |
2115 | { | |
2116 | while (*size) { | |
2117 | if (**buf != v) | |
2118 | break; | |
2119 | (*size)--; | |
2120 | (*buf)++; | |
2121 | } | |
2122 | } | |
2123 | ||
00b7c339 AW |
2124 | #define TMPBUFLEN 22 |
2125 | /** | |
0fc377bd | 2126 | * proc_get_long - reads an ASCII formatted integer from a user buffer |
00b7c339 | 2127 | * |
0fc377bd RD |
2128 | * @buf: a kernel buffer |
2129 | * @size: size of the kernel buffer | |
2130 | * @val: this is where the number will be stored | |
2131 | * @neg: set to %TRUE if number is negative | |
2132 | * @perm_tr: a vector which contains the allowed trailers | |
2133 | * @perm_tr_len: size of the perm_tr vector | |
2134 | * @tr: pointer to store the trailer character | |
00b7c339 | 2135 | * |
0fc377bd RD |
2136 | * In case of success %0 is returned and @buf and @size are updated with |
2137 | * the amount of bytes read. If @tr is non-NULL and a trailing | |
2138 | * character exists (size is non-zero after returning from this | |
2139 | * function), @tr is updated with the trailing character. | |
00b7c339 AW |
2140 | */ |
2141 | static int proc_get_long(char **buf, size_t *size, | |
2142 | unsigned long *val, bool *neg, | |
2143 | const char *perm_tr, unsigned perm_tr_len, char *tr) | |
2144 | { | |
2145 | int len; | |
2146 | char *p, tmp[TMPBUFLEN]; | |
2147 | ||
2148 | if (!*size) | |
2149 | return -EINVAL; | |
2150 | ||
2151 | len = *size; | |
2152 | if (len > TMPBUFLEN - 1) | |
2153 | len = TMPBUFLEN - 1; | |
2154 | ||
2155 | memcpy(tmp, *buf, len); | |
2156 | ||
2157 | tmp[len] = 0; | |
2158 | p = tmp; | |
2159 | if (*p == '-' && *size > 1) { | |
2160 | *neg = true; | |
2161 | p++; | |
2162 | } else | |
2163 | *neg = false; | |
2164 | if (!isdigit(*p)) | |
2165 | return -EINVAL; | |
2166 | ||
2167 | *val = simple_strtoul(p, &p, 0); | |
2168 | ||
2169 | len = p - tmp; | |
2170 | ||
2171 | /* We don't know if the next char is whitespace thus we may accept | |
2172 | * invalid integers (e.g. 1234...a) or two integers instead of one | |
2173 | * (e.g. 123...1). So lets not allow such large numbers. */ | |
2174 | if (len == TMPBUFLEN - 1) | |
2175 | return -EINVAL; | |
2176 | ||
2177 | if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) | |
2178 | return -EINVAL; | |
1da177e4 | 2179 | |
00b7c339 AW |
2180 | if (tr && (len < *size)) |
2181 | *tr = *p; | |
2182 | ||
2183 | *buf += len; | |
2184 | *size -= len; | |
2185 | ||
2186 | return 0; | |
2187 | } | |
2188 | ||
2189 | /** | |
0fc377bd | 2190 | * proc_put_long - converts an integer to a decimal ASCII formatted string |
00b7c339 | 2191 | * |
0fc377bd RD |
2192 | * @buf: the user buffer |
2193 | * @size: the size of the user buffer | |
2194 | * @val: the integer to be converted | |
2195 | * @neg: sign of the number, %TRUE for negative | |
00b7c339 | 2196 | * |
0fc377bd RD |
2197 | * In case of success %0 is returned and @buf and @size are updated with |
2198 | * the amount of bytes written. | |
00b7c339 AW |
2199 | */ |
2200 | static int proc_put_long(void __user **buf, size_t *size, unsigned long val, | |
2201 | bool neg) | |
2202 | { | |
2203 | int len; | |
2204 | char tmp[TMPBUFLEN], *p = tmp; | |
2205 | ||
2206 | sprintf(p, "%s%lu", neg ? "-" : "", val); | |
2207 | len = strlen(tmp); | |
2208 | if (len > *size) | |
2209 | len = *size; | |
2210 | if (copy_to_user(*buf, tmp, len)) | |
2211 | return -EFAULT; | |
2212 | *size -= len; | |
2213 | *buf += len; | |
2214 | return 0; | |
2215 | } | |
2216 | #undef TMPBUFLEN | |
2217 | ||
2218 | static int proc_put_char(void __user **buf, size_t *size, char c) | |
2219 | { | |
2220 | if (*size) { | |
2221 | char __user **buffer = (char __user **)buf; | |
2222 | if (put_user(c, *buffer)) | |
2223 | return -EFAULT; | |
2224 | (*size)--, (*buffer)++; | |
2225 | *buf = *buffer; | |
2226 | } | |
2227 | return 0; | |
2228 | } | |
1da177e4 | 2229 | |
00b7c339 | 2230 | static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
2231 | int *valp, |
2232 | int write, void *data) | |
2233 | { | |
2234 | if (write) { | |
2235 | *valp = *negp ? -*lvalp : *lvalp; | |
2236 | } else { | |
2237 | int val = *valp; | |
2238 | if (val < 0) { | |
00b7c339 | 2239 | *negp = true; |
1da177e4 LT |
2240 | *lvalp = (unsigned long)-val; |
2241 | } else { | |
00b7c339 | 2242 | *negp = false; |
1da177e4 LT |
2243 | *lvalp = (unsigned long)val; |
2244 | } | |
2245 | } | |
2246 | return 0; | |
2247 | } | |
2248 | ||
00b7c339 AW |
2249 | static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; |
2250 | ||
d8217f07 | 2251 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, |
8d65af78 | 2252 | int write, void __user *buffer, |
fcfbd547 | 2253 | size_t *lenp, loff_t *ppos, |
00b7c339 | 2254 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
1da177e4 LT |
2255 | int write, void *data), |
2256 | void *data) | |
2257 | { | |
00b7c339 AW |
2258 | int *i, vleft, first = 1, err = 0; |
2259 | unsigned long page = 0; | |
2260 | size_t left; | |
2261 | char *kbuf; | |
1da177e4 | 2262 | |
00b7c339 | 2263 | if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { |
1da177e4 LT |
2264 | *lenp = 0; |
2265 | return 0; | |
2266 | } | |
2267 | ||
fcfbd547 | 2268 | i = (int *) tbl_data; |
1da177e4 LT |
2269 | vleft = table->maxlen / sizeof(*i); |
2270 | left = *lenp; | |
2271 | ||
2272 | if (!conv) | |
2273 | conv = do_proc_dointvec_conv; | |
2274 | ||
00b7c339 AW |
2275 | if (write) { |
2276 | if (left > PAGE_SIZE - 1) | |
2277 | left = PAGE_SIZE - 1; | |
2278 | page = __get_free_page(GFP_TEMPORARY); | |
2279 | kbuf = (char *) page; | |
2280 | if (!kbuf) | |
2281 | return -ENOMEM; | |
2282 | if (copy_from_user(kbuf, buffer, left)) { | |
2283 | err = -EFAULT; | |
2284 | goto free; | |
2285 | } | |
2286 | kbuf[left] = 0; | |
2287 | } | |
2288 | ||
1da177e4 | 2289 | for (; left && vleft--; i++, first=0) { |
00b7c339 AW |
2290 | unsigned long lval; |
2291 | bool neg; | |
1da177e4 | 2292 | |
00b7c339 AW |
2293 | if (write) { |
2294 | left -= proc_skip_spaces(&kbuf); | |
1da177e4 | 2295 | |
563b0467 O |
2296 | if (!left) |
2297 | break; | |
00b7c339 AW |
2298 | err = proc_get_long(&kbuf, &left, &lval, &neg, |
2299 | proc_wspace_sep, | |
2300 | sizeof(proc_wspace_sep), NULL); | |
2301 | if (err) | |
1da177e4 | 2302 | break; |
00b7c339 AW |
2303 | if (conv(&neg, &lval, i, 1, data)) { |
2304 | err = -EINVAL; | |
1da177e4 | 2305 | break; |
00b7c339 | 2306 | } |
1da177e4 | 2307 | } else { |
00b7c339 AW |
2308 | if (conv(&neg, &lval, i, 0, data)) { |
2309 | err = -EINVAL; | |
2310 | break; | |
2311 | } | |
1da177e4 | 2312 | if (!first) |
00b7c339 AW |
2313 | err = proc_put_char(&buffer, &left, '\t'); |
2314 | if (err) | |
2315 | break; | |
2316 | err = proc_put_long(&buffer, &left, lval, neg); | |
2317 | if (err) | |
1da177e4 | 2318 | break; |
1da177e4 LT |
2319 | } |
2320 | } | |
2321 | ||
00b7c339 AW |
2322 | if (!write && !first && left && !err) |
2323 | err = proc_put_char(&buffer, &left, '\n'); | |
563b0467 | 2324 | if (write && !err && left) |
00b7c339 AW |
2325 | left -= proc_skip_spaces(&kbuf); |
2326 | free: | |
1da177e4 | 2327 | if (write) { |
00b7c339 AW |
2328 | free_page(page); |
2329 | if (first) | |
2330 | return err ? : -EINVAL; | |
1da177e4 | 2331 | } |
1da177e4 LT |
2332 | *lenp -= left; |
2333 | *ppos += *lenp; | |
00b7c339 | 2334 | return err; |
1da177e4 LT |
2335 | } |
2336 | ||
8d65af78 | 2337 | static int do_proc_dointvec(struct ctl_table *table, int write, |
fcfbd547 | 2338 | void __user *buffer, size_t *lenp, loff_t *ppos, |
00b7c339 | 2339 | int (*conv)(bool *negp, unsigned long *lvalp, int *valp, |
fcfbd547 KK |
2340 | int write, void *data), |
2341 | void *data) | |
2342 | { | |
8d65af78 | 2343 | return __do_proc_dointvec(table->data, table, write, |
fcfbd547 KK |
2344 | buffer, lenp, ppos, conv, data); |
2345 | } | |
2346 | ||
1da177e4 LT |
2347 | /** |
2348 | * proc_dointvec - read a vector of integers | |
2349 | * @table: the sysctl table | |
2350 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2351 | * @buffer: the user buffer |
2352 | * @lenp: the size of the user buffer | |
2353 | * @ppos: file position | |
2354 | * | |
2355 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2356 | * values from/to the user buffer, treated as an ASCII string. | |
2357 | * | |
2358 | * Returns 0 on success. | |
2359 | */ | |
8d65af78 | 2360 | int proc_dointvec(struct ctl_table *table, int write, |
1da177e4 LT |
2361 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2362 | { | |
8d65af78 | 2363 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
1da177e4 LT |
2364 | NULL,NULL); |
2365 | } | |
2366 | ||
34f5a398 | 2367 | /* |
25ddbb18 AK |
2368 | * Taint values can only be increased |
2369 | * This means we can safely use a temporary. | |
34f5a398 | 2370 | */ |
8d65af78 | 2371 | static int proc_taint(struct ctl_table *table, int write, |
34f5a398 TT |
2372 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2373 | { | |
25ddbb18 AK |
2374 | struct ctl_table t; |
2375 | unsigned long tmptaint = get_taint(); | |
2376 | int err; | |
34f5a398 | 2377 | |
91fcd412 | 2378 | if (write && !capable(CAP_SYS_ADMIN)) |
34f5a398 TT |
2379 | return -EPERM; |
2380 | ||
25ddbb18 AK |
2381 | t = *table; |
2382 | t.data = &tmptaint; | |
8d65af78 | 2383 | err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); |
25ddbb18 AK |
2384 | if (err < 0) |
2385 | return err; | |
2386 | ||
2387 | if (write) { | |
2388 | /* | |
2389 | * Poor man's atomic or. Not worth adding a primitive | |
2390 | * to everyone's atomic.h for this | |
2391 | */ | |
2392 | int i; | |
2393 | for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { | |
2394 | if ((tmptaint >> i) & 1) | |
2395 | add_taint(i); | |
2396 | } | |
2397 | } | |
2398 | ||
2399 | return err; | |
34f5a398 TT |
2400 | } |
2401 | ||
bfdc0b49 RW |
2402 | #ifdef CONFIG_PRINTK |
2403 | static int proc_dmesg_restrict(struct ctl_table *table, int write, | |
2404 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2405 | { | |
2406 | if (write && !capable(CAP_SYS_ADMIN)) | |
2407 | return -EPERM; | |
2408 | ||
2409 | return proc_dointvec_minmax(table, write, buffer, lenp, ppos); | |
2410 | } | |
2411 | #endif | |
2412 | ||
1da177e4 LT |
2413 | struct do_proc_dointvec_minmax_conv_param { |
2414 | int *min; | |
2415 | int *max; | |
2416 | }; | |
2417 | ||
00b7c339 AW |
2418 | static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, |
2419 | int *valp, | |
1da177e4 LT |
2420 | int write, void *data) |
2421 | { | |
2422 | struct do_proc_dointvec_minmax_conv_param *param = data; | |
2423 | if (write) { | |
2424 | int val = *negp ? -*lvalp : *lvalp; | |
2425 | if ((param->min && *param->min > val) || | |
2426 | (param->max && *param->max < val)) | |
2427 | return -EINVAL; | |
2428 | *valp = val; | |
2429 | } else { | |
2430 | int val = *valp; | |
2431 | if (val < 0) { | |
00b7c339 | 2432 | *negp = true; |
1da177e4 LT |
2433 | *lvalp = (unsigned long)-val; |
2434 | } else { | |
00b7c339 | 2435 | *negp = false; |
1da177e4 LT |
2436 | *lvalp = (unsigned long)val; |
2437 | } | |
2438 | } | |
2439 | return 0; | |
2440 | } | |
2441 | ||
2442 | /** | |
2443 | * proc_dointvec_minmax - read a vector of integers with min/max values | |
2444 | * @table: the sysctl table | |
2445 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2446 | * @buffer: the user buffer |
2447 | * @lenp: the size of the user buffer | |
2448 | * @ppos: file position | |
2449 | * | |
2450 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2451 | * values from/to the user buffer, treated as an ASCII string. | |
2452 | * | |
2453 | * This routine will ensure the values are within the range specified by | |
2454 | * table->extra1 (min) and table->extra2 (max). | |
2455 | * | |
2456 | * Returns 0 on success. | |
2457 | */ | |
8d65af78 | 2458 | int proc_dointvec_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2459 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2460 | { | |
2461 | struct do_proc_dointvec_minmax_conv_param param = { | |
2462 | .min = (int *) table->extra1, | |
2463 | .max = (int *) table->extra2, | |
2464 | }; | |
8d65af78 | 2465 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1da177e4 LT |
2466 | do_proc_dointvec_minmax_conv, ¶m); |
2467 | } | |
2468 | ||
d8217f07 | 2469 | static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, |
1da177e4 LT |
2470 | void __user *buffer, |
2471 | size_t *lenp, loff_t *ppos, | |
2472 | unsigned long convmul, | |
2473 | unsigned long convdiv) | |
2474 | { | |
00b7c339 AW |
2475 | unsigned long *i, *min, *max; |
2476 | int vleft, first = 1, err = 0; | |
2477 | unsigned long page = 0; | |
2478 | size_t left; | |
2479 | char *kbuf; | |
2480 | ||
2481 | if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { | |
1da177e4 LT |
2482 | *lenp = 0; |
2483 | return 0; | |
2484 | } | |
00b7c339 | 2485 | |
fcfbd547 | 2486 | i = (unsigned long *) data; |
1da177e4 LT |
2487 | min = (unsigned long *) table->extra1; |
2488 | max = (unsigned long *) table->extra2; | |
2489 | vleft = table->maxlen / sizeof(unsigned long); | |
2490 | left = *lenp; | |
00b7c339 AW |
2491 | |
2492 | if (write) { | |
2493 | if (left > PAGE_SIZE - 1) | |
2494 | left = PAGE_SIZE - 1; | |
2495 | page = __get_free_page(GFP_TEMPORARY); | |
2496 | kbuf = (char *) page; | |
2497 | if (!kbuf) | |
2498 | return -ENOMEM; | |
2499 | if (copy_from_user(kbuf, buffer, left)) { | |
2500 | err = -EFAULT; | |
2501 | goto free; | |
2502 | } | |
2503 | kbuf[left] = 0; | |
2504 | } | |
2505 | ||
27b3d80a | 2506 | for (; left && vleft--; i++, first = 0) { |
00b7c339 AW |
2507 | unsigned long val; |
2508 | ||
1da177e4 | 2509 | if (write) { |
00b7c339 AW |
2510 | bool neg; |
2511 | ||
2512 | left -= proc_skip_spaces(&kbuf); | |
2513 | ||
2514 | err = proc_get_long(&kbuf, &left, &val, &neg, | |
2515 | proc_wspace_sep, | |
2516 | sizeof(proc_wspace_sep), NULL); | |
2517 | if (err) | |
1da177e4 LT |
2518 | break; |
2519 | if (neg) | |
1da177e4 LT |
2520 | continue; |
2521 | if ((min && val < *min) || (max && val > *max)) | |
2522 | continue; | |
2523 | *i = val; | |
2524 | } else { | |
00b7c339 | 2525 | val = convdiv * (*i) / convmul; |
1da177e4 | 2526 | if (!first) |
00b7c339 AW |
2527 | err = proc_put_char(&buffer, &left, '\t'); |
2528 | err = proc_put_long(&buffer, &left, val, false); | |
2529 | if (err) | |
2530 | break; | |
1da177e4 LT |
2531 | } |
2532 | } | |
2533 | ||
00b7c339 AW |
2534 | if (!write && !first && left && !err) |
2535 | err = proc_put_char(&buffer, &left, '\n'); | |
2536 | if (write && !err) | |
2537 | left -= proc_skip_spaces(&kbuf); | |
2538 | free: | |
1da177e4 | 2539 | if (write) { |
00b7c339 AW |
2540 | free_page(page); |
2541 | if (first) | |
2542 | return err ? : -EINVAL; | |
1da177e4 | 2543 | } |
1da177e4 LT |
2544 | *lenp -= left; |
2545 | *ppos += *lenp; | |
00b7c339 | 2546 | return err; |
1da177e4 LT |
2547 | } |
2548 | ||
d8217f07 | 2549 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, |
fcfbd547 KK |
2550 | void __user *buffer, |
2551 | size_t *lenp, loff_t *ppos, | |
2552 | unsigned long convmul, | |
2553 | unsigned long convdiv) | |
2554 | { | |
2555 | return __do_proc_doulongvec_minmax(table->data, table, write, | |
8d65af78 | 2556 | buffer, lenp, ppos, convmul, convdiv); |
fcfbd547 KK |
2557 | } |
2558 | ||
1da177e4 LT |
2559 | /** |
2560 | * proc_doulongvec_minmax - read a vector of long integers with min/max values | |
2561 | * @table: the sysctl table | |
2562 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2563 | * @buffer: the user buffer |
2564 | * @lenp: the size of the user buffer | |
2565 | * @ppos: file position | |
2566 | * | |
2567 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
2568 | * values from/to the user buffer, treated as an ASCII string. | |
2569 | * | |
2570 | * This routine will ensure the values are within the range specified by | |
2571 | * table->extra1 (min) and table->extra2 (max). | |
2572 | * | |
2573 | * Returns 0 on success. | |
2574 | */ | |
8d65af78 | 2575 | int proc_doulongvec_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2576 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2577 | { | |
8d65af78 | 2578 | return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); |
1da177e4 LT |
2579 | } |
2580 | ||
2581 | /** | |
2582 | * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values | |
2583 | * @table: the sysctl table | |
2584 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2585 | * @buffer: the user buffer |
2586 | * @lenp: the size of the user buffer | |
2587 | * @ppos: file position | |
2588 | * | |
2589 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
2590 | * values from/to the user buffer, treated as an ASCII string. The values | |
2591 | * are treated as milliseconds, and converted to jiffies when they are stored. | |
2592 | * | |
2593 | * This routine will ensure the values are within the range specified by | |
2594 | * table->extra1 (min) and table->extra2 (max). | |
2595 | * | |
2596 | * Returns 0 on success. | |
2597 | */ | |
d8217f07 | 2598 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2599 | void __user *buffer, |
2600 | size_t *lenp, loff_t *ppos) | |
2601 | { | |
8d65af78 | 2602 | return do_proc_doulongvec_minmax(table, write, buffer, |
1da177e4 LT |
2603 | lenp, ppos, HZ, 1000l); |
2604 | } | |
2605 | ||
2606 | ||
00b7c339 | 2607 | static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
2608 | int *valp, |
2609 | int write, void *data) | |
2610 | { | |
2611 | if (write) { | |
cba9f33d BS |
2612 | if (*lvalp > LONG_MAX / HZ) |
2613 | return 1; | |
1da177e4 LT |
2614 | *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); |
2615 | } else { | |
2616 | int val = *valp; | |
2617 | unsigned long lval; | |
2618 | if (val < 0) { | |
00b7c339 | 2619 | *negp = true; |
1da177e4 LT |
2620 | lval = (unsigned long)-val; |
2621 | } else { | |
00b7c339 | 2622 | *negp = false; |
1da177e4 LT |
2623 | lval = (unsigned long)val; |
2624 | } | |
2625 | *lvalp = lval / HZ; | |
2626 | } | |
2627 | return 0; | |
2628 | } | |
2629 | ||
00b7c339 | 2630 | static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
2631 | int *valp, |
2632 | int write, void *data) | |
2633 | { | |
2634 | if (write) { | |
cba9f33d BS |
2635 | if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) |
2636 | return 1; | |
1da177e4 LT |
2637 | *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); |
2638 | } else { | |
2639 | int val = *valp; | |
2640 | unsigned long lval; | |
2641 | if (val < 0) { | |
00b7c339 | 2642 | *negp = true; |
1da177e4 LT |
2643 | lval = (unsigned long)-val; |
2644 | } else { | |
00b7c339 | 2645 | *negp = false; |
1da177e4 LT |
2646 | lval = (unsigned long)val; |
2647 | } | |
2648 | *lvalp = jiffies_to_clock_t(lval); | |
2649 | } | |
2650 | return 0; | |
2651 | } | |
2652 | ||
00b7c339 | 2653 | static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, |
1da177e4 LT |
2654 | int *valp, |
2655 | int write, void *data) | |
2656 | { | |
2657 | if (write) { | |
2658 | *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); | |
2659 | } else { | |
2660 | int val = *valp; | |
2661 | unsigned long lval; | |
2662 | if (val < 0) { | |
00b7c339 | 2663 | *negp = true; |
1da177e4 LT |
2664 | lval = (unsigned long)-val; |
2665 | } else { | |
00b7c339 | 2666 | *negp = false; |
1da177e4 LT |
2667 | lval = (unsigned long)val; |
2668 | } | |
2669 | *lvalp = jiffies_to_msecs(lval); | |
2670 | } | |
2671 | return 0; | |
2672 | } | |
2673 | ||
2674 | /** | |
2675 | * proc_dointvec_jiffies - read a vector of integers as seconds | |
2676 | * @table: the sysctl table | |
2677 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2678 | * @buffer: the user buffer |
2679 | * @lenp: the size of the user buffer | |
2680 | * @ppos: file position | |
2681 | * | |
2682 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2683 | * values from/to the user buffer, treated as an ASCII string. | |
2684 | * The values read are assumed to be in seconds, and are converted into | |
2685 | * jiffies. | |
2686 | * | |
2687 | * Returns 0 on success. | |
2688 | */ | |
8d65af78 | 2689 | int proc_dointvec_jiffies(struct ctl_table *table, int write, |
1da177e4 LT |
2690 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2691 | { | |
8d65af78 | 2692 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
1da177e4 LT |
2693 | do_proc_dointvec_jiffies_conv,NULL); |
2694 | } | |
2695 | ||
2696 | /** | |
2697 | * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds | |
2698 | * @table: the sysctl table | |
2699 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2700 | * @buffer: the user buffer |
2701 | * @lenp: the size of the user buffer | |
1e5d5331 | 2702 | * @ppos: pointer to the file position |
1da177e4 LT |
2703 | * |
2704 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2705 | * values from/to the user buffer, treated as an ASCII string. | |
2706 | * The values read are assumed to be in 1/USER_HZ seconds, and | |
2707 | * are converted into jiffies. | |
2708 | * | |
2709 | * Returns 0 on success. | |
2710 | */ | |
8d65af78 | 2711 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, |
1da177e4 LT |
2712 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2713 | { | |
8d65af78 | 2714 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
1da177e4 LT |
2715 | do_proc_dointvec_userhz_jiffies_conv,NULL); |
2716 | } | |
2717 | ||
2718 | /** | |
2719 | * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds | |
2720 | * @table: the sysctl table | |
2721 | * @write: %TRUE if this is a write to the sysctl file | |
1da177e4 LT |
2722 | * @buffer: the user buffer |
2723 | * @lenp: the size of the user buffer | |
67be2dd1 MW |
2724 | * @ppos: file position |
2725 | * @ppos: the current position in the file | |
1da177e4 LT |
2726 | * |
2727 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2728 | * values from/to the user buffer, treated as an ASCII string. | |
2729 | * The values read are assumed to be in 1/1000 seconds, and | |
2730 | * are converted into jiffies. | |
2731 | * | |
2732 | * Returns 0 on success. | |
2733 | */ | |
8d65af78 | 2734 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, |
1da177e4 LT |
2735 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2736 | { | |
8d65af78 | 2737 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
1da177e4 LT |
2738 | do_proc_dointvec_ms_jiffies_conv, NULL); |
2739 | } | |
2740 | ||
8d65af78 | 2741 | static int proc_do_cad_pid(struct ctl_table *table, int write, |
9ec52099 CLG |
2742 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2743 | { | |
2744 | struct pid *new_pid; | |
2745 | pid_t tmp; | |
2746 | int r; | |
2747 | ||
6c5f3e7b | 2748 | tmp = pid_vnr(cad_pid); |
9ec52099 | 2749 | |
8d65af78 | 2750 | r = __do_proc_dointvec(&tmp, table, write, buffer, |
9ec52099 CLG |
2751 | lenp, ppos, NULL, NULL); |
2752 | if (r || !write) | |
2753 | return r; | |
2754 | ||
2755 | new_pid = find_get_pid(tmp); | |
2756 | if (!new_pid) | |
2757 | return -ESRCH; | |
2758 | ||
2759 | put_pid(xchg(&cad_pid, new_pid)); | |
2760 | return 0; | |
2761 | } | |
2762 | ||
9f977fb7 OP |
2763 | /** |
2764 | * proc_do_large_bitmap - read/write from/to a large bitmap | |
2765 | * @table: the sysctl table | |
2766 | * @write: %TRUE if this is a write to the sysctl file | |
2767 | * @buffer: the user buffer | |
2768 | * @lenp: the size of the user buffer | |
2769 | * @ppos: file position | |
2770 | * | |
2771 | * The bitmap is stored at table->data and the bitmap length (in bits) | |
2772 | * in table->maxlen. | |
2773 | * | |
2774 | * We use a range comma separated format (e.g. 1,3-4,10-10) so that | |
2775 | * large bitmaps may be represented in a compact manner. Writing into | |
2776 | * the file will clear the bitmap then update it with the given input. | |
2777 | * | |
2778 | * Returns 0 on success. | |
2779 | */ | |
2780 | int proc_do_large_bitmap(struct ctl_table *table, int write, | |
2781 | void __user *buffer, size_t *lenp, loff_t *ppos) | |
2782 | { | |
2783 | int err = 0; | |
2784 | bool first = 1; | |
2785 | size_t left = *lenp; | |
2786 | unsigned long bitmap_len = table->maxlen; | |
2787 | unsigned long *bitmap = (unsigned long *) table->data; | |
2788 | unsigned long *tmp_bitmap = NULL; | |
2789 | char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; | |
2790 | ||
2791 | if (!bitmap_len || !left || (*ppos && !write)) { | |
2792 | *lenp = 0; | |
2793 | return 0; | |
2794 | } | |
2795 | ||
2796 | if (write) { | |
2797 | unsigned long page = 0; | |
2798 | char *kbuf; | |
2799 | ||
2800 | if (left > PAGE_SIZE - 1) | |
2801 | left = PAGE_SIZE - 1; | |
2802 | ||
2803 | page = __get_free_page(GFP_TEMPORARY); | |
2804 | kbuf = (char *) page; | |
2805 | if (!kbuf) | |
2806 | return -ENOMEM; | |
2807 | if (copy_from_user(kbuf, buffer, left)) { | |
2808 | free_page(page); | |
2809 | return -EFAULT; | |
2810 | } | |
2811 | kbuf[left] = 0; | |
2812 | ||
2813 | tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long), | |
2814 | GFP_KERNEL); | |
2815 | if (!tmp_bitmap) { | |
2816 | free_page(page); | |
2817 | return -ENOMEM; | |
2818 | } | |
2819 | proc_skip_char(&kbuf, &left, '\n'); | |
2820 | while (!err && left) { | |
2821 | unsigned long val_a, val_b; | |
2822 | bool neg; | |
2823 | ||
2824 | err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a, | |
2825 | sizeof(tr_a), &c); | |
2826 | if (err) | |
2827 | break; | |
2828 | if (val_a >= bitmap_len || neg) { | |
2829 | err = -EINVAL; | |
2830 | break; | |
2831 | } | |
2832 | ||
2833 | val_b = val_a; | |
2834 | if (left) { | |
2835 | kbuf++; | |
2836 | left--; | |
2837 | } | |
2838 | ||
2839 | if (c == '-') { | |
2840 | err = proc_get_long(&kbuf, &left, &val_b, | |
2841 | &neg, tr_b, sizeof(tr_b), | |
2842 | &c); | |
2843 | if (err) | |
2844 | break; | |
2845 | if (val_b >= bitmap_len || neg || | |
2846 | val_a > val_b) { | |
2847 | err = -EINVAL; | |
2848 | break; | |
2849 | } | |
2850 | if (left) { | |
2851 | kbuf++; | |
2852 | left--; | |
2853 | } | |
2854 | } | |
2855 | ||
2856 | while (val_a <= val_b) | |
2857 | set_bit(val_a++, tmp_bitmap); | |
2858 | ||
2859 | first = 0; | |
2860 | proc_skip_char(&kbuf, &left, '\n'); | |
2861 | } | |
2862 | free_page(page); | |
2863 | } else { | |
2864 | unsigned long bit_a, bit_b = 0; | |
2865 | ||
2866 | while (left) { | |
2867 | bit_a = find_next_bit(bitmap, bitmap_len, bit_b); | |
2868 | if (bit_a >= bitmap_len) | |
2869 | break; | |
2870 | bit_b = find_next_zero_bit(bitmap, bitmap_len, | |
2871 | bit_a + 1) - 1; | |
2872 | ||
2873 | if (!first) { | |
2874 | err = proc_put_char(&buffer, &left, ','); | |
2875 | if (err) | |
2876 | break; | |
2877 | } | |
2878 | err = proc_put_long(&buffer, &left, bit_a, false); | |
2879 | if (err) | |
2880 | break; | |
2881 | if (bit_a != bit_b) { | |
2882 | err = proc_put_char(&buffer, &left, '-'); | |
2883 | if (err) | |
2884 | break; | |
2885 | err = proc_put_long(&buffer, &left, bit_b, false); | |
2886 | if (err) | |
2887 | break; | |
2888 | } | |
2889 | ||
2890 | first = 0; bit_b++; | |
2891 | } | |
2892 | if (!err) | |
2893 | err = proc_put_char(&buffer, &left, '\n'); | |
2894 | } | |
2895 | ||
2896 | if (!err) { | |
2897 | if (write) { | |
2898 | if (*ppos) | |
2899 | bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); | |
2900 | else | |
2901 | memcpy(bitmap, tmp_bitmap, | |
2902 | BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long)); | |
2903 | } | |
2904 | kfree(tmp_bitmap); | |
2905 | *lenp -= left; | |
2906 | *ppos += *lenp; | |
2907 | return 0; | |
2908 | } else { | |
2909 | kfree(tmp_bitmap); | |
2910 | return err; | |
2911 | } | |
2912 | } | |
2913 | ||
55610500 | 2914 | #else /* CONFIG_PROC_SYSCTL */ |
1da177e4 | 2915 | |
8d65af78 | 2916 | int proc_dostring(struct ctl_table *table, int write, |
1da177e4 LT |
2917 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2918 | { | |
2919 | return -ENOSYS; | |
2920 | } | |
2921 | ||
8d65af78 | 2922 | int proc_dointvec(struct ctl_table *table, int write, |
1da177e4 | 2923 | void __user *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
2924 | { |
2925 | return -ENOSYS; | |
2926 | } | |
2927 | ||
8d65af78 | 2928 | int proc_dointvec_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2929 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2930 | { | |
2931 | return -ENOSYS; | |
2932 | } | |
2933 | ||
8d65af78 | 2934 | int proc_dointvec_jiffies(struct ctl_table *table, int write, |
1da177e4 LT |
2935 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2936 | { | |
2937 | return -ENOSYS; | |
2938 | } | |
2939 | ||
8d65af78 | 2940 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, |
1da177e4 LT |
2941 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2942 | { | |
2943 | return -ENOSYS; | |
2944 | } | |
2945 | ||
8d65af78 | 2946 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, |
1da177e4 LT |
2947 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2948 | { | |
2949 | return -ENOSYS; | |
2950 | } | |
2951 | ||
8d65af78 | 2952 | int proc_doulongvec_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2953 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2954 | { | |
2955 | return -ENOSYS; | |
2956 | } | |
2957 | ||
d8217f07 | 2958 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2959 | void __user *buffer, |
2960 | size_t *lenp, loff_t *ppos) | |
2961 | { | |
2962 | return -ENOSYS; | |
2963 | } | |
2964 | ||
2965 | ||
55610500 | 2966 | #endif /* CONFIG_PROC_SYSCTL */ |
1da177e4 | 2967 | |
1da177e4 LT |
2968 | /* |
2969 | * No sense putting this after each symbol definition, twice, | |
2970 | * exception granted :-) | |
2971 | */ | |
2972 | EXPORT_SYMBOL(proc_dointvec); | |
2973 | EXPORT_SYMBOL(proc_dointvec_jiffies); | |
2974 | EXPORT_SYMBOL(proc_dointvec_minmax); | |
2975 | EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); | |
2976 | EXPORT_SYMBOL(proc_dointvec_ms_jiffies); | |
2977 | EXPORT_SYMBOL(proc_dostring); | |
2978 | EXPORT_SYMBOL(proc_doulongvec_minmax); | |
2979 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); | |
2980 | EXPORT_SYMBOL(register_sysctl_table); | |
29e796fd | 2981 | EXPORT_SYMBOL(register_sysctl_paths); |
1da177e4 | 2982 | EXPORT_SYMBOL(unregister_sysctl_table); |