blob: 0d562d6531ebc7b394e2552bfe8806d2e0b40aae [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>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020049#include <linux/ftrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#include <asm/uaccess.h>
52#include <asm/processor.h>
53
Andi Kleen29cbc782006-09-30 01:47:55 +020054#ifdef CONFIG_X86
55#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010056#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010057#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020058#endif
59
Eric W. Biederman7058cb02007-10-18 03:05:58 -070060static int deprecated_sysctl_warning(struct __sysctl_args *args);
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#if defined(CONFIG_SYSCTL)
63
64/* External variables not in a header file. */
65extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070066extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067extern int sysctl_overcommit_memory;
68extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070069extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070070extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080071extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070074extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int pid_max;
77extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080079extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080080extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020081extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070082extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070083extern int sysctl_stat_interval;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070087/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080088#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070089static int one = 1;
Bron Gondwana195cf452008-02-04 22:29:20 -080090#endif
91
92#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093static int sixty = 60;
94#endif
95
96#ifdef CONFIG_MMU
97static int two = 2;
98#endif
99
100static int zero;
101static int one_hundred = 100;
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104static int maxolduid = 65535;
105static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800106static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108static int ngroups_max = NGROUPS_MAX;
109
110#ifdef CONFIG_KMOD
111extern char modprobe_path[];
112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#ifdef CONFIG_CHR_DEV_SG
114extern int sg_big_buff;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117#ifdef __sparc__
118extern char reboot_command [];
119extern int stop_a_enabled;
120extern int scons_pwroff;
121#endif
122
123#ifdef __hppa__
124extern int pwrsw_enabled;
125extern int unaligned_enabled;
126#endif
127
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800128#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#ifdef CONFIG_MATHEMU
130extern int sysctl_ieee_emulation_warnings;
131#endif
132extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700133extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef CONFIG_BSD_PROCESS_ACCT
137extern int acct_parm[];
138#endif
139
Jes Sorensend2b176e2006-02-28 09:42:23 -0800140#ifdef CONFIG_IA64
141extern int no_unaligned_warning;
142#endif
143
Ingo Molnar23f78d42006-06-27 02:54:53 -0700144#ifdef CONFIG_RT_MUTEXES
145extern int max_lock_depth;
146#endif
147
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700148#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700149static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700150 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700151static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800152 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700153#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700154
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100156static struct ctl_table_root sysctl_table_root;
157static struct ctl_table_header root_table_header = {
158 .ctl_table = root_table,
159 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
160 .root = &sysctl_table_root,
161};
162static struct ctl_table_root sysctl_table_root = {
163 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
164 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
165};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700167static struct ctl_table kern_table[];
168static struct ctl_table vm_table[];
169static struct ctl_table fs_table[];
170static struct ctl_table debug_table[];
171static struct ctl_table dev_table[];
172extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700173#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700174extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400175#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
178int sysctl_legacy_va_layout;
179#endif
180
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700181extern int prove_locking;
182extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* The default sysctl tables: */
185
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700186static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 {
188 .ctl_name = CTL_KERN,
189 .procname = "kernel",
190 .mode = 0555,
191 .child = kern_table,
192 },
193 {
194 .ctl_name = CTL_VM,
195 .procname = "vm",
196 .mode = 0555,
197 .child = vm_table,
198 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 .ctl_name = CTL_FS,
201 .procname = "fs",
202 .mode = 0555,
203 .child = fs_table,
204 },
205 {
206 .ctl_name = CTL_DEBUG,
207 .procname = "debug",
208 .mode = 0555,
209 .child = debug_table,
210 },
211 {
212 .ctl_name = CTL_DEV,
213 .procname = "dev",
214 .mode = 0555,
215 .child = dev_table,
216 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700217/*
218 * NOTE: do not add new entries to this table unless you have read
219 * Documentation/sysctl/ctl_unnumbered.txt
220 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 { .ctl_name = 0 }
222};
223
Ingo Molnar77e54a12007-07-09 18:52:00 +0200224#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100225static int min_sched_granularity_ns = 100000; /* 100 usecs */
226static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
227static int min_wakeup_granularity_ns; /* 0 usecs */
228static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200229#endif
230
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700231static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200232#ifdef CONFIG_SCHED_DEBUG
233 {
234 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100235 .procname = "sched_min_granularity_ns",
236 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200237 .maxlen = sizeof(unsigned int),
238 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100239 .proc_handler = &sched_nr_latency_handler,
240 .strategy = &sysctl_intvec,
241 .extra1 = &min_sched_granularity_ns,
242 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243 },
244 {
245 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200246 .procname = "sched_latency_ns",
247 .data = &sysctl_sched_latency,
248 .maxlen = sizeof(unsigned int),
249 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100250 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200251 .strategy = &sysctl_intvec,
252 .extra1 = &min_sched_granularity_ns,
253 .extra2 = &max_sched_granularity_ns,
254 },
255 {
256 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 .procname = "sched_wakeup_granularity_ns",
258 .data = &sysctl_sched_wakeup_granularity,
259 .maxlen = sizeof(unsigned int),
260 .mode = 0644,
261 .proc_handler = &proc_dointvec_minmax,
262 .strategy = &sysctl_intvec,
263 .extra1 = &min_wakeup_granularity_ns,
264 .extra2 = &max_wakeup_granularity_ns,
265 },
266 {
267 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200268 .procname = "sched_shares_ratelimit",
269 .data = &sysctl_sched_shares_ratelimit,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
272 .proc_handler = &proc_dointvec,
273 },
274 {
275 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
280 .proc_handler = &proc_dointvec,
281 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200282 {
283 .ctl_name = CTL_UNNUMBERED,
284 .procname = "sched_features",
285 .data = &sysctl_sched_features,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = &proc_dointvec,
289 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200290 {
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_migration_cost",
293 .data = &sysctl_sched_migration_cost,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
297 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100298 {
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_nr_migrate",
301 .data = &sysctl_sched_nr_migrate,
302 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200306#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200307 {
308 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100309 .procname = "sched_rt_period_us",
310 .data = &sysctl_sched_rt_period,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200313 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100314 },
315 {
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "sched_rt_runtime_us",
318 .data = &sysctl_sched_rt_runtime,
319 .maxlen = sizeof(int),
320 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200321 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100322 },
323 {
324 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200325 .procname = "sched_compat_yield",
326 .data = &sysctl_sched_compat_yield,
327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
330 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700331#ifdef CONFIG_PROVE_LOCKING
332 {
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "prove_locking",
335 .data = &prove_locking,
336 .maxlen = sizeof(int),
337 .mode = 0644,
338 .proc_handler = &proc_dointvec,
339 },
340#endif
341#ifdef CONFIG_LOCK_STAT
342 {
343 .ctl_name = CTL_UNNUMBERED,
344 .procname = "lock_stat",
345 .data = &lock_stat,
346 .maxlen = sizeof(int),
347 .mode = 0644,
348 .proc_handler = &proc_dointvec,
349 },
350#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200351 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 .ctl_name = KERN_PANIC,
353 .procname = "panic",
354 .data = &panic_timeout,
355 .maxlen = sizeof(int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
358 },
359 {
360 .ctl_name = KERN_CORE_USES_PID,
361 .procname = "core_uses_pid",
362 .data = &core_uses_pid,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
366 },
367 {
368 .ctl_name = KERN_CORE_PATTERN,
369 .procname = "core_pattern",
370 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700371 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .mode = 0644,
373 .proc_handler = &proc_dostring,
374 .strategy = &sysctl_string,
375 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800376#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .procname = "tainted",
379 .data = &tainted,
380 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800381 .mode = 0644,
382 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800384#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100385#ifdef CONFIG_LATENCYTOP
386 {
387 .procname = "latencytop",
388 .data = &latencytop_enabled,
389 .maxlen = sizeof(int),
390 .mode = 0644,
391 .proc_handler = &proc_dointvec,
392 },
393#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#ifdef CONFIG_BLK_DEV_INITRD
395 {
396 .ctl_name = KERN_REALROOTDEV,
397 .procname = "real-root-dev",
398 .data = &real_root_dev,
399 .maxlen = sizeof(int),
400 .mode = 0644,
401 .proc_handler = &proc_dointvec,
402 },
403#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700404 {
405 .ctl_name = CTL_UNNUMBERED,
406 .procname = "print-fatal-signals",
407 .data = &print_fatal_signals,
408 .maxlen = sizeof(int),
409 .mode = 0644,
410 .proc_handler = &proc_dointvec,
411 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#ifdef __sparc__
413 {
414 .ctl_name = KERN_SPARC_REBOOT,
415 .procname = "reboot-cmd",
416 .data = reboot_command,
417 .maxlen = 256,
418 .mode = 0644,
419 .proc_handler = &proc_dostring,
420 .strategy = &sysctl_string,
421 },
422 {
423 .ctl_name = KERN_SPARC_STOP_A,
424 .procname = "stop-a",
425 .data = &stop_a_enabled,
426 .maxlen = sizeof (int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
429 },
430 {
431 .ctl_name = KERN_SPARC_SCONS_PWROFF,
432 .procname = "scons-poweroff",
433 .data = &scons_pwroff,
434 .maxlen = sizeof (int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
437 },
438#endif
439#ifdef __hppa__
440 {
441 .ctl_name = KERN_HPPA_PWRSW,
442 .procname = "soft-power",
443 .data = &pwrsw_enabled,
444 .maxlen = sizeof (int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
448 {
449 .ctl_name = KERN_HPPA_UNALIGNED,
450 .procname = "unaligned-trap",
451 .data = &unaligned_enabled,
452 .maxlen = sizeof (int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
455 },
456#endif
457 {
458 .ctl_name = KERN_CTLALTDEL,
459 .procname = "ctrl-alt-del",
460 .data = &C_A_D,
461 .maxlen = sizeof(int),
462 .mode = 0644,
463 .proc_handler = &proc_dointvec,
464 },
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200465#ifdef CONFIG_FTRACE
466 {
467 .ctl_name = CTL_UNNUMBERED,
468 .procname = "ftrace_enabled",
469 .data = &ftrace_enabled,
470 .maxlen = sizeof(int),
471 .mode = 0644,
472 .proc_handler = &ftrace_enable_sysctl,
473 },
474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475#ifdef CONFIG_KMOD
476 {
477 .ctl_name = KERN_MODPROBE,
478 .procname = "modprobe",
479 .data = &modprobe_path,
480 .maxlen = KMOD_PATH_LEN,
481 .mode = 0644,
482 .proc_handler = &proc_dostring,
483 .strategy = &sysctl_string,
484 },
485#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700486#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 {
488 .ctl_name = KERN_HOTPLUG,
489 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100490 .data = &uevent_helper,
491 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .mode = 0644,
493 .proc_handler = &proc_dostring,
494 .strategy = &sysctl_string,
495 },
496#endif
497#ifdef CONFIG_CHR_DEV_SG
498 {
499 .ctl_name = KERN_SG_BIG_BUFF,
500 .procname = "sg-big-buff",
501 .data = &sg_big_buff,
502 .maxlen = sizeof (int),
503 .mode = 0444,
504 .proc_handler = &proc_dointvec,
505 },
506#endif
507#ifdef CONFIG_BSD_PROCESS_ACCT
508 {
509 .ctl_name = KERN_ACCT,
510 .procname = "acct",
511 .data = &acct_parm,
512 .maxlen = 3*sizeof(int),
513 .mode = 0644,
514 .proc_handler = &proc_dointvec,
515 },
516#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517#ifdef CONFIG_MAGIC_SYSRQ
518 {
519 .ctl_name = KERN_SYSRQ,
520 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800521 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .maxlen = sizeof (int),
523 .mode = 0644,
524 .proc_handler = &proc_dointvec,
525 },
526#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700527#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700530 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 .maxlen = sizeof (int),
532 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700533 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700535#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 {
537 .ctl_name = KERN_MAX_THREADS,
538 .procname = "threads-max",
539 .data = &max_threads,
540 .maxlen = sizeof(int),
541 .mode = 0644,
542 .proc_handler = &proc_dointvec,
543 },
544 {
545 .ctl_name = KERN_RANDOM,
546 .procname = "random",
547 .mode = 0555,
548 .child = random_table,
549 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 {
551 .ctl_name = KERN_OVERFLOWUID,
552 .procname = "overflowuid",
553 .data = &overflowuid,
554 .maxlen = sizeof(int),
555 .mode = 0644,
556 .proc_handler = &proc_dointvec_minmax,
557 .strategy = &sysctl_intvec,
558 .extra1 = &minolduid,
559 .extra2 = &maxolduid,
560 },
561 {
562 .ctl_name = KERN_OVERFLOWGID,
563 .procname = "overflowgid",
564 .data = &overflowgid,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec_minmax,
568 .strategy = &sysctl_intvec,
569 .extra1 = &minolduid,
570 .extra2 = &maxolduid,
571 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800572#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#ifdef CONFIG_MATHEMU
574 {
575 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
576 .procname = "ieee_emulation_warnings",
577 .data = &sysctl_ieee_emulation_warnings,
578 .maxlen = sizeof(int),
579 .mode = 0644,
580 .proc_handler = &proc_dointvec,
581 },
582#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 {
584 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
585 .procname = "userprocess_debug",
586 .data = &sysctl_userprocess_debug,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = &proc_dointvec,
590 },
591#endif
592 {
593 .ctl_name = KERN_PIDMAX,
594 .procname = "pid_max",
595 .data = &pid_max,
596 .maxlen = sizeof (int),
597 .mode = 0644,
598 .proc_handler = &proc_dointvec_minmax,
599 .strategy = sysctl_intvec,
600 .extra1 = &pid_max_min,
601 .extra2 = &pid_max_max,
602 },
603 {
604 .ctl_name = KERN_PANIC_ON_OOPS,
605 .procname = "panic_on_oops",
606 .data = &panic_on_oops,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
610 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800611#if defined CONFIG_PRINTK
612 {
613 .ctl_name = KERN_PRINTK,
614 .procname = "printk",
615 .data = &console_loglevel,
616 .maxlen = 4*sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
619 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 {
621 .ctl_name = KERN_PRINTK_RATELIMIT,
622 .procname = "printk_ratelimit",
623 .data = &printk_ratelimit_jiffies,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec_jiffies,
627 .strategy = &sysctl_jiffies,
628 },
629 {
630 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
631 .procname = "printk_ratelimit_burst",
632 .data = &printk_ratelimit_burst,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 .proc_handler = &proc_dointvec,
636 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800637#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 {
639 .ctl_name = KERN_NGROUPS_MAX,
640 .procname = "ngroups_max",
641 .data = &ngroups_max,
642 .maxlen = sizeof (int),
643 .mode = 0444,
644 .proc_handler = &proc_dointvec,
645 },
646#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
647 {
648 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
649 .procname = "unknown_nmi_panic",
650 .data = &unknown_nmi_panic,
651 .maxlen = sizeof (int),
652 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200653 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
Don Zickus407984f2006-09-26 10:52:27 +0200655 {
Don Zickus407984f2006-09-26 10:52:27 +0200656 .procname = "nmi_watchdog",
657 .data = &nmi_watchdog_enabled,
658 .maxlen = sizeof (int),
659 .mode = 0644,
660 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 },
662#endif
663#if defined(CONFIG_X86)
664 {
Don Zickus8da5add2006-09-26 10:52:27 +0200665 .ctl_name = KERN_PANIC_ON_NMI,
666 .procname = "panic_on_unrecovered_nmi",
667 .data = &panic_on_unrecovered_nmi,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
671 },
672 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 .ctl_name = KERN_BOOTLOADER_TYPE,
674 .procname = "bootloader_type",
675 .data = &bootloader_type,
676 .maxlen = sizeof (int),
677 .mode = 0444,
678 .proc_handler = &proc_dointvec,
679 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100680 {
681 .ctl_name = CTL_UNNUMBERED,
682 .procname = "kstack_depth_to_print",
683 .data = &kstack_depth_to_print,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100688 {
689 .ctl_name = CTL_UNNUMBERED,
690 .procname = "io_delay_type",
691 .data = &io_delay_type,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = &proc_dointvec,
695 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800697#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 {
699 .ctl_name = KERN_RANDOMIZE,
700 .procname = "randomize_va_space",
701 .data = &randomize_va_space,
702 .maxlen = sizeof(int),
703 .mode = 0644,
704 .proc_handler = &proc_dointvec,
705 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800706#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800707#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700708 {
709 .ctl_name = KERN_SPIN_RETRY,
710 .procname = "spin_retry",
711 .data = &spin_retry,
712 .maxlen = sizeof (int),
713 .mode = 0644,
714 .proc_handler = &proc_dointvec,
715 },
716#endif
Len Brown673d5b42007-07-28 03:33:16 -0400717#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800718 {
Pavel Machekc255d842006-02-20 18:27:58 -0800719 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700720 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800721 .maxlen = sizeof (unsigned long),
722 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800723 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800724 },
725#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800726#ifdef CONFIG_IA64
727 {
728 .ctl_name = KERN_IA64_UNALIGNED,
729 .procname = "ignore-unaligned-usertrap",
730 .data = &no_unaligned_warning,
731 .maxlen = sizeof (int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec,
734 },
735#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700736#ifdef CONFIG_DETECT_SOFTLOCKUP
737 {
738 .ctl_name = CTL_UNNUMBERED,
739 .procname = "softlockup_thresh",
740 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100741 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700742 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100743 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700744 .strategy = &sysctl_intvec,
745 .extra1 = &one,
746 .extra2 = &sixty,
747 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100748 {
749 .ctl_name = CTL_UNNUMBERED,
750 .procname = "hung_task_check_count",
751 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100752 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100753 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100754 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100755 .strategy = &sysctl_intvec,
756 },
757 {
758 .ctl_name = CTL_UNNUMBERED,
759 .procname = "hung_task_timeout_secs",
760 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100761 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100762 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100763 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100764 .strategy = &sysctl_intvec,
765 },
766 {
767 .ctl_name = CTL_UNNUMBERED,
768 .procname = "hung_task_warnings",
769 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100770 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100771 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100772 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100773 .strategy = &sysctl_intvec,
774 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700775#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200776#ifdef CONFIG_COMPAT
777 {
778 .ctl_name = KERN_COMPAT_LOG,
779 .procname = "compat-log",
780 .data = &compat_log,
781 .maxlen = sizeof (int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec,
784 },
785#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700786#ifdef CONFIG_RT_MUTEXES
787 {
788 .ctl_name = KERN_MAX_LOCK_DEPTH,
789 .procname = "max_lock_depth",
790 .data = &max_lock_depth,
791 .maxlen = sizeof(int),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
795#endif
Kees Cook5096add2007-05-08 00:26:04 -0700796#ifdef CONFIG_PROC_FS
797 {
798 .ctl_name = CTL_UNNUMBERED,
799 .procname = "maps_protect",
800 .data = &maps_protect,
801 .maxlen = sizeof(int),
802 .mode = 0644,
803 .proc_handler = &proc_dointvec,
804 },
805#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700806 {
807 .ctl_name = CTL_UNNUMBERED,
808 .procname = "poweroff_cmd",
809 .data = &poweroff_cmd,
810 .maxlen = POWEROFF_CMD_PATH_LEN,
811 .mode = 0644,
812 .proc_handler = &proc_dostring,
813 .strategy = &sysctl_string,
814 },
David Howells0b77f5b2008-04-29 01:01:32 -0700815#ifdef CONFIG_KEYS
816 {
817 .ctl_name = CTL_UNNUMBERED,
818 .procname = "keys",
819 .mode = 0555,
820 .child = key_sysctls,
821 },
822#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700823/*
824 * NOTE: do not add new entries to this table unless you have read
825 * Documentation/sysctl/ctl_unnumbered.txt
826 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 { .ctl_name = 0 }
828};
829
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700830static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 {
832 .ctl_name = VM_OVERCOMMIT_MEMORY,
833 .procname = "overcommit_memory",
834 .data = &sysctl_overcommit_memory,
835 .maxlen = sizeof(sysctl_overcommit_memory),
836 .mode = 0644,
837 .proc_handler = &proc_dointvec,
838 },
839 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700840 .ctl_name = VM_PANIC_ON_OOM,
841 .procname = "panic_on_oom",
842 .data = &sysctl_panic_on_oom,
843 .maxlen = sizeof(sysctl_panic_on_oom),
844 .mode = 0644,
845 .proc_handler = &proc_dointvec,
846 },
847 {
David Rientjesfe071d72007-10-16 23:25:56 -0700848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "oom_kill_allocating_task",
850 .data = &sysctl_oom_kill_allocating_task,
851 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec,
854 },
855 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800856 .ctl_name = CTL_UNNUMBERED,
857 .procname = "oom_dump_tasks",
858 .data = &sysctl_oom_dump_tasks,
859 .maxlen = sizeof(sysctl_oom_dump_tasks),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec,
862 },
863 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 .ctl_name = VM_OVERCOMMIT_RATIO,
865 .procname = "overcommit_ratio",
866 .data = &sysctl_overcommit_ratio,
867 .maxlen = sizeof(sysctl_overcommit_ratio),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
870 },
871 {
872 .ctl_name = VM_PAGE_CLUSTER,
873 .procname = "page-cluster",
874 .data = &page_cluster,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
878 },
879 {
880 .ctl_name = VM_DIRTY_BACKGROUND,
881 .procname = "dirty_background_ratio",
882 .data = &dirty_background_ratio,
883 .maxlen = sizeof(dirty_background_ratio),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec_minmax,
886 .strategy = &sysctl_intvec,
887 .extra1 = &zero,
888 .extra2 = &one_hundred,
889 },
890 {
891 .ctl_name = VM_DIRTY_RATIO,
892 .procname = "dirty_ratio",
893 .data = &vm_dirty_ratio,
894 .maxlen = sizeof(vm_dirty_ratio),
895 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700896 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 .strategy = &sysctl_intvec,
898 .extra1 = &zero,
899 .extra2 = &one_hundred,
900 },
901 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800903 .data = &dirty_writeback_interval,
904 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 .mode = 0644,
906 .proc_handler = &dirty_writeback_centisecs_handler,
907 },
908 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800910 .data = &dirty_expire_interval,
911 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800913 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 },
915 {
916 .ctl_name = VM_NR_PDFLUSH_THREADS,
917 .procname = "nr_pdflush_threads",
918 .data = &nr_pdflush_threads,
919 .maxlen = sizeof nr_pdflush_threads,
920 .mode = 0444 /* read-only*/,
921 .proc_handler = &proc_dointvec,
922 },
923 {
924 .ctl_name = VM_SWAPPINESS,
925 .procname = "swappiness",
926 .data = &vm_swappiness,
927 .maxlen = sizeof(vm_swappiness),
928 .mode = 0644,
929 .proc_handler = &proc_dointvec_minmax,
930 .strategy = &sysctl_intvec,
931 .extra1 = &zero,
932 .extra2 = &one_hundred,
933 },
934#ifdef CONFIG_HUGETLB_PAGE
935 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 .procname = "nr_hugepages",
937 .data = &max_huge_pages,
938 .maxlen = sizeof(unsigned long),
939 .mode = 0644,
940 .proc_handler = &hugetlb_sysctl_handler,
941 .extra1 = (void *)&hugetlb_zero,
942 .extra2 = (void *)&hugetlb_infinity,
943 },
944 {
945 .ctl_name = VM_HUGETLB_GROUP,
946 .procname = "hugetlb_shm_group",
947 .data = &sysctl_hugetlb_shm_group,
948 .maxlen = sizeof(gid_t),
949 .mode = 0644,
950 .proc_handler = &proc_dointvec,
951 },
Mel Gorman396faf02007-07-17 04:03:13 -0700952 {
953 .ctl_name = CTL_UNNUMBERED,
954 .procname = "hugepages_treat_as_movable",
955 .data = &hugepages_treat_as_movable,
956 .maxlen = sizeof(int),
957 .mode = 0644,
958 .proc_handler = &hugetlb_treat_movable_handler,
959 },
Adam Litke54f9f802007-10-16 01:26:20 -0700960 {
961 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800962 .procname = "nr_overcommit_hugepages",
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -0800963 .data = &sysctl_overcommit_huge_pages,
964 .maxlen = sizeof(sysctl_overcommit_huge_pages),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800965 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800966 .proc_handler = &hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800967 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968#endif
969 {
970 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
971 .procname = "lowmem_reserve_ratio",
972 .data = &sysctl_lowmem_reserve_ratio,
973 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
974 .mode = 0644,
975 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
976 .strategy = &sysctl_intvec,
977 },
978 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800979 .ctl_name = VM_DROP_PAGECACHE,
980 .procname = "drop_caches",
981 .data = &sysctl_drop_caches,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = drop_caches_sysctl_handler,
985 .strategy = &sysctl_intvec,
986 },
987 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .ctl_name = VM_MIN_FREE_KBYTES,
989 .procname = "min_free_kbytes",
990 .data = &min_free_kbytes,
991 .maxlen = sizeof(min_free_kbytes),
992 .mode = 0644,
993 .proc_handler = &min_free_kbytes_sysctl_handler,
994 .strategy = &sysctl_intvec,
995 .extra1 = &zero,
996 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800997 {
998 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
999 .procname = "percpu_pagelist_fraction",
1000 .data = &percpu_pagelist_fraction,
1001 .maxlen = sizeof(percpu_pagelist_fraction),
1002 .mode = 0644,
1003 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1004 .strategy = &sysctl_intvec,
1005 .extra1 = &min_percpu_pagelist_fract,
1006 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007#ifdef CONFIG_MMU
1008 {
1009 .ctl_name = VM_MAX_MAP_COUNT,
1010 .procname = "max_map_count",
1011 .data = &sysctl_max_map_count,
1012 .maxlen = sizeof(sysctl_max_map_count),
1013 .mode = 0644,
1014 .proc_handler = &proc_dointvec
1015 },
1016#endif
1017 {
1018 .ctl_name = VM_LAPTOP_MODE,
1019 .procname = "laptop_mode",
1020 .data = &laptop_mode,
1021 .maxlen = sizeof(laptop_mode),
1022 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001023 .proc_handler = &proc_dointvec_jiffies,
1024 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 },
1026 {
1027 .ctl_name = VM_BLOCK_DUMP,
1028 .procname = "block_dump",
1029 .data = &block_dump,
1030 .maxlen = sizeof(block_dump),
1031 .mode = 0644,
1032 .proc_handler = &proc_dointvec,
1033 .strategy = &sysctl_intvec,
1034 .extra1 = &zero,
1035 },
1036 {
1037 .ctl_name = VM_VFS_CACHE_PRESSURE,
1038 .procname = "vfs_cache_pressure",
1039 .data = &sysctl_vfs_cache_pressure,
1040 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1041 .mode = 0644,
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &zero,
1045 },
1046#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1047 {
1048 .ctl_name = VM_LEGACY_VA_LAYOUT,
1049 .procname = "legacy_va_layout",
1050 .data = &sysctl_legacy_va_layout,
1051 .maxlen = sizeof(sysctl_legacy_va_layout),
1052 .mode = 0644,
1053 .proc_handler = &proc_dointvec,
1054 .strategy = &sysctl_intvec,
1055 .extra1 = &zero,
1056 },
1057#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001058#ifdef CONFIG_NUMA
1059 {
1060 .ctl_name = VM_ZONE_RECLAIM_MODE,
1061 .procname = "zone_reclaim_mode",
1062 .data = &zone_reclaim_mode,
1063 .maxlen = sizeof(zone_reclaim_mode),
1064 .mode = 0644,
1065 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001066 .strategy = &sysctl_intvec,
1067 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001068 },
Christoph Lameter96146342006-07-03 00:24:13 -07001069 {
1070 .ctl_name = VM_MIN_UNMAPPED,
1071 .procname = "min_unmapped_ratio",
1072 .data = &sysctl_min_unmapped_ratio,
1073 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1074 .mode = 0644,
1075 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1076 .strategy = &sysctl_intvec,
1077 .extra1 = &zero,
1078 .extra2 = &one_hundred,
1079 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001080 {
1081 .ctl_name = VM_MIN_SLAB,
1082 .procname = "min_slab_ratio",
1083 .data = &sysctl_min_slab_ratio,
1084 .maxlen = sizeof(sysctl_min_slab_ratio),
1085 .mode = 0644,
1086 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1087 .strategy = &sysctl_intvec,
1088 .extra1 = &zero,
1089 .extra2 = &one_hundred,
1090 },
Christoph Lameter17436602006-01-18 17:42:32 -08001091#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001092#ifdef CONFIG_SMP
1093 {
1094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "stat_interval",
1096 .data = &sysctl_stat_interval,
1097 .maxlen = sizeof(sysctl_stat_interval),
1098 .mode = 0644,
1099 .proc_handler = &proc_dointvec_jiffies,
1100 .strategy = &sysctl_jiffies,
1101 },
1102#endif
Eric Parised032182007-06-28 15:55:21 -04001103#ifdef CONFIG_SECURITY
1104 {
1105 .ctl_name = CTL_UNNUMBERED,
1106 .procname = "mmap_min_addr",
1107 .data = &mmap_min_addr,
1108 .maxlen = sizeof(unsigned long),
1109 .mode = 0644,
1110 .proc_handler = &proc_doulongvec_minmax,
1111 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001112#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001113#ifdef CONFIG_NUMA
1114 {
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "numa_zonelist_order",
1117 .data = &numa_zonelist_order,
1118 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1119 .mode = 0644,
1120 .proc_handler = &numa_zonelist_order_handler,
1121 .strategy = &sysctl_string,
1122 },
1123#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001124#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001125 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001126 {
1127 .ctl_name = VM_VDSO_ENABLED,
1128 .procname = "vdso_enabled",
1129 .data = &vdso_enabled,
1130 .maxlen = sizeof(vdso_enabled),
1131 .mode = 0644,
1132 .proc_handler = &proc_dointvec,
1133 .strategy = &sysctl_intvec,
1134 .extra1 = &zero,
1135 },
1136#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001137#ifdef CONFIG_HIGHMEM
1138 {
1139 .ctl_name = CTL_UNNUMBERED,
1140 .procname = "highmem_is_dirtyable",
1141 .data = &vm_highmem_is_dirtyable,
1142 .maxlen = sizeof(vm_highmem_is_dirtyable),
1143 .mode = 0644,
1144 .proc_handler = &proc_dointvec_minmax,
1145 .strategy = &sysctl_intvec,
1146 .extra1 = &zero,
1147 .extra2 = &one,
1148 },
1149#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001150/*
1151 * NOTE: do not add new entries to this table unless you have read
1152 * Documentation/sysctl/ctl_unnumbered.txt
1153 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 { .ctl_name = 0 }
1155};
1156
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001157#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001158static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001159 { .ctl_name = 0 }
1160};
1161#endif
1162
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001163static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 {
1165 .ctl_name = FS_NRINODE,
1166 .procname = "inode-nr",
1167 .data = &inodes_stat,
1168 .maxlen = 2*sizeof(int),
1169 .mode = 0444,
1170 .proc_handler = &proc_dointvec,
1171 },
1172 {
1173 .ctl_name = FS_STATINODE,
1174 .procname = "inode-state",
1175 .data = &inodes_stat,
1176 .maxlen = 7*sizeof(int),
1177 .mode = 0444,
1178 .proc_handler = &proc_dointvec,
1179 },
1180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .procname = "file-nr",
1182 .data = &files_stat,
1183 .maxlen = 3*sizeof(int),
1184 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001185 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 },
1187 {
1188 .ctl_name = FS_MAXFILE,
1189 .procname = "file-max",
1190 .data = &files_stat.max_files,
1191 .maxlen = sizeof(int),
1192 .mode = 0644,
1193 .proc_handler = &proc_dointvec,
1194 },
1195 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001196 .ctl_name = CTL_UNNUMBERED,
1197 .procname = "nr_open",
1198 .data = &sysctl_nr_open,
1199 .maxlen = sizeof(int),
1200 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001201 .proc_handler = &proc_dointvec_minmax,
1202 .extra1 = &sysctl_nr_open_min,
1203 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001204 },
1205 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 .ctl_name = FS_DENTRY,
1207 .procname = "dentry-state",
1208 .data = &dentry_stat,
1209 .maxlen = 6*sizeof(int),
1210 .mode = 0444,
1211 .proc_handler = &proc_dointvec,
1212 },
1213 {
1214 .ctl_name = FS_OVERFLOWUID,
1215 .procname = "overflowuid",
1216 .data = &fs_overflowuid,
1217 .maxlen = sizeof(int),
1218 .mode = 0644,
1219 .proc_handler = &proc_dointvec_minmax,
1220 .strategy = &sysctl_intvec,
1221 .extra1 = &minolduid,
1222 .extra2 = &maxolduid,
1223 },
1224 {
1225 .ctl_name = FS_OVERFLOWGID,
1226 .procname = "overflowgid",
1227 .data = &fs_overflowgid,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
1230 .proc_handler = &proc_dointvec_minmax,
1231 .strategy = &sysctl_intvec,
1232 .extra1 = &minolduid,
1233 .extra2 = &maxolduid,
1234 },
1235 {
1236 .ctl_name = FS_LEASES,
1237 .procname = "leases-enable",
1238 .data = &leases_enable,
1239 .maxlen = sizeof(int),
1240 .mode = 0644,
1241 .proc_handler = &proc_dointvec,
1242 },
1243#ifdef CONFIG_DNOTIFY
1244 {
1245 .ctl_name = FS_DIR_NOTIFY,
1246 .procname = "dir-notify-enable",
1247 .data = &dir_notify_enable,
1248 .maxlen = sizeof(int),
1249 .mode = 0644,
1250 .proc_handler = &proc_dointvec,
1251 },
1252#endif
1253#ifdef CONFIG_MMU
1254 {
1255 .ctl_name = FS_LEASE_TIME,
1256 .procname = "lease-break-time",
1257 .data = &lease_break_time,
1258 .maxlen = sizeof(int),
1259 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001260 .proc_handler = &proc_dointvec_minmax,
1261 .strategy = &sysctl_intvec,
1262 .extra1 = &zero,
1263 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 },
1265 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 .procname = "aio-nr",
1267 .data = &aio_nr,
1268 .maxlen = sizeof(aio_nr),
1269 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001270 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 },
1272 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 .procname = "aio-max-nr",
1274 .data = &aio_max_nr,
1275 .maxlen = sizeof(aio_max_nr),
1276 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001277 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001279#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001280 {
1281 .ctl_name = FS_INOTIFY,
1282 .procname = "inotify",
1283 .mode = 0555,
1284 .child = inotify_table,
1285 },
1286#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001288 {
1289 .ctl_name = KERN_SETUID_DUMPABLE,
1290 .procname = "suid_dumpable",
1291 .data = &suid_dumpable,
1292 .maxlen = sizeof(int),
1293 .mode = 0644,
1294 .proc_handler = &proc_dointvec,
1295 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001296#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1297 {
1298 .ctl_name = CTL_UNNUMBERED,
1299 .procname = "binfmt_misc",
1300 .mode = 0555,
1301 .child = binfmt_misc_table,
1302 },
1303#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001304/*
1305 * NOTE: do not add new entries to this table unless you have read
1306 * Documentation/sysctl/ctl_unnumbered.txt
1307 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 { .ctl_name = 0 }
1309};
1310
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001311static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001312#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001313 {
1314 .ctl_name = CTL_UNNUMBERED,
1315 .procname = "exception-trace",
1316 .data = &show_unhandled_signals,
1317 .maxlen = sizeof(int),
1318 .mode = 0644,
1319 .proc_handler = proc_dointvec
1320 },
1321#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 { .ctl_name = 0 }
1323};
1324
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001325static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001327};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Al Viro330d57f2005-11-04 10:18:40 +00001329static DEFINE_SPINLOCK(sysctl_lock);
1330
1331/* called under sysctl_lock */
1332static int use_table(struct ctl_table_header *p)
1333{
1334 if (unlikely(p->unregistering))
1335 return 0;
1336 p->used++;
1337 return 1;
1338}
1339
1340/* called under sysctl_lock */
1341static void unuse_table(struct ctl_table_header *p)
1342{
1343 if (!--p->used)
1344 if (unlikely(p->unregistering))
1345 complete(p->unregistering);
1346}
1347
1348/* called under sysctl_lock, will reacquire if has to wait */
1349static void start_unregistering(struct ctl_table_header *p)
1350{
1351 /*
1352 * if p->used is 0, nobody will ever touch that entry again;
1353 * we'll eliminate all paths to it before dropping sysctl_lock
1354 */
1355 if (unlikely(p->used)) {
1356 struct completion wait;
1357 init_completion(&wait);
1358 p->unregistering = &wait;
1359 spin_unlock(&sysctl_lock);
1360 wait_for_completion(&wait);
1361 spin_lock(&sysctl_lock);
1362 }
1363 /*
1364 * do not remove from the list until nobody holds it; walking the
1365 * list in do_sysctl() relies on that.
1366 */
1367 list_del_init(&p->ctl_entry);
1368}
1369
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001370void sysctl_head_finish(struct ctl_table_header *head)
1371{
1372 if (!head)
1373 return;
1374 spin_lock(&sysctl_lock);
1375 unuse_table(head);
1376 spin_unlock(&sysctl_lock);
1377}
1378
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001379static struct list_head *
1380lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001381{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001382 struct list_head *header_list;
1383 header_list = &root->header_list;
1384 if (root->lookup)
1385 header_list = root->lookup(root, namespaces);
1386 return header_list;
1387}
1388
1389struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1390 struct ctl_table_header *prev)
1391{
1392 struct ctl_table_root *root;
1393 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001394 struct ctl_table_header *head;
1395 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001396
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001397 spin_lock(&sysctl_lock);
1398 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001399 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001400 tmp = &prev->ctl_entry;
1401 unuse_table(prev);
1402 goto next;
1403 }
1404 tmp = &root_table_header.ctl_entry;
1405 for (;;) {
1406 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1407
1408 if (!use_table(head))
1409 goto next;
1410 spin_unlock(&sysctl_lock);
1411 return head;
1412 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001413 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001414 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001415 header_list = lookup_header_list(root, namespaces);
1416 if (tmp != header_list)
1417 continue;
1418
1419 do {
1420 root = list_entry(root->root_list.next,
1421 struct ctl_table_root, root_list);
1422 if (root == &sysctl_table_root)
1423 goto out;
1424 header_list = lookup_header_list(root, namespaces);
1425 } while (list_empty(header_list));
1426 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001427 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001428out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001429 spin_unlock(&sysctl_lock);
1430 return NULL;
1431}
1432
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001433struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1434{
1435 return __sysctl_head_next(current->nsproxy, prev);
1436}
1437
1438void register_sysctl_root(struct ctl_table_root *root)
1439{
1440 spin_lock(&sysctl_lock);
1441 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1442 spin_unlock(&sysctl_lock);
1443}
1444
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001445#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001446/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001447static int do_sysctl_strategy(struct ctl_table_root *root,
1448 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001449 int __user *name, int nlen,
1450 void __user *oldval, size_t __user *oldlenp,
1451 void __user *newval, size_t newlen)
1452{
1453 int op = 0, rc;
1454
1455 if (oldval)
1456 op |= 004;
1457 if (newval)
1458 op |= 002;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001459 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001460 return -EPERM;
1461
1462 if (table->strategy) {
1463 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1464 newval, newlen);
1465 if (rc < 0)
1466 return rc;
1467 if (rc > 0)
1468 return 0;
1469 }
1470
1471 /* If there is no strategy routine, or if the strategy returns
1472 * zero, proceed with automatic r/w */
1473 if (table->data && table->maxlen) {
1474 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1475 newval, newlen);
1476 if (rc < 0)
1477 return rc;
1478 }
1479 return 0;
1480}
1481
1482static int parse_table(int __user *name, int nlen,
1483 void __user *oldval, size_t __user *oldlenp,
1484 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001485 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001486 struct ctl_table *table)
1487{
1488 int n;
1489repeat:
1490 if (!nlen)
1491 return -ENOTDIR;
1492 if (get_user(n, name))
1493 return -EFAULT;
1494 for ( ; table->ctl_name || table->procname; table++) {
1495 if (!table->ctl_name)
1496 continue;
1497 if (n == table->ctl_name) {
1498 int error;
1499 if (table->child) {
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001500 if (sysctl_perm(root, table, 001))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001501 return -EPERM;
1502 name++;
1503 nlen--;
1504 table = table->child;
1505 goto repeat;
1506 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001507 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001508 oldval, oldlenp,
1509 newval, newlen);
1510 return error;
1511 }
1512 }
1513 return -ENOTDIR;
1514}
1515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1517 void __user *newval, size_t newlen)
1518{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001519 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001520 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1523 return -ENOTDIR;
1524 if (oldval) {
1525 int old_len;
1526 if (!oldlenp || get_user(old_len, oldlenp))
1527 return -EFAULT;
1528 }
Al Viro330d57f2005-11-04 10:18:40 +00001529
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001530 for (head = sysctl_head_next(NULL); head;
1531 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001532 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001533 newval, newlen,
1534 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001535 if (error != -ENOTDIR) {
1536 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001537 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001538 }
1539 }
Al Viro330d57f2005-11-04 10:18:40 +00001540 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
1543asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1544{
1545 struct __sysctl_args tmp;
1546 int error;
1547
1548 if (copy_from_user(&tmp, args, sizeof(tmp)))
1549 return -EFAULT;
1550
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001551 error = deprecated_sysctl_warning(&tmp);
1552 if (error)
1553 goto out;
1554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 lock_kernel();
1556 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1557 tmp.newval, tmp.newlen);
1558 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001559out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 return error;
1561}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001562#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001565 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 * some sysctl variables are readonly even to root.
1567 */
1568
1569static int test_perm(int mode, int op)
1570{
1571 if (!current->euid)
1572 mode >>= 6;
1573 else if (in_egroup_p(0))
1574 mode >>= 3;
1575 if ((mode & op & 0007) == op)
1576 return 0;
1577 return -EACCES;
1578}
1579
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001580int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
1582 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001583 int mode;
1584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 error = security_sysctl(table, op);
1586 if (error)
1587 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001588
1589 if (root->permissions)
1590 mode = root->permissions(root, current->nsproxy, table);
1591 else
1592 mode = table->mode;
1593
1594 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
1596
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001597static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1598{
1599 for (; table->ctl_name || table->procname; table++) {
1600 table->parent = parent;
1601 if (table->child)
1602 sysctl_set_parent(table, table->child);
1603 }
1604}
1605
1606static __init int sysctl_init(void)
1607{
1608 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001609#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1610 {
1611 int err;
1612 err = sysctl_check_table(current->nsproxy, root_table);
1613 }
1614#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001615 return 0;
1616}
1617
1618core_initcall(sysctl_init);
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001621 * __register_sysctl_paths - register a sysctl hierarchy
1622 * @root: List of sysctl headers to register on
1623 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001624 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 *
1627 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001628 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001630 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 *
1632 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1633 * must be unique within that level of sysctl
1634 *
1635 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1636 * enter a sysctl file
1637 *
1638 * data - a pointer to data for use by proc_handler
1639 *
1640 * maxlen - the maximum size in bytes of the data
1641 *
1642 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1643 *
1644 * child - a pointer to the child sysctl table if this entry is a directory, or
1645 * %NULL.
1646 *
1647 * proc_handler - the text handler routine (described below)
1648 *
1649 * strategy - the strategy routine (described below)
1650 *
1651 * de - for internal use by the sysctl routines
1652 *
1653 * extra1, extra2 - extra pointers usable by the proc handler routines
1654 *
1655 * Leaf nodes in the sysctl tree will be represented by a single file
1656 * under /proc; non-leaf nodes will be represented by directories.
1657 *
1658 * sysctl(2) can automatically manage read and write requests through
1659 * the sysctl table. The data and maxlen fields of the ctl_table
1660 * struct enable minimal validation of the values being written to be
1661 * performed, and the mode field allows minimal authentication.
1662 *
1663 * More sophisticated management can be enabled by the provision of a
1664 * strategy routine with the table entry. This will be called before
1665 * any automatic read or write of the data is performed.
1666 *
1667 * The strategy routine may return
1668 *
1669 * < 0 - Error occurred (error is passed to user process)
1670 *
1671 * 0 - OK - proceed with automatic read or write.
1672 *
1673 * > 0 - OK - read or write has been done by the strategy routine, so
1674 * return immediately.
1675 *
1676 * There must be a proc_handler routine for any terminal nodes
1677 * mirrored under /proc/sys (non-terminals are handled by a built-in
1678 * directory handler). Several default handlers are available to
1679 * cover common cases -
1680 *
1681 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1682 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1683 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1684 *
1685 * It is the handler's job to read the input buffer from user memory
1686 * and process it. The handler should return 0 on success.
1687 *
1688 * This routine returns %NULL on a failure to register, and a pointer
1689 * to the table header on success.
1690 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001691struct ctl_table_header *__register_sysctl_paths(
1692 struct ctl_table_root *root,
1693 struct nsproxy *namespaces,
1694 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001696 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001697 struct ctl_table_header *header;
1698 struct ctl_table *new, **prevp;
1699 unsigned int n, npath;
1700
1701 /* Count the path components */
1702 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1703 ;
1704
1705 /*
1706 * For each path component, allocate a 2-element ctl_table array.
1707 * The first array element will be filled with the sysctl entry
1708 * for this, the second will be the sentinel (ctl_name == 0).
1709 *
1710 * We allocate everything in one go so that we don't have to
1711 * worry about freeing additional memory in unregister_sysctl_table.
1712 */
1713 header = kzalloc(sizeof(struct ctl_table_header) +
1714 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1715 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001717
1718 new = (struct ctl_table *) (header + 1);
1719
1720 /* Now connect the dots */
1721 prevp = &header->ctl_table;
1722 for (n = 0; n < npath; ++n, ++path) {
1723 /* Copy the procname */
1724 new->procname = path->procname;
1725 new->ctl_name = path->ctl_name;
1726 new->mode = 0555;
1727
1728 *prevp = new;
1729 prevp = &new->child;
1730
1731 new += 2;
1732 }
1733 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001734 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001735
1736 INIT_LIST_HEAD(&header->ctl_entry);
1737 header->used = 0;
1738 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001739 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001740 sysctl_set_parent(NULL, header->ctl_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001741#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001742 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001743 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001744 return NULL;
1745 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001746#endif
Al Viro330d57f2005-11-04 10:18:40 +00001747 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001748 header_list = lookup_header_list(root, namespaces);
1749 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001750 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001751
1752 return header;
1753}
1754
1755/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001756 * register_sysctl_table_path - register a sysctl table hierarchy
1757 * @path: The path to the directory the sysctl table is in.
1758 * @table: the top-level table structure
1759 *
1760 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1761 * array. A completely 0 filled entry terminates the table.
1762 *
1763 * See __register_sysctl_paths for more details.
1764 */
1765struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1766 struct ctl_table *table)
1767{
1768 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1769 path, table);
1770}
1771
1772/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001773 * register_sysctl_table - register a sysctl table hierarchy
1774 * @table: the top-level table structure
1775 *
1776 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1777 * array. A completely 0 filled entry terminates the table.
1778 *
1779 * See register_sysctl_paths for more details.
1780 */
1781struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1782{
1783 static const struct ctl_path null_path[] = { {} };
1784
1785 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786}
1787
1788/**
1789 * unregister_sysctl_table - unregister a sysctl table hierarchy
1790 * @header: the header returned from register_sysctl_table
1791 *
1792 * Unregisters the sysctl table and all children. proc entries may not
1793 * actually be removed until they are no longer used by anyone.
1794 */
1795void unregister_sysctl_table(struct ctl_table_header * header)
1796{
Al Viro330d57f2005-11-04 10:18:40 +00001797 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001798
1799 if (header == NULL)
1800 return;
1801
Al Viro330d57f2005-11-04 10:18:40 +00001802 spin_lock(&sysctl_lock);
1803 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001804 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 kfree(header);
1806}
1807
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001808#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001809struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001810{
1811 return NULL;
1812}
1813
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001814struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1815 struct ctl_table *table)
1816{
1817 return NULL;
1818}
1819
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001820void unregister_sysctl_table(struct ctl_table_header * table)
1821{
1822}
1823
1824#endif /* CONFIG_SYSCTL */
1825
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826/*
1827 * /proc/sys support
1828 */
1829
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001830#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001832static int _proc_do_string(void* data, int maxlen, int write,
1833 struct file *filp, void __user *buffer,
1834 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001835{
1836 size_t len;
1837 char __user *p;
1838 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001839
1840 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001841 *lenp = 0;
1842 return 0;
1843 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001844
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001845 if (write) {
1846 len = 0;
1847 p = buffer;
1848 while (len < *lenp) {
1849 if (get_user(c, p++))
1850 return -EFAULT;
1851 if (c == 0 || c == '\n')
1852 break;
1853 len++;
1854 }
1855 if (len >= maxlen)
1856 len = maxlen-1;
1857 if(copy_from_user(data, buffer, len))
1858 return -EFAULT;
1859 ((char *) data)[len] = 0;
1860 *ppos += *lenp;
1861 } else {
1862 len = strlen(data);
1863 if (len > maxlen)
1864 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001865
1866 if (*ppos > len) {
1867 *lenp = 0;
1868 return 0;
1869 }
1870
1871 data += *ppos;
1872 len -= *ppos;
1873
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001874 if (len > *lenp)
1875 len = *lenp;
1876 if (len)
1877 if(copy_to_user(buffer, data, len))
1878 return -EFAULT;
1879 if (len < *lenp) {
1880 if(put_user('\n', ((char __user *) buffer) + len))
1881 return -EFAULT;
1882 len++;
1883 }
1884 *lenp = len;
1885 *ppos += len;
1886 }
1887 return 0;
1888}
1889
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890/**
1891 * proc_dostring - read a string sysctl
1892 * @table: the sysctl table
1893 * @write: %TRUE if this is a write to the sysctl file
1894 * @filp: the file structure
1895 * @buffer: the user buffer
1896 * @lenp: the size of the user buffer
1897 * @ppos: file position
1898 *
1899 * Reads/writes a string from/to the user buffer. If the kernel
1900 * buffer provided is not large enough to hold the string, the
1901 * string is truncated. The copied string is %NULL-terminated.
1902 * If the string is being read by the user process, it is copied
1903 * and a newline '\n' is added. It is truncated if the buffer is
1904 * not large enough.
1905 *
1906 * Returns 0 on success.
1907 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001908int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 void __user *buffer, size_t *lenp, loff_t *ppos)
1910{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001911 return _proc_do_string(table->data, table->maxlen, write, filp,
1912 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913}
1914
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
1916static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1917 int *valp,
1918 int write, void *data)
1919{
1920 if (write) {
1921 *valp = *negp ? -*lvalp : *lvalp;
1922 } else {
1923 int val = *valp;
1924 if (val < 0) {
1925 *negp = -1;
1926 *lvalp = (unsigned long)-val;
1927 } else {
1928 *negp = 0;
1929 *lvalp = (unsigned long)val;
1930 }
1931 }
1932 return 0;
1933}
1934
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001935static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001936 int write, struct file *filp, void __user *buffer,
1937 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1939 int write, void *data),
1940 void *data)
1941{
1942#define TMPBUFLEN 21
1943 int *i, vleft, first=1, neg, val;
1944 unsigned long lval;
1945 size_t left, len;
1946
1947 char buf[TMPBUFLEN], *p;
1948 char __user *s = buffer;
1949
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001950 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 (*ppos && !write)) {
1952 *lenp = 0;
1953 return 0;
1954 }
1955
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001956 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 vleft = table->maxlen / sizeof(*i);
1958 left = *lenp;
1959
1960 if (!conv)
1961 conv = do_proc_dointvec_conv;
1962
1963 for (; left && vleft--; i++, first=0) {
1964 if (write) {
1965 while (left) {
1966 char c;
1967 if (get_user(c, s))
1968 return -EFAULT;
1969 if (!isspace(c))
1970 break;
1971 left--;
1972 s++;
1973 }
1974 if (!left)
1975 break;
1976 neg = 0;
1977 len = left;
1978 if (len > sizeof(buf) - 1)
1979 len = sizeof(buf) - 1;
1980 if (copy_from_user(buf, s, len))
1981 return -EFAULT;
1982 buf[len] = 0;
1983 p = buf;
1984 if (*p == '-' && left > 1) {
1985 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001986 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 }
1988 if (*p < '0' || *p > '9')
1989 break;
1990
1991 lval = simple_strtoul(p, &p, 0);
1992
1993 len = p-buf;
1994 if ((len < left) && *p && !isspace(*p))
1995 break;
1996 if (neg)
1997 val = -val;
1998 s += len;
1999 left -= len;
2000
2001 if (conv(&neg, &lval, i, 1, data))
2002 break;
2003 } else {
2004 p = buf;
2005 if (!first)
2006 *p++ = '\t';
2007
2008 if (conv(&neg, &lval, i, 0, data))
2009 break;
2010
2011 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2012 len = strlen(buf);
2013 if (len > left)
2014 len = left;
2015 if(copy_to_user(s, buf, len))
2016 return -EFAULT;
2017 left -= len;
2018 s += len;
2019 }
2020 }
2021
2022 if (!write && !first && left) {
2023 if(put_user('\n', s))
2024 return -EFAULT;
2025 left--, s++;
2026 }
2027 if (write) {
2028 while (left) {
2029 char c;
2030 if (get_user(c, s++))
2031 return -EFAULT;
2032 if (!isspace(c))
2033 break;
2034 left--;
2035 }
2036 }
2037 if (write && first)
2038 return -EINVAL;
2039 *lenp -= left;
2040 *ppos += *lenp;
2041 return 0;
2042#undef TMPBUFLEN
2043}
2044
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002045static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002046 void __user *buffer, size_t *lenp, loff_t *ppos,
2047 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2048 int write, void *data),
2049 void *data)
2050{
2051 return __do_proc_dointvec(table->data, table, write, filp,
2052 buffer, lenp, ppos, conv, data);
2053}
2054
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055/**
2056 * proc_dointvec - read a vector of integers
2057 * @table: the sysctl table
2058 * @write: %TRUE if this is a write to the sysctl file
2059 * @filp: the file structure
2060 * @buffer: the user buffer
2061 * @lenp: the size of the user buffer
2062 * @ppos: file position
2063 *
2064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2065 * values from/to the user buffer, treated as an ASCII string.
2066 *
2067 * Returns 0 on success.
2068 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002069int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 void __user *buffer, size_t *lenp, loff_t *ppos)
2071{
2072 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2073 NULL,NULL);
2074}
2075
2076#define OP_SET 0
2077#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002078#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
2080static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2081 int *valp,
2082 int write, void *data)
2083{
2084 int op = *(int *)data;
2085 if (write) {
2086 int val = *negp ? -*lvalp : *lvalp;
2087 switch(op) {
2088 case OP_SET: *valp = val; break;
2089 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002090 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 }
2092 } else {
2093 int val = *valp;
2094 if (val < 0) {
2095 *negp = -1;
2096 *lvalp = (unsigned long)-val;
2097 } else {
2098 *negp = 0;
2099 *lvalp = (unsigned long)val;
2100 }
2101 }
2102 return 0;
2103}
2104
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002105/*
2106 * Taint values can only be increased
2107 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002108static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002109 void __user *buffer, size_t *lenp, loff_t *ppos)
2110{
2111 int op;
2112
Bastian Blank91fcd412007-04-23 14:41:14 -07002113 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002114 return -EPERM;
2115
2116 op = OP_OR;
2117 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2118 do_proc_dointvec_bset_conv,&op);
2119}
2120
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121struct do_proc_dointvec_minmax_conv_param {
2122 int *min;
2123 int *max;
2124};
2125
2126static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2127 int *valp,
2128 int write, void *data)
2129{
2130 struct do_proc_dointvec_minmax_conv_param *param = data;
2131 if (write) {
2132 int val = *negp ? -*lvalp : *lvalp;
2133 if ((param->min && *param->min > val) ||
2134 (param->max && *param->max < val))
2135 return -EINVAL;
2136 *valp = val;
2137 } else {
2138 int val = *valp;
2139 if (val < 0) {
2140 *negp = -1;
2141 *lvalp = (unsigned long)-val;
2142 } else {
2143 *negp = 0;
2144 *lvalp = (unsigned long)val;
2145 }
2146 }
2147 return 0;
2148}
2149
2150/**
2151 * proc_dointvec_minmax - read a vector of integers with min/max values
2152 * @table: the sysctl table
2153 * @write: %TRUE if this is a write to the sysctl file
2154 * @filp: the file structure
2155 * @buffer: the user buffer
2156 * @lenp: the size of the user buffer
2157 * @ppos: file position
2158 *
2159 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2160 * values from/to the user buffer, treated as an ASCII string.
2161 *
2162 * This routine will ensure the values are within the range specified by
2163 * table->extra1 (min) and table->extra2 (max).
2164 *
2165 * Returns 0 on success.
2166 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002167int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 void __user *buffer, size_t *lenp, loff_t *ppos)
2169{
2170 struct do_proc_dointvec_minmax_conv_param param = {
2171 .min = (int *) table->extra1,
2172 .max = (int *) table->extra2,
2173 };
2174 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2175 do_proc_dointvec_minmax_conv, &param);
2176}
2177
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002178static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct file *filp,
2180 void __user *buffer,
2181 size_t *lenp, loff_t *ppos,
2182 unsigned long convmul,
2183 unsigned long convdiv)
2184{
2185#define TMPBUFLEN 21
2186 unsigned long *i, *min, *max, val;
2187 int vleft, first=1, neg;
2188 size_t len, left;
2189 char buf[TMPBUFLEN], *p;
2190 char __user *s = buffer;
2191
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002192 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 (*ppos && !write)) {
2194 *lenp = 0;
2195 return 0;
2196 }
2197
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002198 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 min = (unsigned long *) table->extra1;
2200 max = (unsigned long *) table->extra2;
2201 vleft = table->maxlen / sizeof(unsigned long);
2202 left = *lenp;
2203
2204 for (; left && vleft--; i++, min++, max++, first=0) {
2205 if (write) {
2206 while (left) {
2207 char c;
2208 if (get_user(c, s))
2209 return -EFAULT;
2210 if (!isspace(c))
2211 break;
2212 left--;
2213 s++;
2214 }
2215 if (!left)
2216 break;
2217 neg = 0;
2218 len = left;
2219 if (len > TMPBUFLEN-1)
2220 len = TMPBUFLEN-1;
2221 if (copy_from_user(buf, s, len))
2222 return -EFAULT;
2223 buf[len] = 0;
2224 p = buf;
2225 if (*p == '-' && left > 1) {
2226 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002227 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 }
2229 if (*p < '0' || *p > '9')
2230 break;
2231 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2232 len = p-buf;
2233 if ((len < left) && *p && !isspace(*p))
2234 break;
2235 if (neg)
2236 val = -val;
2237 s += len;
2238 left -= len;
2239
2240 if(neg)
2241 continue;
2242 if ((min && val < *min) || (max && val > *max))
2243 continue;
2244 *i = val;
2245 } else {
2246 p = buf;
2247 if (!first)
2248 *p++ = '\t';
2249 sprintf(p, "%lu", convdiv * (*i) / convmul);
2250 len = strlen(buf);
2251 if (len > left)
2252 len = left;
2253 if(copy_to_user(s, buf, len))
2254 return -EFAULT;
2255 left -= len;
2256 s += len;
2257 }
2258 }
2259
2260 if (!write && !first && left) {
2261 if(put_user('\n', s))
2262 return -EFAULT;
2263 left--, s++;
2264 }
2265 if (write) {
2266 while (left) {
2267 char c;
2268 if (get_user(c, s++))
2269 return -EFAULT;
2270 if (!isspace(c))
2271 break;
2272 left--;
2273 }
2274 }
2275 if (write && first)
2276 return -EINVAL;
2277 *lenp -= left;
2278 *ppos += *lenp;
2279 return 0;
2280#undef TMPBUFLEN
2281}
2282
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002283static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002284 struct file *filp,
2285 void __user *buffer,
2286 size_t *lenp, loff_t *ppos,
2287 unsigned long convmul,
2288 unsigned long convdiv)
2289{
2290 return __do_proc_doulongvec_minmax(table->data, table, write,
2291 filp, buffer, lenp, ppos, convmul, convdiv);
2292}
2293
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294/**
2295 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2296 * @table: the sysctl table
2297 * @write: %TRUE if this is a write to the sysctl file
2298 * @filp: the file structure
2299 * @buffer: the user buffer
2300 * @lenp: the size of the user buffer
2301 * @ppos: file position
2302 *
2303 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2304 * values from/to the user buffer, treated as an ASCII string.
2305 *
2306 * This routine will ensure the values are within the range specified by
2307 * table->extra1 (min) and table->extra2 (max).
2308 *
2309 * Returns 0 on success.
2310 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002311int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2315}
2316
2317/**
2318 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2319 * @table: the sysctl table
2320 * @write: %TRUE if this is a write to the sysctl file
2321 * @filp: the file structure
2322 * @buffer: the user buffer
2323 * @lenp: the size of the user buffer
2324 * @ppos: file position
2325 *
2326 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2327 * values from/to the user buffer, treated as an ASCII string. The values
2328 * are treated as milliseconds, and converted to jiffies when they are stored.
2329 *
2330 * This routine will ensure the values are within the range specified by
2331 * table->extra1 (min) and table->extra2 (max).
2332 *
2333 * Returns 0 on success.
2334 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002335int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct file *filp,
2337 void __user *buffer,
2338 size_t *lenp, loff_t *ppos)
2339{
2340 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2341 lenp, ppos, HZ, 1000l);
2342}
2343
2344
2345static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2346 int *valp,
2347 int write, void *data)
2348{
2349 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002350 if (*lvalp > LONG_MAX / HZ)
2351 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2353 } else {
2354 int val = *valp;
2355 unsigned long lval;
2356 if (val < 0) {
2357 *negp = -1;
2358 lval = (unsigned long)-val;
2359 } else {
2360 *negp = 0;
2361 lval = (unsigned long)val;
2362 }
2363 *lvalp = lval / HZ;
2364 }
2365 return 0;
2366}
2367
2368static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2369 int *valp,
2370 int write, void *data)
2371{
2372 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002373 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2374 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2376 } else {
2377 int val = *valp;
2378 unsigned long lval;
2379 if (val < 0) {
2380 *negp = -1;
2381 lval = (unsigned long)-val;
2382 } else {
2383 *negp = 0;
2384 lval = (unsigned long)val;
2385 }
2386 *lvalp = jiffies_to_clock_t(lval);
2387 }
2388 return 0;
2389}
2390
2391static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2392 int *valp,
2393 int write, void *data)
2394{
2395 if (write) {
2396 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2397 } else {
2398 int val = *valp;
2399 unsigned long lval;
2400 if (val < 0) {
2401 *negp = -1;
2402 lval = (unsigned long)-val;
2403 } else {
2404 *negp = 0;
2405 lval = (unsigned long)val;
2406 }
2407 *lvalp = jiffies_to_msecs(lval);
2408 }
2409 return 0;
2410}
2411
2412/**
2413 * proc_dointvec_jiffies - read a vector of integers as seconds
2414 * @table: the sysctl table
2415 * @write: %TRUE if this is a write to the sysctl file
2416 * @filp: the file structure
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: file position
2420 *
2421 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2422 * values from/to the user buffer, treated as an ASCII string.
2423 * The values read are assumed to be in seconds, and are converted into
2424 * jiffies.
2425 *
2426 * Returns 0 on success.
2427 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002428int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 void __user *buffer, size_t *lenp, loff_t *ppos)
2430{
2431 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2432 do_proc_dointvec_jiffies_conv,NULL);
2433}
2434
2435/**
2436 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @filp: the file structure
2440 * @buffer: the user buffer
2441 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002442 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 *
2444 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2445 * values from/to the user buffer, treated as an ASCII string.
2446 * The values read are assumed to be in 1/USER_HZ seconds, and
2447 * are converted into jiffies.
2448 *
2449 * Returns 0 on success.
2450 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002451int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 void __user *buffer, size_t *lenp, loff_t *ppos)
2453{
2454 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2455 do_proc_dointvec_userhz_jiffies_conv,NULL);
2456}
2457
2458/**
2459 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2460 * @table: the sysctl table
2461 * @write: %TRUE if this is a write to the sysctl file
2462 * @filp: the file structure
2463 * @buffer: the user buffer
2464 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002465 * @ppos: file position
2466 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 *
2468 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2469 * values from/to the user buffer, treated as an ASCII string.
2470 * The values read are assumed to be in 1/1000 seconds, and
2471 * are converted into jiffies.
2472 *
2473 * Returns 0 on success.
2474 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002475int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 void __user *buffer, size_t *lenp, loff_t *ppos)
2477{
2478 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2479 do_proc_dointvec_ms_jiffies_conv, NULL);
2480}
2481
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002482static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002483 void __user *buffer, size_t *lenp, loff_t *ppos)
2484{
2485 struct pid *new_pid;
2486 pid_t tmp;
2487 int r;
2488
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002489 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002490
2491 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2492 lenp, ppos, NULL, NULL);
2493 if (r || !write)
2494 return r;
2495
2496 new_pid = find_get_pid(tmp);
2497 if (!new_pid)
2498 return -ESRCH;
2499
2500 put_pid(xchg(&cad_pid, new_pid));
2501 return 0;
2502}
2503
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504#else /* CONFIG_PROC_FS */
2505
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002506int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 void __user *buffer, size_t *lenp, loff_t *ppos)
2508{
2509 return -ENOSYS;
2510}
2511
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002512int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 void __user *buffer, size_t *lenp, loff_t *ppos)
2514{
2515 return -ENOSYS;
2516}
2517
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002518int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 void __user *buffer, size_t *lenp, loff_t *ppos)
2520{
2521 return -ENOSYS;
2522}
2523
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002524int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 void __user *buffer, size_t *lenp, loff_t *ppos)
2526{
2527 return -ENOSYS;
2528}
2529
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002530int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 void __user *buffer, size_t *lenp, loff_t *ppos)
2532{
2533 return -ENOSYS;
2534}
2535
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002536int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 void __user *buffer, size_t *lenp, loff_t *ppos)
2538{
2539 return -ENOSYS;
2540}
2541
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002542int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 void __user *buffer, size_t *lenp, loff_t *ppos)
2544{
2545 return -ENOSYS;
2546}
2547
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002548int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 struct file *filp,
2550 void __user *buffer,
2551 size_t *lenp, loff_t *ppos)
2552{
2553 return -ENOSYS;
2554}
2555
2556
2557#endif /* CONFIG_PROC_FS */
2558
2559
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002560#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561/*
2562 * General sysctl support routines
2563 */
2564
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002565/* The generic sysctl data routine (used if no strategy routine supplied) */
2566int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2567 void __user *oldval, size_t __user *oldlenp,
2568 void __user *newval, size_t newlen)
2569{
2570 size_t len;
2571
2572 /* Get out of I don't have a variable */
2573 if (!table->data || !table->maxlen)
2574 return -ENOTDIR;
2575
2576 if (oldval && oldlenp) {
2577 if (get_user(len, oldlenp))
2578 return -EFAULT;
2579 if (len) {
2580 if (len > table->maxlen)
2581 len = table->maxlen;
2582 if (copy_to_user(oldval, table->data, len))
2583 return -EFAULT;
2584 if (put_user(len, oldlenp))
2585 return -EFAULT;
2586 }
2587 }
2588
2589 if (newval && newlen) {
2590 if (newlen > table->maxlen)
2591 newlen = table->maxlen;
2592
2593 if (copy_from_user(table->data, newval, newlen))
2594 return -EFAULT;
2595 }
2596 return 1;
2597}
2598
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002600int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002602 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 if (!table->data || !table->maxlen)
2605 return -ENOTDIR;
2606
2607 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002608 size_t bufsize;
2609 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002611 if (bufsize) {
2612 size_t len = strlen(table->data), copied;
2613
2614 /* This shouldn't trigger for a well-formed sysctl */
2615 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002617
2618 /* Copy up to a max of bufsize-1 bytes of the string */
2619 copied = (len >= bufsize) ? bufsize - 1 : len;
2620
2621 if (copy_to_user(oldval, table->data, copied) ||
2622 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002624 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 return -EFAULT;
2626 }
2627 }
2628 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002629 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 if (len > table->maxlen)
2631 len = table->maxlen;
2632 if(copy_from_user(table->data, newval, len))
2633 return -EFAULT;
2634 if (len == table->maxlen)
2635 len--;
2636 ((char *) table->data)[len] = 0;
2637 }
Yi Yang82c9df82005-12-30 16:37:10 +08002638 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641/*
2642 * This function makes sure that all of the integers in the vector
2643 * are between the minimum and maximum values given in the arrays
2644 * table->extra1 and table->extra2, respectively.
2645 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002646int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002648 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
2650
2651 if (newval && newlen) {
2652 int __user *vec = (int __user *) newval;
2653 int *min = (int *) table->extra1;
2654 int *max = (int *) table->extra2;
2655 size_t length;
2656 int i;
2657
2658 if (newlen % sizeof(int) != 0)
2659 return -EINVAL;
2660
2661 if (!table->extra1 && !table->extra2)
2662 return 0;
2663
2664 if (newlen > table->maxlen)
2665 newlen = table->maxlen;
2666 length = newlen / sizeof(int);
2667
2668 for (i = 0; i < length; i++) {
2669 int value;
2670 if (get_user(value, vec + i))
2671 return -EFAULT;
2672 if (min && value < min[i])
2673 return -EINVAL;
2674 if (max && value > max[i])
2675 return -EINVAL;
2676 }
2677 }
2678 return 0;
2679}
2680
2681/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002682int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002684 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002686 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002688
2689 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002691 if (olen) {
2692 int val;
2693
2694 if (olen < sizeof(int))
2695 return -EINVAL;
2696
2697 val = *(int *)(table->data) / HZ;
2698 if (put_user(val, (int __user *)oldval))
2699 return -EFAULT;
2700 if (put_user(sizeof(int), oldlenp))
2701 return -EFAULT;
2702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 }
2704 if (newval && newlen) {
2705 int new;
2706 if (newlen != sizeof(int))
2707 return -EINVAL;
2708 if (get_user(new, (int __user *)newval))
2709 return -EFAULT;
2710 *(int *)(table->data) = new*HZ;
2711 }
2712 return 1;
2713}
2714
2715/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002716int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002718 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002720 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002722
2723 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002725 if (olen) {
2726 int val;
2727
2728 if (olen < sizeof(int))
2729 return -EINVAL;
2730
2731 val = jiffies_to_msecs(*(int *)(table->data));
2732 if (put_user(val, (int __user *)oldval))
2733 return -EFAULT;
2734 if (put_user(sizeof(int), oldlenp))
2735 return -EFAULT;
2736 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 }
2738 if (newval && newlen) {
2739 int new;
2740 if (newlen != sizeof(int))
2741 return -EINVAL;
2742 if (get_user(new, (int __user *)newval))
2743 return -EFAULT;
2744 *(int *)(table->data) = msecs_to_jiffies(new);
2745 }
2746 return 1;
2747}
2748
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002749
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002750
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002751#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
2753
2754asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2755{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002756 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002757 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002758
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002759 if (copy_from_user(&tmp, args, sizeof(tmp)))
2760 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002761
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002762 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002763
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002764 /* If no error reading the parameters then just -ENOSYS ... */
2765 if (!error)
2766 error = -ENOSYS;
2767
2768 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769}
2770
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002771int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2772 void __user *oldval, size_t __user *oldlenp,
2773 void __user *newval, size_t newlen)
2774{
2775 return -ENOSYS;
2776}
2777
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002778int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002780 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781{
2782 return -ENOSYS;
2783}
2784
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002785int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002787 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788{
2789 return -ENOSYS;
2790}
2791
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002792int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002794 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795{
2796 return -ENOSYS;
2797}
2798
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002799int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002801 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802{
2803 return -ENOSYS;
2804}
2805
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002806#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002808static int deprecated_sysctl_warning(struct __sysctl_args *args)
2809{
2810 static int msg_count;
2811 int name[CTL_MAXNAME];
2812 int i;
2813
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002814 /* Check args->nlen. */
2815 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2816 return -ENOTDIR;
2817
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002818 /* Read in the sysctl name for better debug message logging */
2819 for (i = 0; i < args->nlen; i++)
2820 if (get_user(name[i], args->name + i))
2821 return -EFAULT;
2822
2823 /* Ignore accesses to kernel.version */
2824 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2825 return 0;
2826
2827 if (msg_count < 5) {
2828 msg_count++;
2829 printk(KERN_INFO
2830 "warning: process `%s' used the deprecated sysctl "
2831 "system call with ", current->comm);
2832 for (i = 0; i < args->nlen; i++)
2833 printk("%d.", name[i]);
2834 printk("\n");
2835 }
2836 return 0;
2837}
2838
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839/*
2840 * No sense putting this after each symbol definition, twice,
2841 * exception granted :-)
2842 */
2843EXPORT_SYMBOL(proc_dointvec);
2844EXPORT_SYMBOL(proc_dointvec_jiffies);
2845EXPORT_SYMBOL(proc_dointvec_minmax);
2846EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2847EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2848EXPORT_SYMBOL(proc_dostring);
2849EXPORT_SYMBOL(proc_doulongvec_minmax);
2850EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2851EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002852EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853EXPORT_SYMBOL(sysctl_intvec);
2854EXPORT_SYMBOL(sysctl_jiffies);
2855EXPORT_SYMBOL(sysctl_ms_jiffies);
2856EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002857EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858EXPORT_SYMBOL(unregister_sysctl_table);