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