blob: fe8cdc80ff028ac5542e0a342c5a2c9c5a823833 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010056#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020057#endif
58
Eric W. Biederman7058cb02007-10-18 03:05:58 -070059static int deprecated_sysctl_warning(struct __sysctl_args *args);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#if defined(CONFIG_SYSCTL)
62
63/* External variables not in a header file. */
64extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070065extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int sysctl_overcommit_memory;
67extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070068extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070069extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080070extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070073extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int pid_max;
76extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Arjan van de Ven97455122008-01-25 21:08:34 +010083extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040084extern int sysctl_nr_open_min, sysctl_nr_open_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070086/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080087#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070088static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080089#endif
90
91#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int sixty = 60;
93#endif
94
95#ifdef CONFIG_MMU
96static int two = 2;
97#endif
98
99static int zero;
100static int one_hundred = 100;
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
103static int maxolduid = 65535;
104static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800105static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static int ngroups_max = NGROUPS_MAX;
108
109#ifdef CONFIG_KMOD
110extern char modprobe_path[];
111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#ifdef CONFIG_CHR_DEV_SG
113extern int sg_big_buff;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116#ifdef __sparc__
117extern char reboot_command [];
118extern int stop_a_enabled;
119extern int scons_pwroff;
120#endif
121
122#ifdef __hppa__
123extern int pwrsw_enabled;
124extern int unaligned_enabled;
125#endif
126
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800127#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef CONFIG_MATHEMU
129extern int sysctl_ieee_emulation_warnings;
130#endif
131extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700132extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#endif
134
135extern int sysctl_hz_timer;
136
137#ifdef CONFIG_BSD_PROCESS_ACCT
138extern int acct_parm[];
139#endif
140
Jes Sorensend2b176e2006-02-28 09:42:23 -0800141#ifdef CONFIG_IA64
142extern int no_unaligned_warning;
143#endif
144
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700145#ifdef CONFIG_RT_MUTEXES
146extern int max_lock_depth;
147#endif
148
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700149#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700150static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700151 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700152static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800153 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100157static struct ctl_table_root sysctl_table_root;
158static struct ctl_table_header root_table_header = {
159 .ctl_table = root_table,
160 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
161 .root = &sysctl_table_root,
162};
163static struct ctl_table_root sysctl_table_root = {
164 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
165 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
166};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700168static struct ctl_table kern_table[];
169static struct ctl_table vm_table[];
170static struct ctl_table fs_table[];
171static struct ctl_table debug_table[];
172static struct ctl_table dev_table[];
173extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700174#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700175extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400176#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
179int sysctl_legacy_va_layout;
180#endif
181
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700182extern int prove_locking;
183extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* The default sysctl tables: */
186
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700187static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 {
189 .ctl_name = CTL_KERN,
190 .procname = "kernel",
191 .mode = 0555,
192 .child = kern_table,
193 },
194 {
195 .ctl_name = CTL_VM,
196 .procname = "vm",
197 .mode = 0555,
198 .child = vm_table,
199 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 .ctl_name = CTL_FS,
202 .procname = "fs",
203 .mode = 0555,
204 .child = fs_table,
205 },
206 {
207 .ctl_name = CTL_DEBUG,
208 .procname = "debug",
209 .mode = 0555,
210 .child = debug_table,
211 },
212 {
213 .ctl_name = CTL_DEV,
214 .procname = "dev",
215 .mode = 0555,
216 .child = dev_table,
217 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700218/*
219 * NOTE: do not add new entries to this table unless you have read
220 * Documentation/sysctl/ctl_unnumbered.txt
221 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 { .ctl_name = 0 }
223};
224
Ingo Molnar77e54a12007-07-09 18:52:00 +0200225#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100226static int min_sched_granularity_ns = 100000; /* 100 usecs */
227static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
228static int min_wakeup_granularity_ns; /* 0 usecs */
229static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200230#endif
231
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700232static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200233#ifdef CONFIG_SCHED_DEBUG
234 {
235 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100236 .procname = "sched_min_granularity_ns",
237 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238 .maxlen = sizeof(unsigned int),
239 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100240 .proc_handler = &sched_nr_latency_handler,
241 .strategy = &sysctl_intvec,
242 .extra1 = &min_sched_granularity_ns,
243 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244 },
245 {
246 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200247 .procname = "sched_latency_ns",
248 .data = &sysctl_sched_latency,
249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100251 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200252 .strategy = &sysctl_intvec,
253 .extra1 = &min_sched_granularity_ns,
254 .extra2 = &max_sched_granularity_ns,
255 },
256 {
257 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200258 .procname = "sched_wakeup_granularity_ns",
259 .data = &sysctl_sched_wakeup_granularity,
260 .maxlen = sizeof(unsigned int),
261 .mode = 0644,
262 .proc_handler = &proc_dointvec_minmax,
263 .strategy = &sysctl_intvec,
264 .extra1 = &min_wakeup_granularity_ns,
265 .extra2 = &max_wakeup_granularity_ns,
266 },
267 {
268 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200269 .procname = "sched_shares_ratelimit",
270 .data = &sysctl_sched_shares_ratelimit,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec,
274 },
275 {
276 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
281 .proc_handler = &proc_dointvec,
282 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200283 {
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_features",
286 .data = &sysctl_sched_features,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec,
290 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200291 {
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_migration_cost",
294 .data = &sysctl_sched_migration_cost,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec,
298 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100299 {
300 .ctl_name = CTL_UNNUMBERED,
301 .procname = "sched_nr_migrate",
302 .data = &sysctl_sched_nr_migrate,
303 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
306 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200307#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200308 {
309 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100310 .procname = "sched_rt_period_us",
311 .data = &sysctl_sched_rt_period,
312 .maxlen = sizeof(unsigned int),
313 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200314 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100315 },
316 {
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_rt_runtime_us",
319 .data = &sysctl_sched_rt_runtime,
320 .maxlen = sizeof(int),
321 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200322 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100323 },
324 {
325 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200326 .procname = "sched_compat_yield",
327 .data = &sysctl_sched_compat_yield,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
331 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700332#ifdef CONFIG_PROVE_LOCKING
333 {
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "prove_locking",
336 .data = &prove_locking,
337 .maxlen = sizeof(int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341#endif
342#ifdef CONFIG_LOCK_STAT
343 {
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "lock_stat",
346 .data = &lock_stat,
347 .maxlen = sizeof(int),
348 .mode = 0644,
349 .proc_handler = &proc_dointvec,
350 },
351#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200352 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 .ctl_name = KERN_PANIC,
354 .procname = "panic",
355 .data = &panic_timeout,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = &proc_dointvec,
359 },
360 {
361 .ctl_name = KERN_CORE_USES_PID,
362 .procname = "core_uses_pid",
363 .data = &core_uses_pid,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = &proc_dointvec,
367 },
368 {
369 .ctl_name = KERN_CORE_PATTERN,
370 .procname = "core_pattern",
371 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700372 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 .mode = 0644,
374 .proc_handler = &proc_dostring,
375 .strategy = &sysctl_string,
376 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800377#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 .procname = "tainted",
380 .data = &tainted,
381 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800382 .mode = 0644,
383 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800385#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100386#ifdef CONFIG_LATENCYTOP
387 {
388 .procname = "latencytop",
389 .data = &latencytop_enabled,
390 .maxlen = sizeof(int),
391 .mode = 0644,
392 .proc_handler = &proc_dointvec,
393 },
394#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#ifdef CONFIG_BLK_DEV_INITRD
396 {
397 .ctl_name = KERN_REALROOTDEV,
398 .procname = "real-root-dev",
399 .data = &real_root_dev,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
403 },
404#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700405 {
406 .ctl_name = CTL_UNNUMBERED,
407 .procname = "print-fatal-signals",
408 .data = &print_fatal_signals,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#ifdef __sparc__
414 {
415 .ctl_name = KERN_SPARC_REBOOT,
416 .procname = "reboot-cmd",
417 .data = reboot_command,
418 .maxlen = 256,
419 .mode = 0644,
420 .proc_handler = &proc_dostring,
421 .strategy = &sysctl_string,
422 },
423 {
424 .ctl_name = KERN_SPARC_STOP_A,
425 .procname = "stop-a",
426 .data = &stop_a_enabled,
427 .maxlen = sizeof (int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431 {
432 .ctl_name = KERN_SPARC_SCONS_PWROFF,
433 .procname = "scons-poweroff",
434 .data = &scons_pwroff,
435 .maxlen = sizeof (int),
436 .mode = 0644,
437 .proc_handler = &proc_dointvec,
438 },
439#endif
440#ifdef __hppa__
441 {
442 .ctl_name = KERN_HPPA_PWRSW,
443 .procname = "soft-power",
444 .data = &pwrsw_enabled,
445 .maxlen = sizeof (int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
448 },
449 {
450 .ctl_name = KERN_HPPA_UNALIGNED,
451 .procname = "unaligned-trap",
452 .data = &unaligned_enabled,
453 .maxlen = sizeof (int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
456 },
457#endif
458 {
459 .ctl_name = KERN_CTLALTDEL,
460 .procname = "ctrl-alt-del",
461 .data = &C_A_D,
462 .maxlen = sizeof(int),
463 .mode = 0644,
464 .proc_handler = &proc_dointvec,
465 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#ifdef CONFIG_KMOD
467 {
468 .ctl_name = KERN_MODPROBE,
469 .procname = "modprobe",
470 .data = &modprobe_path,
471 .maxlen = KMOD_PATH_LEN,
472 .mode = 0644,
473 .proc_handler = &proc_dostring,
474 .strategy = &sysctl_string,
475 },
476#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700477#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 {
479 .ctl_name = KERN_HOTPLUG,
480 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100481 .data = &uevent_helper,
482 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .mode = 0644,
484 .proc_handler = &proc_dostring,
485 .strategy = &sysctl_string,
486 },
487#endif
488#ifdef CONFIG_CHR_DEV_SG
489 {
490 .ctl_name = KERN_SG_BIG_BUFF,
491 .procname = "sg-big-buff",
492 .data = &sg_big_buff,
493 .maxlen = sizeof (int),
494 .mode = 0444,
495 .proc_handler = &proc_dointvec,
496 },
497#endif
498#ifdef CONFIG_BSD_PROCESS_ACCT
499 {
500 .ctl_name = KERN_ACCT,
501 .procname = "acct",
502 .data = &acct_parm,
503 .maxlen = 3*sizeof(int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
506 },
507#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508#ifdef CONFIG_MAGIC_SYSRQ
509 {
510 .ctl_name = KERN_SYSRQ,
511 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800512 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .maxlen = sizeof (int),
514 .mode = 0644,
515 .proc_handler = &proc_dointvec,
516 },
517#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700518#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700521 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .maxlen = sizeof (int),
523 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700524 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700526#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 {
528 .ctl_name = KERN_MAX_THREADS,
529 .procname = "threads-max",
530 .data = &max_threads,
531 .maxlen = sizeof(int),
532 .mode = 0644,
533 .proc_handler = &proc_dointvec,
534 },
535 {
536 .ctl_name = KERN_RANDOM,
537 .procname = "random",
538 .mode = 0555,
539 .child = random_table,
540 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 {
542 .ctl_name = KERN_OVERFLOWUID,
543 .procname = "overflowuid",
544 .data = &overflowuid,
545 .maxlen = sizeof(int),
546 .mode = 0644,
547 .proc_handler = &proc_dointvec_minmax,
548 .strategy = &sysctl_intvec,
549 .extra1 = &minolduid,
550 .extra2 = &maxolduid,
551 },
552 {
553 .ctl_name = KERN_OVERFLOWGID,
554 .procname = "overflowgid",
555 .data = &overflowgid,
556 .maxlen = sizeof(int),
557 .mode = 0644,
558 .proc_handler = &proc_dointvec_minmax,
559 .strategy = &sysctl_intvec,
560 .extra1 = &minolduid,
561 .extra2 = &maxolduid,
562 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800563#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#ifdef CONFIG_MATHEMU
565 {
566 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
567 .procname = "ieee_emulation_warnings",
568 .data = &sysctl_ieee_emulation_warnings,
569 .maxlen = sizeof(int),
570 .mode = 0644,
571 .proc_handler = &proc_dointvec,
572 },
573#endif
574#ifdef CONFIG_NO_IDLE_HZ
575 {
576 .ctl_name = KERN_HZ_TIMER,
577 .procname = "hz_timer",
578 .data = &sysctl_hz_timer,
579 .maxlen = sizeof(int),
580 .mode = 0644,
581 .proc_handler = &proc_dointvec,
582 },
583#endif
584 {
585 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
586 .procname = "userprocess_debug",
587 .data = &sysctl_userprocess_debug,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec,
591 },
592#endif
593 {
594 .ctl_name = KERN_PIDMAX,
595 .procname = "pid_max",
596 .data = &pid_max,
597 .maxlen = sizeof (int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec_minmax,
600 .strategy = sysctl_intvec,
601 .extra1 = &pid_max_min,
602 .extra2 = &pid_max_max,
603 },
604 {
605 .ctl_name = KERN_PANIC_ON_OOPS,
606 .procname = "panic_on_oops",
607 .data = &panic_on_oops,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec,
611 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800612#if defined CONFIG_PRINTK
613 {
614 .ctl_name = KERN_PRINTK,
615 .procname = "printk",
616 .data = &console_loglevel,
617 .maxlen = 4*sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec,
620 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 {
622 .ctl_name = KERN_PRINTK_RATELIMIT,
623 .procname = "printk_ratelimit",
624 .data = &printk_ratelimit_jiffies,
625 .maxlen = sizeof(int),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec_jiffies,
628 .strategy = &sysctl_jiffies,
629 },
630 {
631 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
632 .procname = "printk_ratelimit_burst",
633 .data = &printk_ratelimit_burst,
634 .maxlen = sizeof(int),
635 .mode = 0644,
636 .proc_handler = &proc_dointvec,
637 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800638#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 {
640 .ctl_name = KERN_NGROUPS_MAX,
641 .procname = "ngroups_max",
642 .data = &ngroups_max,
643 .maxlen = sizeof (int),
644 .mode = 0444,
645 .proc_handler = &proc_dointvec,
646 },
647#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
648 {
649 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
650 .procname = "unknown_nmi_panic",
651 .data = &unknown_nmi_panic,
652 .maxlen = sizeof (int),
653 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200654 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 },
Don Zickus407984f2006-09-26 10:52:27 +0200656 {
Don Zickus407984f2006-09-26 10:52:27 +0200657 .procname = "nmi_watchdog",
658 .data = &nmi_watchdog_enabled,
659 .maxlen = sizeof (int),
660 .mode = 0644,
661 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
663#endif
664#if defined(CONFIG_X86)
665 {
Don Zickus8da5add2006-09-26 10:52:27 +0200666 .ctl_name = KERN_PANIC_ON_NMI,
667 .procname = "panic_on_unrecovered_nmi",
668 .data = &panic_on_unrecovered_nmi,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
673 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .ctl_name = KERN_BOOTLOADER_TYPE,
675 .procname = "bootloader_type",
676 .data = &bootloader_type,
677 .maxlen = sizeof (int),
678 .mode = 0444,
679 .proc_handler = &proc_dointvec,
680 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100681 {
682 .ctl_name = CTL_UNNUMBERED,
683 .procname = "kstack_depth_to_print",
684 .data = &kstack_depth_to_print,
685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = &proc_dointvec,
688 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100689 {
690 .ctl_name = CTL_UNNUMBERED,
691 .procname = "io_delay_type",
692 .data = &io_delay_type,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = &proc_dointvec,
696 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800698#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 {
700 .ctl_name = KERN_RANDOMIZE,
701 .procname = "randomize_va_space",
702 .data = &randomize_va_space,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = &proc_dointvec,
706 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800707#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800708#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700709 {
710 .ctl_name = KERN_SPIN_RETRY,
711 .procname = "spin_retry",
712 .data = &spin_retry,
713 .maxlen = sizeof (int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
716 },
717#endif
Len Brown673d5b42007-07-28 03:33:16 -0400718#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800719 {
Pavel Machekc255d842006-02-20 18:27:58 -0800720 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700721 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800722 .maxlen = sizeof (unsigned long),
723 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800724 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800725 },
726#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800727#ifdef CONFIG_IA64
728 {
729 .ctl_name = KERN_IA64_UNALIGNED,
730 .procname = "ignore-unaligned-usertrap",
731 .data = &no_unaligned_warning,
732 .maxlen = sizeof (int),
733 .mode = 0644,
734 .proc_handler = &proc_dointvec,
735 },
736#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700737#ifdef CONFIG_DETECT_SOFTLOCKUP
738 {
739 .ctl_name = CTL_UNNUMBERED,
740 .procname = "softlockup_thresh",
741 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100742 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700743 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100744 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700745 .strategy = &sysctl_intvec,
746 .extra1 = &one,
747 .extra2 = &sixty,
748 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100749 {
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "hung_task_check_count",
752 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100753 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100754 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100755 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100756 .strategy = &sysctl_intvec,
757 },
758 {
759 .ctl_name = CTL_UNNUMBERED,
760 .procname = "hung_task_timeout_secs",
761 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100762 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100763 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100764 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100765 .strategy = &sysctl_intvec,
766 },
767 {
768 .ctl_name = CTL_UNNUMBERED,
769 .procname = "hung_task_warnings",
770 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100771 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100772 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100773 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100774 .strategy = &sysctl_intvec,
775 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700776#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200777#ifdef CONFIG_COMPAT
778 {
779 .ctl_name = KERN_COMPAT_LOG,
780 .procname = "compat-log",
781 .data = &compat_log,
782 .maxlen = sizeof (int),
783 .mode = 0644,
784 .proc_handler = &proc_dointvec,
785 },
786#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700787#ifdef CONFIG_RT_MUTEXES
788 {
789 .ctl_name = KERN_MAX_LOCK_DEPTH,
790 .procname = "max_lock_depth",
791 .data = &max_lock_depth,
792 .maxlen = sizeof(int),
793 .mode = 0644,
794 .proc_handler = &proc_dointvec,
795 },
796#endif
Kees Cook5096add2007-05-08 00:26:04 -0700797#ifdef CONFIG_PROC_FS
798 {
799 .ctl_name = CTL_UNNUMBERED,
800 .procname = "maps_protect",
801 .data = &maps_protect,
802 .maxlen = sizeof(int),
803 .mode = 0644,
804 .proc_handler = &proc_dointvec,
805 },
806#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700807 {
808 .ctl_name = CTL_UNNUMBERED,
809 .procname = "poweroff_cmd",
810 .data = &poweroff_cmd,
811 .maxlen = POWEROFF_CMD_PATH_LEN,
812 .mode = 0644,
813 .proc_handler = &proc_dostring,
814 .strategy = &sysctl_string,
815 },
David Howells0b77f5b2008-04-29 01:01:32 -0700816#ifdef CONFIG_KEYS
817 {
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "keys",
820 .mode = 0555,
821 .child = key_sysctls,
822 },
823#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700824/*
825 * NOTE: do not add new entries to this table unless you have read
826 * Documentation/sysctl/ctl_unnumbered.txt
827 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 { .ctl_name = 0 }
829};
830
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700831static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 {
833 .ctl_name = VM_OVERCOMMIT_MEMORY,
834 .procname = "overcommit_memory",
835 .data = &sysctl_overcommit_memory,
836 .maxlen = sizeof(sysctl_overcommit_memory),
837 .mode = 0644,
838 .proc_handler = &proc_dointvec,
839 },
840 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700841 .ctl_name = VM_PANIC_ON_OOM,
842 .procname = "panic_on_oom",
843 .data = &sysctl_panic_on_oom,
844 .maxlen = sizeof(sysctl_panic_on_oom),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
847 },
848 {
David Rientjesfe071d72007-10-16 23:25:56 -0700849 .ctl_name = CTL_UNNUMBERED,
850 .procname = "oom_kill_allocating_task",
851 .data = &sysctl_oom_kill_allocating_task,
852 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
853 .mode = 0644,
854 .proc_handler = &proc_dointvec,
855 },
856 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800857 .ctl_name = CTL_UNNUMBERED,
858 .procname = "oom_dump_tasks",
859 .data = &sysctl_oom_dump_tasks,
860 .maxlen = sizeof(sysctl_oom_dump_tasks),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
863 },
864 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 .ctl_name = VM_OVERCOMMIT_RATIO,
866 .procname = "overcommit_ratio",
867 .data = &sysctl_overcommit_ratio,
868 .maxlen = sizeof(sysctl_overcommit_ratio),
869 .mode = 0644,
870 .proc_handler = &proc_dointvec,
871 },
872 {
873 .ctl_name = VM_PAGE_CLUSTER,
874 .procname = "page-cluster",
875 .data = &page_cluster,
876 .maxlen = sizeof(int),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec,
879 },
880 {
881 .ctl_name = VM_DIRTY_BACKGROUND,
882 .procname = "dirty_background_ratio",
883 .data = &dirty_background_ratio,
884 .maxlen = sizeof(dirty_background_ratio),
885 .mode = 0644,
886 .proc_handler = &proc_dointvec_minmax,
887 .strategy = &sysctl_intvec,
888 .extra1 = &zero,
889 .extra2 = &one_hundred,
890 },
891 {
892 .ctl_name = VM_DIRTY_RATIO,
893 .procname = "dirty_ratio",
894 .data = &vm_dirty_ratio,
895 .maxlen = sizeof(vm_dirty_ratio),
896 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700897 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 .strategy = &sysctl_intvec,
899 .extra1 = &zero,
900 .extra2 = &one_hundred,
901 },
902 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800904 .data = &dirty_writeback_interval,
905 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 .mode = 0644,
907 .proc_handler = &dirty_writeback_centisecs_handler,
908 },
909 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800911 .data = &dirty_expire_interval,
912 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800914 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 },
916 {
917 .ctl_name = VM_NR_PDFLUSH_THREADS,
918 .procname = "nr_pdflush_threads",
919 .data = &nr_pdflush_threads,
920 .maxlen = sizeof nr_pdflush_threads,
921 .mode = 0444 /* read-only*/,
922 .proc_handler = &proc_dointvec,
923 },
924 {
925 .ctl_name = VM_SWAPPINESS,
926 .procname = "swappiness",
927 .data = &vm_swappiness,
928 .maxlen = sizeof(vm_swappiness),
929 .mode = 0644,
930 .proc_handler = &proc_dointvec_minmax,
931 .strategy = &sysctl_intvec,
932 .extra1 = &zero,
933 .extra2 = &one_hundred,
934 },
935#ifdef CONFIG_HUGETLB_PAGE
936 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 .procname = "nr_hugepages",
938 .data = &max_huge_pages,
939 .maxlen = sizeof(unsigned long),
940 .mode = 0644,
941 .proc_handler = &hugetlb_sysctl_handler,
942 .extra1 = (void *)&hugetlb_zero,
943 .extra2 = (void *)&hugetlb_infinity,
944 },
945 {
946 .ctl_name = VM_HUGETLB_GROUP,
947 .procname = "hugetlb_shm_group",
948 .data = &sysctl_hugetlb_shm_group,
949 .maxlen = sizeof(gid_t),
950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 },
Mel Gorman396faf02007-07-17 04:03:13 -0700953 {
954 .ctl_name = CTL_UNNUMBERED,
955 .procname = "hugepages_treat_as_movable",
956 .data = &hugepages_treat_as_movable,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = &hugetlb_treat_movable_handler,
960 },
Adam Litke54f9f802007-10-16 01:26:20 -0700961 {
962 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800963 .procname = "nr_overcommit_hugepages",
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -0800964 .data = &sysctl_overcommit_huge_pages,
965 .maxlen = sizeof(sysctl_overcommit_huge_pages),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800966 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800967 .proc_handler = &hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800968 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969#endif
970 {
971 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
972 .procname = "lowmem_reserve_ratio",
973 .data = &sysctl_lowmem_reserve_ratio,
974 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
975 .mode = 0644,
976 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
977 .strategy = &sysctl_intvec,
978 },
979 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800980 .ctl_name = VM_DROP_PAGECACHE,
981 .procname = "drop_caches",
982 .data = &sysctl_drop_caches,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = drop_caches_sysctl_handler,
986 .strategy = &sysctl_intvec,
987 },
988 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 .ctl_name = VM_MIN_FREE_KBYTES,
990 .procname = "min_free_kbytes",
991 .data = &min_free_kbytes,
992 .maxlen = sizeof(min_free_kbytes),
993 .mode = 0644,
994 .proc_handler = &min_free_kbytes_sysctl_handler,
995 .strategy = &sysctl_intvec,
996 .extra1 = &zero,
997 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800998 {
999 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1000 .procname = "percpu_pagelist_fraction",
1001 .data = &percpu_pagelist_fraction,
1002 .maxlen = sizeof(percpu_pagelist_fraction),
1003 .mode = 0644,
1004 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1005 .strategy = &sysctl_intvec,
1006 .extra1 = &min_percpu_pagelist_fract,
1007 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008#ifdef CONFIG_MMU
1009 {
1010 .ctl_name = VM_MAX_MAP_COUNT,
1011 .procname = "max_map_count",
1012 .data = &sysctl_max_map_count,
1013 .maxlen = sizeof(sysctl_max_map_count),
1014 .mode = 0644,
1015 .proc_handler = &proc_dointvec
1016 },
1017#endif
1018 {
1019 .ctl_name = VM_LAPTOP_MODE,
1020 .procname = "laptop_mode",
1021 .data = &laptop_mode,
1022 .maxlen = sizeof(laptop_mode),
1023 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001024 .proc_handler = &proc_dointvec_jiffies,
1025 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 },
1027 {
1028 .ctl_name = VM_BLOCK_DUMP,
1029 .procname = "block_dump",
1030 .data = &block_dump,
1031 .maxlen = sizeof(block_dump),
1032 .mode = 0644,
1033 .proc_handler = &proc_dointvec,
1034 .strategy = &sysctl_intvec,
1035 .extra1 = &zero,
1036 },
1037 {
1038 .ctl_name = VM_VFS_CACHE_PRESSURE,
1039 .procname = "vfs_cache_pressure",
1040 .data = &sysctl_vfs_cache_pressure,
1041 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1042 .mode = 0644,
1043 .proc_handler = &proc_dointvec,
1044 .strategy = &sysctl_intvec,
1045 .extra1 = &zero,
1046 },
1047#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1048 {
1049 .ctl_name = VM_LEGACY_VA_LAYOUT,
1050 .procname = "legacy_va_layout",
1051 .data = &sysctl_legacy_va_layout,
1052 .maxlen = sizeof(sysctl_legacy_va_layout),
1053 .mode = 0644,
1054 .proc_handler = &proc_dointvec,
1055 .strategy = &sysctl_intvec,
1056 .extra1 = &zero,
1057 },
1058#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001059#ifdef CONFIG_NUMA
1060 {
1061 .ctl_name = VM_ZONE_RECLAIM_MODE,
1062 .procname = "zone_reclaim_mode",
1063 .data = &zone_reclaim_mode,
1064 .maxlen = sizeof(zone_reclaim_mode),
1065 .mode = 0644,
1066 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001067 .strategy = &sysctl_intvec,
1068 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001069 },
Christoph Lameter96146342006-07-03 00:24:13 -07001070 {
1071 .ctl_name = VM_MIN_UNMAPPED,
1072 .procname = "min_unmapped_ratio",
1073 .data = &sysctl_min_unmapped_ratio,
1074 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1075 .mode = 0644,
1076 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1077 .strategy = &sysctl_intvec,
1078 .extra1 = &zero,
1079 .extra2 = &one_hundred,
1080 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001081 {
1082 .ctl_name = VM_MIN_SLAB,
1083 .procname = "min_slab_ratio",
1084 .data = &sysctl_min_slab_ratio,
1085 .maxlen = sizeof(sysctl_min_slab_ratio),
1086 .mode = 0644,
1087 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1088 .strategy = &sysctl_intvec,
1089 .extra1 = &zero,
1090 .extra2 = &one_hundred,
1091 },
Christoph Lameter17436602006-01-18 17:42:32 -08001092#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001093#ifdef CONFIG_SMP
1094 {
1095 .ctl_name = CTL_UNNUMBERED,
1096 .procname = "stat_interval",
1097 .data = &sysctl_stat_interval,
1098 .maxlen = sizeof(sysctl_stat_interval),
1099 .mode = 0644,
1100 .proc_handler = &proc_dointvec_jiffies,
1101 .strategy = &sysctl_jiffies,
1102 },
1103#endif
Eric Parised032182007-06-28 15:55:21 -04001104#ifdef CONFIG_SECURITY
1105 {
1106 .ctl_name = CTL_UNNUMBERED,
1107 .procname = "mmap_min_addr",
1108 .data = &mmap_min_addr,
1109 .maxlen = sizeof(unsigned long),
1110 .mode = 0644,
1111 .proc_handler = &proc_doulongvec_minmax,
1112 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001113#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001114#ifdef CONFIG_NUMA
1115 {
1116 .ctl_name = CTL_UNNUMBERED,
1117 .procname = "numa_zonelist_order",
1118 .data = &numa_zonelist_order,
1119 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1120 .mode = 0644,
1121 .proc_handler = &numa_zonelist_order_handler,
1122 .strategy = &sysctl_string,
1123 },
1124#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001125#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001126 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001127 {
1128 .ctl_name = VM_VDSO_ENABLED,
1129 .procname = "vdso_enabled",
1130 .data = &vdso_enabled,
1131 .maxlen = sizeof(vdso_enabled),
1132 .mode = 0644,
1133 .proc_handler = &proc_dointvec,
1134 .strategy = &sysctl_intvec,
1135 .extra1 = &zero,
1136 },
1137#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001138#ifdef CONFIG_HIGHMEM
1139 {
1140 .ctl_name = CTL_UNNUMBERED,
1141 .procname = "highmem_is_dirtyable",
1142 .data = &vm_highmem_is_dirtyable,
1143 .maxlen = sizeof(vm_highmem_is_dirtyable),
1144 .mode = 0644,
1145 .proc_handler = &proc_dointvec_minmax,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &zero,
1148 .extra2 = &one,
1149 },
1150#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001151/*
1152 * NOTE: do not add new entries to this table unless you have read
1153 * Documentation/sysctl/ctl_unnumbered.txt
1154 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 { .ctl_name = 0 }
1156};
1157
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001158#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001159static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001160 { .ctl_name = 0 }
1161};
1162#endif
1163
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001164static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 {
1166 .ctl_name = FS_NRINODE,
1167 .procname = "inode-nr",
1168 .data = &inodes_stat,
1169 .maxlen = 2*sizeof(int),
1170 .mode = 0444,
1171 .proc_handler = &proc_dointvec,
1172 },
1173 {
1174 .ctl_name = FS_STATINODE,
1175 .procname = "inode-state",
1176 .data = &inodes_stat,
1177 .maxlen = 7*sizeof(int),
1178 .mode = 0444,
1179 .proc_handler = &proc_dointvec,
1180 },
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "file-nr",
1183 .data = &files_stat,
1184 .maxlen = 3*sizeof(int),
1185 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001186 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 },
1188 {
1189 .ctl_name = FS_MAXFILE,
1190 .procname = "file-max",
1191 .data = &files_stat.max_files,
1192 .maxlen = sizeof(int),
1193 .mode = 0644,
1194 .proc_handler = &proc_dointvec,
1195 },
1196 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001197 .ctl_name = CTL_UNNUMBERED,
1198 .procname = "nr_open",
1199 .data = &sysctl_nr_open,
1200 .maxlen = sizeof(int),
1201 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001202 .proc_handler = &proc_dointvec_minmax,
1203 .extra1 = &sysctl_nr_open_min,
1204 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001205 },
1206 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 .ctl_name = FS_DENTRY,
1208 .procname = "dentry-state",
1209 .data = &dentry_stat,
1210 .maxlen = 6*sizeof(int),
1211 .mode = 0444,
1212 .proc_handler = &proc_dointvec,
1213 },
1214 {
1215 .ctl_name = FS_OVERFLOWUID,
1216 .procname = "overflowuid",
1217 .data = &fs_overflowuid,
1218 .maxlen = sizeof(int),
1219 .mode = 0644,
1220 .proc_handler = &proc_dointvec_minmax,
1221 .strategy = &sysctl_intvec,
1222 .extra1 = &minolduid,
1223 .extra2 = &maxolduid,
1224 },
1225 {
1226 .ctl_name = FS_OVERFLOWGID,
1227 .procname = "overflowgid",
1228 .data = &fs_overflowgid,
1229 .maxlen = sizeof(int),
1230 .mode = 0644,
1231 .proc_handler = &proc_dointvec_minmax,
1232 .strategy = &sysctl_intvec,
1233 .extra1 = &minolduid,
1234 .extra2 = &maxolduid,
1235 },
1236 {
1237 .ctl_name = FS_LEASES,
1238 .procname = "leases-enable",
1239 .data = &leases_enable,
1240 .maxlen = sizeof(int),
1241 .mode = 0644,
1242 .proc_handler = &proc_dointvec,
1243 },
1244#ifdef CONFIG_DNOTIFY
1245 {
1246 .ctl_name = FS_DIR_NOTIFY,
1247 .procname = "dir-notify-enable",
1248 .data = &dir_notify_enable,
1249 .maxlen = sizeof(int),
1250 .mode = 0644,
1251 .proc_handler = &proc_dointvec,
1252 },
1253#endif
1254#ifdef CONFIG_MMU
1255 {
1256 .ctl_name = FS_LEASE_TIME,
1257 .procname = "lease-break-time",
1258 .data = &lease_break_time,
1259 .maxlen = sizeof(int),
1260 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001261 .proc_handler = &proc_dointvec_minmax,
1262 .strategy = &sysctl_intvec,
1263 .extra1 = &zero,
1264 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 },
1266 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 .procname = "aio-nr",
1268 .data = &aio_nr,
1269 .maxlen = sizeof(aio_nr),
1270 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001271 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 },
1273 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 .procname = "aio-max-nr",
1275 .data = &aio_max_nr,
1276 .maxlen = sizeof(aio_max_nr),
1277 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001278 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001280#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001281 {
1282 .ctl_name = FS_INOTIFY,
1283 .procname = "inotify",
1284 .mode = 0555,
1285 .child = inotify_table,
1286 },
1287#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001289 {
1290 .ctl_name = KERN_SETUID_DUMPABLE,
1291 .procname = "suid_dumpable",
1292 .data = &suid_dumpable,
1293 .maxlen = sizeof(int),
1294 .mode = 0644,
1295 .proc_handler = &proc_dointvec,
1296 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001297#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1298 {
1299 .ctl_name = CTL_UNNUMBERED,
1300 .procname = "binfmt_misc",
1301 .mode = 0555,
1302 .child = binfmt_misc_table,
1303 },
1304#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001305/*
1306 * NOTE: do not add new entries to this table unless you have read
1307 * Documentation/sysctl/ctl_unnumbered.txt
1308 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 { .ctl_name = 0 }
1310};
1311
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001312static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001313#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001314 {
1315 .ctl_name = CTL_UNNUMBERED,
1316 .procname = "exception-trace",
1317 .data = &show_unhandled_signals,
1318 .maxlen = sizeof(int),
1319 .mode = 0644,
1320 .proc_handler = proc_dointvec
1321 },
1322#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 { .ctl_name = 0 }
1324};
1325
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001326static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001328};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Al Viro330d57f2005-11-04 10:18:40 +00001330static DEFINE_SPINLOCK(sysctl_lock);
1331
1332/* called under sysctl_lock */
1333static int use_table(struct ctl_table_header *p)
1334{
1335 if (unlikely(p->unregistering))
1336 return 0;
1337 p->used++;
1338 return 1;
1339}
1340
1341/* called under sysctl_lock */
1342static void unuse_table(struct ctl_table_header *p)
1343{
1344 if (!--p->used)
1345 if (unlikely(p->unregistering))
1346 complete(p->unregistering);
1347}
1348
1349/* called under sysctl_lock, will reacquire if has to wait */
1350static void start_unregistering(struct ctl_table_header *p)
1351{
1352 /*
1353 * if p->used is 0, nobody will ever touch that entry again;
1354 * we'll eliminate all paths to it before dropping sysctl_lock
1355 */
1356 if (unlikely(p->used)) {
1357 struct completion wait;
1358 init_completion(&wait);
1359 p->unregistering = &wait;
1360 spin_unlock(&sysctl_lock);
1361 wait_for_completion(&wait);
1362 spin_lock(&sysctl_lock);
1363 }
1364 /*
1365 * do not remove from the list until nobody holds it; walking the
1366 * list in do_sysctl() relies on that.
1367 */
1368 list_del_init(&p->ctl_entry);
1369}
1370
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001371void sysctl_head_finish(struct ctl_table_header *head)
1372{
1373 if (!head)
1374 return;
1375 spin_lock(&sysctl_lock);
1376 unuse_table(head);
1377 spin_unlock(&sysctl_lock);
1378}
1379
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001380static struct list_head *
1381lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001382{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001383 struct list_head *header_list;
1384 header_list = &root->header_list;
1385 if (root->lookup)
1386 header_list = root->lookup(root, namespaces);
1387 return header_list;
1388}
1389
1390struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1391 struct ctl_table_header *prev)
1392{
1393 struct ctl_table_root *root;
1394 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001395 struct ctl_table_header *head;
1396 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001397
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001398 spin_lock(&sysctl_lock);
1399 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001400 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001401 tmp = &prev->ctl_entry;
1402 unuse_table(prev);
1403 goto next;
1404 }
1405 tmp = &root_table_header.ctl_entry;
1406 for (;;) {
1407 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1408
1409 if (!use_table(head))
1410 goto next;
1411 spin_unlock(&sysctl_lock);
1412 return head;
1413 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001414 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001415 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001416 header_list = lookup_header_list(root, namespaces);
1417 if (tmp != header_list)
1418 continue;
1419
1420 do {
1421 root = list_entry(root->root_list.next,
1422 struct ctl_table_root, root_list);
1423 if (root == &sysctl_table_root)
1424 goto out;
1425 header_list = lookup_header_list(root, namespaces);
1426 } while (list_empty(header_list));
1427 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001428 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001429out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001430 spin_unlock(&sysctl_lock);
1431 return NULL;
1432}
1433
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001434struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1435{
1436 return __sysctl_head_next(current->nsproxy, prev);
1437}
1438
1439void register_sysctl_root(struct ctl_table_root *root)
1440{
1441 spin_lock(&sysctl_lock);
1442 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1443 spin_unlock(&sysctl_lock);
1444}
1445
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001446#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001447/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001448static int do_sysctl_strategy(struct ctl_table_root *root,
1449 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001450 int __user *name, int nlen,
1451 void __user *oldval, size_t __user *oldlenp,
1452 void __user *newval, size_t newlen)
1453{
1454 int op = 0, rc;
1455
1456 if (oldval)
1457 op |= 004;
1458 if (newval)
1459 op |= 002;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001460 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001461 return -EPERM;
1462
1463 if (table->strategy) {
1464 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1465 newval, newlen);
1466 if (rc < 0)
1467 return rc;
1468 if (rc > 0)
1469 return 0;
1470 }
1471
1472 /* If there is no strategy routine, or if the strategy returns
1473 * zero, proceed with automatic r/w */
1474 if (table->data && table->maxlen) {
1475 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1476 newval, newlen);
1477 if (rc < 0)
1478 return rc;
1479 }
1480 return 0;
1481}
1482
1483static int parse_table(int __user *name, int nlen,
1484 void __user *oldval, size_t __user *oldlenp,
1485 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001486 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001487 struct ctl_table *table)
1488{
1489 int n;
1490repeat:
1491 if (!nlen)
1492 return -ENOTDIR;
1493 if (get_user(n, name))
1494 return -EFAULT;
1495 for ( ; table->ctl_name || table->procname; table++) {
1496 if (!table->ctl_name)
1497 continue;
1498 if (n == table->ctl_name) {
1499 int error;
1500 if (table->child) {
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001501 if (sysctl_perm(root, table, 001))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001502 return -EPERM;
1503 name++;
1504 nlen--;
1505 table = table->child;
1506 goto repeat;
1507 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001508 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001509 oldval, oldlenp,
1510 newval, newlen);
1511 return error;
1512 }
1513 }
1514 return -ENOTDIR;
1515}
1516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1518 void __user *newval, size_t newlen)
1519{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001520 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001521 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1524 return -ENOTDIR;
1525 if (oldval) {
1526 int old_len;
1527 if (!oldlenp || get_user(old_len, oldlenp))
1528 return -EFAULT;
1529 }
Al Viro330d57f2005-11-04 10:18:40 +00001530
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001531 for (head = sysctl_head_next(NULL); head;
1532 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001533 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001534 newval, newlen,
1535 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001536 if (error != -ENOTDIR) {
1537 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001538 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001539 }
1540 }
Al Viro330d57f2005-11-04 10:18:40 +00001541 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
1544asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1545{
1546 struct __sysctl_args tmp;
1547 int error;
1548
1549 if (copy_from_user(&tmp, args, sizeof(tmp)))
1550 return -EFAULT;
1551
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001552 error = deprecated_sysctl_warning(&tmp);
1553 if (error)
1554 goto out;
1555
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 lock_kernel();
1557 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1558 tmp.newval, tmp.newlen);
1559 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001560out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 return error;
1562}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001563#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001566 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 * some sysctl variables are readonly even to root.
1568 */
1569
1570static int test_perm(int mode, int op)
1571{
1572 if (!current->euid)
1573 mode >>= 6;
1574 else if (in_egroup_p(0))
1575 mode >>= 3;
1576 if ((mode & op & 0007) == op)
1577 return 0;
1578 return -EACCES;
1579}
1580
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001581int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582{
1583 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001584 int mode;
1585
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 error = security_sysctl(table, op);
1587 if (error)
1588 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001589
1590 if (root->permissions)
1591 mode = root->permissions(root, current->nsproxy, table);
1592 else
1593 mode = table->mode;
1594
1595 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001598static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1599{
1600 for (; table->ctl_name || table->procname; table++) {
1601 table->parent = parent;
1602 if (table->child)
1603 sysctl_set_parent(table, table->child);
1604 }
1605}
1606
1607static __init int sysctl_init(void)
1608{
1609 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001610#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1611 {
1612 int err;
1613 err = sysctl_check_table(current->nsproxy, root_table);
1614 }
1615#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001616 return 0;
1617}
1618
1619core_initcall(sysctl_init);
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001622 * __register_sysctl_paths - register a sysctl hierarchy
1623 * @root: List of sysctl headers to register on
1624 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001625 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 *
1628 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001629 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001631 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 *
1633 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1634 * must be unique within that level of sysctl
1635 *
1636 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1637 * enter a sysctl file
1638 *
1639 * data - a pointer to data for use by proc_handler
1640 *
1641 * maxlen - the maximum size in bytes of the data
1642 *
1643 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1644 *
1645 * child - a pointer to the child sysctl table if this entry is a directory, or
1646 * %NULL.
1647 *
1648 * proc_handler - the text handler routine (described below)
1649 *
1650 * strategy - the strategy routine (described below)
1651 *
1652 * de - for internal use by the sysctl routines
1653 *
1654 * extra1, extra2 - extra pointers usable by the proc handler routines
1655 *
1656 * Leaf nodes in the sysctl tree will be represented by a single file
1657 * under /proc; non-leaf nodes will be represented by directories.
1658 *
1659 * sysctl(2) can automatically manage read and write requests through
1660 * the sysctl table. The data and maxlen fields of the ctl_table
1661 * struct enable minimal validation of the values being written to be
1662 * performed, and the mode field allows minimal authentication.
1663 *
1664 * More sophisticated management can be enabled by the provision of a
1665 * strategy routine with the table entry. This will be called before
1666 * any automatic read or write of the data is performed.
1667 *
1668 * The strategy routine may return
1669 *
1670 * < 0 - Error occurred (error is passed to user process)
1671 *
1672 * 0 - OK - proceed with automatic read or write.
1673 *
1674 * > 0 - OK - read or write has been done by the strategy routine, so
1675 * return immediately.
1676 *
1677 * There must be a proc_handler routine for any terminal nodes
1678 * mirrored under /proc/sys (non-terminals are handled by a built-in
1679 * directory handler). Several default handlers are available to
1680 * cover common cases -
1681 *
1682 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1683 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1684 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1685 *
1686 * It is the handler's job to read the input buffer from user memory
1687 * and process it. The handler should return 0 on success.
1688 *
1689 * This routine returns %NULL on a failure to register, and a pointer
1690 * to the table header on success.
1691 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001692struct ctl_table_header *__register_sysctl_paths(
1693 struct ctl_table_root *root,
1694 struct nsproxy *namespaces,
1695 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001697 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001698 struct ctl_table_header *header;
1699 struct ctl_table *new, **prevp;
1700 unsigned int n, npath;
1701
1702 /* Count the path components */
1703 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1704 ;
1705
1706 /*
1707 * For each path component, allocate a 2-element ctl_table array.
1708 * The first array element will be filled with the sysctl entry
1709 * for this, the second will be the sentinel (ctl_name == 0).
1710 *
1711 * We allocate everything in one go so that we don't have to
1712 * worry about freeing additional memory in unregister_sysctl_table.
1713 */
1714 header = kzalloc(sizeof(struct ctl_table_header) +
1715 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1716 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001718
1719 new = (struct ctl_table *) (header + 1);
1720
1721 /* Now connect the dots */
1722 prevp = &header->ctl_table;
1723 for (n = 0; n < npath; ++n, ++path) {
1724 /* Copy the procname */
1725 new->procname = path->procname;
1726 new->ctl_name = path->ctl_name;
1727 new->mode = 0555;
1728
1729 *prevp = new;
1730 prevp = &new->child;
1731
1732 new += 2;
1733 }
1734 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001735 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001736
1737 INIT_LIST_HEAD(&header->ctl_entry);
1738 header->used = 0;
1739 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001740 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001741 sysctl_set_parent(NULL, header->ctl_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001742#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001743 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001744 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001745 return NULL;
1746 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001747#endif
Al Viro330d57f2005-11-04 10:18:40 +00001748 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001749 header_list = lookup_header_list(root, namespaces);
1750 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001751 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001752
1753 return header;
1754}
1755
1756/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001757 * register_sysctl_table_path - register a sysctl table hierarchy
1758 * @path: The path to the directory the sysctl table is in.
1759 * @table: the top-level table structure
1760 *
1761 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1762 * array. A completely 0 filled entry terminates the table.
1763 *
1764 * See __register_sysctl_paths for more details.
1765 */
1766struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1767 struct ctl_table *table)
1768{
1769 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1770 path, table);
1771}
1772
1773/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001774 * register_sysctl_table - register a sysctl table hierarchy
1775 * @table: the top-level table structure
1776 *
1777 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1778 * array. A completely 0 filled entry terminates the table.
1779 *
1780 * See register_sysctl_paths for more details.
1781 */
1782struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1783{
1784 static const struct ctl_path null_path[] = { {} };
1785
1786 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
1789/**
1790 * unregister_sysctl_table - unregister a sysctl table hierarchy
1791 * @header: the header returned from register_sysctl_table
1792 *
1793 * Unregisters the sysctl table and all children. proc entries may not
1794 * actually be removed until they are no longer used by anyone.
1795 */
1796void unregister_sysctl_table(struct ctl_table_header * header)
1797{
Al Viro330d57f2005-11-04 10:18:40 +00001798 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001799
1800 if (header == NULL)
1801 return;
1802
Al Viro330d57f2005-11-04 10:18:40 +00001803 spin_lock(&sysctl_lock);
1804 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001805 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 kfree(header);
1807}
1808
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001809#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001810struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001811{
1812 return NULL;
1813}
1814
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001815struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1816 struct ctl_table *table)
1817{
1818 return NULL;
1819}
1820
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001821void unregister_sysctl_table(struct ctl_table_header * table)
1822{
1823}
1824
1825#endif /* CONFIG_SYSCTL */
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827/*
1828 * /proc/sys support
1829 */
1830
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001831#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001833static int _proc_do_string(void* data, int maxlen, int write,
1834 struct file *filp, void __user *buffer,
1835 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001836{
1837 size_t len;
1838 char __user *p;
1839 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001840
1841 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001842 *lenp = 0;
1843 return 0;
1844 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001845
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846 if (write) {
1847 len = 0;
1848 p = buffer;
1849 while (len < *lenp) {
1850 if (get_user(c, p++))
1851 return -EFAULT;
1852 if (c == 0 || c == '\n')
1853 break;
1854 len++;
1855 }
1856 if (len >= maxlen)
1857 len = maxlen-1;
1858 if(copy_from_user(data, buffer, len))
1859 return -EFAULT;
1860 ((char *) data)[len] = 0;
1861 *ppos += *lenp;
1862 } else {
1863 len = strlen(data);
1864 if (len > maxlen)
1865 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001866
1867 if (*ppos > len) {
1868 *lenp = 0;
1869 return 0;
1870 }
1871
1872 data += *ppos;
1873 len -= *ppos;
1874
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001875 if (len > *lenp)
1876 len = *lenp;
1877 if (len)
1878 if(copy_to_user(buffer, data, len))
1879 return -EFAULT;
1880 if (len < *lenp) {
1881 if(put_user('\n', ((char __user *) buffer) + len))
1882 return -EFAULT;
1883 len++;
1884 }
1885 *lenp = len;
1886 *ppos += len;
1887 }
1888 return 0;
1889}
1890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891/**
1892 * proc_dostring - read a string sysctl
1893 * @table: the sysctl table
1894 * @write: %TRUE if this is a write to the sysctl file
1895 * @filp: the file structure
1896 * @buffer: the user buffer
1897 * @lenp: the size of the user buffer
1898 * @ppos: file position
1899 *
1900 * Reads/writes a string from/to the user buffer. If the kernel
1901 * buffer provided is not large enough to hold the string, the
1902 * string is truncated. The copied string is %NULL-terminated.
1903 * If the string is being read by the user process, it is copied
1904 * and a newline '\n' is added. It is truncated if the buffer is
1905 * not large enough.
1906 *
1907 * Returns 0 on success.
1908 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001909int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 void __user *buffer, size_t *lenp, loff_t *ppos)
1911{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001912 return _proc_do_string(table->data, table->maxlen, write, filp,
1913 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914}
1915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
1917static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1918 int *valp,
1919 int write, void *data)
1920{
1921 if (write) {
1922 *valp = *negp ? -*lvalp : *lvalp;
1923 } else {
1924 int val = *valp;
1925 if (val < 0) {
1926 *negp = -1;
1927 *lvalp = (unsigned long)-val;
1928 } else {
1929 *negp = 0;
1930 *lvalp = (unsigned long)val;
1931 }
1932 }
1933 return 0;
1934}
1935
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001936static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001937 int write, struct file *filp, void __user *buffer,
1938 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1940 int write, void *data),
1941 void *data)
1942{
1943#define TMPBUFLEN 21
1944 int *i, vleft, first=1, neg, val;
1945 unsigned long lval;
1946 size_t left, len;
1947
1948 char buf[TMPBUFLEN], *p;
1949 char __user *s = buffer;
1950
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001951 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 (*ppos && !write)) {
1953 *lenp = 0;
1954 return 0;
1955 }
1956
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001957 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 vleft = table->maxlen / sizeof(*i);
1959 left = *lenp;
1960
1961 if (!conv)
1962 conv = do_proc_dointvec_conv;
1963
1964 for (; left && vleft--; i++, first=0) {
1965 if (write) {
1966 while (left) {
1967 char c;
1968 if (get_user(c, s))
1969 return -EFAULT;
1970 if (!isspace(c))
1971 break;
1972 left--;
1973 s++;
1974 }
1975 if (!left)
1976 break;
1977 neg = 0;
1978 len = left;
1979 if (len > sizeof(buf) - 1)
1980 len = sizeof(buf) - 1;
1981 if (copy_from_user(buf, s, len))
1982 return -EFAULT;
1983 buf[len] = 0;
1984 p = buf;
1985 if (*p == '-' && left > 1) {
1986 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001987 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
1989 if (*p < '0' || *p > '9')
1990 break;
1991
1992 lval = simple_strtoul(p, &p, 0);
1993
1994 len = p-buf;
1995 if ((len < left) && *p && !isspace(*p))
1996 break;
1997 if (neg)
1998 val = -val;
1999 s += len;
2000 left -= len;
2001
2002 if (conv(&neg, &lval, i, 1, data))
2003 break;
2004 } else {
2005 p = buf;
2006 if (!first)
2007 *p++ = '\t';
2008
2009 if (conv(&neg, &lval, i, 0, data))
2010 break;
2011
2012 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2013 len = strlen(buf);
2014 if (len > left)
2015 len = left;
2016 if(copy_to_user(s, buf, len))
2017 return -EFAULT;
2018 left -= len;
2019 s += len;
2020 }
2021 }
2022
2023 if (!write && !first && left) {
2024 if(put_user('\n', s))
2025 return -EFAULT;
2026 left--, s++;
2027 }
2028 if (write) {
2029 while (left) {
2030 char c;
2031 if (get_user(c, s++))
2032 return -EFAULT;
2033 if (!isspace(c))
2034 break;
2035 left--;
2036 }
2037 }
2038 if (write && first)
2039 return -EINVAL;
2040 *lenp -= left;
2041 *ppos += *lenp;
2042 return 0;
2043#undef TMPBUFLEN
2044}
2045
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002046static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002047 void __user *buffer, size_t *lenp, loff_t *ppos,
2048 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2049 int write, void *data),
2050 void *data)
2051{
2052 return __do_proc_dointvec(table->data, table, write, filp,
2053 buffer, lenp, ppos, conv, data);
2054}
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056/**
2057 * proc_dointvec - read a vector of integers
2058 * @table: the sysctl table
2059 * @write: %TRUE if this is a write to the sysctl file
2060 * @filp: the file structure
2061 * @buffer: the user buffer
2062 * @lenp: the size of the user buffer
2063 * @ppos: file position
2064 *
2065 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2066 * values from/to the user buffer, treated as an ASCII string.
2067 *
2068 * Returns 0 on success.
2069 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002070int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 void __user *buffer, size_t *lenp, loff_t *ppos)
2072{
2073 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2074 NULL,NULL);
2075}
2076
2077#define OP_SET 0
2078#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002079#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2082 int *valp,
2083 int write, void *data)
2084{
2085 int op = *(int *)data;
2086 if (write) {
2087 int val = *negp ? -*lvalp : *lvalp;
2088 switch(op) {
2089 case OP_SET: *valp = val; break;
2090 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002091 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 }
2093 } else {
2094 int val = *valp;
2095 if (val < 0) {
2096 *negp = -1;
2097 *lvalp = (unsigned long)-val;
2098 } else {
2099 *negp = 0;
2100 *lvalp = (unsigned long)val;
2101 }
2102 }
2103 return 0;
2104}
2105
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002106/*
2107 * Taint values can only be increased
2108 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002109static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002110 void __user *buffer, size_t *lenp, loff_t *ppos)
2111{
2112 int op;
2113
Bastian Blank91fcd412007-04-23 14:41:14 -07002114 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002115 return -EPERM;
2116
2117 op = OP_OR;
2118 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2119 do_proc_dointvec_bset_conv,&op);
2120}
2121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122struct do_proc_dointvec_minmax_conv_param {
2123 int *min;
2124 int *max;
2125};
2126
2127static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2128 int *valp,
2129 int write, void *data)
2130{
2131 struct do_proc_dointvec_minmax_conv_param *param = data;
2132 if (write) {
2133 int val = *negp ? -*lvalp : *lvalp;
2134 if ((param->min && *param->min > val) ||
2135 (param->max && *param->max < val))
2136 return -EINVAL;
2137 *valp = val;
2138 } else {
2139 int val = *valp;
2140 if (val < 0) {
2141 *negp = -1;
2142 *lvalp = (unsigned long)-val;
2143 } else {
2144 *negp = 0;
2145 *lvalp = (unsigned long)val;
2146 }
2147 }
2148 return 0;
2149}
2150
2151/**
2152 * proc_dointvec_minmax - read a vector of integers with min/max values
2153 * @table: the sysctl table
2154 * @write: %TRUE if this is a write to the sysctl file
2155 * @filp: the file structure
2156 * @buffer: the user buffer
2157 * @lenp: the size of the user buffer
2158 * @ppos: file position
2159 *
2160 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2161 * values from/to the user buffer, treated as an ASCII string.
2162 *
2163 * This routine will ensure the values are within the range specified by
2164 * table->extra1 (min) and table->extra2 (max).
2165 *
2166 * Returns 0 on success.
2167 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002168int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 void __user *buffer, size_t *lenp, loff_t *ppos)
2170{
2171 struct do_proc_dointvec_minmax_conv_param param = {
2172 .min = (int *) table->extra1,
2173 .max = (int *) table->extra2,
2174 };
2175 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2176 do_proc_dointvec_minmax_conv, &param);
2177}
2178
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002179static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 struct file *filp,
2181 void __user *buffer,
2182 size_t *lenp, loff_t *ppos,
2183 unsigned long convmul,
2184 unsigned long convdiv)
2185{
2186#define TMPBUFLEN 21
2187 unsigned long *i, *min, *max, val;
2188 int vleft, first=1, neg;
2189 size_t len, left;
2190 char buf[TMPBUFLEN], *p;
2191 char __user *s = buffer;
2192
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002193 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 (*ppos && !write)) {
2195 *lenp = 0;
2196 return 0;
2197 }
2198
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002199 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 min = (unsigned long *) table->extra1;
2201 max = (unsigned long *) table->extra2;
2202 vleft = table->maxlen / sizeof(unsigned long);
2203 left = *lenp;
2204
2205 for (; left && vleft--; i++, min++, max++, first=0) {
2206 if (write) {
2207 while (left) {
2208 char c;
2209 if (get_user(c, s))
2210 return -EFAULT;
2211 if (!isspace(c))
2212 break;
2213 left--;
2214 s++;
2215 }
2216 if (!left)
2217 break;
2218 neg = 0;
2219 len = left;
2220 if (len > TMPBUFLEN-1)
2221 len = TMPBUFLEN-1;
2222 if (copy_from_user(buf, s, len))
2223 return -EFAULT;
2224 buf[len] = 0;
2225 p = buf;
2226 if (*p == '-' && left > 1) {
2227 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002228 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 }
2230 if (*p < '0' || *p > '9')
2231 break;
2232 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2233 len = p-buf;
2234 if ((len < left) && *p && !isspace(*p))
2235 break;
2236 if (neg)
2237 val = -val;
2238 s += len;
2239 left -= len;
2240
2241 if(neg)
2242 continue;
2243 if ((min && val < *min) || (max && val > *max))
2244 continue;
2245 *i = val;
2246 } else {
2247 p = buf;
2248 if (!first)
2249 *p++ = '\t';
2250 sprintf(p, "%lu", convdiv * (*i) / convmul);
2251 len = strlen(buf);
2252 if (len > left)
2253 len = left;
2254 if(copy_to_user(s, buf, len))
2255 return -EFAULT;
2256 left -= len;
2257 s += len;
2258 }
2259 }
2260
2261 if (!write && !first && left) {
2262 if(put_user('\n', s))
2263 return -EFAULT;
2264 left--, s++;
2265 }
2266 if (write) {
2267 while (left) {
2268 char c;
2269 if (get_user(c, s++))
2270 return -EFAULT;
2271 if (!isspace(c))
2272 break;
2273 left--;
2274 }
2275 }
2276 if (write && first)
2277 return -EINVAL;
2278 *lenp -= left;
2279 *ppos += *lenp;
2280 return 0;
2281#undef TMPBUFLEN
2282}
2283
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002284static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002285 struct file *filp,
2286 void __user *buffer,
2287 size_t *lenp, loff_t *ppos,
2288 unsigned long convmul,
2289 unsigned long convdiv)
2290{
2291 return __do_proc_doulongvec_minmax(table->data, table, write,
2292 filp, buffer, lenp, ppos, convmul, convdiv);
2293}
2294
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295/**
2296 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2297 * @table: the sysctl table
2298 * @write: %TRUE if this is a write to the sysctl file
2299 * @filp: the file structure
2300 * @buffer: the user buffer
2301 * @lenp: the size of the user buffer
2302 * @ppos: file position
2303 *
2304 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2305 * values from/to the user buffer, treated as an ASCII string.
2306 *
2307 * This routine will ensure the values are within the range specified by
2308 * table->extra1 (min) and table->extra2 (max).
2309 *
2310 * Returns 0 on success.
2311 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002312int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 void __user *buffer, size_t *lenp, loff_t *ppos)
2314{
2315 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2316}
2317
2318/**
2319 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2320 * @table: the sysctl table
2321 * @write: %TRUE if this is a write to the sysctl file
2322 * @filp: the file structure
2323 * @buffer: the user buffer
2324 * @lenp: the size of the user buffer
2325 * @ppos: file position
2326 *
2327 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2328 * values from/to the user buffer, treated as an ASCII string. The values
2329 * are treated as milliseconds, and converted to jiffies when they are stored.
2330 *
2331 * This routine will ensure the values are within the range specified by
2332 * table->extra1 (min) and table->extra2 (max).
2333 *
2334 * Returns 0 on success.
2335 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002336int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 struct file *filp,
2338 void __user *buffer,
2339 size_t *lenp, loff_t *ppos)
2340{
2341 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2342 lenp, ppos, HZ, 1000l);
2343}
2344
2345
2346static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2347 int *valp,
2348 int write, void *data)
2349{
2350 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002351 if (*lvalp > LONG_MAX / HZ)
2352 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2354 } else {
2355 int val = *valp;
2356 unsigned long lval;
2357 if (val < 0) {
2358 *negp = -1;
2359 lval = (unsigned long)-val;
2360 } else {
2361 *negp = 0;
2362 lval = (unsigned long)val;
2363 }
2364 *lvalp = lval / HZ;
2365 }
2366 return 0;
2367}
2368
2369static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2370 int *valp,
2371 int write, void *data)
2372{
2373 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002374 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2375 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2377 } else {
2378 int val = *valp;
2379 unsigned long lval;
2380 if (val < 0) {
2381 *negp = -1;
2382 lval = (unsigned long)-val;
2383 } else {
2384 *negp = 0;
2385 lval = (unsigned long)val;
2386 }
2387 *lvalp = jiffies_to_clock_t(lval);
2388 }
2389 return 0;
2390}
2391
2392static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2393 int *valp,
2394 int write, void *data)
2395{
2396 if (write) {
2397 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2398 } else {
2399 int val = *valp;
2400 unsigned long lval;
2401 if (val < 0) {
2402 *negp = -1;
2403 lval = (unsigned long)-val;
2404 } else {
2405 *negp = 0;
2406 lval = (unsigned long)val;
2407 }
2408 *lvalp = jiffies_to_msecs(lval);
2409 }
2410 return 0;
2411}
2412
2413/**
2414 * proc_dointvec_jiffies - read a vector of integers as seconds
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @filp: the file structure
2418 * @buffer: the user buffer
2419 * @lenp: the size of the user buffer
2420 * @ppos: file position
2421 *
2422 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2423 * values from/to the user buffer, treated as an ASCII string.
2424 * The values read are assumed to be in seconds, and are converted into
2425 * jiffies.
2426 *
2427 * Returns 0 on success.
2428 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002429int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 void __user *buffer, size_t *lenp, loff_t *ppos)
2431{
2432 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2433 do_proc_dointvec_jiffies_conv,NULL);
2434}
2435
2436/**
2437 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2438 * @table: the sysctl table
2439 * @write: %TRUE if this is a write to the sysctl file
2440 * @filp: the file structure
2441 * @buffer: the user buffer
2442 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002443 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 *
2445 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2446 * values from/to the user buffer, treated as an ASCII string.
2447 * The values read are assumed to be in 1/USER_HZ seconds, and
2448 * are converted into jiffies.
2449 *
2450 * Returns 0 on success.
2451 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002452int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 void __user *buffer, size_t *lenp, loff_t *ppos)
2454{
2455 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2456 do_proc_dointvec_userhz_jiffies_conv,NULL);
2457}
2458
2459/**
2460 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @filp: the file structure
2464 * @buffer: the user buffer
2465 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002466 * @ppos: file position
2467 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 *
2469 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2470 * values from/to the user buffer, treated as an ASCII string.
2471 * The values read are assumed to be in 1/1000 seconds, and
2472 * are converted into jiffies.
2473 *
2474 * Returns 0 on success.
2475 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002476int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 void __user *buffer, size_t *lenp, loff_t *ppos)
2478{
2479 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2480 do_proc_dointvec_ms_jiffies_conv, NULL);
2481}
2482
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002483static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002484 void __user *buffer, size_t *lenp, loff_t *ppos)
2485{
2486 struct pid *new_pid;
2487 pid_t tmp;
2488 int r;
2489
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002490 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002491
2492 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2493 lenp, ppos, NULL, NULL);
2494 if (r || !write)
2495 return r;
2496
2497 new_pid = find_get_pid(tmp);
2498 if (!new_pid)
2499 return -ESRCH;
2500
2501 put_pid(xchg(&cad_pid, new_pid));
2502 return 0;
2503}
2504
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505#else /* CONFIG_PROC_FS */
2506
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002507int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 void __user *buffer, size_t *lenp, loff_t *ppos)
2509{
2510 return -ENOSYS;
2511}
2512
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002513int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 void __user *buffer, size_t *lenp, loff_t *ppos)
2515{
2516 return -ENOSYS;
2517}
2518
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002519int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 void __user *buffer, size_t *lenp, loff_t *ppos)
2521{
2522 return -ENOSYS;
2523}
2524
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002525int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 void __user *buffer, size_t *lenp, loff_t *ppos)
2527{
2528 return -ENOSYS;
2529}
2530
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002531int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 void __user *buffer, size_t *lenp, loff_t *ppos)
2533{
2534 return -ENOSYS;
2535}
2536
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002537int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 void __user *buffer, size_t *lenp, loff_t *ppos)
2539{
2540 return -ENOSYS;
2541}
2542
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002543int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 void __user *buffer, size_t *lenp, loff_t *ppos)
2545{
2546 return -ENOSYS;
2547}
2548
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002549int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 struct file *filp,
2551 void __user *buffer,
2552 size_t *lenp, loff_t *ppos)
2553{
2554 return -ENOSYS;
2555}
2556
2557
2558#endif /* CONFIG_PROC_FS */
2559
2560
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002561#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562/*
2563 * General sysctl support routines
2564 */
2565
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002566/* The generic sysctl data routine (used if no strategy routine supplied) */
2567int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2568 void __user *oldval, size_t __user *oldlenp,
2569 void __user *newval, size_t newlen)
2570{
2571 size_t len;
2572
2573 /* Get out of I don't have a variable */
2574 if (!table->data || !table->maxlen)
2575 return -ENOTDIR;
2576
2577 if (oldval && oldlenp) {
2578 if (get_user(len, oldlenp))
2579 return -EFAULT;
2580 if (len) {
2581 if (len > table->maxlen)
2582 len = table->maxlen;
2583 if (copy_to_user(oldval, table->data, len))
2584 return -EFAULT;
2585 if (put_user(len, oldlenp))
2586 return -EFAULT;
2587 }
2588 }
2589
2590 if (newval && newlen) {
2591 if (newlen > table->maxlen)
2592 newlen = table->maxlen;
2593
2594 if (copy_from_user(table->data, newval, newlen))
2595 return -EFAULT;
2596 }
2597 return 1;
2598}
2599
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002601int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002603 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 if (!table->data || !table->maxlen)
2606 return -ENOTDIR;
2607
2608 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002609 size_t bufsize;
2610 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002612 if (bufsize) {
2613 size_t len = strlen(table->data), copied;
2614
2615 /* This shouldn't trigger for a well-formed sysctl */
2616 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002618
2619 /* Copy up to a max of bufsize-1 bytes of the string */
2620 copied = (len >= bufsize) ? bufsize - 1 : len;
2621
2622 if (copy_to_user(oldval, table->data, copied) ||
2623 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002625 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 return -EFAULT;
2627 }
2628 }
2629 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002630 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 if (len > table->maxlen)
2632 len = table->maxlen;
2633 if(copy_from_user(table->data, newval, len))
2634 return -EFAULT;
2635 if (len == table->maxlen)
2636 len--;
2637 ((char *) table->data)[len] = 0;
2638 }
Yi Yang82c9df82005-12-30 16:37:10 +08002639 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640}
2641
2642/*
2643 * This function makes sure that all of the integers in the vector
2644 * are between the minimum and maximum values given in the arrays
2645 * table->extra1 and table->extra2, respectively.
2646 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002647int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002649 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
2651
2652 if (newval && newlen) {
2653 int __user *vec = (int __user *) newval;
2654 int *min = (int *) table->extra1;
2655 int *max = (int *) table->extra2;
2656 size_t length;
2657 int i;
2658
2659 if (newlen % sizeof(int) != 0)
2660 return -EINVAL;
2661
2662 if (!table->extra1 && !table->extra2)
2663 return 0;
2664
2665 if (newlen > table->maxlen)
2666 newlen = table->maxlen;
2667 length = newlen / sizeof(int);
2668
2669 for (i = 0; i < length; i++) {
2670 int value;
2671 if (get_user(value, vec + i))
2672 return -EFAULT;
2673 if (min && value < min[i])
2674 return -EINVAL;
2675 if (max && value > max[i])
2676 return -EINVAL;
2677 }
2678 }
2679 return 0;
2680}
2681
2682/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002683int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002685 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002687 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002689
2690 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002692 if (olen) {
2693 int val;
2694
2695 if (olen < sizeof(int))
2696 return -EINVAL;
2697
2698 val = *(int *)(table->data) / HZ;
2699 if (put_user(val, (int __user *)oldval))
2700 return -EFAULT;
2701 if (put_user(sizeof(int), oldlenp))
2702 return -EFAULT;
2703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 }
2705 if (newval && newlen) {
2706 int new;
2707 if (newlen != sizeof(int))
2708 return -EINVAL;
2709 if (get_user(new, (int __user *)newval))
2710 return -EFAULT;
2711 *(int *)(table->data) = new*HZ;
2712 }
2713 return 1;
2714}
2715
2716/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002717int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002719 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002721 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002723
2724 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002726 if (olen) {
2727 int val;
2728
2729 if (olen < sizeof(int))
2730 return -EINVAL;
2731
2732 val = jiffies_to_msecs(*(int *)(table->data));
2733 if (put_user(val, (int __user *)oldval))
2734 return -EFAULT;
2735 if (put_user(sizeof(int), oldlenp))
2736 return -EFAULT;
2737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 }
2739 if (newval && newlen) {
2740 int new;
2741 if (newlen != sizeof(int))
2742 return -EINVAL;
2743 if (get_user(new, (int __user *)newval))
2744 return -EFAULT;
2745 *(int *)(table->data) = msecs_to_jiffies(new);
2746 }
2747 return 1;
2748}
2749
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002750
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002751
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002752#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754
2755asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2756{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002757 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002758 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002759
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002760 if (copy_from_user(&tmp, args, sizeof(tmp)))
2761 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002762
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002763 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002764
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002765 /* If no error reading the parameters then just -ENOSYS ... */
2766 if (!error)
2767 error = -ENOSYS;
2768
2769 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770}
2771
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002772int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2773 void __user *oldval, size_t __user *oldlenp,
2774 void __user *newval, size_t newlen)
2775{
2776 return -ENOSYS;
2777}
2778
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002779int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002781 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782{
2783 return -ENOSYS;
2784}
2785
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002786int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002788 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789{
2790 return -ENOSYS;
2791}
2792
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002793int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002795 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796{
2797 return -ENOSYS;
2798}
2799
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002800int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002802 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803{
2804 return -ENOSYS;
2805}
2806
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002807#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002809static int deprecated_sysctl_warning(struct __sysctl_args *args)
2810{
2811 static int msg_count;
2812 int name[CTL_MAXNAME];
2813 int i;
2814
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002815 /* Check args->nlen. */
2816 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2817 return -ENOTDIR;
2818
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002819 /* Read in the sysctl name for better debug message logging */
2820 for (i = 0; i < args->nlen; i++)
2821 if (get_user(name[i], args->name + i))
2822 return -EFAULT;
2823
2824 /* Ignore accesses to kernel.version */
2825 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2826 return 0;
2827
2828 if (msg_count < 5) {
2829 msg_count++;
2830 printk(KERN_INFO
2831 "warning: process `%s' used the deprecated sysctl "
2832 "system call with ", current->comm);
2833 for (i = 0; i < args->nlen; i++)
2834 printk("%d.", name[i]);
2835 printk("\n");
2836 }
2837 return 0;
2838}
2839
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840/*
2841 * No sense putting this after each symbol definition, twice,
2842 * exception granted :-)
2843 */
2844EXPORT_SYMBOL(proc_dointvec);
2845EXPORT_SYMBOL(proc_dointvec_jiffies);
2846EXPORT_SYMBOL(proc_dointvec_minmax);
2847EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2848EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2849EXPORT_SYMBOL(proc_dostring);
2850EXPORT_SYMBOL(proc_doulongvec_minmax);
2851EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2852EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002853EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854EXPORT_SYMBOL(sysctl_intvec);
2855EXPORT_SYMBOL(sysctl_jiffies);
2856EXPORT_SYMBOL(sysctl_ms_jiffies);
2857EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002858EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859EXPORT_SYMBOL(unregister_sysctl_table);