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