blob: d0b47b85906731a5cda80d5630ea3dbb11a86810 [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>
40#include <linux/security.h>
41#include <linux/initrd.h>
42#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010056#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020057#endif
58
Eric W. Biederman7058cb02007-10-18 03:05:58 -070059static int deprecated_sysctl_warning(struct __sysctl_args *args);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#if defined(CONFIG_SYSCTL)
62
63/* External variables not in a header file. */
64extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070065extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int sysctl_overcommit_memory;
67extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070068extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070069extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070072extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int pid_max;
75extern int min_free_kbytes;
76extern int printk_ratelimit_jiffies;
77extern int printk_ratelimit_burst;
78extern 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070086/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080087#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070088static int one = 1;
Bron Gondwana195cf452008-02-04 22:29:20 -080089#endif
90
91#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int sixty = 60;
93#endif
94
95#ifdef CONFIG_MMU
96static int two = 2;
97#endif
98
99static int zero;
100static int one_hundred = 100;
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
103static int maxolduid = 65535;
104static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800105static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static int ngroups_max = NGROUPS_MAX;
108
109#ifdef CONFIG_KMOD
110extern char modprobe_path[];
111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#ifdef CONFIG_CHR_DEV_SG
113extern int sg_big_buff;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116#ifdef __sparc__
117extern char reboot_command [];
118extern int stop_a_enabled;
119extern int scons_pwroff;
120#endif
121
122#ifdef __hppa__
123extern int pwrsw_enabled;
124extern int unaligned_enabled;
125#endif
126
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800127#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef CONFIG_MATHEMU
129extern int sysctl_ieee_emulation_warnings;
130#endif
131extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700132extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#endif
134
135extern int sysctl_hz_timer;
136
137#ifdef CONFIG_BSD_PROCESS_ACCT
138extern int acct_parm[];
139#endif
140
Jes Sorensend2b176e2006-02-28 09:42:23 -0800141#ifdef CONFIG_IA64
142extern int no_unaligned_warning;
143#endif
144
Ingo Molnar23f78d42006-06-27 02:54:53 -0700145#ifdef CONFIG_RT_MUTEXES
146extern int max_lock_depth;
147#endif
148
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700149#ifdef CONFIG_SYSCTL_SYSCALL
150static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700151 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700152#endif
153
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800154
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700155#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700157 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800159 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700160#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700161
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700162static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100163static struct ctl_table_root sysctl_table_root;
164static struct ctl_table_header root_table_header = {
165 .ctl_table = root_table,
166 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
167 .root = &sysctl_table_root,
168};
169static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
171 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700174static struct ctl_table kern_table[];
175static struct ctl_table vm_table[];
176static struct ctl_table fs_table[];
177static struct ctl_table debug_table[];
178static struct ctl_table dev_table[];
179extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700180#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400182#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
185int sysctl_legacy_va_layout;
186#endif
187
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700188extern int prove_locking;
189extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/* The default sysctl tables: */
192
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700193static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 {
195 .ctl_name = CTL_KERN,
196 .procname = "kernel",
197 .mode = 0555,
198 .child = kern_table,
199 },
200 {
201 .ctl_name = CTL_VM,
202 .procname = "vm",
203 .mode = 0555,
204 .child = vm_table,
205 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .ctl_name = CTL_FS,
208 .procname = "fs",
209 .mode = 0555,
210 .child = fs_table,
211 },
212 {
213 .ctl_name = CTL_DEBUG,
214 .procname = "debug",
215 .mode = 0555,
216 .child = debug_table,
217 },
218 {
219 .ctl_name = CTL_DEV,
220 .procname = "dev",
221 .mode = 0555,
222 .child = dev_table,
223 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700224/*
225 * NOTE: do not add new entries to this table unless you have read
226 * Documentation/sysctl/ctl_unnumbered.txt
227 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 { .ctl_name = 0 }
229};
230
Ingo Molnar77e54a12007-07-09 18:52:00 +0200231#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100232static int min_sched_granularity_ns = 100000; /* 100 usecs */
233static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
234static int min_wakeup_granularity_ns; /* 0 usecs */
235static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#endif
237
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700238static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239#ifdef CONFIG_SCHED_DEBUG
240 {
241 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .procname = "sched_min_granularity_ns",
243 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244 .maxlen = sizeof(unsigned int),
245 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100246 .proc_handler = &sched_nr_latency_handler,
247 .strategy = &sysctl_intvec,
248 .extra1 = &min_sched_granularity_ns,
249 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200250 },
251 {
252 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200253 .procname = "sched_latency_ns",
254 .data = &sysctl_sched_latency,
255 .maxlen = sizeof(unsigned int),
256 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100257 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200258 .strategy = &sysctl_intvec,
259 .extra1 = &min_sched_granularity_ns,
260 .extra2 = &max_sched_granularity_ns,
261 },
262 {
263 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264 .procname = "sched_wakeup_granularity_ns",
265 .data = &sysctl_sched_wakeup_granularity,
266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
268 .proc_handler = &proc_dointvec_minmax,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_wakeup_granularity_ns,
271 .extra2 = &max_wakeup_granularity_ns,
272 },
273 {
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_batch_wakeup_granularity_ns",
276 .data = &sysctl_sched_batch_wakeup_granularity,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = &proc_dointvec_minmax,
280 .strategy = &sysctl_intvec,
281 .extra1 = &min_wakeup_granularity_ns,
282 .extra2 = &max_wakeup_granularity_ns,
283 },
284 {
285 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec,
291 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200292 {
293 .ctl_name = CTL_UNNUMBERED,
294 .procname = "sched_features",
295 .data = &sysctl_sched_features,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = &proc_dointvec,
299 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200300 {
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_migration_cost",
303 .data = &sysctl_sched_migration_cost,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100308 {
309 .ctl_name = CTL_UNNUMBERED,
310 .procname = "sched_nr_migrate",
311 .data = &sysctl_sched_nr_migrate,
312 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100313 .mode = 0644,
314 .proc_handler = &proc_dointvec,
315 },
316 {
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_rt_period_ms",
319 .data = &sysctl_sched_rt_period,
320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
323 },
324 {
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_rt_ratio",
327 .data = &sysctl_sched_rt_ratio,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100330 .proc_handler = &proc_dointvec,
331 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100332#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
333 {
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "sched_min_bal_int_shares",
336 .data = &sysctl_sched_min_bal_int_shares,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "sched_max_bal_int_shares",
344 .data = &sysctl_sched_max_bal_int_shares,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
348 },
349#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200350#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200351 {
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "sched_compat_yield",
354 .data = &sysctl_sched_compat_yield,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
358 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700359#ifdef CONFIG_PROVE_LOCKING
360 {
361 .ctl_name = CTL_UNNUMBERED,
362 .procname = "prove_locking",
363 .data = &prove_locking,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = &proc_dointvec,
367 },
368#endif
369#ifdef CONFIG_LOCK_STAT
370 {
371 .ctl_name = CTL_UNNUMBERED,
372 .procname = "lock_stat",
373 .data = &lock_stat,
374 .maxlen = sizeof(int),
375 .mode = 0644,
376 .proc_handler = &proc_dointvec,
377 },
378#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200379 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 .ctl_name = KERN_PANIC,
381 .procname = "panic",
382 .data = &panic_timeout,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387 {
388 .ctl_name = KERN_CORE_USES_PID,
389 .procname = "core_uses_pid",
390 .data = &core_uses_pid,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
395 {
396 .ctl_name = KERN_CORE_PATTERN,
397 .procname = "core_pattern",
398 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700399 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .mode = 0644,
401 .proc_handler = &proc_dostring,
402 .strategy = &sysctl_string,
403 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "tainted",
407 .data = &tainted,
408 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800409 .mode = 0644,
410 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800412#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100413#ifdef CONFIG_LATENCYTOP
414 {
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700422#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .procname = "cap-bound",
425 .data = &cap_bset,
426 .maxlen = sizeof(kernel_cap_t),
427 .mode = 0600,
428 .proc_handler = &proc_dointvec_bset,
429 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700430#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#ifdef CONFIG_BLK_DEV_INITRD
432 {
433 .ctl_name = KERN_REALROOTDEV,
434 .procname = "real-root-dev",
435 .data = &real_root_dev,
436 .maxlen = sizeof(int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
440#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700441 {
442 .ctl_name = CTL_UNNUMBERED,
443 .procname = "print-fatal-signals",
444 .data = &print_fatal_signals,
445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
448 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#ifdef __sparc__
450 {
451 .ctl_name = KERN_SPARC_REBOOT,
452 .procname = "reboot-cmd",
453 .data = reboot_command,
454 .maxlen = 256,
455 .mode = 0644,
456 .proc_handler = &proc_dostring,
457 .strategy = &sysctl_string,
458 },
459 {
460 .ctl_name = KERN_SPARC_STOP_A,
461 .procname = "stop-a",
462 .data = &stop_a_enabled,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
466 },
467 {
468 .ctl_name = KERN_SPARC_SCONS_PWROFF,
469 .procname = "scons-poweroff",
470 .data = &scons_pwroff,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
474 },
475#endif
476#ifdef __hppa__
477 {
478 .ctl_name = KERN_HPPA_PWRSW,
479 .procname = "soft-power",
480 .data = &pwrsw_enabled,
481 .maxlen = sizeof (int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec,
484 },
485 {
486 .ctl_name = KERN_HPPA_UNALIGNED,
487 .procname = "unaligned-trap",
488 .data = &unaligned_enabled,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
492 },
493#endif
494 {
495 .ctl_name = KERN_CTLALTDEL,
496 .procname = "ctrl-alt-del",
497 .data = &C_A_D,
498 .maxlen = sizeof(int),
499 .mode = 0644,
500 .proc_handler = &proc_dointvec,
501 },
502 {
503 .ctl_name = KERN_PRINTK,
504 .procname = "printk",
505 .data = &console_loglevel,
506 .maxlen = 4*sizeof(int),
507 .mode = 0644,
508 .proc_handler = &proc_dointvec,
509 },
510#ifdef CONFIG_KMOD
511 {
512 .ctl_name = KERN_MODPROBE,
513 .procname = "modprobe",
514 .data = &modprobe_path,
515 .maxlen = KMOD_PATH_LEN,
516 .mode = 0644,
517 .proc_handler = &proc_dostring,
518 .strategy = &sysctl_string,
519 },
520#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700521#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 {
523 .ctl_name = KERN_HOTPLUG,
524 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100525 .data = &uevent_helper,
526 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .mode = 0644,
528 .proc_handler = &proc_dostring,
529 .strategy = &sysctl_string,
530 },
531#endif
532#ifdef CONFIG_CHR_DEV_SG
533 {
534 .ctl_name = KERN_SG_BIG_BUFF,
535 .procname = "sg-big-buff",
536 .data = &sg_big_buff,
537 .maxlen = sizeof (int),
538 .mode = 0444,
539 .proc_handler = &proc_dointvec,
540 },
541#endif
542#ifdef CONFIG_BSD_PROCESS_ACCT
543 {
544 .ctl_name = KERN_ACCT,
545 .procname = "acct",
546 .data = &acct_parm,
547 .maxlen = 3*sizeof(int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec,
550 },
551#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#ifdef CONFIG_MAGIC_SYSRQ
553 {
554 .ctl_name = KERN_SYSRQ,
555 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800556 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .maxlen = sizeof (int),
558 .mode = 0644,
559 .proc_handler = &proc_dointvec,
560 },
561#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700562#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700565 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .maxlen = sizeof (int),
567 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700568 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700570#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 {
572 .ctl_name = KERN_MAX_THREADS,
573 .procname = "threads-max",
574 .data = &max_threads,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579 {
580 .ctl_name = KERN_RANDOM,
581 .procname = "random",
582 .mode = 0555,
583 .child = random_table,
584 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 {
586 .ctl_name = KERN_OVERFLOWUID,
587 .procname = "overflowuid",
588 .data = &overflowuid,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = &proc_dointvec_minmax,
592 .strategy = &sysctl_intvec,
593 .extra1 = &minolduid,
594 .extra2 = &maxolduid,
595 },
596 {
597 .ctl_name = KERN_OVERFLOWGID,
598 .procname = "overflowgid",
599 .data = &overflowgid,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec_minmax,
603 .strategy = &sysctl_intvec,
604 .extra1 = &minolduid,
605 .extra2 = &maxolduid,
606 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800607#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#ifdef CONFIG_MATHEMU
609 {
610 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
611 .procname = "ieee_emulation_warnings",
612 .data = &sysctl_ieee_emulation_warnings,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = &proc_dointvec,
616 },
617#endif
618#ifdef CONFIG_NO_IDLE_HZ
619 {
620 .ctl_name = KERN_HZ_TIMER,
621 .procname = "hz_timer",
622 .data = &sysctl_hz_timer,
623 .maxlen = sizeof(int),
624 .mode = 0644,
625 .proc_handler = &proc_dointvec,
626 },
627#endif
628 {
629 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
630 .procname = "userprocess_debug",
631 .data = &sysctl_userprocess_debug,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 .proc_handler = &proc_dointvec,
635 },
636#endif
637 {
638 .ctl_name = KERN_PIDMAX,
639 .procname = "pid_max",
640 .data = &pid_max,
641 .maxlen = sizeof (int),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec_minmax,
644 .strategy = sysctl_intvec,
645 .extra1 = &pid_max_min,
646 .extra2 = &pid_max_max,
647 },
648 {
649 .ctl_name = KERN_PANIC_ON_OOPS,
650 .procname = "panic_on_oops",
651 .data = &panic_on_oops,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec,
655 },
656 {
657 .ctl_name = KERN_PRINTK_RATELIMIT,
658 .procname = "printk_ratelimit",
659 .data = &printk_ratelimit_jiffies,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec_jiffies,
663 .strategy = &sysctl_jiffies,
664 },
665 {
666 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
667 .procname = "printk_ratelimit_burst",
668 .data = &printk_ratelimit_burst,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
673 {
674 .ctl_name = KERN_NGROUPS_MAX,
675 .procname = "ngroups_max",
676 .data = &ngroups_max,
677 .maxlen = sizeof (int),
678 .mode = 0444,
679 .proc_handler = &proc_dointvec,
680 },
681#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
682 {
683 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
684 .procname = "unknown_nmi_panic",
685 .data = &unknown_nmi_panic,
686 .maxlen = sizeof (int),
687 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200688 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 },
Don Zickus407984f2006-09-26 10:52:27 +0200690 {
Don Zickus407984f2006-09-26 10:52:27 +0200691 .procname = "nmi_watchdog",
692 .data = &nmi_watchdog_enabled,
693 .maxlen = sizeof (int),
694 .mode = 0644,
695 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
697#endif
698#if defined(CONFIG_X86)
699 {
Don Zickus8da5add2006-09-26 10:52:27 +0200700 .ctl_name = KERN_PANIC_ON_NMI,
701 .procname = "panic_on_unrecovered_nmi",
702 .data = &panic_on_unrecovered_nmi,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = &proc_dointvec,
706 },
707 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 .ctl_name = KERN_BOOTLOADER_TYPE,
709 .procname = "bootloader_type",
710 .data = &bootloader_type,
711 .maxlen = sizeof (int),
712 .mode = 0444,
713 .proc_handler = &proc_dointvec,
714 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100715 {
716 .ctl_name = CTL_UNNUMBERED,
717 .procname = "kstack_depth_to_print",
718 .data = &kstack_depth_to_print,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
722 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100723 {
724 .ctl_name = CTL_UNNUMBERED,
725 .procname = "io_delay_type",
726 .data = &io_delay_type,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
730 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800732#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 {
734 .ctl_name = KERN_RANDOMIZE,
735 .procname = "randomize_va_space",
736 .data = &randomize_va_space,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec,
740 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800741#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800742#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700743 {
744 .ctl_name = KERN_SPIN_RETRY,
745 .procname = "spin_retry",
746 .data = &spin_retry,
747 .maxlen = sizeof (int),
748 .mode = 0644,
749 .proc_handler = &proc_dointvec,
750 },
751#endif
Len Brown673d5b42007-07-28 03:33:16 -0400752#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800753 {
Pavel Machekc255d842006-02-20 18:27:58 -0800754 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700755 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800756 .maxlen = sizeof (unsigned long),
757 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800758 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800759 },
760#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800761#ifdef CONFIG_IA64
762 {
763 .ctl_name = KERN_IA64_UNALIGNED,
764 .procname = "ignore-unaligned-usertrap",
765 .data = &no_unaligned_warning,
766 .maxlen = sizeof (int),
767 .mode = 0644,
768 .proc_handler = &proc_dointvec,
769 },
770#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700771#ifdef CONFIG_DETECT_SOFTLOCKUP
772 {
773 .ctl_name = CTL_UNNUMBERED,
774 .procname = "softlockup_thresh",
775 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100776 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700777 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100778 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700779 .strategy = &sysctl_intvec,
780 .extra1 = &one,
781 .extra2 = &sixty,
782 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100783 {
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "hung_task_check_count",
786 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100787 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100788 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100789 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100790 .strategy = &sysctl_intvec,
791 },
792 {
793 .ctl_name = CTL_UNNUMBERED,
794 .procname = "hung_task_timeout_secs",
795 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100796 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100797 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100798 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100799 .strategy = &sysctl_intvec,
800 },
801 {
802 .ctl_name = CTL_UNNUMBERED,
803 .procname = "hung_task_warnings",
804 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100805 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100806 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100807 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100808 .strategy = &sysctl_intvec,
809 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700810#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200811#ifdef CONFIG_COMPAT
812 {
813 .ctl_name = KERN_COMPAT_LOG,
814 .procname = "compat-log",
815 .data = &compat_log,
816 .maxlen = sizeof (int),
817 .mode = 0644,
818 .proc_handler = &proc_dointvec,
819 },
820#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700821#ifdef CONFIG_RT_MUTEXES
822 {
823 .ctl_name = KERN_MAX_LOCK_DEPTH,
824 .procname = "max_lock_depth",
825 .data = &max_lock_depth,
826 .maxlen = sizeof(int),
827 .mode = 0644,
828 .proc_handler = &proc_dointvec,
829 },
830#endif
Kees Cook5096add2007-05-08 00:26:04 -0700831#ifdef CONFIG_PROC_FS
832 {
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "maps_protect",
835 .data = &maps_protect,
836 .maxlen = sizeof(int),
837 .mode = 0644,
838 .proc_handler = &proc_dointvec,
839 },
840#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700841 {
842 .ctl_name = CTL_UNNUMBERED,
843 .procname = "poweroff_cmd",
844 .data = &poweroff_cmd,
845 .maxlen = POWEROFF_CMD_PATH_LEN,
846 .mode = 0644,
847 .proc_handler = &proc_dostring,
848 .strategy = &sysctl_string,
849 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700850/*
851 * NOTE: do not add new entries to this table unless you have read
852 * Documentation/sysctl/ctl_unnumbered.txt
853 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 { .ctl_name = 0 }
855};
856
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700857static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 {
859 .ctl_name = VM_OVERCOMMIT_MEMORY,
860 .procname = "overcommit_memory",
861 .data = &sysctl_overcommit_memory,
862 .maxlen = sizeof(sysctl_overcommit_memory),
863 .mode = 0644,
864 .proc_handler = &proc_dointvec,
865 },
866 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700867 .ctl_name = VM_PANIC_ON_OOM,
868 .procname = "panic_on_oom",
869 .data = &sysctl_panic_on_oom,
870 .maxlen = sizeof(sysctl_panic_on_oom),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
873 },
874 {
David Rientjesfe071d72007-10-16 23:25:56 -0700875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "oom_kill_allocating_task",
877 .data = &sysctl_oom_kill_allocating_task,
878 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
881 },
882 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 .ctl_name = VM_OVERCOMMIT_RATIO,
884 .procname = "overcommit_ratio",
885 .data = &sysctl_overcommit_ratio,
886 .maxlen = sizeof(sysctl_overcommit_ratio),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
889 },
890 {
891 .ctl_name = VM_PAGE_CLUSTER,
892 .procname = "page-cluster",
893 .data = &page_cluster,
894 .maxlen = sizeof(int),
895 .mode = 0644,
896 .proc_handler = &proc_dointvec,
897 },
898 {
899 .ctl_name = VM_DIRTY_BACKGROUND,
900 .procname = "dirty_background_ratio",
901 .data = &dirty_background_ratio,
902 .maxlen = sizeof(dirty_background_ratio),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec_minmax,
905 .strategy = &sysctl_intvec,
906 .extra1 = &zero,
907 .extra2 = &one_hundred,
908 },
909 {
910 .ctl_name = VM_DIRTY_RATIO,
911 .procname = "dirty_ratio",
912 .data = &vm_dirty_ratio,
913 .maxlen = sizeof(vm_dirty_ratio),
914 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700915 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 .strategy = &sysctl_intvec,
917 .extra1 = &zero,
918 .extra2 = &one_hundred,
919 },
920 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800922 .data = &dirty_writeback_interval,
923 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 .mode = 0644,
925 .proc_handler = &dirty_writeback_centisecs_handler,
926 },
927 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800929 .data = &dirty_expire_interval,
930 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800932 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 },
934 {
935 .ctl_name = VM_NR_PDFLUSH_THREADS,
936 .procname = "nr_pdflush_threads",
937 .data = &nr_pdflush_threads,
938 .maxlen = sizeof nr_pdflush_threads,
939 .mode = 0444 /* read-only*/,
940 .proc_handler = &proc_dointvec,
941 },
942 {
943 .ctl_name = VM_SWAPPINESS,
944 .procname = "swappiness",
945 .data = &vm_swappiness,
946 .maxlen = sizeof(vm_swappiness),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec_minmax,
949 .strategy = &sysctl_intvec,
950 .extra1 = &zero,
951 .extra2 = &one_hundred,
952 },
953#ifdef CONFIG_HUGETLB_PAGE
954 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 .procname = "nr_hugepages",
956 .data = &max_huge_pages,
957 .maxlen = sizeof(unsigned long),
958 .mode = 0644,
959 .proc_handler = &hugetlb_sysctl_handler,
960 .extra1 = (void *)&hugetlb_zero,
961 .extra2 = (void *)&hugetlb_infinity,
962 },
963 {
964 .ctl_name = VM_HUGETLB_GROUP,
965 .procname = "hugetlb_shm_group",
966 .data = &sysctl_hugetlb_shm_group,
967 .maxlen = sizeof(gid_t),
968 .mode = 0644,
969 .proc_handler = &proc_dointvec,
970 },
Mel Gorman396faf02007-07-17 04:03:13 -0700971 {
972 .ctl_name = CTL_UNNUMBERED,
973 .procname = "hugepages_treat_as_movable",
974 .data = &hugepages_treat_as_movable,
975 .maxlen = sizeof(int),
976 .mode = 0644,
977 .proc_handler = &hugetlb_treat_movable_handler,
978 },
Adam Litke54f9f802007-10-16 01:26:20 -0700979 {
980 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800981 .procname = "nr_overcommit_hugepages",
982 .data = &nr_overcommit_huge_pages,
983 .maxlen = sizeof(nr_overcommit_huge_pages),
984 .mode = 0644,
985 .proc_handler = &proc_doulongvec_minmax,
986 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987#endif
988 {
989 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
990 .procname = "lowmem_reserve_ratio",
991 .data = &sysctl_lowmem_reserve_ratio,
992 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
993 .mode = 0644,
994 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
995 .strategy = &sysctl_intvec,
996 },
997 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800998 .ctl_name = VM_DROP_PAGECACHE,
999 .procname = "drop_caches",
1000 .data = &sysctl_drop_caches,
1001 .maxlen = sizeof(int),
1002 .mode = 0644,
1003 .proc_handler = drop_caches_sysctl_handler,
1004 .strategy = &sysctl_intvec,
1005 },
1006 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 .ctl_name = VM_MIN_FREE_KBYTES,
1008 .procname = "min_free_kbytes",
1009 .data = &min_free_kbytes,
1010 .maxlen = sizeof(min_free_kbytes),
1011 .mode = 0644,
1012 .proc_handler = &min_free_kbytes_sysctl_handler,
1013 .strategy = &sysctl_intvec,
1014 .extra1 = &zero,
1015 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001016 {
1017 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1018 .procname = "percpu_pagelist_fraction",
1019 .data = &percpu_pagelist_fraction,
1020 .maxlen = sizeof(percpu_pagelist_fraction),
1021 .mode = 0644,
1022 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1023 .strategy = &sysctl_intvec,
1024 .extra1 = &min_percpu_pagelist_fract,
1025 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026#ifdef CONFIG_MMU
1027 {
1028 .ctl_name = VM_MAX_MAP_COUNT,
1029 .procname = "max_map_count",
1030 .data = &sysctl_max_map_count,
1031 .maxlen = sizeof(sysctl_max_map_count),
1032 .mode = 0644,
1033 .proc_handler = &proc_dointvec
1034 },
1035#endif
1036 {
1037 .ctl_name = VM_LAPTOP_MODE,
1038 .procname = "laptop_mode",
1039 .data = &laptop_mode,
1040 .maxlen = sizeof(laptop_mode),
1041 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001042 .proc_handler = &proc_dointvec_jiffies,
1043 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 },
1045 {
1046 .ctl_name = VM_BLOCK_DUMP,
1047 .procname = "block_dump",
1048 .data = &block_dump,
1049 .maxlen = sizeof(block_dump),
1050 .mode = 0644,
1051 .proc_handler = &proc_dointvec,
1052 .strategy = &sysctl_intvec,
1053 .extra1 = &zero,
1054 },
1055 {
1056 .ctl_name = VM_VFS_CACHE_PRESSURE,
1057 .procname = "vfs_cache_pressure",
1058 .data = &sysctl_vfs_cache_pressure,
1059 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1060 .mode = 0644,
1061 .proc_handler = &proc_dointvec,
1062 .strategy = &sysctl_intvec,
1063 .extra1 = &zero,
1064 },
1065#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1066 {
1067 .ctl_name = VM_LEGACY_VA_LAYOUT,
1068 .procname = "legacy_va_layout",
1069 .data = &sysctl_legacy_va_layout,
1070 .maxlen = sizeof(sysctl_legacy_va_layout),
1071 .mode = 0644,
1072 .proc_handler = &proc_dointvec,
1073 .strategy = &sysctl_intvec,
1074 .extra1 = &zero,
1075 },
1076#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001077#ifdef CONFIG_NUMA
1078 {
1079 .ctl_name = VM_ZONE_RECLAIM_MODE,
1080 .procname = "zone_reclaim_mode",
1081 .data = &zone_reclaim_mode,
1082 .maxlen = sizeof(zone_reclaim_mode),
1083 .mode = 0644,
1084 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001085 .strategy = &sysctl_intvec,
1086 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001087 },
Christoph Lameter96146342006-07-03 00:24:13 -07001088 {
1089 .ctl_name = VM_MIN_UNMAPPED,
1090 .procname = "min_unmapped_ratio",
1091 .data = &sysctl_min_unmapped_ratio,
1092 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1093 .mode = 0644,
1094 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1095 .strategy = &sysctl_intvec,
1096 .extra1 = &zero,
1097 .extra2 = &one_hundred,
1098 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001099 {
1100 .ctl_name = VM_MIN_SLAB,
1101 .procname = "min_slab_ratio",
1102 .data = &sysctl_min_slab_ratio,
1103 .maxlen = sizeof(sysctl_min_slab_ratio),
1104 .mode = 0644,
1105 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1106 .strategy = &sysctl_intvec,
1107 .extra1 = &zero,
1108 .extra2 = &one_hundred,
1109 },
Christoph Lameter17436602006-01-18 17:42:32 -08001110#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001111#ifdef CONFIG_SMP
1112 {
1113 .ctl_name = CTL_UNNUMBERED,
1114 .procname = "stat_interval",
1115 .data = &sysctl_stat_interval,
1116 .maxlen = sizeof(sysctl_stat_interval),
1117 .mode = 0644,
1118 .proc_handler = &proc_dointvec_jiffies,
1119 .strategy = &sysctl_jiffies,
1120 },
1121#endif
Eric Parised032182007-06-28 15:55:21 -04001122#ifdef CONFIG_SECURITY
1123 {
1124 .ctl_name = CTL_UNNUMBERED,
1125 .procname = "mmap_min_addr",
1126 .data = &mmap_min_addr,
1127 .maxlen = sizeof(unsigned long),
1128 .mode = 0644,
1129 .proc_handler = &proc_doulongvec_minmax,
1130 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001131#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001132#ifdef CONFIG_NUMA
1133 {
1134 .ctl_name = CTL_UNNUMBERED,
1135 .procname = "numa_zonelist_order",
1136 .data = &numa_zonelist_order,
1137 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1138 .mode = 0644,
1139 .proc_handler = &numa_zonelist_order_handler,
1140 .strategy = &sysctl_string,
1141 },
1142#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001143#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001144 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001145 {
1146 .ctl_name = VM_VDSO_ENABLED,
1147 .procname = "vdso_enabled",
1148 .data = &vdso_enabled,
1149 .maxlen = sizeof(vdso_enabled),
1150 .mode = 0644,
1151 .proc_handler = &proc_dointvec,
1152 .strategy = &sysctl_intvec,
1153 .extra1 = &zero,
1154 },
1155#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001156#ifdef CONFIG_HIGHMEM
1157 {
1158 .ctl_name = CTL_UNNUMBERED,
1159 .procname = "highmem_is_dirtyable",
1160 .data = &vm_highmem_is_dirtyable,
1161 .maxlen = sizeof(vm_highmem_is_dirtyable),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec_minmax,
1164 .strategy = &sysctl_intvec,
1165 .extra1 = &zero,
1166 .extra2 = &one,
1167 },
1168#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001169/*
1170 * NOTE: do not add new entries to this table unless you have read
1171 * Documentation/sysctl/ctl_unnumbered.txt
1172 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 { .ctl_name = 0 }
1174};
1175
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001176#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001177static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001178 { .ctl_name = 0 }
1179};
1180#endif
1181
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001182static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 {
1184 .ctl_name = FS_NRINODE,
1185 .procname = "inode-nr",
1186 .data = &inodes_stat,
1187 .maxlen = 2*sizeof(int),
1188 .mode = 0444,
1189 .proc_handler = &proc_dointvec,
1190 },
1191 {
1192 .ctl_name = FS_STATINODE,
1193 .procname = "inode-state",
1194 .data = &inodes_stat,
1195 .maxlen = 7*sizeof(int),
1196 .mode = 0444,
1197 .proc_handler = &proc_dointvec,
1198 },
1199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .procname = "file-nr",
1201 .data = &files_stat,
1202 .maxlen = 3*sizeof(int),
1203 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001204 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 },
1206 {
1207 .ctl_name = FS_MAXFILE,
1208 .procname = "file-max",
1209 .data = &files_stat.max_files,
1210 .maxlen = sizeof(int),
1211 .mode = 0644,
1212 .proc_handler = &proc_dointvec,
1213 },
1214 {
1215 .ctl_name = FS_DENTRY,
1216 .procname = "dentry-state",
1217 .data = &dentry_stat,
1218 .maxlen = 6*sizeof(int),
1219 .mode = 0444,
1220 .proc_handler = &proc_dointvec,
1221 },
1222 {
1223 .ctl_name = FS_OVERFLOWUID,
1224 .procname = "overflowuid",
1225 .data = &fs_overflowuid,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = &proc_dointvec_minmax,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &minolduid,
1231 .extra2 = &maxolduid,
1232 },
1233 {
1234 .ctl_name = FS_OVERFLOWGID,
1235 .procname = "overflowgid",
1236 .data = &fs_overflowgid,
1237 .maxlen = sizeof(int),
1238 .mode = 0644,
1239 .proc_handler = &proc_dointvec_minmax,
1240 .strategy = &sysctl_intvec,
1241 .extra1 = &minolduid,
1242 .extra2 = &maxolduid,
1243 },
1244 {
1245 .ctl_name = FS_LEASES,
1246 .procname = "leases-enable",
1247 .data = &leases_enable,
1248 .maxlen = sizeof(int),
1249 .mode = 0644,
1250 .proc_handler = &proc_dointvec,
1251 },
1252#ifdef CONFIG_DNOTIFY
1253 {
1254 .ctl_name = FS_DIR_NOTIFY,
1255 .procname = "dir-notify-enable",
1256 .data = &dir_notify_enable,
1257 .maxlen = sizeof(int),
1258 .mode = 0644,
1259 .proc_handler = &proc_dointvec,
1260 },
1261#endif
1262#ifdef CONFIG_MMU
1263 {
1264 .ctl_name = FS_LEASE_TIME,
1265 .procname = "lease-break-time",
1266 .data = &lease_break_time,
1267 .maxlen = sizeof(int),
1268 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001269 .proc_handler = &proc_dointvec_minmax,
1270 .strategy = &sysctl_intvec,
1271 .extra1 = &zero,
1272 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 },
1274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 .procname = "aio-nr",
1276 .data = &aio_nr,
1277 .maxlen = sizeof(aio_nr),
1278 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001279 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 },
1281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 .procname = "aio-max-nr",
1283 .data = &aio_max_nr,
1284 .maxlen = sizeof(aio_max_nr),
1285 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001286 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001288#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001289 {
1290 .ctl_name = FS_INOTIFY,
1291 .procname = "inotify",
1292 .mode = 0555,
1293 .child = inotify_table,
1294 },
1295#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001297 {
1298 .ctl_name = KERN_SETUID_DUMPABLE,
1299 .procname = "suid_dumpable",
1300 .data = &suid_dumpable,
1301 .maxlen = sizeof(int),
1302 .mode = 0644,
1303 .proc_handler = &proc_dointvec,
1304 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001305#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1306 {
1307 .ctl_name = CTL_UNNUMBERED,
1308 .procname = "binfmt_misc",
1309 .mode = 0555,
1310 .child = binfmt_misc_table,
1311 },
1312#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001313/*
1314 * NOTE: do not add new entries to this table unless you have read
1315 * Documentation/sysctl/ctl_unnumbered.txt
1316 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 { .ctl_name = 0 }
1318};
1319
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001320static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001321#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001322 {
1323 .ctl_name = CTL_UNNUMBERED,
1324 .procname = "exception-trace",
1325 .data = &show_unhandled_signals,
1326 .maxlen = sizeof(int),
1327 .mode = 0644,
1328 .proc_handler = proc_dointvec
1329 },
1330#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 { .ctl_name = 0 }
1332};
1333
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001334static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001336};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Al Viro330d57f2005-11-04 10:18:40 +00001338static DEFINE_SPINLOCK(sysctl_lock);
1339
1340/* called under sysctl_lock */
1341static int use_table(struct ctl_table_header *p)
1342{
1343 if (unlikely(p->unregistering))
1344 return 0;
1345 p->used++;
1346 return 1;
1347}
1348
1349/* called under sysctl_lock */
1350static void unuse_table(struct ctl_table_header *p)
1351{
1352 if (!--p->used)
1353 if (unlikely(p->unregistering))
1354 complete(p->unregistering);
1355}
1356
1357/* called under sysctl_lock, will reacquire if has to wait */
1358static void start_unregistering(struct ctl_table_header *p)
1359{
1360 /*
1361 * if p->used is 0, nobody will ever touch that entry again;
1362 * we'll eliminate all paths to it before dropping sysctl_lock
1363 */
1364 if (unlikely(p->used)) {
1365 struct completion wait;
1366 init_completion(&wait);
1367 p->unregistering = &wait;
1368 spin_unlock(&sysctl_lock);
1369 wait_for_completion(&wait);
1370 spin_lock(&sysctl_lock);
1371 }
1372 /*
1373 * do not remove from the list until nobody holds it; walking the
1374 * list in do_sysctl() relies on that.
1375 */
1376 list_del_init(&p->ctl_entry);
1377}
1378
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001379void sysctl_head_finish(struct ctl_table_header *head)
1380{
1381 if (!head)
1382 return;
1383 spin_lock(&sysctl_lock);
1384 unuse_table(head);
1385 spin_unlock(&sysctl_lock);
1386}
1387
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001388static struct list_head *
1389lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001390{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001391 struct list_head *header_list;
1392 header_list = &root->header_list;
1393 if (root->lookup)
1394 header_list = root->lookup(root, namespaces);
1395 return header_list;
1396}
1397
1398struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1399 struct ctl_table_header *prev)
1400{
1401 struct ctl_table_root *root;
1402 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001403 struct ctl_table_header *head;
1404 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001405
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001406 spin_lock(&sysctl_lock);
1407 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001408 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001409 tmp = &prev->ctl_entry;
1410 unuse_table(prev);
1411 goto next;
1412 }
1413 tmp = &root_table_header.ctl_entry;
1414 for (;;) {
1415 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1416
1417 if (!use_table(head))
1418 goto next;
1419 spin_unlock(&sysctl_lock);
1420 return head;
1421 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001422 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001423 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001424 header_list = lookup_header_list(root, namespaces);
1425 if (tmp != header_list)
1426 continue;
1427
1428 do {
1429 root = list_entry(root->root_list.next,
1430 struct ctl_table_root, root_list);
1431 if (root == &sysctl_table_root)
1432 goto out;
1433 header_list = lookup_header_list(root, namespaces);
1434 } while (list_empty(header_list));
1435 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001436 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001437out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001438 spin_unlock(&sysctl_lock);
1439 return NULL;
1440}
1441
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001442struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1443{
1444 return __sysctl_head_next(current->nsproxy, prev);
1445}
1446
1447void register_sysctl_root(struct ctl_table_root *root)
1448{
1449 spin_lock(&sysctl_lock);
1450 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1451 spin_unlock(&sysctl_lock);
1452}
1453
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001454#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1456 void __user *newval, size_t newlen)
1457{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001458 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001459 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1462 return -ENOTDIR;
1463 if (oldval) {
1464 int old_len;
1465 if (!oldlenp || get_user(old_len, oldlenp))
1466 return -EFAULT;
1467 }
Al Viro330d57f2005-11-04 10:18:40 +00001468
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001469 for (head = sysctl_head_next(NULL); head;
1470 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001471 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001472 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001473 if (error != -ENOTDIR) {
1474 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001475 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001476 }
1477 }
Al Viro330d57f2005-11-04 10:18:40 +00001478 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
1481asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1482{
1483 struct __sysctl_args tmp;
1484 int error;
1485
1486 if (copy_from_user(&tmp, args, sizeof(tmp)))
1487 return -EFAULT;
1488
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001489 error = deprecated_sysctl_warning(&tmp);
1490 if (error)
1491 goto out;
1492
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 lock_kernel();
1494 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1495 tmp.newval, tmp.newlen);
1496 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001497out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 return error;
1499}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001500#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
1502/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001503 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 * some sysctl variables are readonly even to root.
1505 */
1506
1507static int test_perm(int mode, int op)
1508{
1509 if (!current->euid)
1510 mode >>= 6;
1511 else if (in_egroup_p(0))
1512 mode >>= 3;
1513 if ((mode & op & 0007) == op)
1514 return 0;
1515 return -EACCES;
1516}
1517
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001518int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
1520 int error;
1521 error = security_sysctl(table, op);
1522 if (error)
1523 return error;
1524 return test_perm(table->mode, op);
1525}
1526
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001527#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528static int parse_table(int __user *name, int nlen,
1529 void __user *oldval, size_t __user *oldlenp,
1530 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001531 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
1533 int n;
1534repeat:
1535 if (!nlen)
1536 return -ENOTDIR;
1537 if (get_user(n, name))
1538 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001539 for ( ; table->ctl_name || table->procname; table++) {
1540 if (!table->ctl_name)
1541 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001542 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 int error;
1544 if (table->child) {
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001545 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 name++;
1548 nlen--;
1549 table = table->child;
1550 goto repeat;
1551 }
1552 error = do_sysctl_strategy(table, name, nlen,
1553 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001554 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 return error;
1556 }
1557 }
1558 return -ENOTDIR;
1559}
1560
1561/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001562int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 int __user *name, int nlen,
1564 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001565 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566{
1567 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 if (oldval)
1570 op |= 004;
1571 if (newval)
1572 op |= 002;
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001573 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 return -EPERM;
1575
1576 if (table->strategy) {
1577 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001578 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 if (rc < 0)
1580 return rc;
1581 if (rc > 0)
1582 return 0;
1583 }
1584
1585 /* If there is no strategy routine, or if the strategy returns
1586 * zero, proceed with automatic r/w */
1587 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001588 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1589 newval, newlen);
1590 if (rc < 0)
1591 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 }
1593 return 0;
1594}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001595#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
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{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001608 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001609 sysctl_set_parent(NULL, root_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001610 err = sysctl_check_table(current->nsproxy, root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001611 return 0;
1612}
1613
1614core_initcall(sysctl_init);
1615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001617 * __register_sysctl_paths - register a sysctl hierarchy
1618 * @root: List of sysctl headers to register on
1619 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001620 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 *
1623 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001624 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001626 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 *
1628 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1629 * must be unique within that level of sysctl
1630 *
1631 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1632 * enter a sysctl file
1633 *
1634 * data - a pointer to data for use by proc_handler
1635 *
1636 * maxlen - the maximum size in bytes of the data
1637 *
1638 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1639 *
1640 * child - a pointer to the child sysctl table if this entry is a directory, or
1641 * %NULL.
1642 *
1643 * proc_handler - the text handler routine (described below)
1644 *
1645 * strategy - the strategy routine (described below)
1646 *
1647 * de - for internal use by the sysctl routines
1648 *
1649 * extra1, extra2 - extra pointers usable by the proc handler routines
1650 *
1651 * Leaf nodes in the sysctl tree will be represented by a single file
1652 * under /proc; non-leaf nodes will be represented by directories.
1653 *
1654 * sysctl(2) can automatically manage read and write requests through
1655 * the sysctl table. The data and maxlen fields of the ctl_table
1656 * struct enable minimal validation of the values being written to be
1657 * performed, and the mode field allows minimal authentication.
1658 *
1659 * More sophisticated management can be enabled by the provision of a
1660 * strategy routine with the table entry. This will be called before
1661 * any automatic read or write of the data is performed.
1662 *
1663 * The strategy routine may return
1664 *
1665 * < 0 - Error occurred (error is passed to user process)
1666 *
1667 * 0 - OK - proceed with automatic read or write.
1668 *
1669 * > 0 - OK - read or write has been done by the strategy routine, so
1670 * return immediately.
1671 *
1672 * There must be a proc_handler routine for any terminal nodes
1673 * mirrored under /proc/sys (non-terminals are handled by a built-in
1674 * directory handler). Several default handlers are available to
1675 * cover common cases -
1676 *
1677 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1678 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1679 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1680 *
1681 * It is the handler's job to read the input buffer from user memory
1682 * and process it. The handler should return 0 on success.
1683 *
1684 * This routine returns %NULL on a failure to register, and a pointer
1685 * to the table header on success.
1686 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001687struct ctl_table_header *__register_sysctl_paths(
1688 struct ctl_table_root *root,
1689 struct nsproxy *namespaces,
1690 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001692 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001693 struct ctl_table_header *header;
1694 struct ctl_table *new, **prevp;
1695 unsigned int n, npath;
1696
1697 /* Count the path components */
1698 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1699 ;
1700
1701 /*
1702 * For each path component, allocate a 2-element ctl_table array.
1703 * The first array element will be filled with the sysctl entry
1704 * for this, the second will be the sentinel (ctl_name == 0).
1705 *
1706 * We allocate everything in one go so that we don't have to
1707 * worry about freeing additional memory in unregister_sysctl_table.
1708 */
1709 header = kzalloc(sizeof(struct ctl_table_header) +
1710 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1711 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001713
1714 new = (struct ctl_table *) (header + 1);
1715
1716 /* Now connect the dots */
1717 prevp = &header->ctl_table;
1718 for (n = 0; n < npath; ++n, ++path) {
1719 /* Copy the procname */
1720 new->procname = path->procname;
1721 new->ctl_name = path->ctl_name;
1722 new->mode = 0555;
1723
1724 *prevp = new;
1725 prevp = &new->child;
1726
1727 new += 2;
1728 }
1729 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001730 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001731
1732 INIT_LIST_HEAD(&header->ctl_entry);
1733 header->used = 0;
1734 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001735 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001736 sysctl_set_parent(NULL, header->ctl_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001737 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001738 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001739 return NULL;
1740 }
Al Viro330d57f2005-11-04 10:18:40 +00001741 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001742 header_list = lookup_header_list(root, namespaces);
1743 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001744 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001745
1746 return header;
1747}
1748
1749/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001750 * register_sysctl_table_path - register a sysctl table hierarchy
1751 * @path: The path to the directory the sysctl table is in.
1752 * @table: the top-level table structure
1753 *
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1755 * array. A completely 0 filled entry terminates the table.
1756 *
1757 * See __register_sysctl_paths for more details.
1758 */
1759struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1760 struct ctl_table *table)
1761{
1762 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1763 path, table);
1764}
1765
1766/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001767 * register_sysctl_table - register a sysctl table hierarchy
1768 * @table: the top-level table structure
1769 *
1770 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1771 * array. A completely 0 filled entry terminates the table.
1772 *
1773 * See register_sysctl_paths for more details.
1774 */
1775struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1776{
1777 static const struct ctl_path null_path[] = { {} };
1778
1779 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780}
1781
1782/**
1783 * unregister_sysctl_table - unregister a sysctl table hierarchy
1784 * @header: the header returned from register_sysctl_table
1785 *
1786 * Unregisters the sysctl table and all children. proc entries may not
1787 * actually be removed until they are no longer used by anyone.
1788 */
1789void unregister_sysctl_table(struct ctl_table_header * header)
1790{
Al Viro330d57f2005-11-04 10:18:40 +00001791 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001792
1793 if (header == NULL)
1794 return;
1795
Al Viro330d57f2005-11-04 10:18:40 +00001796 spin_lock(&sysctl_lock);
1797 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001798 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 kfree(header);
1800}
1801
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001802#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001803struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001804{
1805 return NULL;
1806}
1807
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001808struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1809 struct ctl_table *table)
1810{
1811 return NULL;
1812}
1813
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001814void unregister_sysctl_table(struct ctl_table_header * table)
1815{
1816}
1817
1818#endif /* CONFIG_SYSCTL */
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820/*
1821 * /proc/sys support
1822 */
1823
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001824#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001826static int _proc_do_string(void* data, int maxlen, int write,
1827 struct file *filp, void __user *buffer,
1828 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001829{
1830 size_t len;
1831 char __user *p;
1832 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001833
1834 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001835 *lenp = 0;
1836 return 0;
1837 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001838
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001839 if (write) {
1840 len = 0;
1841 p = buffer;
1842 while (len < *lenp) {
1843 if (get_user(c, p++))
1844 return -EFAULT;
1845 if (c == 0 || c == '\n')
1846 break;
1847 len++;
1848 }
1849 if (len >= maxlen)
1850 len = maxlen-1;
1851 if(copy_from_user(data, buffer, len))
1852 return -EFAULT;
1853 ((char *) data)[len] = 0;
1854 *ppos += *lenp;
1855 } else {
1856 len = strlen(data);
1857 if (len > maxlen)
1858 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001859
1860 if (*ppos > len) {
1861 *lenp = 0;
1862 return 0;
1863 }
1864
1865 data += *ppos;
1866 len -= *ppos;
1867
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001868 if (len > *lenp)
1869 len = *lenp;
1870 if (len)
1871 if(copy_to_user(buffer, data, len))
1872 return -EFAULT;
1873 if (len < *lenp) {
1874 if(put_user('\n', ((char __user *) buffer) + len))
1875 return -EFAULT;
1876 len++;
1877 }
1878 *lenp = len;
1879 *ppos += len;
1880 }
1881 return 0;
1882}
1883
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884/**
1885 * proc_dostring - read a string sysctl
1886 * @table: the sysctl table
1887 * @write: %TRUE if this is a write to the sysctl file
1888 * @filp: the file structure
1889 * @buffer: the user buffer
1890 * @lenp: the size of the user buffer
1891 * @ppos: file position
1892 *
1893 * Reads/writes a string from/to the user buffer. If the kernel
1894 * buffer provided is not large enough to hold the string, the
1895 * string is truncated. The copied string is %NULL-terminated.
1896 * If the string is being read by the user process, it is copied
1897 * and a newline '\n' is added. It is truncated if the buffer is
1898 * not large enough.
1899 *
1900 * Returns 0 on success.
1901 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001902int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 void __user *buffer, size_t *lenp, loff_t *ppos)
1904{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001905 return _proc_do_string(table->data, table->maxlen, write, filp,
1906 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907}
1908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1911 int *valp,
1912 int write, void *data)
1913{
1914 if (write) {
1915 *valp = *negp ? -*lvalp : *lvalp;
1916 } else {
1917 int val = *valp;
1918 if (val < 0) {
1919 *negp = -1;
1920 *lvalp = (unsigned long)-val;
1921 } else {
1922 *negp = 0;
1923 *lvalp = (unsigned long)val;
1924 }
1925 }
1926 return 0;
1927}
1928
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001929static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001930 int write, struct file *filp, void __user *buffer,
1931 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1933 int write, void *data),
1934 void *data)
1935{
1936#define TMPBUFLEN 21
1937 int *i, vleft, first=1, neg, val;
1938 unsigned long lval;
1939 size_t left, len;
1940
1941 char buf[TMPBUFLEN], *p;
1942 char __user *s = buffer;
1943
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001944 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 (*ppos && !write)) {
1946 *lenp = 0;
1947 return 0;
1948 }
1949
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001950 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 vleft = table->maxlen / sizeof(*i);
1952 left = *lenp;
1953
1954 if (!conv)
1955 conv = do_proc_dointvec_conv;
1956
1957 for (; left && vleft--; i++, first=0) {
1958 if (write) {
1959 while (left) {
1960 char c;
1961 if (get_user(c, s))
1962 return -EFAULT;
1963 if (!isspace(c))
1964 break;
1965 left--;
1966 s++;
1967 }
1968 if (!left)
1969 break;
1970 neg = 0;
1971 len = left;
1972 if (len > sizeof(buf) - 1)
1973 len = sizeof(buf) - 1;
1974 if (copy_from_user(buf, s, len))
1975 return -EFAULT;
1976 buf[len] = 0;
1977 p = buf;
1978 if (*p == '-' && left > 1) {
1979 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001980 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 }
1982 if (*p < '0' || *p > '9')
1983 break;
1984
1985 lval = simple_strtoul(p, &p, 0);
1986
1987 len = p-buf;
1988 if ((len < left) && *p && !isspace(*p))
1989 break;
1990 if (neg)
1991 val = -val;
1992 s += len;
1993 left -= len;
1994
1995 if (conv(&neg, &lval, i, 1, data))
1996 break;
1997 } else {
1998 p = buf;
1999 if (!first)
2000 *p++ = '\t';
2001
2002 if (conv(&neg, &lval, i, 0, data))
2003 break;
2004
2005 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2006 len = strlen(buf);
2007 if (len > left)
2008 len = left;
2009 if(copy_to_user(s, buf, len))
2010 return -EFAULT;
2011 left -= len;
2012 s += len;
2013 }
2014 }
2015
2016 if (!write && !first && left) {
2017 if(put_user('\n', s))
2018 return -EFAULT;
2019 left--, s++;
2020 }
2021 if (write) {
2022 while (left) {
2023 char c;
2024 if (get_user(c, s++))
2025 return -EFAULT;
2026 if (!isspace(c))
2027 break;
2028 left--;
2029 }
2030 }
2031 if (write && first)
2032 return -EINVAL;
2033 *lenp -= left;
2034 *ppos += *lenp;
2035 return 0;
2036#undef TMPBUFLEN
2037}
2038
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002039static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002040 void __user *buffer, size_t *lenp, loff_t *ppos,
2041 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2042 int write, void *data),
2043 void *data)
2044{
2045 return __do_proc_dointvec(table->data, table, write, filp,
2046 buffer, lenp, ppos, conv, data);
2047}
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049/**
2050 * proc_dointvec - read a vector of integers
2051 * @table: the sysctl table
2052 * @write: %TRUE if this is a write to the sysctl file
2053 * @filp: the file structure
2054 * @buffer: the user buffer
2055 * @lenp: the size of the user buffer
2056 * @ppos: file position
2057 *
2058 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2059 * values from/to the user buffer, treated as an ASCII string.
2060 *
2061 * Returns 0 on success.
2062 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002063int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 void __user *buffer, size_t *lenp, loff_t *ppos)
2065{
2066 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2067 NULL,NULL);
2068}
2069
2070#define OP_SET 0
2071#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002072#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2075 int *valp,
2076 int write, void *data)
2077{
2078 int op = *(int *)data;
2079 if (write) {
2080 int val = *negp ? -*lvalp : *lvalp;
2081 switch(op) {
2082 case OP_SET: *valp = val; break;
2083 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002084 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 }
2086 } else {
2087 int val = *valp;
2088 if (val < 0) {
2089 *negp = -1;
2090 *lvalp = (unsigned long)-val;
2091 } else {
2092 *negp = 0;
2093 *lvalp = (unsigned long)val;
2094 }
2095 }
2096 return 0;
2097}
2098
Andrew Morgan72c2d582007-10-18 03:05:59 -07002099#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100/*
2101 * init may raise the set.
2102 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07002103
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002104int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 void __user *buffer, size_t *lenp, loff_t *ppos)
2106{
2107 int op;
2108
Eric Paris6ff1b442007-02-10 01:43:19 -08002109 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 return -EPERM;
2111 }
2112
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07002113 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2115 do_proc_dointvec_bset_conv,&op);
2116}
Andrew Morgan72c2d582007-10-18 03:05:59 -07002117#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002119/*
2120 * Taint values can only be increased
2121 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002122static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002123 void __user *buffer, size_t *lenp, loff_t *ppos)
2124{
2125 int op;
2126
Bastian Blank91fcd412007-04-23 14:41:14 -07002127 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002128 return -EPERM;
2129
2130 op = OP_OR;
2131 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2132 do_proc_dointvec_bset_conv,&op);
2133}
2134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135struct do_proc_dointvec_minmax_conv_param {
2136 int *min;
2137 int *max;
2138};
2139
2140static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2141 int *valp,
2142 int write, void *data)
2143{
2144 struct do_proc_dointvec_minmax_conv_param *param = data;
2145 if (write) {
2146 int val = *negp ? -*lvalp : *lvalp;
2147 if ((param->min && *param->min > val) ||
2148 (param->max && *param->max < val))
2149 return -EINVAL;
2150 *valp = val;
2151 } else {
2152 int val = *valp;
2153 if (val < 0) {
2154 *negp = -1;
2155 *lvalp = (unsigned long)-val;
2156 } else {
2157 *negp = 0;
2158 *lvalp = (unsigned long)val;
2159 }
2160 }
2161 return 0;
2162}
2163
2164/**
2165 * proc_dointvec_minmax - read a vector of integers with min/max values
2166 * @table: the sysctl table
2167 * @write: %TRUE if this is a write to the sysctl file
2168 * @filp: the file structure
2169 * @buffer: the user buffer
2170 * @lenp: the size of the user buffer
2171 * @ppos: file position
2172 *
2173 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2174 * values from/to the user buffer, treated as an ASCII string.
2175 *
2176 * This routine will ensure the values are within the range specified by
2177 * table->extra1 (min) and table->extra2 (max).
2178 *
2179 * Returns 0 on success.
2180 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002181int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 void __user *buffer, size_t *lenp, loff_t *ppos)
2183{
2184 struct do_proc_dointvec_minmax_conv_param param = {
2185 .min = (int *) table->extra1,
2186 .max = (int *) table->extra2,
2187 };
2188 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2189 do_proc_dointvec_minmax_conv, &param);
2190}
2191
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002192static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 struct file *filp,
2194 void __user *buffer,
2195 size_t *lenp, loff_t *ppos,
2196 unsigned long convmul,
2197 unsigned long convdiv)
2198{
2199#define TMPBUFLEN 21
2200 unsigned long *i, *min, *max, val;
2201 int vleft, first=1, neg;
2202 size_t len, left;
2203 char buf[TMPBUFLEN], *p;
2204 char __user *s = buffer;
2205
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002206 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 (*ppos && !write)) {
2208 *lenp = 0;
2209 return 0;
2210 }
2211
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002212 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 min = (unsigned long *) table->extra1;
2214 max = (unsigned long *) table->extra2;
2215 vleft = table->maxlen / sizeof(unsigned long);
2216 left = *lenp;
2217
2218 for (; left && vleft--; i++, min++, max++, first=0) {
2219 if (write) {
2220 while (left) {
2221 char c;
2222 if (get_user(c, s))
2223 return -EFAULT;
2224 if (!isspace(c))
2225 break;
2226 left--;
2227 s++;
2228 }
2229 if (!left)
2230 break;
2231 neg = 0;
2232 len = left;
2233 if (len > TMPBUFLEN-1)
2234 len = TMPBUFLEN-1;
2235 if (copy_from_user(buf, s, len))
2236 return -EFAULT;
2237 buf[len] = 0;
2238 p = buf;
2239 if (*p == '-' && left > 1) {
2240 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002241 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 }
2243 if (*p < '0' || *p > '9')
2244 break;
2245 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2246 len = p-buf;
2247 if ((len < left) && *p && !isspace(*p))
2248 break;
2249 if (neg)
2250 val = -val;
2251 s += len;
2252 left -= len;
2253
2254 if(neg)
2255 continue;
2256 if ((min && val < *min) || (max && val > *max))
2257 continue;
2258 *i = val;
2259 } else {
2260 p = buf;
2261 if (!first)
2262 *p++ = '\t';
2263 sprintf(p, "%lu", convdiv * (*i) / convmul);
2264 len = strlen(buf);
2265 if (len > left)
2266 len = left;
2267 if(copy_to_user(s, buf, len))
2268 return -EFAULT;
2269 left -= len;
2270 s += len;
2271 }
2272 }
2273
2274 if (!write && !first && left) {
2275 if(put_user('\n', s))
2276 return -EFAULT;
2277 left--, s++;
2278 }
2279 if (write) {
2280 while (left) {
2281 char c;
2282 if (get_user(c, s++))
2283 return -EFAULT;
2284 if (!isspace(c))
2285 break;
2286 left--;
2287 }
2288 }
2289 if (write && first)
2290 return -EINVAL;
2291 *lenp -= left;
2292 *ppos += *lenp;
2293 return 0;
2294#undef TMPBUFLEN
2295}
2296
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002297static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002298 struct file *filp,
2299 void __user *buffer,
2300 size_t *lenp, loff_t *ppos,
2301 unsigned long convmul,
2302 unsigned long convdiv)
2303{
2304 return __do_proc_doulongvec_minmax(table->data, table, write,
2305 filp, buffer, lenp, ppos, convmul, convdiv);
2306}
2307
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308/**
2309 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2310 * @table: the sysctl table
2311 * @write: %TRUE if this is a write to the sysctl file
2312 * @filp: the file structure
2313 * @buffer: the user buffer
2314 * @lenp: the size of the user buffer
2315 * @ppos: file position
2316 *
2317 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2318 * values from/to the user buffer, treated as an ASCII string.
2319 *
2320 * This routine will ensure the values are within the range specified by
2321 * table->extra1 (min) and table->extra2 (max).
2322 *
2323 * Returns 0 on success.
2324 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002325int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 void __user *buffer, size_t *lenp, loff_t *ppos)
2327{
2328 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2329}
2330
2331/**
2332 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2333 * @table: the sysctl table
2334 * @write: %TRUE if this is a write to the sysctl file
2335 * @filp: the file structure
2336 * @buffer: the user buffer
2337 * @lenp: the size of the user buffer
2338 * @ppos: file position
2339 *
2340 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2341 * values from/to the user buffer, treated as an ASCII string. The values
2342 * are treated as milliseconds, and converted to jiffies when they are stored.
2343 *
2344 * This routine will ensure the values are within the range specified by
2345 * table->extra1 (min) and table->extra2 (max).
2346 *
2347 * Returns 0 on success.
2348 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002349int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 struct file *filp,
2351 void __user *buffer,
2352 size_t *lenp, loff_t *ppos)
2353{
2354 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2355 lenp, ppos, HZ, 1000l);
2356}
2357
2358
2359static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2360 int *valp,
2361 int write, void *data)
2362{
2363 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002364 if (*lvalp > LONG_MAX / HZ)
2365 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2367 } else {
2368 int val = *valp;
2369 unsigned long lval;
2370 if (val < 0) {
2371 *negp = -1;
2372 lval = (unsigned long)-val;
2373 } else {
2374 *negp = 0;
2375 lval = (unsigned long)val;
2376 }
2377 *lvalp = lval / HZ;
2378 }
2379 return 0;
2380}
2381
2382static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2383 int *valp,
2384 int write, void *data)
2385{
2386 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002387 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2388 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2390 } else {
2391 int val = *valp;
2392 unsigned long lval;
2393 if (val < 0) {
2394 *negp = -1;
2395 lval = (unsigned long)-val;
2396 } else {
2397 *negp = 0;
2398 lval = (unsigned long)val;
2399 }
2400 *lvalp = jiffies_to_clock_t(lval);
2401 }
2402 return 0;
2403}
2404
2405static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2406 int *valp,
2407 int write, void *data)
2408{
2409 if (write) {
2410 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2411 } else {
2412 int val = *valp;
2413 unsigned long lval;
2414 if (val < 0) {
2415 *negp = -1;
2416 lval = (unsigned long)-val;
2417 } else {
2418 *negp = 0;
2419 lval = (unsigned long)val;
2420 }
2421 *lvalp = jiffies_to_msecs(lval);
2422 }
2423 return 0;
2424}
2425
2426/**
2427 * proc_dointvec_jiffies - read a vector of integers as seconds
2428 * @table: the sysctl table
2429 * @write: %TRUE if this is a write to the sysctl file
2430 * @filp: the file structure
2431 * @buffer: the user buffer
2432 * @lenp: the size of the user buffer
2433 * @ppos: file position
2434 *
2435 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2436 * values from/to the user buffer, treated as an ASCII string.
2437 * The values read are assumed to be in seconds, and are converted into
2438 * jiffies.
2439 *
2440 * Returns 0 on success.
2441 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002442int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 void __user *buffer, size_t *lenp, loff_t *ppos)
2444{
2445 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2446 do_proc_dointvec_jiffies_conv,NULL);
2447}
2448
2449/**
2450 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2451 * @table: the sysctl table
2452 * @write: %TRUE if this is a write to the sysctl file
2453 * @filp: the file structure
2454 * @buffer: the user buffer
2455 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002456 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 *
2458 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2459 * values from/to the user buffer, treated as an ASCII string.
2460 * The values read are assumed to be in 1/USER_HZ seconds, and
2461 * are converted into jiffies.
2462 *
2463 * Returns 0 on success.
2464 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002465int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 void __user *buffer, size_t *lenp, loff_t *ppos)
2467{
2468 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2469 do_proc_dointvec_userhz_jiffies_conv,NULL);
2470}
2471
2472/**
2473 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2474 * @table: the sysctl table
2475 * @write: %TRUE if this is a write to the sysctl file
2476 * @filp: the file structure
2477 * @buffer: the user buffer
2478 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002479 * @ppos: file position
2480 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 *
2482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2483 * values from/to the user buffer, treated as an ASCII string.
2484 * The values read are assumed to be in 1/1000 seconds, and
2485 * are converted into jiffies.
2486 *
2487 * Returns 0 on success.
2488 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002489int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 void __user *buffer, size_t *lenp, loff_t *ppos)
2491{
2492 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2493 do_proc_dointvec_ms_jiffies_conv, NULL);
2494}
2495
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002496static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002497 void __user *buffer, size_t *lenp, loff_t *ppos)
2498{
2499 struct pid *new_pid;
2500 pid_t tmp;
2501 int r;
2502
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002503 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002504
2505 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2506 lenp, ppos, NULL, NULL);
2507 if (r || !write)
2508 return r;
2509
2510 new_pid = find_get_pid(tmp);
2511 if (!new_pid)
2512 return -ESRCH;
2513
2514 put_pid(xchg(&cad_pid, new_pid));
2515 return 0;
2516}
2517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518#else /* CONFIG_PROC_FS */
2519
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002520int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 void __user *buffer, size_t *lenp, loff_t *ppos)
2522{
2523 return -ENOSYS;
2524}
2525
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002526int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 void __user *buffer, size_t *lenp, loff_t *ppos)
2528{
2529 return -ENOSYS;
2530}
2531
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002532int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 void __user *buffer, size_t *lenp, loff_t *ppos)
2534{
2535 return -ENOSYS;
2536}
2537
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002538int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 void __user *buffer, size_t *lenp, loff_t *ppos)
2540{
2541 return -ENOSYS;
2542}
2543
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002544int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 void __user *buffer, size_t *lenp, loff_t *ppos)
2546{
2547 return -ENOSYS;
2548}
2549
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002550int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 void __user *buffer, size_t *lenp, loff_t *ppos)
2552{
2553 return -ENOSYS;
2554}
2555
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002556int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 void __user *buffer, size_t *lenp, loff_t *ppos)
2558{
2559 return -ENOSYS;
2560}
2561
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002562int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 void __user *buffer, size_t *lenp, loff_t *ppos)
2564{
2565 return -ENOSYS;
2566}
2567
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002568int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 struct file *filp,
2570 void __user *buffer,
2571 size_t *lenp, loff_t *ppos)
2572{
2573 return -ENOSYS;
2574}
2575
2576
2577#endif /* CONFIG_PROC_FS */
2578
2579
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002580#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581/*
2582 * General sysctl support routines
2583 */
2584
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002585/* The generic sysctl data routine (used if no strategy routine supplied) */
2586int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen)
2589{
2590 size_t len;
2591
2592 /* Get out of I don't have a variable */
2593 if (!table->data || !table->maxlen)
2594 return -ENOTDIR;
2595
2596 if (oldval && oldlenp) {
2597 if (get_user(len, oldlenp))
2598 return -EFAULT;
2599 if (len) {
2600 if (len > table->maxlen)
2601 len = table->maxlen;
2602 if (copy_to_user(oldval, table->data, len))
2603 return -EFAULT;
2604 if (put_user(len, oldlenp))
2605 return -EFAULT;
2606 }
2607 }
2608
2609 if (newval && newlen) {
2610 if (newlen > table->maxlen)
2611 newlen = table->maxlen;
2612
2613 if (copy_from_user(table->data, newval, newlen))
2614 return -EFAULT;
2615 }
2616 return 1;
2617}
2618
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002620int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002622 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 if (!table->data || !table->maxlen)
2625 return -ENOTDIR;
2626
2627 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002628 size_t bufsize;
2629 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002631 if (bufsize) {
2632 size_t len = strlen(table->data), copied;
2633
2634 /* This shouldn't trigger for a well-formed sysctl */
2635 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002637
2638 /* Copy up to a max of bufsize-1 bytes of the string */
2639 copied = (len >= bufsize) ? bufsize - 1 : len;
2640
2641 if (copy_to_user(oldval, table->data, copied) ||
2642 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002644 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 return -EFAULT;
2646 }
2647 }
2648 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002649 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if (len > table->maxlen)
2651 len = table->maxlen;
2652 if(copy_from_user(table->data, newval, len))
2653 return -EFAULT;
2654 if (len == table->maxlen)
2655 len--;
2656 ((char *) table->data)[len] = 0;
2657 }
Yi Yang82c9df82005-12-30 16:37:10 +08002658 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
2660
2661/*
2662 * This function makes sure that all of the integers in the vector
2663 * are between the minimum and maximum values given in the arrays
2664 * table->extra1 and table->extra2, respectively.
2665 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002666int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002668 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
2670
2671 if (newval && newlen) {
2672 int __user *vec = (int __user *) newval;
2673 int *min = (int *) table->extra1;
2674 int *max = (int *) table->extra2;
2675 size_t length;
2676 int i;
2677
2678 if (newlen % sizeof(int) != 0)
2679 return -EINVAL;
2680
2681 if (!table->extra1 && !table->extra2)
2682 return 0;
2683
2684 if (newlen > table->maxlen)
2685 newlen = table->maxlen;
2686 length = newlen / sizeof(int);
2687
2688 for (i = 0; i < length; i++) {
2689 int value;
2690 if (get_user(value, vec + i))
2691 return -EFAULT;
2692 if (min && value < min[i])
2693 return -EINVAL;
2694 if (max && value > max[i])
2695 return -EINVAL;
2696 }
2697 }
2698 return 0;
2699}
2700
2701/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002702int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002704 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002706 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002708
2709 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002711 if (olen) {
2712 int val;
2713
2714 if (olen < sizeof(int))
2715 return -EINVAL;
2716
2717 val = *(int *)(table->data) / HZ;
2718 if (put_user(val, (int __user *)oldval))
2719 return -EFAULT;
2720 if (put_user(sizeof(int), oldlenp))
2721 return -EFAULT;
2722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 }
2724 if (newval && newlen) {
2725 int new;
2726 if (newlen != sizeof(int))
2727 return -EINVAL;
2728 if (get_user(new, (int __user *)newval))
2729 return -EFAULT;
2730 *(int *)(table->data) = new*HZ;
2731 }
2732 return 1;
2733}
2734
2735/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002736int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002738 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002740 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002742
2743 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002745 if (olen) {
2746 int val;
2747
2748 if (olen < sizeof(int))
2749 return -EINVAL;
2750
2751 val = jiffies_to_msecs(*(int *)(table->data));
2752 if (put_user(val, (int __user *)oldval))
2753 return -EFAULT;
2754 if (put_user(sizeof(int), oldlenp))
2755 return -EFAULT;
2756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 }
2758 if (newval && newlen) {
2759 int new;
2760 if (newlen != sizeof(int))
2761 return -EINVAL;
2762 if (get_user(new, (int __user *)newval))
2763 return -EFAULT;
2764 *(int *)(table->data) = msecs_to_jiffies(new);
2765 }
2766 return 1;
2767}
2768
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002769
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002770
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002771#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
2773
2774asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2775{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002776 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002777 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002778
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002779 if (copy_from_user(&tmp, args, sizeof(tmp)))
2780 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002781
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002782 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002783
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002784 /* If no error reading the parameters then just -ENOSYS ... */
2785 if (!error)
2786 error = -ENOSYS;
2787
2788 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789}
2790
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002791int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2792 void __user *oldval, size_t __user *oldlenp,
2793 void __user *newval, size_t newlen)
2794{
2795 return -ENOSYS;
2796}
2797
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002798int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002800 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801{
2802 return -ENOSYS;
2803}
2804
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002805int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002807 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808{
2809 return -ENOSYS;
2810}
2811
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002812int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002814 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815{
2816 return -ENOSYS;
2817}
2818
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002819int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002821 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822{
2823 return -ENOSYS;
2824}
2825
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002826#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002828static int deprecated_sysctl_warning(struct __sysctl_args *args)
2829{
2830 static int msg_count;
2831 int name[CTL_MAXNAME];
2832 int i;
2833
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002834 /* Check args->nlen. */
2835 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2836 return -ENOTDIR;
2837
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002838 /* Read in the sysctl name for better debug message logging */
2839 for (i = 0; i < args->nlen; i++)
2840 if (get_user(name[i], args->name + i))
2841 return -EFAULT;
2842
2843 /* Ignore accesses to kernel.version */
2844 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2845 return 0;
2846
2847 if (msg_count < 5) {
2848 msg_count++;
2849 printk(KERN_INFO
2850 "warning: process `%s' used the deprecated sysctl "
2851 "system call with ", current->comm);
2852 for (i = 0; i < args->nlen; i++)
2853 printk("%d.", name[i]);
2854 printk("\n");
2855 }
2856 return 0;
2857}
2858
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859/*
2860 * No sense putting this after each symbol definition, twice,
2861 * exception granted :-)
2862 */
2863EXPORT_SYMBOL(proc_dointvec);
2864EXPORT_SYMBOL(proc_dointvec_jiffies);
2865EXPORT_SYMBOL(proc_dointvec_minmax);
2866EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2867EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2868EXPORT_SYMBOL(proc_dostring);
2869EXPORT_SYMBOL(proc_doulongvec_minmax);
2870EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2871EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002872EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873EXPORT_SYMBOL(sysctl_intvec);
2874EXPORT_SYMBOL(sysctl_jiffies);
2875EXPORT_SYMBOL(sysctl_ms_jiffies);
2876EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002877EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878EXPORT_SYMBOL(unregister_sysctl_table);