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