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