Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sysctl.c: General linux system control interface |
| 3 | * |
| 4 | * Begun 24 March 1995, Stephen Tweedie |
| 5 | * Added /proc support, Dec 1995 |
| 6 | * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. |
| 7 | * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. |
| 8 | * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. |
| 9 | * Dynamic registration fixes, Stephen Tweedie. |
| 10 | * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. |
| 11 | * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris |
| 12 | * Horn. |
| 13 | * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. |
| 14 | * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. |
| 15 | * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill |
| 16 | * Wendling. |
| 17 | * The list_for_each() macro wasn't appropriate for the sysctl loop. |
| 18 | * Removed it and replaced it with older style, 03/23/00, Bill Wendling |
| 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/swap.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/sysctl.h> |
| 26 | #include <linux/proc_fs.h> |
Andrew Morgan | 72c2d58 | 2007-10-18 03:05:59 -0700 | [diff] [blame] | 27 | #include <linux/security.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/ctype.h> |
| 29 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/smp_lock.h> |
Adrian Bunk | 62239ac | 2007-07-17 04:03:45 -0700 | [diff] [blame] | 31 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/kernel.h> |
Kay Sievers | 0296b22 | 2005-11-11 05:33:52 +0100 | [diff] [blame] | 34 | #include <linux/kobject.h> |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 35 | #include <linux/net.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/sysrq.h> |
| 37 | #include <linux/highuid.h> |
| 38 | #include <linux/writeback.h> |
| 39 | #include <linux/hugetlb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/initrd.h> |
David Howells | 0b77f5b | 2008-04-29 01:01:32 -0700 | [diff] [blame] | 41 | #include <linux/key.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/times.h> |
| 43 | #include <linux/limits.h> |
| 44 | #include <linux/dcache.h> |
| 45 | #include <linux/syscalls.h> |
Adrian Bunk | c748e13 | 2008-07-23 21:27:03 -0700 | [diff] [blame] | 46 | #include <linux/vmstat.h> |
Pavel Machek | c255d84 | 2006-02-20 18:27:58 -0800 | [diff] [blame] | 47 | #include <linux/nfs_fs.h> |
| 48 | #include <linux/acpi.h> |
Jeremy Fitzhardinge | 10a0a8d | 2007-07-17 18:37:02 -0700 | [diff] [blame] | 49 | #include <linux/reboot.h> |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 50 | #include <linux/ftrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #include <asm/uaccess.h> |
| 53 | #include <asm/processor.h> |
| 54 | |
Andi Kleen | 29cbc78 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 55 | #ifdef CONFIG_X86 |
| 56 | #include <asm/nmi.h> |
Chuck Ebbert | 0741f4d | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 57 | #include <asm/stacktrace.h> |
Ingo Molnar | 6e7c402 | 2008-01-30 13:30:05 +0100 | [diff] [blame] | 58 | #include <asm/io.h> |
Andi Kleen | 29cbc78 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 59 | #endif |
| 60 | |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 61 | static int deprecated_sysctl_warning(struct __sysctl_args *args); |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #if defined(CONFIG_SYSCTL) |
| 64 | |
| 65 | /* External variables not in a header file. */ |
| 66 | extern int C_A_D; |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 67 | extern int print_fatal_signals; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | extern int sysctl_overcommit_memory; |
| 69 | extern int sysctl_overcommit_ratio; |
KAMEZAWA Hiroyuki | fadd8fb | 2006-06-23 02:03:13 -0700 | [diff] [blame] | 70 | extern int sysctl_panic_on_oom; |
David Rientjes | fe071d7 | 2007-10-16 23:25:56 -0700 | [diff] [blame] | 71 | extern int sysctl_oom_kill_allocating_task; |
David Rientjes | fef1bdd | 2008-02-07 00:14:07 -0800 | [diff] [blame] | 72 | extern int sysctl_oom_dump_tasks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | extern int max_threads; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | extern int core_uses_pid; |
Alan Cox | d6e7114 | 2005-06-23 00:09:43 -0700 | [diff] [blame] | 75 | extern int suid_dumpable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | extern char core_pattern[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | extern int pid_max; |
| 78 | extern int min_free_kbytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | extern int pid_max_min, pid_max_max; |
Andrew Morton | 9d0243b | 2006-01-08 01:00:39 -0800 | [diff] [blame] | 80 | extern int sysctl_drop_caches; |
Rohit Seth | 8ad4b1f | 2006-01-08 01:00:40 -0800 | [diff] [blame] | 81 | extern int percpu_pagelist_fraction; |
Andi Kleen | bebfa10 | 2006-06-26 13:56:52 +0200 | [diff] [blame] | 82 | extern int compat_log; |
Kees Cook | 5096add | 2007-05-08 00:26:04 -0700 | [diff] [blame] | 83 | extern int maps_protect; |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 84 | extern int latencytop_enabled; |
Al Viro | eceea0b | 2008-05-10 10:08:32 -0400 | [diff] [blame] | 85 | extern int sysctl_nr_open_min, sysctl_nr_open_max; |
Paul E. McKenney | 31a72bc | 2008-06-18 09:26:49 -0700 | [diff] [blame] | 86 | #ifdef CONFIG_RCU_TORTURE_TEST |
| 87 | extern int rcutorture_runnable; |
| 88 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 90 | /* Constants used for minimum and maximum */ |
Ingo Molnar | 1c4cd6d | 2008-05-12 21:21:14 +0200 | [diff] [blame] | 91 | #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP) |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 92 | static int one = 1; |
Bron Gondwana | 195cf45 | 2008-02-04 22:29:20 -0800 | [diff] [blame] | 93 | #endif |
| 94 | |
| 95 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 96 | static int sixty = 60; |
Dimitri Sivanich | 9383d96 | 2008-05-12 21:21:14 +0200 | [diff] [blame] | 97 | static int neg_one = -1; |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 98 | #endif |
| 99 | |
| 100 | #ifdef CONFIG_MMU |
| 101 | static int two = 2; |
| 102 | #endif |
| 103 | |
| 104 | static int zero; |
| 105 | static int one_hundred = 100; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ |
| 108 | static int maxolduid = 65535; |
| 109 | static int minolduid; |
Rohit Seth | 8ad4b1f | 2006-01-08 01:00:40 -0800 | [diff] [blame] | 110 | static int min_percpu_pagelist_fract = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | static int ngroups_max = NGROUPS_MAX; |
| 113 | |
Johannes Berg | a1ef5ad | 2008-07-08 19:00:17 +0200 | [diff] [blame] | 114 | #ifdef CONFIG_MODULES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | extern char modprobe_path[]; |
| 116 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #ifdef CONFIG_CHR_DEV_SG |
| 118 | extern int sg_big_buff; |
| 119 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | #ifdef __sparc__ |
| 122 | extern char reboot_command []; |
| 123 | extern int stop_a_enabled; |
| 124 | extern int scons_pwroff; |
| 125 | #endif |
| 126 | |
| 127 | #ifdef __hppa__ |
| 128 | extern int pwrsw_enabled; |
| 129 | extern int unaligned_enabled; |
| 130 | #endif |
| 131 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 132 | #ifdef CONFIG_S390 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #ifdef CONFIG_MATHEMU |
| 134 | extern int sysctl_ieee_emulation_warnings; |
| 135 | #endif |
| 136 | extern int sysctl_userprocess_debug; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 137 | extern int spin_retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #endif |
| 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | #ifdef CONFIG_BSD_PROCESS_ACCT |
| 141 | extern int acct_parm[]; |
| 142 | #endif |
| 143 | |
Jes Sorensen | d2b176e | 2006-02-28 09:42:23 -0800 | [diff] [blame] | 144 | #ifdef CONFIG_IA64 |
| 145 | extern int no_unaligned_warning; |
| 146 | #endif |
| 147 | |
Ingo Molnar | 23f78d4 | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 148 | #ifdef CONFIG_RT_MUTEXES |
| 149 | extern int max_lock_depth; |
| 150 | #endif |
| 151 | |
Randy Dunlap | d6f8ff7 | 2006-10-19 23:28:34 -0700 | [diff] [blame] | 152 | #ifdef CONFIG_PROC_SYSCTL |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 153 | static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 154 | void __user *buffer, size_t *lenp, loff_t *ppos); |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 155 | static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 156 | void __user *buffer, size_t *lenp, loff_t *ppos); |
Randy Dunlap | d6f8ff7 | 2006-10-19 23:28:34 -0700 | [diff] [blame] | 157 | #endif |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 158 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 159 | static struct ctl_table root_table[]; |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 160 | static struct ctl_table_root sysctl_table_root; |
| 161 | static struct ctl_table_header root_table_header = { |
| 162 | .ctl_table = root_table, |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 163 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 164 | .root = &sysctl_table_root, |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 165 | .set = &sysctl_table_root.default_set, |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 166 | }; |
| 167 | static struct ctl_table_root sysctl_table_root = { |
| 168 | .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 169 | .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 170 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 172 | static struct ctl_table kern_table[]; |
| 173 | static struct ctl_table vm_table[]; |
| 174 | static struct ctl_table fs_table[]; |
| 175 | static struct ctl_table debug_table[]; |
| 176 | static struct ctl_table dev_table[]; |
| 177 | extern struct ctl_table random_table[]; |
Amy Griffis | 2d9048e | 2006-06-01 13:10:59 -0700 | [diff] [blame] | 178 | #ifdef CONFIG_INOTIFY_USER |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 179 | extern struct ctl_table inotify_table[]; |
Robert Love | 0399cb0 | 2005-07-13 12:38:18 -0400 | [diff] [blame] | 180 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT |
| 183 | int sysctl_legacy_va_layout; |
| 184 | #endif |
| 185 | |
Peter Zijlstra | f20786f | 2007-07-19 01:48:56 -0700 | [diff] [blame] | 186 | extern int prove_locking; |
| 187 | extern int lock_stat; |
Eric W. Biederman | 9bc9a6b | 2006-12-08 02:39:56 -0800 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /* The default sysctl tables: */ |
| 190 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 191 | static struct ctl_table root_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | .ctl_name = CTL_KERN, |
| 194 | .procname = "kernel", |
| 195 | .mode = 0555, |
| 196 | .child = kern_table, |
| 197 | }, |
| 198 | { |
| 199 | .ctl_name = CTL_VM, |
| 200 | .procname = "vm", |
| 201 | .mode = 0555, |
| 202 | .child = vm_table, |
| 203 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | .ctl_name = CTL_FS, |
| 206 | .procname = "fs", |
| 207 | .mode = 0555, |
| 208 | .child = fs_table, |
| 209 | }, |
| 210 | { |
| 211 | .ctl_name = CTL_DEBUG, |
| 212 | .procname = "debug", |
| 213 | .mode = 0555, |
| 214 | .child = debug_table, |
| 215 | }, |
| 216 | { |
| 217 | .ctl_name = CTL_DEV, |
| 218 | .procname = "dev", |
| 219 | .mode = 0555, |
| 220 | .child = dev_table, |
| 221 | }, |
Andrew Morton | 2be7fe0 | 2007-07-15 23:41:21 -0700 | [diff] [blame] | 222 | /* |
| 223 | * NOTE: do not add new entries to this table unless you have read |
| 224 | * Documentation/sysctl/ctl_unnumbered.txt |
| 225 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { .ctl_name = 0 } |
| 227 | }; |
| 228 | |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 229 | #ifdef CONFIG_SCHED_DEBUG |
Eric Dumazet | 73c4efd | 2007-12-18 15:21:13 +0100 | [diff] [blame] | 230 | static int min_sched_granularity_ns = 100000; /* 100 usecs */ |
| 231 | static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ |
| 232 | static int min_wakeup_granularity_ns; /* 0 usecs */ |
| 233 | static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 234 | #endif |
| 235 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 236 | static struct ctl_table kern_table[] = { |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 237 | #ifdef CONFIG_SCHED_DEBUG |
| 238 | { |
| 239 | .ctl_name = CTL_UNNUMBERED, |
Peter Zijlstra | b2be5e9 | 2007-11-09 22:39:37 +0100 | [diff] [blame] | 240 | .procname = "sched_min_granularity_ns", |
| 241 | .data = &sysctl_sched_min_granularity, |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 242 | .maxlen = sizeof(unsigned int), |
| 243 | .mode = 0644, |
Peter Zijlstra | b2be5e9 | 2007-11-09 22:39:37 +0100 | [diff] [blame] | 244 | .proc_handler = &sched_nr_latency_handler, |
| 245 | .strategy = &sysctl_intvec, |
| 246 | .extra1 = &min_sched_granularity_ns, |
| 247 | .extra2 = &max_sched_granularity_ns, |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 248 | }, |
| 249 | { |
| 250 | .ctl_name = CTL_UNNUMBERED, |
Peter Zijlstra | 2180508 | 2007-08-25 18:41:53 +0200 | [diff] [blame] | 251 | .procname = "sched_latency_ns", |
| 252 | .data = &sysctl_sched_latency, |
| 253 | .maxlen = sizeof(unsigned int), |
| 254 | .mode = 0644, |
Peter Zijlstra | b2be5e9 | 2007-11-09 22:39:37 +0100 | [diff] [blame] | 255 | .proc_handler = &sched_nr_latency_handler, |
Peter Zijlstra | 2180508 | 2007-08-25 18:41:53 +0200 | [diff] [blame] | 256 | .strategy = &sysctl_intvec, |
| 257 | .extra1 = &min_sched_granularity_ns, |
| 258 | .extra2 = &max_sched_granularity_ns, |
| 259 | }, |
| 260 | { |
| 261 | .ctl_name = CTL_UNNUMBERED, |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 262 | .procname = "sched_wakeup_granularity_ns", |
| 263 | .data = &sysctl_sched_wakeup_granularity, |
| 264 | .maxlen = sizeof(unsigned int), |
| 265 | .mode = 0644, |
| 266 | .proc_handler = &proc_dointvec_minmax, |
| 267 | .strategy = &sysctl_intvec, |
| 268 | .extra1 = &min_wakeup_granularity_ns, |
| 269 | .extra2 = &max_wakeup_granularity_ns, |
| 270 | }, |
| 271 | { |
| 272 | .ctl_name = CTL_UNNUMBERED, |
Peter Zijlstra | 2398f2c | 2008-06-27 13:41:35 +0200 | [diff] [blame] | 273 | .procname = "sched_shares_ratelimit", |
| 274 | .data = &sysctl_sched_shares_ratelimit, |
| 275 | .maxlen = sizeof(unsigned int), |
| 276 | .mode = 0644, |
| 277 | .proc_handler = &proc_dointvec, |
| 278 | }, |
| 279 | { |
| 280 | .ctl_name = CTL_UNNUMBERED, |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 281 | .procname = "sched_child_runs_first", |
| 282 | .data = &sysctl_sched_child_runs_first, |
| 283 | .maxlen = sizeof(unsigned int), |
| 284 | .mode = 0644, |
| 285 | .proc_handler = &proc_dointvec, |
| 286 | }, |
Peter Zijlstra | 1fc84aa | 2007-08-25 18:41:52 +0200 | [diff] [blame] | 287 | { |
| 288 | .ctl_name = CTL_UNNUMBERED, |
| 289 | .procname = "sched_features", |
| 290 | .data = &sysctl_sched_features, |
| 291 | .maxlen = sizeof(unsigned int), |
| 292 | .mode = 0644, |
| 293 | .proc_handler = &proc_dointvec, |
| 294 | }, |
Ingo Molnar | da84d96 | 2007-10-15 17:00:18 +0200 | [diff] [blame] | 295 | { |
| 296 | .ctl_name = CTL_UNNUMBERED, |
| 297 | .procname = "sched_migration_cost", |
| 298 | .data = &sysctl_sched_migration_cost, |
| 299 | .maxlen = sizeof(unsigned int), |
| 300 | .mode = 0644, |
| 301 | .proc_handler = &proc_dointvec, |
| 302 | }, |
Peter Zijlstra | b82d9fd | 2007-11-09 22:39:39 +0100 | [diff] [blame] | 303 | { |
| 304 | .ctl_name = CTL_UNNUMBERED, |
| 305 | .procname = "sched_nr_migrate", |
| 306 | .data = &sysctl_sched_nr_migrate, |
| 307 | .maxlen = sizeof(unsigned int), |
Peter Zijlstra | fa85ae2 | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 308 | .mode = 0644, |
| 309 | .proc_handler = &proc_dointvec, |
| 310 | }, |
Peter Zijlstra | 1fc84aa | 2007-08-25 18:41:52 +0200 | [diff] [blame] | 311 | #endif |
Ingo Molnar | 1799e35 | 2007-09-19 23:34:46 +0200 | [diff] [blame] | 312 | { |
| 313 | .ctl_name = CTL_UNNUMBERED, |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 314 | .procname = "sched_rt_period_us", |
| 315 | .data = &sysctl_sched_rt_period, |
| 316 | .maxlen = sizeof(unsigned int), |
| 317 | .mode = 0644, |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 318 | .proc_handler = &sched_rt_handler, |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 319 | }, |
| 320 | { |
| 321 | .ctl_name = CTL_UNNUMBERED, |
| 322 | .procname = "sched_rt_runtime_us", |
| 323 | .data = &sysctl_sched_rt_runtime, |
| 324 | .maxlen = sizeof(int), |
| 325 | .mode = 0644, |
Peter Zijlstra | d0b27fa | 2008-04-19 19:44:57 +0200 | [diff] [blame] | 326 | .proc_handler = &sched_rt_handler, |
Peter Zijlstra | 9f0c1e5 | 2008-02-13 15:45:39 +0100 | [diff] [blame] | 327 | }, |
| 328 | { |
| 329 | .ctl_name = CTL_UNNUMBERED, |
Ingo Molnar | 1799e35 | 2007-09-19 23:34:46 +0200 | [diff] [blame] | 330 | .procname = "sched_compat_yield", |
| 331 | .data = &sysctl_sched_compat_yield, |
| 332 | .maxlen = sizeof(unsigned int), |
| 333 | .mode = 0644, |
| 334 | .proc_handler = &proc_dointvec, |
| 335 | }, |
Peter Zijlstra | f20786f | 2007-07-19 01:48:56 -0700 | [diff] [blame] | 336 | #ifdef CONFIG_PROVE_LOCKING |
| 337 | { |
| 338 | .ctl_name = CTL_UNNUMBERED, |
| 339 | .procname = "prove_locking", |
| 340 | .data = &prove_locking, |
| 341 | .maxlen = sizeof(int), |
| 342 | .mode = 0644, |
| 343 | .proc_handler = &proc_dointvec, |
| 344 | }, |
| 345 | #endif |
| 346 | #ifdef CONFIG_LOCK_STAT |
| 347 | { |
| 348 | .ctl_name = CTL_UNNUMBERED, |
| 349 | .procname = "lock_stat", |
| 350 | .data = &lock_stat, |
| 351 | .maxlen = sizeof(int), |
| 352 | .mode = 0644, |
| 353 | .proc_handler = &proc_dointvec, |
| 354 | }, |
| 355 | #endif |
Ingo Molnar | 77e54a1 | 2007-07-09 18:52:00 +0200 | [diff] [blame] | 356 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | .ctl_name = KERN_PANIC, |
| 358 | .procname = "panic", |
| 359 | .data = &panic_timeout, |
| 360 | .maxlen = sizeof(int), |
| 361 | .mode = 0644, |
| 362 | .proc_handler = &proc_dointvec, |
| 363 | }, |
| 364 | { |
| 365 | .ctl_name = KERN_CORE_USES_PID, |
| 366 | .procname = "core_uses_pid", |
| 367 | .data = &core_uses_pid, |
| 368 | .maxlen = sizeof(int), |
| 369 | .mode = 0644, |
| 370 | .proc_handler = &proc_dointvec, |
| 371 | }, |
| 372 | { |
| 373 | .ctl_name = KERN_CORE_PATTERN, |
| 374 | .procname = "core_pattern", |
| 375 | .data = core_pattern, |
Dan Aloni | 71ce92f | 2007-05-16 22:11:16 -0700 | [diff] [blame] | 376 | .maxlen = CORENAME_MAX_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | .mode = 0644, |
| 378 | .proc_handler = &proc_dostring, |
| 379 | .strategy = &sysctl_string, |
| 380 | }, |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 381 | #ifdef CONFIG_PROC_SYSCTL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | .procname = "tainted", |
| 384 | .data = &tainted, |
| 385 | .maxlen = sizeof(int), |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 386 | .mode = 0644, |
| 387 | .proc_handler = &proc_dointvec_taint, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | }, |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 389 | #endif |
Arjan van de Ven | 9745512 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 390 | #ifdef CONFIG_LATENCYTOP |
| 391 | { |
| 392 | .procname = "latencytop", |
| 393 | .data = &latencytop_enabled, |
| 394 | .maxlen = sizeof(int), |
| 395 | .mode = 0644, |
| 396 | .proc_handler = &proc_dointvec, |
| 397 | }, |
| 398 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | #ifdef CONFIG_BLK_DEV_INITRD |
| 400 | { |
| 401 | .ctl_name = KERN_REALROOTDEV, |
| 402 | .procname = "real-root-dev", |
| 403 | .data = &real_root_dev, |
| 404 | .maxlen = sizeof(int), |
| 405 | .mode = 0644, |
| 406 | .proc_handler = &proc_dointvec, |
| 407 | }, |
| 408 | #endif |
Ingo Molnar | 45807a1 | 2007-07-15 23:40:10 -0700 | [diff] [blame] | 409 | { |
| 410 | .ctl_name = CTL_UNNUMBERED, |
| 411 | .procname = "print-fatal-signals", |
| 412 | .data = &print_fatal_signals, |
| 413 | .maxlen = sizeof(int), |
| 414 | .mode = 0644, |
| 415 | .proc_handler = &proc_dointvec, |
| 416 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | #ifdef __sparc__ |
| 418 | { |
| 419 | .ctl_name = KERN_SPARC_REBOOT, |
| 420 | .procname = "reboot-cmd", |
| 421 | .data = reboot_command, |
| 422 | .maxlen = 256, |
| 423 | .mode = 0644, |
| 424 | .proc_handler = &proc_dostring, |
| 425 | .strategy = &sysctl_string, |
| 426 | }, |
| 427 | { |
| 428 | .ctl_name = KERN_SPARC_STOP_A, |
| 429 | .procname = "stop-a", |
| 430 | .data = &stop_a_enabled, |
| 431 | .maxlen = sizeof (int), |
| 432 | .mode = 0644, |
| 433 | .proc_handler = &proc_dointvec, |
| 434 | }, |
| 435 | { |
| 436 | .ctl_name = KERN_SPARC_SCONS_PWROFF, |
| 437 | .procname = "scons-poweroff", |
| 438 | .data = &scons_pwroff, |
| 439 | .maxlen = sizeof (int), |
| 440 | .mode = 0644, |
| 441 | .proc_handler = &proc_dointvec, |
| 442 | }, |
| 443 | #endif |
| 444 | #ifdef __hppa__ |
| 445 | { |
| 446 | .ctl_name = KERN_HPPA_PWRSW, |
| 447 | .procname = "soft-power", |
| 448 | .data = &pwrsw_enabled, |
| 449 | .maxlen = sizeof (int), |
| 450 | .mode = 0644, |
| 451 | .proc_handler = &proc_dointvec, |
| 452 | }, |
| 453 | { |
| 454 | .ctl_name = KERN_HPPA_UNALIGNED, |
| 455 | .procname = "unaligned-trap", |
| 456 | .data = &unaligned_enabled, |
| 457 | .maxlen = sizeof (int), |
| 458 | .mode = 0644, |
| 459 | .proc_handler = &proc_dointvec, |
| 460 | }, |
| 461 | #endif |
| 462 | { |
| 463 | .ctl_name = KERN_CTLALTDEL, |
| 464 | .procname = "ctrl-alt-del", |
| 465 | .data = &C_A_D, |
| 466 | .maxlen = sizeof(int), |
| 467 | .mode = 0644, |
| 468 | .proc_handler = &proc_dointvec, |
| 469 | }, |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 470 | #ifdef CONFIG_FTRACE |
| 471 | { |
| 472 | .ctl_name = CTL_UNNUMBERED, |
| 473 | .procname = "ftrace_enabled", |
| 474 | .data = &ftrace_enabled, |
| 475 | .maxlen = sizeof(int), |
| 476 | .mode = 0644, |
| 477 | .proc_handler = &ftrace_enable_sysctl, |
| 478 | }, |
| 479 | #endif |
Johannes Berg | a1ef5ad | 2008-07-08 19:00:17 +0200 | [diff] [blame] | 480 | #ifdef CONFIG_MODULES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
| 482 | .ctl_name = KERN_MODPROBE, |
| 483 | .procname = "modprobe", |
| 484 | .data = &modprobe_path, |
| 485 | .maxlen = KMOD_PATH_LEN, |
| 486 | .mode = 0644, |
| 487 | .proc_handler = &proc_dostring, |
| 488 | .strategy = &sysctl_string, |
| 489 | }, |
| 490 | #endif |
Andrew Morton | 57ae250 | 2006-06-23 02:05:47 -0700 | [diff] [blame] | 491 | #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
| 493 | .ctl_name = KERN_HOTPLUG, |
| 494 | .procname = "hotplug", |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 495 | .data = &uevent_helper, |
| 496 | .maxlen = UEVENT_HELPER_PATH_LEN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | .mode = 0644, |
| 498 | .proc_handler = &proc_dostring, |
| 499 | .strategy = &sysctl_string, |
| 500 | }, |
| 501 | #endif |
| 502 | #ifdef CONFIG_CHR_DEV_SG |
| 503 | { |
| 504 | .ctl_name = KERN_SG_BIG_BUFF, |
| 505 | .procname = "sg-big-buff", |
| 506 | .data = &sg_big_buff, |
| 507 | .maxlen = sizeof (int), |
| 508 | .mode = 0444, |
| 509 | .proc_handler = &proc_dointvec, |
| 510 | }, |
| 511 | #endif |
| 512 | #ifdef CONFIG_BSD_PROCESS_ACCT |
| 513 | { |
| 514 | .ctl_name = KERN_ACCT, |
| 515 | .procname = "acct", |
| 516 | .data = &acct_parm, |
| 517 | .maxlen = 3*sizeof(int), |
| 518 | .mode = 0644, |
| 519 | .proc_handler = &proc_dointvec, |
| 520 | }, |
| 521 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | #ifdef CONFIG_MAGIC_SYSRQ |
| 523 | { |
| 524 | .ctl_name = KERN_SYSRQ, |
| 525 | .procname = "sysrq", |
Ingo Molnar | 5d6f647 | 2006-12-13 00:34:36 -0800 | [diff] [blame] | 526 | .data = &__sysrq_enabled, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | .maxlen = sizeof (int), |
| 528 | .mode = 0644, |
| 529 | .proc_handler = &proc_dointvec, |
| 530 | }, |
| 531 | #endif |
Randy Dunlap | d6f8ff7 | 2006-10-19 23:28:34 -0700 | [diff] [blame] | 532 | #ifdef CONFIG_PROC_SYSCTL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | .procname = "cad_pid", |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 535 | .data = NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | .maxlen = sizeof (int), |
| 537 | .mode = 0600, |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 538 | .proc_handler = &proc_do_cad_pid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | }, |
Randy Dunlap | d6f8ff7 | 2006-10-19 23:28:34 -0700 | [diff] [blame] | 540 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | { |
| 542 | .ctl_name = KERN_MAX_THREADS, |
| 543 | .procname = "threads-max", |
| 544 | .data = &max_threads, |
| 545 | .maxlen = sizeof(int), |
| 546 | .mode = 0644, |
| 547 | .proc_handler = &proc_dointvec, |
| 548 | }, |
| 549 | { |
| 550 | .ctl_name = KERN_RANDOM, |
| 551 | .procname = "random", |
| 552 | .mode = 0555, |
| 553 | .child = random_table, |
| 554 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
| 556 | .ctl_name = KERN_OVERFLOWUID, |
| 557 | .procname = "overflowuid", |
| 558 | .data = &overflowuid, |
| 559 | .maxlen = sizeof(int), |
| 560 | .mode = 0644, |
| 561 | .proc_handler = &proc_dointvec_minmax, |
| 562 | .strategy = &sysctl_intvec, |
| 563 | .extra1 = &minolduid, |
| 564 | .extra2 = &maxolduid, |
| 565 | }, |
| 566 | { |
| 567 | .ctl_name = KERN_OVERFLOWGID, |
| 568 | .procname = "overflowgid", |
| 569 | .data = &overflowgid, |
| 570 | .maxlen = sizeof(int), |
| 571 | .mode = 0644, |
| 572 | .proc_handler = &proc_dointvec_minmax, |
| 573 | .strategy = &sysctl_intvec, |
| 574 | .extra1 = &minolduid, |
| 575 | .extra2 = &maxolduid, |
| 576 | }, |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 577 | #ifdef CONFIG_S390 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | #ifdef CONFIG_MATHEMU |
| 579 | { |
| 580 | .ctl_name = KERN_IEEE_EMULATION_WARNINGS, |
| 581 | .procname = "ieee_emulation_warnings", |
| 582 | .data = &sysctl_ieee_emulation_warnings, |
| 583 | .maxlen = sizeof(int), |
| 584 | .mode = 0644, |
| 585 | .proc_handler = &proc_dointvec, |
| 586 | }, |
| 587 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
| 589 | .ctl_name = KERN_S390_USER_DEBUG_LOGGING, |
| 590 | .procname = "userprocess_debug", |
| 591 | .data = &sysctl_userprocess_debug, |
| 592 | .maxlen = sizeof(int), |
| 593 | .mode = 0644, |
| 594 | .proc_handler = &proc_dointvec, |
| 595 | }, |
| 596 | #endif |
| 597 | { |
| 598 | .ctl_name = KERN_PIDMAX, |
| 599 | .procname = "pid_max", |
| 600 | .data = &pid_max, |
| 601 | .maxlen = sizeof (int), |
| 602 | .mode = 0644, |
| 603 | .proc_handler = &proc_dointvec_minmax, |
| 604 | .strategy = sysctl_intvec, |
| 605 | .extra1 = &pid_max_min, |
| 606 | .extra2 = &pid_max_max, |
| 607 | }, |
| 608 | { |
| 609 | .ctl_name = KERN_PANIC_ON_OOPS, |
| 610 | .procname = "panic_on_oops", |
| 611 | .data = &panic_on_oops, |
| 612 | .maxlen = sizeof(int), |
| 613 | .mode = 0644, |
| 614 | .proc_handler = &proc_dointvec, |
| 615 | }, |
Joe Perches | 7ef3d2f | 2008-02-08 04:21:25 -0800 | [diff] [blame] | 616 | #if defined CONFIG_PRINTK |
| 617 | { |
| 618 | .ctl_name = KERN_PRINTK, |
| 619 | .procname = "printk", |
| 620 | .data = &console_loglevel, |
| 621 | .maxlen = 4*sizeof(int), |
| 622 | .mode = 0644, |
| 623 | .proc_handler = &proc_dointvec, |
| 624 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
| 626 | .ctl_name = KERN_PRINTK_RATELIMIT, |
| 627 | .procname = "printk_ratelimit", |
Dave Young | 717115e | 2008-07-25 01:45:58 -0700 | [diff] [blame] | 628 | .data = &printk_ratelimit_state.interval, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | .maxlen = sizeof(int), |
| 630 | .mode = 0644, |
| 631 | .proc_handler = &proc_dointvec_jiffies, |
| 632 | .strategy = &sysctl_jiffies, |
| 633 | }, |
| 634 | { |
| 635 | .ctl_name = KERN_PRINTK_RATELIMIT_BURST, |
| 636 | .procname = "printk_ratelimit_burst", |
Dave Young | 717115e | 2008-07-25 01:45:58 -0700 | [diff] [blame] | 637 | .data = &printk_ratelimit_state.burst, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | .maxlen = sizeof(int), |
| 639 | .mode = 0644, |
| 640 | .proc_handler = &proc_dointvec, |
| 641 | }, |
Joe Perches | 7ef3d2f | 2008-02-08 04:21:25 -0800 | [diff] [blame] | 642 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
| 644 | .ctl_name = KERN_NGROUPS_MAX, |
| 645 | .procname = "ngroups_max", |
| 646 | .data = &ngroups_max, |
| 647 | .maxlen = sizeof (int), |
| 648 | .mode = 0444, |
| 649 | .proc_handler = &proc_dointvec, |
| 650 | }, |
| 651 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) |
| 652 | { |
| 653 | .ctl_name = KERN_UNKNOWN_NMI_PANIC, |
| 654 | .procname = "unknown_nmi_panic", |
| 655 | .data = &unknown_nmi_panic, |
| 656 | .maxlen = sizeof (int), |
| 657 | .mode = 0644, |
Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 658 | .proc_handler = &proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | }, |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 660 | { |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 661 | .procname = "nmi_watchdog", |
| 662 | .data = &nmi_watchdog_enabled, |
| 663 | .maxlen = sizeof (int), |
| 664 | .mode = 0644, |
| 665 | .proc_handler = &proc_nmi_enabled, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | }, |
| 667 | #endif |
| 668 | #if defined(CONFIG_X86) |
| 669 | { |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 670 | .ctl_name = KERN_PANIC_ON_NMI, |
| 671 | .procname = "panic_on_unrecovered_nmi", |
| 672 | .data = &panic_on_unrecovered_nmi, |
| 673 | .maxlen = sizeof(int), |
| 674 | .mode = 0644, |
| 675 | .proc_handler = &proc_dointvec, |
| 676 | }, |
| 677 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | .ctl_name = KERN_BOOTLOADER_TYPE, |
| 679 | .procname = "bootloader_type", |
| 680 | .data = &bootloader_type, |
| 681 | .maxlen = sizeof (int), |
| 682 | .mode = 0444, |
| 683 | .proc_handler = &proc_dointvec, |
| 684 | }, |
Chuck Ebbert | 0741f4d | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 685 | { |
| 686 | .ctl_name = CTL_UNNUMBERED, |
| 687 | .procname = "kstack_depth_to_print", |
| 688 | .data = &kstack_depth_to_print, |
| 689 | .maxlen = sizeof(int), |
| 690 | .mode = 0644, |
| 691 | .proc_handler = &proc_dointvec, |
| 692 | }, |
Ingo Molnar | 6e7c402 | 2008-01-30 13:30:05 +0100 | [diff] [blame] | 693 | { |
| 694 | .ctl_name = CTL_UNNUMBERED, |
| 695 | .procname = "io_delay_type", |
| 696 | .data = &io_delay_type, |
| 697 | .maxlen = sizeof(int), |
| 698 | .mode = 0644, |
| 699 | .proc_handler = &proc_dointvec, |
| 700 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | #endif |
Luke Yang | 7a9166e | 2006-02-20 18:28:07 -0800 | [diff] [blame] | 702 | #if defined(CONFIG_MMU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
| 704 | .ctl_name = KERN_RANDOMIZE, |
| 705 | .procname = "randomize_va_space", |
| 706 | .data = &randomize_va_space, |
| 707 | .maxlen = sizeof(int), |
| 708 | .mode = 0644, |
| 709 | .proc_handler = &proc_dointvec, |
| 710 | }, |
Luke Yang | 7a9166e | 2006-02-20 18:28:07 -0800 | [diff] [blame] | 711 | #endif |
Martin Schwidefsky | 0152fb3 | 2006-01-14 13:21:00 -0800 | [diff] [blame] | 712 | #if defined(CONFIG_S390) && defined(CONFIG_SMP) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 713 | { |
| 714 | .ctl_name = KERN_SPIN_RETRY, |
| 715 | .procname = "spin_retry", |
| 716 | .data = &spin_retry, |
| 717 | .maxlen = sizeof (int), |
| 718 | .mode = 0644, |
| 719 | .proc_handler = &proc_dointvec, |
| 720 | }, |
| 721 | #endif |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 722 | #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) |
Pavel Machek | c255d84 | 2006-02-20 18:27:58 -0800 | [diff] [blame] | 723 | { |
Pavel Machek | c255d84 | 2006-02-20 18:27:58 -0800 | [diff] [blame] | 724 | .procname = "acpi_video_flags", |
Pavel Machek | 77afcf7 | 2007-07-19 01:47:41 -0700 | [diff] [blame] | 725 | .data = &acpi_realmode_flags, |
Pavel Machek | c255d84 | 2006-02-20 18:27:58 -0800 | [diff] [blame] | 726 | .maxlen = sizeof (unsigned long), |
| 727 | .mode = 0644, |
Stefan Seyfried | 7f99f06 | 2006-03-02 02:54:34 -0800 | [diff] [blame] | 728 | .proc_handler = &proc_doulongvec_minmax, |
Pavel Machek | c255d84 | 2006-02-20 18:27:58 -0800 | [diff] [blame] | 729 | }, |
| 730 | #endif |
Jes Sorensen | d2b176e | 2006-02-28 09:42:23 -0800 | [diff] [blame] | 731 | #ifdef CONFIG_IA64 |
| 732 | { |
| 733 | .ctl_name = KERN_IA64_UNALIGNED, |
| 734 | .procname = "ignore-unaligned-usertrap", |
| 735 | .data = &no_unaligned_warning, |
| 736 | .maxlen = sizeof (int), |
| 737 | .mode = 0644, |
| 738 | .proc_handler = &proc_dointvec, |
| 739 | }, |
| 740 | #endif |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 741 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
| 742 | { |
| 743 | .ctl_name = CTL_UNNUMBERED, |
Ingo Molnar | 9c44bc0 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 744 | .procname = "softlockup_panic", |
| 745 | .data = &softlockup_panic, |
| 746 | .maxlen = sizeof(int), |
| 747 | .mode = 0644, |
Hiroshi Shimamoto | 4dca10a | 2008-07-07 18:37:04 -0700 | [diff] [blame] | 748 | .proc_handler = &proc_dointvec_minmax, |
Ingo Molnar | 9c44bc0 | 2008-05-12 21:21:04 +0200 | [diff] [blame] | 749 | .strategy = &sysctl_intvec, |
| 750 | .extra1 = &zero, |
| 751 | .extra2 = &one, |
| 752 | }, |
| 753 | { |
| 754 | .ctl_name = CTL_UNNUMBERED, |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 755 | .procname = "softlockup_thresh", |
| 756 | .data = &softlockup_thresh, |
Dimitri Sivanich | 9383d96 | 2008-05-12 21:21:14 +0200 | [diff] [blame] | 757 | .maxlen = sizeof(int), |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 758 | .mode = 0644, |
Dimitri Sivanich | 9383d96 | 2008-05-12 21:21:14 +0200 | [diff] [blame] | 759 | .proc_handler = &proc_dointvec_minmax, |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 760 | .strategy = &sysctl_intvec, |
Dimitri Sivanich | 9383d96 | 2008-05-12 21:21:14 +0200 | [diff] [blame] | 761 | .extra1 = &neg_one, |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 762 | .extra2 = &sixty, |
| 763 | }, |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 764 | { |
| 765 | .ctl_name = CTL_UNNUMBERED, |
| 766 | .procname = "hung_task_check_count", |
| 767 | .data = &sysctl_hung_task_check_count, |
Ingo Molnar | 9073908 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 768 | .maxlen = sizeof(unsigned long), |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 769 | .mode = 0644, |
Ingo Molnar | 9073908 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 770 | .proc_handler = &proc_doulongvec_minmax, |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 771 | .strategy = &sysctl_intvec, |
| 772 | }, |
| 773 | { |
| 774 | .ctl_name = CTL_UNNUMBERED, |
| 775 | .procname = "hung_task_timeout_secs", |
| 776 | .data = &sysctl_hung_task_timeout_secs, |
Ingo Molnar | 9073908 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 777 | .maxlen = sizeof(unsigned long), |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 778 | .mode = 0644, |
Ingo Molnar | 9073908 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 779 | .proc_handler = &proc_doulongvec_minmax, |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 780 | .strategy = &sysctl_intvec, |
| 781 | }, |
| 782 | { |
| 783 | .ctl_name = CTL_UNNUMBERED, |
| 784 | .procname = "hung_task_warnings", |
| 785 | .data = &sysctl_hung_task_warnings, |
Ingo Molnar | 9073908 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 786 | .maxlen = sizeof(unsigned long), |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 787 | .mode = 0644, |
Ingo Molnar | 9073908 | 2008-01-25 21:08:34 +0100 | [diff] [blame] | 788 | .proc_handler = &proc_doulongvec_minmax, |
Ingo Molnar | 82a1fcb | 2008-01-25 21:08:02 +0100 | [diff] [blame] | 789 | .strategy = &sysctl_intvec, |
| 790 | }, |
Ravikiran G Thirumalai | c4f3b63 | 2007-10-16 23:26:09 -0700 | [diff] [blame] | 791 | #endif |
Andi Kleen | bebfa10 | 2006-06-26 13:56:52 +0200 | [diff] [blame] | 792 | #ifdef CONFIG_COMPAT |
| 793 | { |
| 794 | .ctl_name = KERN_COMPAT_LOG, |
| 795 | .procname = "compat-log", |
| 796 | .data = &compat_log, |
| 797 | .maxlen = sizeof (int), |
| 798 | .mode = 0644, |
| 799 | .proc_handler = &proc_dointvec, |
| 800 | }, |
| 801 | #endif |
Ingo Molnar | 23f78d4 | 2006-06-27 02:54:53 -0700 | [diff] [blame] | 802 | #ifdef CONFIG_RT_MUTEXES |
| 803 | { |
| 804 | .ctl_name = KERN_MAX_LOCK_DEPTH, |
| 805 | .procname = "max_lock_depth", |
| 806 | .data = &max_lock_depth, |
| 807 | .maxlen = sizeof(int), |
| 808 | .mode = 0644, |
| 809 | .proc_handler = &proc_dointvec, |
| 810 | }, |
| 811 | #endif |
Kees Cook | 5096add | 2007-05-08 00:26:04 -0700 | [diff] [blame] | 812 | #ifdef CONFIG_PROC_FS |
| 813 | { |
| 814 | .ctl_name = CTL_UNNUMBERED, |
| 815 | .procname = "maps_protect", |
| 816 | .data = &maps_protect, |
| 817 | .maxlen = sizeof(int), |
| 818 | .mode = 0644, |
| 819 | .proc_handler = &proc_dointvec, |
| 820 | }, |
| 821 | #endif |
Jeremy Fitzhardinge | 10a0a8d | 2007-07-17 18:37:02 -0700 | [diff] [blame] | 822 | { |
| 823 | .ctl_name = CTL_UNNUMBERED, |
| 824 | .procname = "poweroff_cmd", |
| 825 | .data = &poweroff_cmd, |
| 826 | .maxlen = POWEROFF_CMD_PATH_LEN, |
| 827 | .mode = 0644, |
| 828 | .proc_handler = &proc_dostring, |
| 829 | .strategy = &sysctl_string, |
| 830 | }, |
David Howells | 0b77f5b | 2008-04-29 01:01:32 -0700 | [diff] [blame] | 831 | #ifdef CONFIG_KEYS |
| 832 | { |
| 833 | .ctl_name = CTL_UNNUMBERED, |
| 834 | .procname = "keys", |
| 835 | .mode = 0555, |
| 836 | .child = key_sysctls, |
| 837 | }, |
| 838 | #endif |
Paul E. McKenney | 31a72bc | 2008-06-18 09:26:49 -0700 | [diff] [blame] | 839 | #ifdef CONFIG_RCU_TORTURE_TEST |
| 840 | { |
| 841 | .ctl_name = CTL_UNNUMBERED, |
| 842 | .procname = "rcutorture_runnable", |
| 843 | .data = &rcutorture_runnable, |
| 844 | .maxlen = sizeof(int), |
| 845 | .mode = 0644, |
| 846 | .proc_handler = &proc_dointvec, |
| 847 | }, |
| 848 | #endif |
Andrew Morton | ed2c12f | 2007-07-19 01:50:35 -0700 | [diff] [blame] | 849 | /* |
| 850 | * NOTE: do not add new entries to this table unless you have read |
| 851 | * Documentation/sysctl/ctl_unnumbered.txt |
| 852 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { .ctl_name = 0 } |
| 854 | }; |
| 855 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 856 | static struct ctl_table vm_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | { |
| 858 | .ctl_name = VM_OVERCOMMIT_MEMORY, |
| 859 | .procname = "overcommit_memory", |
| 860 | .data = &sysctl_overcommit_memory, |
| 861 | .maxlen = sizeof(sysctl_overcommit_memory), |
| 862 | .mode = 0644, |
| 863 | .proc_handler = &proc_dointvec, |
| 864 | }, |
| 865 | { |
KAMEZAWA Hiroyuki | fadd8fb | 2006-06-23 02:03:13 -0700 | [diff] [blame] | 866 | .ctl_name = VM_PANIC_ON_OOM, |
| 867 | .procname = "panic_on_oom", |
| 868 | .data = &sysctl_panic_on_oom, |
| 869 | .maxlen = sizeof(sysctl_panic_on_oom), |
| 870 | .mode = 0644, |
| 871 | .proc_handler = &proc_dointvec, |
| 872 | }, |
| 873 | { |
David Rientjes | fe071d7 | 2007-10-16 23:25:56 -0700 | [diff] [blame] | 874 | .ctl_name = CTL_UNNUMBERED, |
| 875 | .procname = "oom_kill_allocating_task", |
| 876 | .data = &sysctl_oom_kill_allocating_task, |
| 877 | .maxlen = sizeof(sysctl_oom_kill_allocating_task), |
| 878 | .mode = 0644, |
| 879 | .proc_handler = &proc_dointvec, |
| 880 | }, |
| 881 | { |
David Rientjes | fef1bdd | 2008-02-07 00:14:07 -0800 | [diff] [blame] | 882 | .ctl_name = CTL_UNNUMBERED, |
| 883 | .procname = "oom_dump_tasks", |
| 884 | .data = &sysctl_oom_dump_tasks, |
| 885 | .maxlen = sizeof(sysctl_oom_dump_tasks), |
| 886 | .mode = 0644, |
| 887 | .proc_handler = &proc_dointvec, |
| 888 | }, |
| 889 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | .ctl_name = VM_OVERCOMMIT_RATIO, |
| 891 | .procname = "overcommit_ratio", |
| 892 | .data = &sysctl_overcommit_ratio, |
| 893 | .maxlen = sizeof(sysctl_overcommit_ratio), |
| 894 | .mode = 0644, |
| 895 | .proc_handler = &proc_dointvec, |
| 896 | }, |
| 897 | { |
| 898 | .ctl_name = VM_PAGE_CLUSTER, |
| 899 | .procname = "page-cluster", |
| 900 | .data = &page_cluster, |
| 901 | .maxlen = sizeof(int), |
| 902 | .mode = 0644, |
| 903 | .proc_handler = &proc_dointvec, |
| 904 | }, |
| 905 | { |
| 906 | .ctl_name = VM_DIRTY_BACKGROUND, |
| 907 | .procname = "dirty_background_ratio", |
| 908 | .data = &dirty_background_ratio, |
| 909 | .maxlen = sizeof(dirty_background_ratio), |
| 910 | .mode = 0644, |
| 911 | .proc_handler = &proc_dointvec_minmax, |
| 912 | .strategy = &sysctl_intvec, |
| 913 | .extra1 = &zero, |
| 914 | .extra2 = &one_hundred, |
| 915 | }, |
| 916 | { |
| 917 | .ctl_name = VM_DIRTY_RATIO, |
| 918 | .procname = "dirty_ratio", |
| 919 | .data = &vm_dirty_ratio, |
| 920 | .maxlen = sizeof(vm_dirty_ratio), |
| 921 | .mode = 0644, |
Peter Zijlstra | 04fbfdc | 2007-10-16 23:25:50 -0700 | [diff] [blame] | 922 | .proc_handler = &dirty_ratio_handler, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | .strategy = &sysctl_intvec, |
| 924 | .extra1 = &zero, |
| 925 | .extra2 = &one_hundred, |
| 926 | }, |
| 927 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | .procname = "dirty_writeback_centisecs", |
Bart Samwel | f6ef943 | 2006-03-24 03:15:48 -0800 | [diff] [blame] | 929 | .data = &dirty_writeback_interval, |
| 930 | .maxlen = sizeof(dirty_writeback_interval), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | .mode = 0644, |
| 932 | .proc_handler = &dirty_writeback_centisecs_handler, |
| 933 | }, |
| 934 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | .procname = "dirty_expire_centisecs", |
Bart Samwel | f6ef943 | 2006-03-24 03:15:48 -0800 | [diff] [blame] | 936 | .data = &dirty_expire_interval, |
| 937 | .maxlen = sizeof(dirty_expire_interval), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | .mode = 0644, |
Bart Samwel | f6ef943 | 2006-03-24 03:15:48 -0800 | [diff] [blame] | 939 | .proc_handler = &proc_dointvec_userhz_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | }, |
| 941 | { |
| 942 | .ctl_name = VM_NR_PDFLUSH_THREADS, |
| 943 | .procname = "nr_pdflush_threads", |
| 944 | .data = &nr_pdflush_threads, |
| 945 | .maxlen = sizeof nr_pdflush_threads, |
| 946 | .mode = 0444 /* read-only*/, |
| 947 | .proc_handler = &proc_dointvec, |
| 948 | }, |
| 949 | { |
| 950 | .ctl_name = VM_SWAPPINESS, |
| 951 | .procname = "swappiness", |
| 952 | .data = &vm_swappiness, |
| 953 | .maxlen = sizeof(vm_swappiness), |
| 954 | .mode = 0644, |
| 955 | .proc_handler = &proc_dointvec_minmax, |
| 956 | .strategy = &sysctl_intvec, |
| 957 | .extra1 = &zero, |
| 958 | .extra2 = &one_hundred, |
| 959 | }, |
| 960 | #ifdef CONFIG_HUGETLB_PAGE |
| 961 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | .procname = "nr_hugepages", |
Andi Kleen | e5ff215 | 2008-07-23 21:27:42 -0700 | [diff] [blame] | 963 | .data = NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | .maxlen = sizeof(unsigned long), |
| 965 | .mode = 0644, |
| 966 | .proc_handler = &hugetlb_sysctl_handler, |
| 967 | .extra1 = (void *)&hugetlb_zero, |
| 968 | .extra2 = (void *)&hugetlb_infinity, |
| 969 | }, |
| 970 | { |
| 971 | .ctl_name = VM_HUGETLB_GROUP, |
| 972 | .procname = "hugetlb_shm_group", |
| 973 | .data = &sysctl_hugetlb_shm_group, |
| 974 | .maxlen = sizeof(gid_t), |
| 975 | .mode = 0644, |
| 976 | .proc_handler = &proc_dointvec, |
| 977 | }, |
Mel Gorman | 396faf0 | 2007-07-17 04:03:13 -0700 | [diff] [blame] | 978 | { |
| 979 | .ctl_name = CTL_UNNUMBERED, |
| 980 | .procname = "hugepages_treat_as_movable", |
| 981 | .data = &hugepages_treat_as_movable, |
| 982 | .maxlen = sizeof(int), |
| 983 | .mode = 0644, |
| 984 | .proc_handler = &hugetlb_treat_movable_handler, |
| 985 | }, |
Adam Litke | 54f9f80 | 2007-10-16 01:26:20 -0700 | [diff] [blame] | 986 | { |
| 987 | .ctl_name = CTL_UNNUMBERED, |
Nishanth Aravamudan | d1c3fb1 | 2007-12-17 16:20:12 -0800 | [diff] [blame] | 988 | .procname = "nr_overcommit_hugepages", |
Andi Kleen | e5ff215 | 2008-07-23 21:27:42 -0700 | [diff] [blame] | 989 | .data = NULL, |
| 990 | .maxlen = sizeof(unsigned long), |
Nishanth Aravamudan | d1c3fb1 | 2007-12-17 16:20:12 -0800 | [diff] [blame] | 991 | .mode = 0644, |
Nishanth Aravamudan | a3d0c6a | 2008-02-08 04:18:18 -0800 | [diff] [blame] | 992 | .proc_handler = &hugetlb_overcommit_handler, |
Andi Kleen | e5ff215 | 2008-07-23 21:27:42 -0700 | [diff] [blame] | 993 | .extra1 = (void *)&hugetlb_zero, |
| 994 | .extra2 = (void *)&hugetlb_infinity, |
Nishanth Aravamudan | d1c3fb1 | 2007-12-17 16:20:12 -0800 | [diff] [blame] | 995 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | #endif |
| 997 | { |
| 998 | .ctl_name = VM_LOWMEM_RESERVE_RATIO, |
| 999 | .procname = "lowmem_reserve_ratio", |
| 1000 | .data = &sysctl_lowmem_reserve_ratio, |
| 1001 | .maxlen = sizeof(sysctl_lowmem_reserve_ratio), |
| 1002 | .mode = 0644, |
| 1003 | .proc_handler = &lowmem_reserve_ratio_sysctl_handler, |
| 1004 | .strategy = &sysctl_intvec, |
| 1005 | }, |
| 1006 | { |
Andrew Morton | 9d0243b | 2006-01-08 01:00:39 -0800 | [diff] [blame] | 1007 | .ctl_name = VM_DROP_PAGECACHE, |
| 1008 | .procname = "drop_caches", |
| 1009 | .data = &sysctl_drop_caches, |
| 1010 | .maxlen = sizeof(int), |
| 1011 | .mode = 0644, |
| 1012 | .proc_handler = drop_caches_sysctl_handler, |
| 1013 | .strategy = &sysctl_intvec, |
| 1014 | }, |
| 1015 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | .ctl_name = VM_MIN_FREE_KBYTES, |
| 1017 | .procname = "min_free_kbytes", |
| 1018 | .data = &min_free_kbytes, |
| 1019 | .maxlen = sizeof(min_free_kbytes), |
| 1020 | .mode = 0644, |
| 1021 | .proc_handler = &min_free_kbytes_sysctl_handler, |
| 1022 | .strategy = &sysctl_intvec, |
| 1023 | .extra1 = &zero, |
| 1024 | }, |
Rohit Seth | 8ad4b1f | 2006-01-08 01:00:40 -0800 | [diff] [blame] | 1025 | { |
| 1026 | .ctl_name = VM_PERCPU_PAGELIST_FRACTION, |
| 1027 | .procname = "percpu_pagelist_fraction", |
| 1028 | .data = &percpu_pagelist_fraction, |
| 1029 | .maxlen = sizeof(percpu_pagelist_fraction), |
| 1030 | .mode = 0644, |
| 1031 | .proc_handler = &percpu_pagelist_fraction_sysctl_handler, |
| 1032 | .strategy = &sysctl_intvec, |
| 1033 | .extra1 = &min_percpu_pagelist_fract, |
| 1034 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | #ifdef CONFIG_MMU |
| 1036 | { |
| 1037 | .ctl_name = VM_MAX_MAP_COUNT, |
| 1038 | .procname = "max_map_count", |
| 1039 | .data = &sysctl_max_map_count, |
| 1040 | .maxlen = sizeof(sysctl_max_map_count), |
| 1041 | .mode = 0644, |
| 1042 | .proc_handler = &proc_dointvec |
| 1043 | }, |
| 1044 | #endif |
| 1045 | { |
| 1046 | .ctl_name = VM_LAPTOP_MODE, |
| 1047 | .procname = "laptop_mode", |
| 1048 | .data = &laptop_mode, |
| 1049 | .maxlen = sizeof(laptop_mode), |
| 1050 | .mode = 0644, |
Bart Samwel | ed5b43f | 2006-03-24 03:15:49 -0800 | [diff] [blame] | 1051 | .proc_handler = &proc_dointvec_jiffies, |
| 1052 | .strategy = &sysctl_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | }, |
| 1054 | { |
| 1055 | .ctl_name = VM_BLOCK_DUMP, |
| 1056 | .procname = "block_dump", |
| 1057 | .data = &block_dump, |
| 1058 | .maxlen = sizeof(block_dump), |
| 1059 | .mode = 0644, |
| 1060 | .proc_handler = &proc_dointvec, |
| 1061 | .strategy = &sysctl_intvec, |
| 1062 | .extra1 = &zero, |
| 1063 | }, |
| 1064 | { |
| 1065 | .ctl_name = VM_VFS_CACHE_PRESSURE, |
| 1066 | .procname = "vfs_cache_pressure", |
| 1067 | .data = &sysctl_vfs_cache_pressure, |
| 1068 | .maxlen = sizeof(sysctl_vfs_cache_pressure), |
| 1069 | .mode = 0644, |
| 1070 | .proc_handler = &proc_dointvec, |
| 1071 | .strategy = &sysctl_intvec, |
| 1072 | .extra1 = &zero, |
| 1073 | }, |
| 1074 | #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT |
| 1075 | { |
| 1076 | .ctl_name = VM_LEGACY_VA_LAYOUT, |
| 1077 | .procname = "legacy_va_layout", |
| 1078 | .data = &sysctl_legacy_va_layout, |
| 1079 | .maxlen = sizeof(sysctl_legacy_va_layout), |
| 1080 | .mode = 0644, |
| 1081 | .proc_handler = &proc_dointvec, |
| 1082 | .strategy = &sysctl_intvec, |
| 1083 | .extra1 = &zero, |
| 1084 | }, |
| 1085 | #endif |
Christoph Lameter | 1743660 | 2006-01-18 17:42:32 -0800 | [diff] [blame] | 1086 | #ifdef CONFIG_NUMA |
| 1087 | { |
| 1088 | .ctl_name = VM_ZONE_RECLAIM_MODE, |
| 1089 | .procname = "zone_reclaim_mode", |
| 1090 | .data = &zone_reclaim_mode, |
| 1091 | .maxlen = sizeof(zone_reclaim_mode), |
| 1092 | .mode = 0644, |
| 1093 | .proc_handler = &proc_dointvec, |
Christoph Lameter | c84db23 | 2006-02-01 03:05:29 -0800 | [diff] [blame] | 1094 | .strategy = &sysctl_intvec, |
| 1095 | .extra1 = &zero, |
Christoph Lameter | 1743660 | 2006-01-18 17:42:32 -0800 | [diff] [blame] | 1096 | }, |
Christoph Lameter | 9614634 | 2006-07-03 00:24:13 -0700 | [diff] [blame] | 1097 | { |
| 1098 | .ctl_name = VM_MIN_UNMAPPED, |
| 1099 | .procname = "min_unmapped_ratio", |
| 1100 | .data = &sysctl_min_unmapped_ratio, |
| 1101 | .maxlen = sizeof(sysctl_min_unmapped_ratio), |
| 1102 | .mode = 0644, |
| 1103 | .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler, |
| 1104 | .strategy = &sysctl_intvec, |
| 1105 | .extra1 = &zero, |
| 1106 | .extra2 = &one_hundred, |
| 1107 | }, |
Christoph Lameter | 0ff3849 | 2006-09-25 23:31:52 -0700 | [diff] [blame] | 1108 | { |
| 1109 | .ctl_name = VM_MIN_SLAB, |
| 1110 | .procname = "min_slab_ratio", |
| 1111 | .data = &sysctl_min_slab_ratio, |
| 1112 | .maxlen = sizeof(sysctl_min_slab_ratio), |
| 1113 | .mode = 0644, |
| 1114 | .proc_handler = &sysctl_min_slab_ratio_sysctl_handler, |
| 1115 | .strategy = &sysctl_intvec, |
| 1116 | .extra1 = &zero, |
| 1117 | .extra2 = &one_hundred, |
| 1118 | }, |
Christoph Lameter | 1743660 | 2006-01-18 17:42:32 -0800 | [diff] [blame] | 1119 | #endif |
Christoph Lameter | 77461ab | 2007-05-09 02:35:13 -0700 | [diff] [blame] | 1120 | #ifdef CONFIG_SMP |
| 1121 | { |
| 1122 | .ctl_name = CTL_UNNUMBERED, |
| 1123 | .procname = "stat_interval", |
| 1124 | .data = &sysctl_stat_interval, |
| 1125 | .maxlen = sizeof(sysctl_stat_interval), |
| 1126 | .mode = 0644, |
| 1127 | .proc_handler = &proc_dointvec_jiffies, |
| 1128 | .strategy = &sysctl_jiffies, |
| 1129 | }, |
| 1130 | #endif |
Eric Paris | ed03218 | 2007-06-28 15:55:21 -0400 | [diff] [blame] | 1131 | #ifdef CONFIG_SECURITY |
| 1132 | { |
| 1133 | .ctl_name = CTL_UNNUMBERED, |
| 1134 | .procname = "mmap_min_addr", |
| 1135 | .data = &mmap_min_addr, |
| 1136 | .maxlen = sizeof(unsigned long), |
| 1137 | .mode = 0644, |
| 1138 | .proc_handler = &proc_doulongvec_minmax, |
| 1139 | }, |
Lee Schermerhorn | 8daec96 | 2007-08-10 13:00:51 -0700 | [diff] [blame] | 1140 | #endif |
KAMEZAWA Hiroyuki | f0c0b2b | 2007-07-15 23:38:01 -0700 | [diff] [blame] | 1141 | #ifdef CONFIG_NUMA |
| 1142 | { |
| 1143 | .ctl_name = CTL_UNNUMBERED, |
| 1144 | .procname = "numa_zonelist_order", |
| 1145 | .data = &numa_zonelist_order, |
| 1146 | .maxlen = NUMA_ZONELIST_ORDER_LEN, |
| 1147 | .mode = 0644, |
| 1148 | .proc_handler = &numa_zonelist_order_handler, |
| 1149 | .strategy = &sysctl_string, |
| 1150 | }, |
| 1151 | #endif |
Al Viro | 2b8232c | 2007-10-13 08:16:04 +0100 | [diff] [blame] | 1152 | #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ |
Paul Mundt | 5c36e65 | 2007-03-01 10:07:42 +0900 | [diff] [blame] | 1153 | (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 1154 | { |
| 1155 | .ctl_name = VM_VDSO_ENABLED, |
| 1156 | .procname = "vdso_enabled", |
| 1157 | .data = &vdso_enabled, |
| 1158 | .maxlen = sizeof(vdso_enabled), |
| 1159 | .mode = 0644, |
| 1160 | .proc_handler = &proc_dointvec, |
| 1161 | .strategy = &sysctl_intvec, |
| 1162 | .extra1 = &zero, |
| 1163 | }, |
| 1164 | #endif |
Bron Gondwana | 195cf45 | 2008-02-04 22:29:20 -0800 | [diff] [blame] | 1165 | #ifdef CONFIG_HIGHMEM |
| 1166 | { |
| 1167 | .ctl_name = CTL_UNNUMBERED, |
| 1168 | .procname = "highmem_is_dirtyable", |
| 1169 | .data = &vm_highmem_is_dirtyable, |
| 1170 | .maxlen = sizeof(vm_highmem_is_dirtyable), |
| 1171 | .mode = 0644, |
| 1172 | .proc_handler = &proc_dointvec_minmax, |
| 1173 | .strategy = &sysctl_intvec, |
| 1174 | .extra1 = &zero, |
| 1175 | .extra2 = &one, |
| 1176 | }, |
| 1177 | #endif |
Andrew Morton | 2be7fe0 | 2007-07-15 23:41:21 -0700 | [diff] [blame] | 1178 | /* |
| 1179 | * NOTE: do not add new entries to this table unless you have read |
| 1180 | * Documentation/sysctl/ctl_unnumbered.txt |
| 1181 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | { .ctl_name = 0 } |
| 1183 | }; |
| 1184 | |
Eric W. Biederman | 2abc26f | 2007-02-14 00:34:07 -0800 | [diff] [blame] | 1185 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1186 | static struct ctl_table binfmt_misc_table[] = { |
Eric W. Biederman | 2abc26f | 2007-02-14 00:34:07 -0800 | [diff] [blame] | 1187 | { .ctl_name = 0 } |
| 1188 | }; |
| 1189 | #endif |
| 1190 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1191 | static struct ctl_table fs_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | { |
| 1193 | .ctl_name = FS_NRINODE, |
| 1194 | .procname = "inode-nr", |
| 1195 | .data = &inodes_stat, |
| 1196 | .maxlen = 2*sizeof(int), |
| 1197 | .mode = 0444, |
| 1198 | .proc_handler = &proc_dointvec, |
| 1199 | }, |
| 1200 | { |
| 1201 | .ctl_name = FS_STATINODE, |
| 1202 | .procname = "inode-state", |
| 1203 | .data = &inodes_stat, |
| 1204 | .maxlen = 7*sizeof(int), |
| 1205 | .mode = 0444, |
| 1206 | .proc_handler = &proc_dointvec, |
| 1207 | }, |
| 1208 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | .procname = "file-nr", |
| 1210 | .data = &files_stat, |
| 1211 | .maxlen = 3*sizeof(int), |
| 1212 | .mode = 0444, |
Dipankar Sarma | 529bf6b | 2006-03-07 21:55:35 -0800 | [diff] [blame] | 1213 | .proc_handler = &proc_nr_files, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | }, |
| 1215 | { |
| 1216 | .ctl_name = FS_MAXFILE, |
| 1217 | .procname = "file-max", |
| 1218 | .data = &files_stat.max_files, |
| 1219 | .maxlen = sizeof(int), |
| 1220 | .mode = 0644, |
| 1221 | .proc_handler = &proc_dointvec, |
| 1222 | }, |
| 1223 | { |
Eric Dumazet | 9cfe015 | 2008-02-06 01:37:16 -0800 | [diff] [blame] | 1224 | .ctl_name = CTL_UNNUMBERED, |
| 1225 | .procname = "nr_open", |
| 1226 | .data = &sysctl_nr_open, |
| 1227 | .maxlen = sizeof(int), |
| 1228 | .mode = 0644, |
Al Viro | eceea0b | 2008-05-10 10:08:32 -0400 | [diff] [blame] | 1229 | .proc_handler = &proc_dointvec_minmax, |
| 1230 | .extra1 = &sysctl_nr_open_min, |
| 1231 | .extra2 = &sysctl_nr_open_max, |
Eric Dumazet | 9cfe015 | 2008-02-06 01:37:16 -0800 | [diff] [blame] | 1232 | }, |
| 1233 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | .ctl_name = FS_DENTRY, |
| 1235 | .procname = "dentry-state", |
| 1236 | .data = &dentry_stat, |
| 1237 | .maxlen = 6*sizeof(int), |
| 1238 | .mode = 0444, |
| 1239 | .proc_handler = &proc_dointvec, |
| 1240 | }, |
| 1241 | { |
| 1242 | .ctl_name = FS_OVERFLOWUID, |
| 1243 | .procname = "overflowuid", |
| 1244 | .data = &fs_overflowuid, |
| 1245 | .maxlen = sizeof(int), |
| 1246 | .mode = 0644, |
| 1247 | .proc_handler = &proc_dointvec_minmax, |
| 1248 | .strategy = &sysctl_intvec, |
| 1249 | .extra1 = &minolduid, |
| 1250 | .extra2 = &maxolduid, |
| 1251 | }, |
| 1252 | { |
| 1253 | .ctl_name = FS_OVERFLOWGID, |
| 1254 | .procname = "overflowgid", |
| 1255 | .data = &fs_overflowgid, |
| 1256 | .maxlen = sizeof(int), |
| 1257 | .mode = 0644, |
| 1258 | .proc_handler = &proc_dointvec_minmax, |
| 1259 | .strategy = &sysctl_intvec, |
| 1260 | .extra1 = &minolduid, |
| 1261 | .extra2 = &maxolduid, |
| 1262 | }, |
| 1263 | { |
| 1264 | .ctl_name = FS_LEASES, |
| 1265 | .procname = "leases-enable", |
| 1266 | .data = &leases_enable, |
| 1267 | .maxlen = sizeof(int), |
| 1268 | .mode = 0644, |
| 1269 | .proc_handler = &proc_dointvec, |
| 1270 | }, |
| 1271 | #ifdef CONFIG_DNOTIFY |
| 1272 | { |
| 1273 | .ctl_name = FS_DIR_NOTIFY, |
| 1274 | .procname = "dir-notify-enable", |
| 1275 | .data = &dir_notify_enable, |
| 1276 | .maxlen = sizeof(int), |
| 1277 | .mode = 0644, |
| 1278 | .proc_handler = &proc_dointvec, |
| 1279 | }, |
| 1280 | #endif |
| 1281 | #ifdef CONFIG_MMU |
| 1282 | { |
| 1283 | .ctl_name = FS_LEASE_TIME, |
| 1284 | .procname = "lease-break-time", |
| 1285 | .data = &lease_break_time, |
| 1286 | .maxlen = sizeof(int), |
| 1287 | .mode = 0644, |
Kawai, Hidehiro | 76fdbb2 | 2007-07-19 01:48:26 -0700 | [diff] [blame] | 1288 | .proc_handler = &proc_dointvec_minmax, |
| 1289 | .strategy = &sysctl_intvec, |
| 1290 | .extra1 = &zero, |
| 1291 | .extra2 = &two, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | }, |
| 1293 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | .procname = "aio-nr", |
| 1295 | .data = &aio_nr, |
| 1296 | .maxlen = sizeof(aio_nr), |
| 1297 | .mode = 0444, |
Zach Brown | d55b5fd | 2005-11-07 00:59:31 -0800 | [diff] [blame] | 1298 | .proc_handler = &proc_doulongvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | }, |
| 1300 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | .procname = "aio-max-nr", |
| 1302 | .data = &aio_max_nr, |
| 1303 | .maxlen = sizeof(aio_max_nr), |
| 1304 | .mode = 0644, |
Zach Brown | d55b5fd | 2005-11-07 00:59:31 -0800 | [diff] [blame] | 1305 | .proc_handler = &proc_doulongvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | }, |
Amy Griffis | 2d9048e | 2006-06-01 13:10:59 -0700 | [diff] [blame] | 1307 | #ifdef CONFIG_INOTIFY_USER |
Robert Love | 0399cb0 | 2005-07-13 12:38:18 -0400 | [diff] [blame] | 1308 | { |
| 1309 | .ctl_name = FS_INOTIFY, |
| 1310 | .procname = "inotify", |
| 1311 | .mode = 0555, |
| 1312 | .child = inotify_table, |
| 1313 | }, |
| 1314 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | #endif |
Alan Cox | d6e7114 | 2005-06-23 00:09:43 -0700 | [diff] [blame] | 1316 | { |
| 1317 | .ctl_name = KERN_SETUID_DUMPABLE, |
| 1318 | .procname = "suid_dumpable", |
| 1319 | .data = &suid_dumpable, |
| 1320 | .maxlen = sizeof(int), |
| 1321 | .mode = 0644, |
| 1322 | .proc_handler = &proc_dointvec, |
| 1323 | }, |
Eric W. Biederman | 2abc26f | 2007-02-14 00:34:07 -0800 | [diff] [blame] | 1324 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
| 1325 | { |
| 1326 | .ctl_name = CTL_UNNUMBERED, |
| 1327 | .procname = "binfmt_misc", |
| 1328 | .mode = 0555, |
| 1329 | .child = binfmt_misc_table, |
| 1330 | }, |
| 1331 | #endif |
Andrew Morton | 2be7fe0 | 2007-07-15 23:41:21 -0700 | [diff] [blame] | 1332 | /* |
| 1333 | * NOTE: do not add new entries to this table unless you have read |
| 1334 | * Documentation/sysctl/ctl_unnumbered.txt |
| 1335 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | { .ctl_name = 0 } |
| 1337 | }; |
| 1338 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1339 | static struct ctl_table debug_table[] = { |
Olof Johansson | d0c3d53 | 2007-10-12 10:20:07 +1000 | [diff] [blame] | 1340 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 1341 | { |
| 1342 | .ctl_name = CTL_UNNUMBERED, |
| 1343 | .procname = "exception-trace", |
| 1344 | .data = &show_unhandled_signals, |
| 1345 | .maxlen = sizeof(int), |
| 1346 | .mode = 0644, |
| 1347 | .proc_handler = proc_dointvec |
| 1348 | }, |
| 1349 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | { .ctl_name = 0 } |
| 1351 | }; |
| 1352 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1353 | static struct ctl_table dev_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | { .ctl_name = 0 } |
Robert Love | 0eeca28 | 2005-07-12 17:06:03 -0400 | [diff] [blame] | 1355 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1357 | static DEFINE_SPINLOCK(sysctl_lock); |
| 1358 | |
| 1359 | /* called under sysctl_lock */ |
| 1360 | static int use_table(struct ctl_table_header *p) |
| 1361 | { |
| 1362 | if (unlikely(p->unregistering)) |
| 1363 | return 0; |
| 1364 | p->used++; |
| 1365 | return 1; |
| 1366 | } |
| 1367 | |
| 1368 | /* called under sysctl_lock */ |
| 1369 | static void unuse_table(struct ctl_table_header *p) |
| 1370 | { |
| 1371 | if (!--p->used) |
| 1372 | if (unlikely(p->unregistering)) |
| 1373 | complete(p->unregistering); |
| 1374 | } |
| 1375 | |
| 1376 | /* called under sysctl_lock, will reacquire if has to wait */ |
| 1377 | static void start_unregistering(struct ctl_table_header *p) |
| 1378 | { |
| 1379 | /* |
| 1380 | * if p->used is 0, nobody will ever touch that entry again; |
| 1381 | * we'll eliminate all paths to it before dropping sysctl_lock |
| 1382 | */ |
| 1383 | if (unlikely(p->used)) { |
| 1384 | struct completion wait; |
| 1385 | init_completion(&wait); |
| 1386 | p->unregistering = &wait; |
| 1387 | spin_unlock(&sysctl_lock); |
| 1388 | wait_for_completion(&wait); |
| 1389 | spin_lock(&sysctl_lock); |
| 1390 | } |
| 1391 | /* |
| 1392 | * do not remove from the list until nobody holds it; walking the |
| 1393 | * list in do_sysctl() relies on that. |
| 1394 | */ |
| 1395 | list_del_init(&p->ctl_entry); |
| 1396 | } |
| 1397 | |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1398 | void sysctl_head_finish(struct ctl_table_header *head) |
| 1399 | { |
| 1400 | if (!head) |
| 1401 | return; |
| 1402 | spin_lock(&sysctl_lock); |
| 1403 | unuse_table(head); |
| 1404 | spin_unlock(&sysctl_lock); |
| 1405 | } |
| 1406 | |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 1407 | static struct ctl_table_set * |
| 1408 | lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) |
| 1409 | { |
| 1410 | struct ctl_table_set *set = &root->default_set; |
| 1411 | if (root->lookup) |
| 1412 | set = root->lookup(root, namespaces); |
| 1413 | return set; |
| 1414 | } |
| 1415 | |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1416 | static struct list_head * |
| 1417 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1418 | { |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 1419 | struct ctl_table_set *set = lookup_header_set(root, namespaces); |
| 1420 | return &set->list; |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, |
| 1424 | struct ctl_table_header *prev) |
| 1425 | { |
| 1426 | struct ctl_table_root *root; |
| 1427 | struct list_head *header_list; |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1428 | struct ctl_table_header *head; |
| 1429 | struct list_head *tmp; |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1430 | |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1431 | spin_lock(&sysctl_lock); |
| 1432 | if (prev) { |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1433 | head = prev; |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1434 | tmp = &prev->ctl_entry; |
| 1435 | unuse_table(prev); |
| 1436 | goto next; |
| 1437 | } |
| 1438 | tmp = &root_table_header.ctl_entry; |
| 1439 | for (;;) { |
| 1440 | head = list_entry(tmp, struct ctl_table_header, ctl_entry); |
| 1441 | |
| 1442 | if (!use_table(head)) |
| 1443 | goto next; |
| 1444 | spin_unlock(&sysctl_lock); |
| 1445 | return head; |
| 1446 | next: |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1447 | root = head->root; |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1448 | tmp = tmp->next; |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1449 | header_list = lookup_header_list(root, namespaces); |
| 1450 | if (tmp != header_list) |
| 1451 | continue; |
| 1452 | |
| 1453 | do { |
| 1454 | root = list_entry(root->root_list.next, |
| 1455 | struct ctl_table_root, root_list); |
| 1456 | if (root == &sysctl_table_root) |
| 1457 | goto out; |
| 1458 | header_list = lookup_header_list(root, namespaces); |
| 1459 | } while (list_empty(header_list)); |
| 1460 | tmp = header_list->next; |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1461 | } |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1462 | out: |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1463 | spin_unlock(&sysctl_lock); |
| 1464 | return NULL; |
| 1465 | } |
| 1466 | |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1467 | struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) |
| 1468 | { |
| 1469 | return __sysctl_head_next(current->nsproxy, prev); |
| 1470 | } |
| 1471 | |
| 1472 | void register_sysctl_root(struct ctl_table_root *root) |
| 1473 | { |
| 1474 | spin_lock(&sysctl_lock); |
| 1475 | list_add_tail(&root->root_list, &sysctl_table_root.root_list); |
| 1476 | spin_unlock(&sysctl_lock); |
| 1477 | } |
| 1478 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1479 | #ifdef CONFIG_SYSCTL_SYSCALL |
Pavel Emelyanov | 2c4c715 | 2008-04-29 01:02:41 -0700 | [diff] [blame] | 1480 | /* Perform the actual read/write of a sysctl table entry. */ |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1481 | static int do_sysctl_strategy(struct ctl_table_root *root, |
| 1482 | struct ctl_table *table, |
Pavel Emelyanov | 2c4c715 | 2008-04-29 01:02:41 -0700 | [diff] [blame] | 1483 | int __user *name, int nlen, |
| 1484 | void __user *oldval, size_t __user *oldlenp, |
| 1485 | void __user *newval, size_t newlen) |
| 1486 | { |
| 1487 | int op = 0, rc; |
| 1488 | |
| 1489 | if (oldval) |
| 1490 | op |= 004; |
| 1491 | if (newval) |
| 1492 | op |= 002; |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1493 | if (sysctl_perm(root, table, op)) |
Pavel Emelyanov | 2c4c715 | 2008-04-29 01:02:41 -0700 | [diff] [blame] | 1494 | return -EPERM; |
| 1495 | |
| 1496 | if (table->strategy) { |
| 1497 | rc = table->strategy(table, name, nlen, oldval, oldlenp, |
| 1498 | newval, newlen); |
| 1499 | if (rc < 0) |
| 1500 | return rc; |
| 1501 | if (rc > 0) |
| 1502 | return 0; |
| 1503 | } |
| 1504 | |
| 1505 | /* If there is no strategy routine, or if the strategy returns |
| 1506 | * zero, proceed with automatic r/w */ |
| 1507 | if (table->data && table->maxlen) { |
| 1508 | rc = sysctl_data(table, name, nlen, oldval, oldlenp, |
| 1509 | newval, newlen); |
| 1510 | if (rc < 0) |
| 1511 | return rc; |
| 1512 | } |
| 1513 | return 0; |
| 1514 | } |
| 1515 | |
| 1516 | static int parse_table(int __user *name, int nlen, |
| 1517 | void __user *oldval, size_t __user *oldlenp, |
| 1518 | void __user *newval, size_t newlen, |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1519 | struct ctl_table_root *root, |
Pavel Emelyanov | 2c4c715 | 2008-04-29 01:02:41 -0700 | [diff] [blame] | 1520 | struct ctl_table *table) |
| 1521 | { |
| 1522 | int n; |
| 1523 | repeat: |
| 1524 | if (!nlen) |
| 1525 | return -ENOTDIR; |
| 1526 | if (get_user(n, name)) |
| 1527 | return -EFAULT; |
| 1528 | for ( ; table->ctl_name || table->procname; table++) { |
| 1529 | if (!table->ctl_name) |
| 1530 | continue; |
| 1531 | if (n == table->ctl_name) { |
| 1532 | int error; |
| 1533 | if (table->child) { |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1534 | if (sysctl_perm(root, table, 001)) |
Pavel Emelyanov | 2c4c715 | 2008-04-29 01:02:41 -0700 | [diff] [blame] | 1535 | return -EPERM; |
| 1536 | name++; |
| 1537 | nlen--; |
| 1538 | table = table->child; |
| 1539 | goto repeat; |
| 1540 | } |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1541 | error = do_sysctl_strategy(root, table, name, nlen, |
Pavel Emelyanov | 2c4c715 | 2008-04-29 01:02:41 -0700 | [diff] [blame] | 1542 | oldval, oldlenp, |
| 1543 | newval, newlen); |
| 1544 | return error; |
| 1545 | } |
| 1546 | } |
| 1547 | return -ENOTDIR; |
| 1548 | } |
| 1549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, |
| 1551 | void __user *newval, size_t newlen) |
| 1552 | { |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1553 | struct ctl_table_header *head; |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1554 | int error = -ENOTDIR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
| 1556 | if (nlen <= 0 || nlen >= CTL_MAXNAME) |
| 1557 | return -ENOTDIR; |
| 1558 | if (oldval) { |
| 1559 | int old_len; |
| 1560 | if (!oldlenp || get_user(old_len, oldlenp)) |
| 1561 | return -EFAULT; |
| 1562 | } |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1563 | |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1564 | for (head = sysctl_head_next(NULL); head; |
| 1565 | head = sysctl_head_next(head)) { |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1566 | error = parse_table(name, nlen, oldval, oldlenp, |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1567 | newval, newlen, |
| 1568 | head->root, head->ctl_table); |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1569 | if (error != -ENOTDIR) { |
| 1570 | sysctl_head_finish(head); |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1571 | break; |
Eric W. Biederman | 805b5d5 | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1572 | } |
| 1573 | } |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1574 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | asmlinkage long sys_sysctl(struct __sysctl_args __user *args) |
| 1578 | { |
| 1579 | struct __sysctl_args tmp; |
| 1580 | int error; |
| 1581 | |
| 1582 | if (copy_from_user(&tmp, args, sizeof(tmp))) |
| 1583 | return -EFAULT; |
| 1584 | |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 1585 | error = deprecated_sysctl_warning(&tmp); |
| 1586 | if (error) |
| 1587 | goto out; |
| 1588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | lock_kernel(); |
| 1590 | error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, |
| 1591 | tmp.newval, tmp.newlen); |
| 1592 | unlock_kernel(); |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 1593 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | return error; |
| 1595 | } |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1596 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | |
| 1598 | /* |
Eric W. Biederman | 1ff007e | 2007-02-14 00:34:11 -0800 | [diff] [blame] | 1599 | * sysctl_perm does NOT grant the superuser all rights automatically, because |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | * some sysctl variables are readonly even to root. |
| 1601 | */ |
| 1602 | |
| 1603 | static int test_perm(int mode, int op) |
| 1604 | { |
| 1605 | if (!current->euid) |
| 1606 | mode >>= 6; |
| 1607 | else if (in_egroup_p(0)) |
| 1608 | mode >>= 3; |
| 1609 | if ((mode & op & 0007) == op) |
| 1610 | return 0; |
| 1611 | return -EACCES; |
| 1612 | } |
| 1613 | |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1614 | int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | { |
| 1616 | int error; |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1617 | int mode; |
| 1618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | error = security_sysctl(table, op); |
| 1620 | if (error) |
| 1621 | return error; |
Pavel Emelyanov | d7321cd | 2008-04-29 01:02:44 -0700 | [diff] [blame] | 1622 | |
| 1623 | if (root->permissions) |
| 1624 | mode = root->permissions(root, current->nsproxy, table); |
| 1625 | else |
| 1626 | mode = table->mode; |
| 1627 | |
| 1628 | return test_perm(mode, op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Eric W. Biederman | d912b0c | 2007-02-14 00:34:13 -0800 | [diff] [blame] | 1631 | static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) |
| 1632 | { |
| 1633 | for (; table->ctl_name || table->procname; table++) { |
| 1634 | table->parent = parent; |
| 1635 | if (table->child) |
| 1636 | sysctl_set_parent(table, table->child); |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | static __init int sysctl_init(void) |
| 1641 | { |
| 1642 | sysctl_set_parent(NULL, root_table); |
Holger Schurig | 88f458e | 2008-04-29 01:02:36 -0700 | [diff] [blame] | 1643 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
| 1644 | { |
| 1645 | int err; |
| 1646 | err = sysctl_check_table(current->nsproxy, root_table); |
| 1647 | } |
| 1648 | #endif |
Eric W. Biederman | d912b0c | 2007-02-14 00:34:13 -0800 | [diff] [blame] | 1649 | return 0; |
| 1650 | } |
| 1651 | |
| 1652 | core_initcall(sysctl_init); |
| 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | /** |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1655 | * __register_sysctl_paths - register a sysctl hierarchy |
| 1656 | * @root: List of sysctl headers to register on |
| 1657 | * @namespaces: Data to compute which lists of sysctl entries are visible |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1658 | * @path: The path to the directory the sysctl table is in. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | * @table: the top-level table structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | * |
| 1661 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1662 | * array. A completely 0 filled entry terminates the table. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | * |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1664 | * The members of the &struct ctl_table structure are used as follows: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | * |
| 1666 | * ctl_name - This is the numeric sysctl value used by sysctl(2). The number |
| 1667 | * must be unique within that level of sysctl |
| 1668 | * |
| 1669 | * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not |
| 1670 | * enter a sysctl file |
| 1671 | * |
| 1672 | * data - a pointer to data for use by proc_handler |
| 1673 | * |
| 1674 | * maxlen - the maximum size in bytes of the data |
| 1675 | * |
| 1676 | * mode - the file permissions for the /proc/sys file, and for sysctl(2) |
| 1677 | * |
| 1678 | * child - a pointer to the child sysctl table if this entry is a directory, or |
| 1679 | * %NULL. |
| 1680 | * |
| 1681 | * proc_handler - the text handler routine (described below) |
| 1682 | * |
| 1683 | * strategy - the strategy routine (described below) |
| 1684 | * |
| 1685 | * de - for internal use by the sysctl routines |
| 1686 | * |
| 1687 | * extra1, extra2 - extra pointers usable by the proc handler routines |
| 1688 | * |
| 1689 | * Leaf nodes in the sysctl tree will be represented by a single file |
| 1690 | * under /proc; non-leaf nodes will be represented by directories. |
| 1691 | * |
| 1692 | * sysctl(2) can automatically manage read and write requests through |
| 1693 | * the sysctl table. The data and maxlen fields of the ctl_table |
| 1694 | * struct enable minimal validation of the values being written to be |
| 1695 | * performed, and the mode field allows minimal authentication. |
| 1696 | * |
| 1697 | * More sophisticated management can be enabled by the provision of a |
| 1698 | * strategy routine with the table entry. This will be called before |
| 1699 | * any automatic read or write of the data is performed. |
| 1700 | * |
| 1701 | * The strategy routine may return |
| 1702 | * |
| 1703 | * < 0 - Error occurred (error is passed to user process) |
| 1704 | * |
| 1705 | * 0 - OK - proceed with automatic read or write. |
| 1706 | * |
| 1707 | * > 0 - OK - read or write has been done by the strategy routine, so |
| 1708 | * return immediately. |
| 1709 | * |
| 1710 | * There must be a proc_handler routine for any terminal nodes |
| 1711 | * mirrored under /proc/sys (non-terminals are handled by a built-in |
| 1712 | * directory handler). Several default handlers are available to |
| 1713 | * cover common cases - |
| 1714 | * |
| 1715 | * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), |
| 1716 | * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), |
| 1717 | * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() |
| 1718 | * |
| 1719 | * It is the handler's job to read the input buffer from user memory |
| 1720 | * and process it. The handler should return 0 on success. |
| 1721 | * |
| 1722 | * This routine returns %NULL on a failure to register, and a pointer |
| 1723 | * to the table header on success. |
| 1724 | */ |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1725 | struct ctl_table_header *__register_sysctl_paths( |
| 1726 | struct ctl_table_root *root, |
| 1727 | struct nsproxy *namespaces, |
| 1728 | const struct ctl_path *path, struct ctl_table *table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | { |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1730 | struct ctl_table_header *header; |
| 1731 | struct ctl_table *new, **prevp; |
| 1732 | unsigned int n, npath; |
| 1733 | |
| 1734 | /* Count the path components */ |
| 1735 | for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) |
| 1736 | ; |
| 1737 | |
| 1738 | /* |
| 1739 | * For each path component, allocate a 2-element ctl_table array. |
| 1740 | * The first array element will be filled with the sysctl entry |
| 1741 | * for this, the second will be the sentinel (ctl_name == 0). |
| 1742 | * |
| 1743 | * We allocate everything in one go so that we don't have to |
| 1744 | * worry about freeing additional memory in unregister_sysctl_table. |
| 1745 | */ |
| 1746 | header = kzalloc(sizeof(struct ctl_table_header) + |
| 1747 | (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); |
| 1748 | if (!header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | return NULL; |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1750 | |
| 1751 | new = (struct ctl_table *) (header + 1); |
| 1752 | |
| 1753 | /* Now connect the dots */ |
| 1754 | prevp = &header->ctl_table; |
| 1755 | for (n = 0; n < npath; ++n, ++path) { |
| 1756 | /* Copy the procname */ |
| 1757 | new->procname = path->procname; |
| 1758 | new->ctl_name = path->ctl_name; |
| 1759 | new->mode = 0555; |
| 1760 | |
| 1761 | *prevp = new; |
| 1762 | prevp = &new->child; |
| 1763 | |
| 1764 | new += 2; |
| 1765 | } |
| 1766 | *prevp = table; |
Eric W. Biederman | 23eb06d | 2007-11-30 23:52:10 +1100 | [diff] [blame] | 1767 | header->ctl_table_arg = table; |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1768 | |
| 1769 | INIT_LIST_HEAD(&header->ctl_entry); |
| 1770 | header->used = 0; |
| 1771 | header->unregistering = NULL; |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1772 | header->root = root; |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1773 | sysctl_set_parent(NULL, header->ctl_table); |
Holger Schurig | 88f458e | 2008-04-29 01:02:36 -0700 | [diff] [blame] | 1774 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1775 | if (sysctl_check_table(namespaces, header->ctl_table)) { |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1776 | kfree(header); |
Eric W. Biederman | fc6cd25 | 2007-10-18 03:05:54 -0700 | [diff] [blame] | 1777 | return NULL; |
| 1778 | } |
Holger Schurig | 88f458e | 2008-04-29 01:02:36 -0700 | [diff] [blame] | 1779 | #endif |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1780 | spin_lock(&sysctl_lock); |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 1781 | header->set = lookup_header_set(root, namespaces); |
| 1782 | list_add_tail(&header->ctl_entry, &header->set->list); |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1783 | spin_unlock(&sysctl_lock); |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1784 | |
| 1785 | return header; |
| 1786 | } |
| 1787 | |
| 1788 | /** |
Eric W. Biederman | e51b6ba | 2007-11-30 23:54:00 +1100 | [diff] [blame] | 1789 | * register_sysctl_table_path - register a sysctl table hierarchy |
| 1790 | * @path: The path to the directory the sysctl table is in. |
| 1791 | * @table: the top-level table structure |
| 1792 | * |
| 1793 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table |
| 1794 | * array. A completely 0 filled entry terminates the table. |
| 1795 | * |
| 1796 | * See __register_sysctl_paths for more details. |
| 1797 | */ |
| 1798 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, |
| 1799 | struct ctl_table *table) |
| 1800 | { |
| 1801 | return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, |
| 1802 | path, table); |
| 1803 | } |
| 1804 | |
| 1805 | /** |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1806 | * register_sysctl_table - register a sysctl table hierarchy |
| 1807 | * @table: the top-level table structure |
| 1808 | * |
| 1809 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table |
| 1810 | * array. A completely 0 filled entry terminates the table. |
| 1811 | * |
| 1812 | * See register_sysctl_paths for more details. |
| 1813 | */ |
| 1814 | struct ctl_table_header *register_sysctl_table(struct ctl_table *table) |
| 1815 | { |
| 1816 | static const struct ctl_path null_path[] = { {} }; |
| 1817 | |
| 1818 | return register_sysctl_paths(null_path, table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * unregister_sysctl_table - unregister a sysctl table hierarchy |
| 1823 | * @header: the header returned from register_sysctl_table |
| 1824 | * |
| 1825 | * Unregisters the sysctl table and all children. proc entries may not |
| 1826 | * actually be removed until they are no longer used by anyone. |
| 1827 | */ |
| 1828 | void unregister_sysctl_table(struct ctl_table_header * header) |
| 1829 | { |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1830 | might_sleep(); |
Pavel Emelyanov | f1dad16 | 2007-12-04 23:45:24 -0800 | [diff] [blame] | 1831 | |
| 1832 | if (header == NULL) |
| 1833 | return; |
| 1834 | |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1835 | spin_lock(&sysctl_lock); |
| 1836 | start_unregistering(header); |
Al Viro | 330d57f | 2005-11-04 10:18:40 +0000 | [diff] [blame] | 1837 | spin_unlock(&sysctl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | kfree(header); |
| 1839 | } |
| 1840 | |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 1841 | void setup_sysctl_set(struct ctl_table_set *p, |
| 1842 | struct ctl_table_set *parent, |
| 1843 | int (*is_seen)(struct ctl_table_set *)) |
| 1844 | { |
| 1845 | INIT_LIST_HEAD(&p->list); |
| 1846 | p->parent = parent ? parent : &sysctl_table_root.default_set; |
| 1847 | p->is_seen = is_seen; |
| 1848 | } |
| 1849 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1850 | #else /* !CONFIG_SYSCTL */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1851 | struct ctl_table_header *register_sysctl_table(struct ctl_table * table) |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1852 | { |
| 1853 | return NULL; |
| 1854 | } |
| 1855 | |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 1856 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, |
| 1857 | struct ctl_table *table) |
| 1858 | { |
| 1859 | return NULL; |
| 1860 | } |
| 1861 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1862 | void unregister_sysctl_table(struct ctl_table_header * table) |
| 1863 | { |
| 1864 | } |
| 1865 | |
Al Viro | 7345509 | 2008-07-14 21:22:20 -0400 | [diff] [blame^] | 1866 | void setup_sysctl_set(struct ctl_table_set *p, |
| 1867 | struct ctl_table_set *parent, |
| 1868 | int (*is_seen)(struct ctl_table_set *)) |
| 1869 | { |
| 1870 | } |
| 1871 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1872 | #endif /* CONFIG_SYSCTL */ |
| 1873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | /* |
| 1875 | * /proc/sys support |
| 1876 | */ |
| 1877 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 1878 | #ifdef CONFIG_PROC_SYSCTL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Adrian Bunk | b1ba4dd | 2006-10-02 02:18:05 -0700 | [diff] [blame] | 1880 | static int _proc_do_string(void* data, int maxlen, int write, |
| 1881 | struct file *filp, void __user *buffer, |
| 1882 | size_t *lenp, loff_t *ppos) |
Sam Vilain | f5dd3d6 | 2006-10-02 02:18:04 -0700 | [diff] [blame] | 1883 | { |
| 1884 | size_t len; |
| 1885 | char __user *p; |
| 1886 | char c; |
Oleg Nesterov | 8d06087 | 2007-02-10 01:46:38 -0800 | [diff] [blame] | 1887 | |
| 1888 | if (!data || !maxlen || !*lenp) { |
Sam Vilain | f5dd3d6 | 2006-10-02 02:18:04 -0700 | [diff] [blame] | 1889 | *lenp = 0; |
| 1890 | return 0; |
| 1891 | } |
Oleg Nesterov | 8d06087 | 2007-02-10 01:46:38 -0800 | [diff] [blame] | 1892 | |
Sam Vilain | f5dd3d6 | 2006-10-02 02:18:04 -0700 | [diff] [blame] | 1893 | if (write) { |
| 1894 | len = 0; |
| 1895 | p = buffer; |
| 1896 | while (len < *lenp) { |
| 1897 | if (get_user(c, p++)) |
| 1898 | return -EFAULT; |
| 1899 | if (c == 0 || c == '\n') |
| 1900 | break; |
| 1901 | len++; |
| 1902 | } |
| 1903 | if (len >= maxlen) |
| 1904 | len = maxlen-1; |
| 1905 | if(copy_from_user(data, buffer, len)) |
| 1906 | return -EFAULT; |
| 1907 | ((char *) data)[len] = 0; |
| 1908 | *ppos += *lenp; |
| 1909 | } else { |
| 1910 | len = strlen(data); |
| 1911 | if (len > maxlen) |
| 1912 | len = maxlen; |
Oleg Nesterov | 8d06087 | 2007-02-10 01:46:38 -0800 | [diff] [blame] | 1913 | |
| 1914 | if (*ppos > len) { |
| 1915 | *lenp = 0; |
| 1916 | return 0; |
| 1917 | } |
| 1918 | |
| 1919 | data += *ppos; |
| 1920 | len -= *ppos; |
| 1921 | |
Sam Vilain | f5dd3d6 | 2006-10-02 02:18:04 -0700 | [diff] [blame] | 1922 | if (len > *lenp) |
| 1923 | len = *lenp; |
| 1924 | if (len) |
| 1925 | if(copy_to_user(buffer, data, len)) |
| 1926 | return -EFAULT; |
| 1927 | if (len < *lenp) { |
| 1928 | if(put_user('\n', ((char __user *) buffer) + len)) |
| 1929 | return -EFAULT; |
| 1930 | len++; |
| 1931 | } |
| 1932 | *lenp = len; |
| 1933 | *ppos += len; |
| 1934 | } |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | /** |
| 1939 | * proc_dostring - read a string sysctl |
| 1940 | * @table: the sysctl table |
| 1941 | * @write: %TRUE if this is a write to the sysctl file |
| 1942 | * @filp: the file structure |
| 1943 | * @buffer: the user buffer |
| 1944 | * @lenp: the size of the user buffer |
| 1945 | * @ppos: file position |
| 1946 | * |
| 1947 | * Reads/writes a string from/to the user buffer. If the kernel |
| 1948 | * buffer provided is not large enough to hold the string, the |
| 1949 | * string is truncated. The copied string is %NULL-terminated. |
| 1950 | * If the string is being read by the user process, it is copied |
| 1951 | * and a newline '\n' is added. It is truncated if the buffer is |
| 1952 | * not large enough. |
| 1953 | * |
| 1954 | * Returns 0 on success. |
| 1955 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1956 | int proc_dostring(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 1958 | { |
Sam Vilain | f5dd3d6 | 2006-10-02 02:18:04 -0700 | [diff] [blame] | 1959 | return _proc_do_string(table->data, table->maxlen, write, filp, |
| 1960 | buffer, lenp, ppos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | |
| 1964 | static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, |
| 1965 | int *valp, |
| 1966 | int write, void *data) |
| 1967 | { |
| 1968 | if (write) { |
| 1969 | *valp = *negp ? -*lvalp : *lvalp; |
| 1970 | } else { |
| 1971 | int val = *valp; |
| 1972 | if (val < 0) { |
| 1973 | *negp = -1; |
| 1974 | *lvalp = (unsigned long)-val; |
| 1975 | } else { |
| 1976 | *negp = 0; |
| 1977 | *lvalp = (unsigned long)val; |
| 1978 | } |
| 1979 | } |
| 1980 | return 0; |
| 1981 | } |
| 1982 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 1983 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 1984 | int write, struct file *filp, void __user *buffer, |
| 1985 | size_t *lenp, loff_t *ppos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, |
| 1987 | int write, void *data), |
| 1988 | void *data) |
| 1989 | { |
| 1990 | #define TMPBUFLEN 21 |
| 1991 | int *i, vleft, first=1, neg, val; |
| 1992 | unsigned long lval; |
| 1993 | size_t left, len; |
| 1994 | |
| 1995 | char buf[TMPBUFLEN], *p; |
| 1996 | char __user *s = buffer; |
| 1997 | |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 1998 | if (!tbl_data || !table->maxlen || !*lenp || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | (*ppos && !write)) { |
| 2000 | *lenp = 0; |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 2004 | i = (int *) tbl_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | vleft = table->maxlen / sizeof(*i); |
| 2006 | left = *lenp; |
| 2007 | |
| 2008 | if (!conv) |
| 2009 | conv = do_proc_dointvec_conv; |
| 2010 | |
| 2011 | for (; left && vleft--; i++, first=0) { |
| 2012 | if (write) { |
| 2013 | while (left) { |
| 2014 | char c; |
| 2015 | if (get_user(c, s)) |
| 2016 | return -EFAULT; |
| 2017 | if (!isspace(c)) |
| 2018 | break; |
| 2019 | left--; |
| 2020 | s++; |
| 2021 | } |
| 2022 | if (!left) |
| 2023 | break; |
| 2024 | neg = 0; |
| 2025 | len = left; |
| 2026 | if (len > sizeof(buf) - 1) |
| 2027 | len = sizeof(buf) - 1; |
| 2028 | if (copy_from_user(buf, s, len)) |
| 2029 | return -EFAULT; |
| 2030 | buf[len] = 0; |
| 2031 | p = buf; |
| 2032 | if (*p == '-' && left > 1) { |
| 2033 | neg = 1; |
BP, Praveen | bd9b0ba | 2006-12-06 20:39:09 -0800 | [diff] [blame] | 2034 | p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
| 2036 | if (*p < '0' || *p > '9') |
| 2037 | break; |
| 2038 | |
| 2039 | lval = simple_strtoul(p, &p, 0); |
| 2040 | |
| 2041 | len = p-buf; |
| 2042 | if ((len < left) && *p && !isspace(*p)) |
| 2043 | break; |
| 2044 | if (neg) |
| 2045 | val = -val; |
| 2046 | s += len; |
| 2047 | left -= len; |
| 2048 | |
| 2049 | if (conv(&neg, &lval, i, 1, data)) |
| 2050 | break; |
| 2051 | } else { |
| 2052 | p = buf; |
| 2053 | if (!first) |
| 2054 | *p++ = '\t'; |
| 2055 | |
| 2056 | if (conv(&neg, &lval, i, 0, data)) |
| 2057 | break; |
| 2058 | |
| 2059 | sprintf(p, "%s%lu", neg ? "-" : "", lval); |
| 2060 | len = strlen(buf); |
| 2061 | if (len > left) |
| 2062 | len = left; |
| 2063 | if(copy_to_user(s, buf, len)) |
| 2064 | return -EFAULT; |
| 2065 | left -= len; |
| 2066 | s += len; |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | if (!write && !first && left) { |
| 2071 | if(put_user('\n', s)) |
| 2072 | return -EFAULT; |
| 2073 | left--, s++; |
| 2074 | } |
| 2075 | if (write) { |
| 2076 | while (left) { |
| 2077 | char c; |
| 2078 | if (get_user(c, s++)) |
| 2079 | return -EFAULT; |
| 2080 | if (!isspace(c)) |
| 2081 | break; |
| 2082 | left--; |
| 2083 | } |
| 2084 | } |
| 2085 | if (write && first) |
| 2086 | return -EINVAL; |
| 2087 | *lenp -= left; |
| 2088 | *ppos += *lenp; |
| 2089 | return 0; |
| 2090 | #undef TMPBUFLEN |
| 2091 | } |
| 2092 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2093 | static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp, |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 2094 | void __user *buffer, size_t *lenp, loff_t *ppos, |
| 2095 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, |
| 2096 | int write, void *data), |
| 2097 | void *data) |
| 2098 | { |
| 2099 | return __do_proc_dointvec(table->data, table, write, filp, |
| 2100 | buffer, lenp, ppos, conv, data); |
| 2101 | } |
| 2102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | /** |
| 2104 | * proc_dointvec - read a vector of integers |
| 2105 | * @table: the sysctl table |
| 2106 | * @write: %TRUE if this is a write to the sysctl file |
| 2107 | * @filp: the file structure |
| 2108 | * @buffer: the user buffer |
| 2109 | * @lenp: the size of the user buffer |
| 2110 | * @ppos: file position |
| 2111 | * |
| 2112 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer |
| 2113 | * values from/to the user buffer, treated as an ASCII string. |
| 2114 | * |
| 2115 | * Returns 0 on success. |
| 2116 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2117 | int proc_dointvec(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2119 | { |
| 2120 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, |
| 2121 | NULL,NULL); |
| 2122 | } |
| 2123 | |
| 2124 | #define OP_SET 0 |
| 2125 | #define OP_AND 1 |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 2126 | #define OP_OR 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | |
| 2128 | static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp, |
| 2129 | int *valp, |
| 2130 | int write, void *data) |
| 2131 | { |
| 2132 | int op = *(int *)data; |
| 2133 | if (write) { |
| 2134 | int val = *negp ? -*lvalp : *lvalp; |
| 2135 | switch(op) { |
| 2136 | case OP_SET: *valp = val; break; |
| 2137 | case OP_AND: *valp &= val; break; |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 2138 | case OP_OR: *valp |= val; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | } |
| 2140 | } else { |
| 2141 | int val = *valp; |
| 2142 | if (val < 0) { |
| 2143 | *negp = -1; |
| 2144 | *lvalp = (unsigned long)-val; |
| 2145 | } else { |
| 2146 | *negp = 0; |
| 2147 | *lvalp = (unsigned long)val; |
| 2148 | } |
| 2149 | } |
| 2150 | return 0; |
| 2151 | } |
| 2152 | |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 2153 | /* |
| 2154 | * Taint values can only be increased |
| 2155 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2156 | static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 2157 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2158 | { |
| 2159 | int op; |
| 2160 | |
Bastian Blank | 91fcd41 | 2007-04-23 14:41:14 -0700 | [diff] [blame] | 2161 | if (write && !capable(CAP_SYS_ADMIN)) |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 2162 | return -EPERM; |
| 2163 | |
| 2164 | op = OP_OR; |
| 2165 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, |
| 2166 | do_proc_dointvec_bset_conv,&op); |
| 2167 | } |
| 2168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | struct do_proc_dointvec_minmax_conv_param { |
| 2170 | int *min; |
| 2171 | int *max; |
| 2172 | }; |
| 2173 | |
| 2174 | static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, |
| 2175 | int *valp, |
| 2176 | int write, void *data) |
| 2177 | { |
| 2178 | struct do_proc_dointvec_minmax_conv_param *param = data; |
| 2179 | if (write) { |
| 2180 | int val = *negp ? -*lvalp : *lvalp; |
| 2181 | if ((param->min && *param->min > val) || |
| 2182 | (param->max && *param->max < val)) |
| 2183 | return -EINVAL; |
| 2184 | *valp = val; |
| 2185 | } else { |
| 2186 | int val = *valp; |
| 2187 | if (val < 0) { |
| 2188 | *negp = -1; |
| 2189 | *lvalp = (unsigned long)-val; |
| 2190 | } else { |
| 2191 | *negp = 0; |
| 2192 | *lvalp = (unsigned long)val; |
| 2193 | } |
| 2194 | } |
| 2195 | return 0; |
| 2196 | } |
| 2197 | |
| 2198 | /** |
| 2199 | * proc_dointvec_minmax - read a vector of integers with min/max values |
| 2200 | * @table: the sysctl table |
| 2201 | * @write: %TRUE if this is a write to the sysctl file |
| 2202 | * @filp: the file structure |
| 2203 | * @buffer: the user buffer |
| 2204 | * @lenp: the size of the user buffer |
| 2205 | * @ppos: file position |
| 2206 | * |
| 2207 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer |
| 2208 | * values from/to the user buffer, treated as an ASCII string. |
| 2209 | * |
| 2210 | * This routine will ensure the values are within the range specified by |
| 2211 | * table->extra1 (min) and table->extra2 (max). |
| 2212 | * |
| 2213 | * Returns 0 on success. |
| 2214 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2215 | int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2217 | { |
| 2218 | struct do_proc_dointvec_minmax_conv_param param = { |
| 2219 | .min = (int *) table->extra1, |
| 2220 | .max = (int *) table->extra2, |
| 2221 | }; |
| 2222 | return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, |
| 2223 | do_proc_dointvec_minmax_conv, ¶m); |
| 2224 | } |
| 2225 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2226 | static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | struct file *filp, |
| 2228 | void __user *buffer, |
| 2229 | size_t *lenp, loff_t *ppos, |
| 2230 | unsigned long convmul, |
| 2231 | unsigned long convdiv) |
| 2232 | { |
| 2233 | #define TMPBUFLEN 21 |
| 2234 | unsigned long *i, *min, *max, val; |
| 2235 | int vleft, first=1, neg; |
| 2236 | size_t len, left; |
| 2237 | char buf[TMPBUFLEN], *p; |
| 2238 | char __user *s = buffer; |
| 2239 | |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 2240 | if (!data || !table->maxlen || !*lenp || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | (*ppos && !write)) { |
| 2242 | *lenp = 0; |
| 2243 | return 0; |
| 2244 | } |
| 2245 | |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 2246 | i = (unsigned long *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | min = (unsigned long *) table->extra1; |
| 2248 | max = (unsigned long *) table->extra2; |
| 2249 | vleft = table->maxlen / sizeof(unsigned long); |
| 2250 | left = *lenp; |
| 2251 | |
| 2252 | for (; left && vleft--; i++, min++, max++, first=0) { |
| 2253 | if (write) { |
| 2254 | while (left) { |
| 2255 | char c; |
| 2256 | if (get_user(c, s)) |
| 2257 | return -EFAULT; |
| 2258 | if (!isspace(c)) |
| 2259 | break; |
| 2260 | left--; |
| 2261 | s++; |
| 2262 | } |
| 2263 | if (!left) |
| 2264 | break; |
| 2265 | neg = 0; |
| 2266 | len = left; |
| 2267 | if (len > TMPBUFLEN-1) |
| 2268 | len = TMPBUFLEN-1; |
| 2269 | if (copy_from_user(buf, s, len)) |
| 2270 | return -EFAULT; |
| 2271 | buf[len] = 0; |
| 2272 | p = buf; |
| 2273 | if (*p == '-' && left > 1) { |
| 2274 | neg = 1; |
BP, Praveen | bd9b0ba | 2006-12-06 20:39:09 -0800 | [diff] [blame] | 2275 | p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | } |
| 2277 | if (*p < '0' || *p > '9') |
| 2278 | break; |
| 2279 | val = simple_strtoul(p, &p, 0) * convmul / convdiv ; |
| 2280 | len = p-buf; |
| 2281 | if ((len < left) && *p && !isspace(*p)) |
| 2282 | break; |
| 2283 | if (neg) |
| 2284 | val = -val; |
| 2285 | s += len; |
| 2286 | left -= len; |
| 2287 | |
| 2288 | if(neg) |
| 2289 | continue; |
| 2290 | if ((min && val < *min) || (max && val > *max)) |
| 2291 | continue; |
| 2292 | *i = val; |
| 2293 | } else { |
| 2294 | p = buf; |
| 2295 | if (!first) |
| 2296 | *p++ = '\t'; |
| 2297 | sprintf(p, "%lu", convdiv * (*i) / convmul); |
| 2298 | len = strlen(buf); |
| 2299 | if (len > left) |
| 2300 | len = left; |
| 2301 | if(copy_to_user(s, buf, len)) |
| 2302 | return -EFAULT; |
| 2303 | left -= len; |
| 2304 | s += len; |
| 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | if (!write && !first && left) { |
| 2309 | if(put_user('\n', s)) |
| 2310 | return -EFAULT; |
| 2311 | left--, s++; |
| 2312 | } |
| 2313 | if (write) { |
| 2314 | while (left) { |
| 2315 | char c; |
| 2316 | if (get_user(c, s++)) |
| 2317 | return -EFAULT; |
| 2318 | if (!isspace(c)) |
| 2319 | break; |
| 2320 | left--; |
| 2321 | } |
| 2322 | } |
| 2323 | if (write && first) |
| 2324 | return -EINVAL; |
| 2325 | *lenp -= left; |
| 2326 | *ppos += *lenp; |
| 2327 | return 0; |
| 2328 | #undef TMPBUFLEN |
| 2329 | } |
| 2330 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2331 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, |
Kirill Korotaev | fcfbd54 | 2006-10-02 02:18:23 -0700 | [diff] [blame] | 2332 | struct file *filp, |
| 2333 | void __user *buffer, |
| 2334 | size_t *lenp, loff_t *ppos, |
| 2335 | unsigned long convmul, |
| 2336 | unsigned long convdiv) |
| 2337 | { |
| 2338 | return __do_proc_doulongvec_minmax(table->data, table, write, |
| 2339 | filp, buffer, lenp, ppos, convmul, convdiv); |
| 2340 | } |
| 2341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | /** |
| 2343 | * proc_doulongvec_minmax - read a vector of long integers with min/max values |
| 2344 | * @table: the sysctl table |
| 2345 | * @write: %TRUE if this is a write to the sysctl file |
| 2346 | * @filp: the file structure |
| 2347 | * @buffer: the user buffer |
| 2348 | * @lenp: the size of the user buffer |
| 2349 | * @ppos: file position |
| 2350 | * |
| 2351 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long |
| 2352 | * values from/to the user buffer, treated as an ASCII string. |
| 2353 | * |
| 2354 | * This routine will ensure the values are within the range specified by |
| 2355 | * table->extra1 (min) and table->extra2 (max). |
| 2356 | * |
| 2357 | * Returns 0 on success. |
| 2358 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2359 | int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2361 | { |
| 2362 | return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); |
| 2363 | } |
| 2364 | |
| 2365 | /** |
| 2366 | * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values |
| 2367 | * @table: the sysctl table |
| 2368 | * @write: %TRUE if this is a write to the sysctl file |
| 2369 | * @filp: the file structure |
| 2370 | * @buffer: the user buffer |
| 2371 | * @lenp: the size of the user buffer |
| 2372 | * @ppos: file position |
| 2373 | * |
| 2374 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long |
| 2375 | * values from/to the user buffer, treated as an ASCII string. The values |
| 2376 | * are treated as milliseconds, and converted to jiffies when they are stored. |
| 2377 | * |
| 2378 | * This routine will ensure the values are within the range specified by |
| 2379 | * table->extra1 (min) and table->extra2 (max). |
| 2380 | * |
| 2381 | * Returns 0 on success. |
| 2382 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2383 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | struct file *filp, |
| 2385 | void __user *buffer, |
| 2386 | size_t *lenp, loff_t *ppos) |
| 2387 | { |
| 2388 | return do_proc_doulongvec_minmax(table, write, filp, buffer, |
| 2389 | lenp, ppos, HZ, 1000l); |
| 2390 | } |
| 2391 | |
| 2392 | |
| 2393 | static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, |
| 2394 | int *valp, |
| 2395 | int write, void *data) |
| 2396 | { |
| 2397 | if (write) { |
Bart Samwel | cba9f33 | 2006-03-24 03:15:50 -0800 | [diff] [blame] | 2398 | if (*lvalp > LONG_MAX / HZ) |
| 2399 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); |
| 2401 | } else { |
| 2402 | int val = *valp; |
| 2403 | unsigned long lval; |
| 2404 | if (val < 0) { |
| 2405 | *negp = -1; |
| 2406 | lval = (unsigned long)-val; |
| 2407 | } else { |
| 2408 | *negp = 0; |
| 2409 | lval = (unsigned long)val; |
| 2410 | } |
| 2411 | *lvalp = lval / HZ; |
| 2412 | } |
| 2413 | return 0; |
| 2414 | } |
| 2415 | |
| 2416 | static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, |
| 2417 | int *valp, |
| 2418 | int write, void *data) |
| 2419 | { |
| 2420 | if (write) { |
Bart Samwel | cba9f33 | 2006-03-24 03:15:50 -0800 | [diff] [blame] | 2421 | if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) |
| 2422 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); |
| 2424 | } else { |
| 2425 | int val = *valp; |
| 2426 | unsigned long lval; |
| 2427 | if (val < 0) { |
| 2428 | *negp = -1; |
| 2429 | lval = (unsigned long)-val; |
| 2430 | } else { |
| 2431 | *negp = 0; |
| 2432 | lval = (unsigned long)val; |
| 2433 | } |
| 2434 | *lvalp = jiffies_to_clock_t(lval); |
| 2435 | } |
| 2436 | return 0; |
| 2437 | } |
| 2438 | |
| 2439 | static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, |
| 2440 | int *valp, |
| 2441 | int write, void *data) |
| 2442 | { |
| 2443 | if (write) { |
| 2444 | *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); |
| 2445 | } else { |
| 2446 | int val = *valp; |
| 2447 | unsigned long lval; |
| 2448 | if (val < 0) { |
| 2449 | *negp = -1; |
| 2450 | lval = (unsigned long)-val; |
| 2451 | } else { |
| 2452 | *negp = 0; |
| 2453 | lval = (unsigned long)val; |
| 2454 | } |
| 2455 | *lvalp = jiffies_to_msecs(lval); |
| 2456 | } |
| 2457 | return 0; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * proc_dointvec_jiffies - read a vector of integers as seconds |
| 2462 | * @table: the sysctl table |
| 2463 | * @write: %TRUE if this is a write to the sysctl file |
| 2464 | * @filp: the file structure |
| 2465 | * @buffer: the user buffer |
| 2466 | * @lenp: the size of the user buffer |
| 2467 | * @ppos: file position |
| 2468 | * |
| 2469 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer |
| 2470 | * values from/to the user buffer, treated as an ASCII string. |
| 2471 | * The values read are assumed to be in seconds, and are converted into |
| 2472 | * jiffies. |
| 2473 | * |
| 2474 | * Returns 0 on success. |
| 2475 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2476 | int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2478 | { |
| 2479 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, |
| 2480 | do_proc_dointvec_jiffies_conv,NULL); |
| 2481 | } |
| 2482 | |
| 2483 | /** |
| 2484 | * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds |
| 2485 | * @table: the sysctl table |
| 2486 | * @write: %TRUE if this is a write to the sysctl file |
| 2487 | * @filp: the file structure |
| 2488 | * @buffer: the user buffer |
| 2489 | * @lenp: the size of the user buffer |
Randy Dunlap | 1e5d533 | 2005-11-07 01:01:06 -0800 | [diff] [blame] | 2490 | * @ppos: pointer to the file position |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | * |
| 2492 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer |
| 2493 | * values from/to the user buffer, treated as an ASCII string. |
| 2494 | * The values read are assumed to be in 1/USER_HZ seconds, and |
| 2495 | * are converted into jiffies. |
| 2496 | * |
| 2497 | * Returns 0 on success. |
| 2498 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2499 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2501 | { |
| 2502 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, |
| 2503 | do_proc_dointvec_userhz_jiffies_conv,NULL); |
| 2504 | } |
| 2505 | |
| 2506 | /** |
| 2507 | * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds |
| 2508 | * @table: the sysctl table |
| 2509 | * @write: %TRUE if this is a write to the sysctl file |
| 2510 | * @filp: the file structure |
| 2511 | * @buffer: the user buffer |
| 2512 | * @lenp: the size of the user buffer |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 2513 | * @ppos: file position |
| 2514 | * @ppos: the current position in the file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | * |
| 2516 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer |
| 2517 | * values from/to the user buffer, treated as an ASCII string. |
| 2518 | * The values read are assumed to be in 1/1000 seconds, and |
| 2519 | * are converted into jiffies. |
| 2520 | * |
| 2521 | * Returns 0 on success. |
| 2522 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2523 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2525 | { |
| 2526 | return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, |
| 2527 | do_proc_dointvec_ms_jiffies_conv, NULL); |
| 2528 | } |
| 2529 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2530 | static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 2531 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2532 | { |
| 2533 | struct pid *new_pid; |
| 2534 | pid_t tmp; |
| 2535 | int r; |
| 2536 | |
Pavel Emelyanov | 6c5f3e7 | 2008-02-08 04:19:20 -0800 | [diff] [blame] | 2537 | tmp = pid_vnr(cad_pid); |
Cedric Le Goater | 9ec5209 | 2006-10-02 02:19:00 -0700 | [diff] [blame] | 2538 | |
| 2539 | r = __do_proc_dointvec(&tmp, table, write, filp, buffer, |
| 2540 | lenp, ppos, NULL, NULL); |
| 2541 | if (r || !write) |
| 2542 | return r; |
| 2543 | |
| 2544 | new_pid = find_get_pid(tmp); |
| 2545 | if (!new_pid) |
| 2546 | return -ESRCH; |
| 2547 | |
| 2548 | put_pid(xchg(&cad_pid, new_pid)); |
| 2549 | return 0; |
| 2550 | } |
| 2551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | #else /* CONFIG_PROC_FS */ |
| 2553 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2554 | int proc_dostring(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2556 | { |
| 2557 | return -ENOSYS; |
| 2558 | } |
| 2559 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2560 | int proc_dointvec(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2562 | { |
| 2563 | return -ENOSYS; |
| 2564 | } |
| 2565 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2566 | int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2568 | { |
| 2569 | return -ENOSYS; |
| 2570 | } |
| 2571 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2572 | int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2574 | { |
| 2575 | return -ENOSYS; |
| 2576 | } |
| 2577 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2578 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2580 | { |
| 2581 | return -ENOSYS; |
| 2582 | } |
| 2583 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2584 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2586 | { |
| 2587 | return -ENOSYS; |
| 2588 | } |
| 2589 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2590 | int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | void __user *buffer, size_t *lenp, loff_t *ppos) |
| 2592 | { |
| 2593 | return -ENOSYS; |
| 2594 | } |
| 2595 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2596 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | struct file *filp, |
| 2598 | void __user *buffer, |
| 2599 | size_t *lenp, loff_t *ppos) |
| 2600 | { |
| 2601 | return -ENOSYS; |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | #endif /* CONFIG_PROC_FS */ |
| 2606 | |
| 2607 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 2608 | #ifdef CONFIG_SYSCTL_SYSCALL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | /* |
| 2610 | * General sysctl support routines |
| 2611 | */ |
| 2612 | |
Eric W. Biederman | 49a0c45 | 2007-10-18 03:05:23 -0700 | [diff] [blame] | 2613 | /* The generic sysctl data routine (used if no strategy routine supplied) */ |
| 2614 | int sysctl_data(struct ctl_table *table, int __user *name, int nlen, |
| 2615 | void __user *oldval, size_t __user *oldlenp, |
| 2616 | void __user *newval, size_t newlen) |
| 2617 | { |
| 2618 | size_t len; |
| 2619 | |
| 2620 | /* Get out of I don't have a variable */ |
| 2621 | if (!table->data || !table->maxlen) |
| 2622 | return -ENOTDIR; |
| 2623 | |
| 2624 | if (oldval && oldlenp) { |
| 2625 | if (get_user(len, oldlenp)) |
| 2626 | return -EFAULT; |
| 2627 | if (len) { |
| 2628 | if (len > table->maxlen) |
| 2629 | len = table->maxlen; |
| 2630 | if (copy_to_user(oldval, table->data, len)) |
| 2631 | return -EFAULT; |
| 2632 | if (put_user(len, oldlenp)) |
| 2633 | return -EFAULT; |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | if (newval && newlen) { |
| 2638 | if (newlen > table->maxlen) |
| 2639 | newlen = table->maxlen; |
| 2640 | |
| 2641 | if (copy_from_user(table->data, newval, newlen)) |
| 2642 | return -EFAULT; |
| 2643 | } |
| 2644 | return 1; |
| 2645 | } |
| 2646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | /* The generic string strategy routine: */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2648 | int sysctl_string(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2650 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | if (!table->data || !table->maxlen) |
| 2653 | return -ENOTDIR; |
| 2654 | |
| 2655 | if (oldval && oldlenp) { |
Linus Torvalds | de9e007 | 2005-12-31 17:00:29 -0800 | [diff] [blame] | 2656 | size_t bufsize; |
| 2657 | if (get_user(bufsize, oldlenp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | return -EFAULT; |
Linus Torvalds | de9e007 | 2005-12-31 17:00:29 -0800 | [diff] [blame] | 2659 | if (bufsize) { |
| 2660 | size_t len = strlen(table->data), copied; |
| 2661 | |
| 2662 | /* This shouldn't trigger for a well-formed sysctl */ |
| 2663 | if (len > table->maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | len = table->maxlen; |
Linus Torvalds | de9e007 | 2005-12-31 17:00:29 -0800 | [diff] [blame] | 2665 | |
| 2666 | /* Copy up to a max of bufsize-1 bytes of the string */ |
| 2667 | copied = (len >= bufsize) ? bufsize - 1 : len; |
| 2668 | |
| 2669 | if (copy_to_user(oldval, table->data, copied) || |
| 2670 | put_user(0, (char __user *)(oldval + copied))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | return -EFAULT; |
Linus Torvalds | de9e007 | 2005-12-31 17:00:29 -0800 | [diff] [blame] | 2672 | if (put_user(len, oldlenp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | return -EFAULT; |
| 2674 | } |
| 2675 | } |
| 2676 | if (newval && newlen) { |
Linus Torvalds | de9e007 | 2005-12-31 17:00:29 -0800 | [diff] [blame] | 2677 | size_t len = newlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | if (len > table->maxlen) |
| 2679 | len = table->maxlen; |
| 2680 | if(copy_from_user(table->data, newval, len)) |
| 2681 | return -EFAULT; |
| 2682 | if (len == table->maxlen) |
| 2683 | len--; |
| 2684 | ((char *) table->data)[len] = 0; |
| 2685 | } |
Yi Yang | 82c9df8 | 2005-12-30 16:37:10 +0800 | [diff] [blame] | 2686 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | /* |
| 2690 | * This function makes sure that all of the integers in the vector |
| 2691 | * are between the minimum and maximum values given in the arrays |
| 2692 | * table->extra1 and table->extra2, respectively. |
| 2693 | */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2694 | int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2696 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | { |
| 2698 | |
| 2699 | if (newval && newlen) { |
| 2700 | int __user *vec = (int __user *) newval; |
| 2701 | int *min = (int *) table->extra1; |
| 2702 | int *max = (int *) table->extra2; |
| 2703 | size_t length; |
| 2704 | int i; |
| 2705 | |
| 2706 | if (newlen % sizeof(int) != 0) |
| 2707 | return -EINVAL; |
| 2708 | |
| 2709 | if (!table->extra1 && !table->extra2) |
| 2710 | return 0; |
| 2711 | |
| 2712 | if (newlen > table->maxlen) |
| 2713 | newlen = table->maxlen; |
| 2714 | length = newlen / sizeof(int); |
| 2715 | |
| 2716 | for (i = 0; i < length; i++) { |
| 2717 | int value; |
| 2718 | if (get_user(value, vec + i)) |
| 2719 | return -EFAULT; |
| 2720 | if (min && value < min[i]) |
| 2721 | return -EINVAL; |
| 2722 | if (max && value > max[i]) |
| 2723 | return -EINVAL; |
| 2724 | } |
| 2725 | } |
| 2726 | return 0; |
| 2727 | } |
| 2728 | |
| 2729 | /* Strategy function to convert jiffies to seconds */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2730 | int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2732 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | { |
Alexey Dobriyan | 3ee75ac | 2007-02-10 01:44:39 -0800 | [diff] [blame] | 2734 | if (oldval && oldlenp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | size_t olen; |
Alexey Dobriyan | 3ee75ac | 2007-02-10 01:44:39 -0800 | [diff] [blame] | 2736 | |
| 2737 | if (get_user(olen, oldlenp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | return -EFAULT; |
Alexey Dobriyan | 3ee75ac | 2007-02-10 01:44:39 -0800 | [diff] [blame] | 2739 | if (olen) { |
| 2740 | int val; |
| 2741 | |
| 2742 | if (olen < sizeof(int)) |
| 2743 | return -EINVAL; |
| 2744 | |
| 2745 | val = *(int *)(table->data) / HZ; |
| 2746 | if (put_user(val, (int __user *)oldval)) |
| 2747 | return -EFAULT; |
| 2748 | if (put_user(sizeof(int), oldlenp)) |
| 2749 | return -EFAULT; |
| 2750 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | } |
| 2752 | if (newval && newlen) { |
| 2753 | int new; |
| 2754 | if (newlen != sizeof(int)) |
| 2755 | return -EINVAL; |
| 2756 | if (get_user(new, (int __user *)newval)) |
| 2757 | return -EFAULT; |
| 2758 | *(int *)(table->data) = new*HZ; |
| 2759 | } |
| 2760 | return 1; |
| 2761 | } |
| 2762 | |
| 2763 | /* Strategy function to convert jiffies to seconds */ |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2764 | int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2766 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | { |
Alexey Dobriyan | 3ee75ac | 2007-02-10 01:44:39 -0800 | [diff] [blame] | 2768 | if (oldval && oldlenp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | size_t olen; |
Alexey Dobriyan | 3ee75ac | 2007-02-10 01:44:39 -0800 | [diff] [blame] | 2770 | |
| 2771 | if (get_user(olen, oldlenp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | return -EFAULT; |
Alexey Dobriyan | 3ee75ac | 2007-02-10 01:44:39 -0800 | [diff] [blame] | 2773 | if (olen) { |
| 2774 | int val; |
| 2775 | |
| 2776 | if (olen < sizeof(int)) |
| 2777 | return -EINVAL; |
| 2778 | |
| 2779 | val = jiffies_to_msecs(*(int *)(table->data)); |
| 2780 | if (put_user(val, (int __user *)oldval)) |
| 2781 | return -EFAULT; |
| 2782 | if (put_user(sizeof(int), oldlenp)) |
| 2783 | return -EFAULT; |
| 2784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | } |
| 2786 | if (newval && newlen) { |
| 2787 | int new; |
| 2788 | if (newlen != sizeof(int)) |
| 2789 | return -EINVAL; |
| 2790 | if (get_user(new, (int __user *)newval)) |
| 2791 | return -EFAULT; |
| 2792 | *(int *)(table->data) = msecs_to_jiffies(new); |
| 2793 | } |
| 2794 | return 1; |
| 2795 | } |
| 2796 | |
Eric W. Biederman | c4b8b76 | 2006-12-08 02:39:55 -0800 | [diff] [blame] | 2797 | |
Eric W. Biederman | c4b8b76 | 2006-12-08 02:39:55 -0800 | [diff] [blame] | 2798 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 2799 | #else /* CONFIG_SYSCTL_SYSCALL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | |
| 2801 | |
| 2802 | asmlinkage long sys_sysctl(struct __sysctl_args __user *args) |
| 2803 | { |
Eric W. Biederman | 0e009be | 2006-11-05 23:52:11 -0800 | [diff] [blame] | 2804 | struct __sysctl_args tmp; |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 2805 | int error; |
Eric W. Biederman | 0e009be | 2006-11-05 23:52:11 -0800 | [diff] [blame] | 2806 | |
Eric W. Biederman | 0e009be | 2006-11-05 23:52:11 -0800 | [diff] [blame] | 2807 | if (copy_from_user(&tmp, args, sizeof(tmp))) |
| 2808 | return -EFAULT; |
Eric W. Biederman | 0e009be | 2006-11-05 23:52:11 -0800 | [diff] [blame] | 2809 | |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 2810 | error = deprecated_sysctl_warning(&tmp); |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 2811 | |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 2812 | /* If no error reading the parameters then just -ENOSYS ... */ |
| 2813 | if (!error) |
| 2814 | error = -ENOSYS; |
| 2815 | |
| 2816 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Eric W. Biederman | 49a0c45 | 2007-10-18 03:05:23 -0700 | [diff] [blame] | 2819 | int sysctl_data(struct ctl_table *table, int __user *name, int nlen, |
| 2820 | void __user *oldval, size_t __user *oldlenp, |
| 2821 | void __user *newval, size_t newlen) |
| 2822 | { |
| 2823 | return -ENOSYS; |
| 2824 | } |
| 2825 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2826 | int sysctl_string(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2828 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | { |
| 2830 | return -ENOSYS; |
| 2831 | } |
| 2832 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2833 | int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2835 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | { |
| 2837 | return -ENOSYS; |
| 2838 | } |
| 2839 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2840 | int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2842 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | { |
| 2844 | return -ENOSYS; |
| 2845 | } |
| 2846 | |
Eric W. Biederman | d8217f0 | 2007-10-18 03:05:22 -0700 | [diff] [blame] | 2847 | int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | void __user *oldval, size_t __user *oldlenp, |
Alexey Dobriyan | 1f29bcd | 2006-12-10 02:19:10 -0800 | [diff] [blame] | 2849 | void __user *newval, size_t newlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | { |
| 2851 | return -ENOSYS; |
| 2852 | } |
| 2853 | |
Eric W. Biederman | b89a817 | 2006-09-27 01:51:04 -0700 | [diff] [blame] | 2854 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 2856 | static int deprecated_sysctl_warning(struct __sysctl_args *args) |
| 2857 | { |
| 2858 | static int msg_count; |
| 2859 | int name[CTL_MAXNAME]; |
| 2860 | int i; |
| 2861 | |
Tetsuo Handa | 6fc48af | 2007-11-14 16:58:38 -0800 | [diff] [blame] | 2862 | /* Check args->nlen. */ |
| 2863 | if (args->nlen < 0 || args->nlen > CTL_MAXNAME) |
| 2864 | return -ENOTDIR; |
| 2865 | |
Eric W. Biederman | 7058cb0 | 2007-10-18 03:05:58 -0700 | [diff] [blame] | 2866 | /* Read in the sysctl name for better debug message logging */ |
| 2867 | for (i = 0; i < args->nlen; i++) |
| 2868 | if (get_user(name[i], args->name + i)) |
| 2869 | return -EFAULT; |
| 2870 | |
| 2871 | /* Ignore accesses to kernel.version */ |
| 2872 | if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) |
| 2873 | return 0; |
| 2874 | |
| 2875 | if (msg_count < 5) { |
| 2876 | msg_count++; |
| 2877 | printk(KERN_INFO |
| 2878 | "warning: process `%s' used the deprecated sysctl " |
| 2879 | "system call with ", current->comm); |
| 2880 | for (i = 0; i < args->nlen; i++) |
| 2881 | printk("%d.", name[i]); |
| 2882 | printk("\n"); |
| 2883 | } |
| 2884 | return 0; |
| 2885 | } |
| 2886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | /* |
| 2888 | * No sense putting this after each symbol definition, twice, |
| 2889 | * exception granted :-) |
| 2890 | */ |
| 2891 | EXPORT_SYMBOL(proc_dointvec); |
| 2892 | EXPORT_SYMBOL(proc_dointvec_jiffies); |
| 2893 | EXPORT_SYMBOL(proc_dointvec_minmax); |
| 2894 | EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); |
| 2895 | EXPORT_SYMBOL(proc_dointvec_ms_jiffies); |
| 2896 | EXPORT_SYMBOL(proc_dostring); |
| 2897 | EXPORT_SYMBOL(proc_doulongvec_minmax); |
| 2898 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); |
| 2899 | EXPORT_SYMBOL(register_sysctl_table); |
Eric W. Biederman | 29e796f | 2007-11-30 23:50:18 +1100 | [diff] [blame] | 2900 | EXPORT_SYMBOL(register_sysctl_paths); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | EXPORT_SYMBOL(sysctl_intvec); |
| 2902 | EXPORT_SYMBOL(sysctl_jiffies); |
| 2903 | EXPORT_SYMBOL(sysctl_ms_jiffies); |
| 2904 | EXPORT_SYMBOL(sysctl_string); |
Eric W. Biederman | 49a0c45 | 2007-10-18 03:05:23 -0700 | [diff] [blame] | 2905 | EXPORT_SYMBOL(sysctl_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | EXPORT_SYMBOL(unregister_sysctl_table); |