blob: 7de6555cfea0f3484e8decbf927c7c456c227175 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070026#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080027#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080028#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070030#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020032#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080065#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include <asm/uaccess.h>
68#include <asm/processor.h>
69
Andi Kleen29cbc782006-09-30 01:47:55 +020070#ifdef CONFIG_X86
71#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010072#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010073#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020074#endif
David Howellsd550bbd2012-03-28 18:30:03 +010075#ifdef CONFIG_SPARC
76#include <asm/setup.h>
77#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080078#ifdef CONFIG_BSD_PROCESS_ACCT
79#include <linux/acct.h>
80#endif
Dave Young4f0e0562010-03-10 15:24:09 -080081#ifdef CONFIG_RT_MUTEXES
82#include <linux/rtmutex.h>
83#endif
Dave Young2edf5e42010-03-10 15:24:10 -080084#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85#include <linux/lockdep.h>
86#endif
Dave Young15485a42010-03-10 15:24:07 -080087#ifdef CONFIG_CHR_DEV_SG
88#include <scsi/sg.h>
89#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020090
Don Zickus58687ac2010-05-07 17:11:44 -040091#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050092#include <linux/nmi.h>
93#endif
94
Eric W. Biederman7058cb02007-10-18 03:05:58 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#if defined(CONFIG_SYSCTL)
97
98/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099extern int max_threads;
Alan Coxd6e71142005-06-23 00:09:43 -0700100extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700104extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800108extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200109extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100110extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400111extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113extern int sysctl_nr_trim_pages;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400117#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int sixty = 60;
119#endif
120
Aaron Tomlin270750db2014-01-20 17:34:13 +0000121static int __maybe_unused neg_one = -1;
122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700126static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800127static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700129#ifdef CONFIG_PRINTK
130static int ten_thousand = 10000;
131#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700132
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700133/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137static int maxolduid = 65535;
138static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800139static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700142static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Liu Hua80df2842014-04-07 15:38:57 -0700144/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145#ifdef CONFIG_DETECT_HUNG_TASK
146static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
147#endif
148
Dave Youngd14f1722010-02-25 20:28:57 -0500149#ifdef CONFIG_INOTIFY_USER
150#include <linux/inotify.h>
151#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700152#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif
154
155#ifdef __hppa__
156extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530157#endif
158
159#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160extern int unaligned_enabled;
161#endif
162
Jes Sorensend2b176e2006-02-28 09:42:23 -0800163#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800164extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800165#endif
166
Vineet Guptab6fca722013-01-09 20:06:28 +0530167#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168extern int no_unaligned_warning;
169#endif
170
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700171#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700172
173#define SYSCTL_WRITES_LEGACY -1
174#define SYSCTL_WRITES_WARN 0
175#define SYSCTL_WRITES_STRICT 1
176
177static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
178
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700179static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700180 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700181static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800182 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700183#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700184
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700185#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700186static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700187 void __user *buffer, size_t *lenp, loff_t *ppos);
188#endif
189
Kees Cook54b50192012-07-30 14:39:18 -0700190static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700192#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700193static int proc_dostring_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700195#endif
Kees Cook54b50192012-07-30 14:39:18 -0700196
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700197#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800198/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100199static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700200
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700201static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700202 void __user *buffer, size_t *lenp,
203 loff_t *ppos)
204{
205 int error;
206
207 error = proc_dointvec(table, write, buffer, lenp, ppos);
208 if (error)
209 return error;
210
211 if (write)
212 sysrq_toggle_support(__sysrq_enabled);
213
214 return 0;
215}
216
217#endif
218
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700219static struct ctl_table kern_table[];
220static struct ctl_table vm_table[];
221static struct ctl_table fs_table[];
222static struct ctl_table debug_table[];
223static struct ctl_table dev_table[];
224extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800225#ifdef CONFIG_EPOLL
226extern struct ctl_table epoll_table[];
227#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230int sysctl_legacy_va_layout;
231#endif
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/* The default sysctl tables: */
234
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800235static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "kernel",
238 .mode = 0555,
239 .child = kern_table,
240 },
241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "vm",
243 .mode = 0555,
244 .child = vm_table,
245 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "fs",
248 .mode = 0555,
249 .child = fs_table,
250 },
251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "debug",
253 .mode = 0555,
254 .child = debug_table,
255 },
256 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .procname = "dev",
258 .mode = 0555,
259 .child = dev_table,
260 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700261 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262};
263
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100265static int min_sched_granularity_ns = 100000; /* 100 usecs */
266static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
267static int min_wakeup_granularity_ns; /* 0 usecs */
268static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200269#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100270static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
271static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200272#endif /* CONFIG_SMP */
273#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200274
Mel Gorman5e771902010-05-24 14:32:31 -0700275#ifdef CONFIG_COMPACTION
276static int min_extfrag_threshold;
277static int max_extfrag_threshold = 1000;
278#endif
279
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700280static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200281 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800286 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200287 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200288#ifdef CONFIG_SCHED_DEBUG
289 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100290 .procname = "sched_min_granularity_ns",
291 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800294 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200297 },
298 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200299 .procname = "sched_latency_ns",
300 .data = &sysctl_sched_latency,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800303 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200304 .extra1 = &min_sched_granularity_ns,
305 .extra2 = &max_sched_granularity_ns,
306 },
307 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200308 .procname = "sched_wakeup_granularity_ns",
309 .data = &sysctl_sched_wakeup_granularity,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800312 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200313 .extra1 = &min_wakeup_granularity_ns,
314 .extra2 = &max_wakeup_granularity_ns,
315 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200316#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200317 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
321 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800322 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200325 },
326 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900327 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800331 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200332 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100333 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100334 .procname = "sched_nr_migrate",
335 .data = &sysctl_sched_nr_migrate,
336 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800338 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100339 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530340 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900341 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800345 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200346 },
347 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900348 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800349 .data = &sysctl_sched_shares_window,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec,
353 },
354 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530355 .procname = "timer_migration",
356 .data = &sysctl_timer_migration,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800359 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530360 .extra1 = &zero,
361 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530362 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200363#endif /* CONFIG_SMP */
364#ifdef CONFIG_NUMA_BALANCING
365 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200366 .procname = "numa_balancing_scan_delay_ms",
367 .data = &sysctl_numa_balancing_scan_delay,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
371 },
372 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200373 .procname = "numa_balancing_scan_period_min_ms",
374 .data = &sysctl_numa_balancing_scan_period_min,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
378 },
379 {
380 .procname = "numa_balancing_scan_period_max_ms",
381 .data = &sysctl_numa_balancing_scan_period_max,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = proc_dointvec,
385 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200386 {
387 .procname = "numa_balancing_scan_size_mb",
388 .data = &sysctl_numa_balancing_scan_size,
389 .maxlen = sizeof(unsigned int),
390 .mode = 0644,
391 .proc_handler = proc_dointvec,
392 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100393 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = sysctl_numa_balancing,
399 .extra1 = &zero,
400 .extra2 = &one,
401 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200402#endif /* CONFIG_NUMA_BALANCING */
403#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200404 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100410 },
411 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800416 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100417 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600418 {
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sched_rr_timeslice,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = sched_rr_handler,
424 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100425#ifdef CONFIG_SCHED_AUTOGROUP
426 {
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800431 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100432 .extra1 = &zero,
433 .extra2 = &one,
434 },
435#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700436#ifdef CONFIG_CFS_BANDWIDTH
437 {
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec_minmax,
443 .extra1 = &one,
444 },
445#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700446#ifdef CONFIG_PROVE_LOCKING
447 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800452 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700453 },
454#endif
455#ifdef CONFIG_LOCK_STAT
456 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700457 .procname = "lock_stat",
458 .data = &lock_stat,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700462 },
463#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "panic",
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800469 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 },
Alex Kelly046d6622012-10-04 17:15:23 -0700471#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800477 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .procname = "core_pattern",
481 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700482 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700484 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
Neil Hormana2939802009-09-23 15:56:56 -0700486 {
Neil Hormana2939802009-09-23 15:56:56 -0700487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700492 },
Alex Kelly046d6622012-10-04 17:15:23 -0700493#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800494#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700497 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800499 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700501 {
502 .procname = "sysctl_writes_strict",
503 .data = &sysctl_writes_strict,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &neg_one,
508 .extra2 = &one,
509 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800510#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100511#ifdef CONFIG_LATENCYTOP
512 {
513 .procname = "latencytop",
514 .data = &latencytop_enabled,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100518 },
519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#ifdef CONFIG_BLK_DEV_INITRD
521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "real-root-dev",
523 .data = &real_root_dev,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
528#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700529 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700530 .procname = "print-fatal-signals",
531 .data = &print_fatal_signals,
532 .maxlen = sizeof(int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700535 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700536#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 .procname = "reboot-cmd",
539 .data = reboot_command,
540 .maxlen = 256,
541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800542 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 },
544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "stop-a",
546 .data = &stop_a_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "scons-poweroff",
553 .data = &scons_pwroff,
554 .maxlen = sizeof (int),
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
558#endif
David S. Miller08714202008-11-16 23:49:24 -0800559#ifdef CONFIG_SPARC64
560 {
David S. Miller08714202008-11-16 23:49:24 -0800561 .procname = "tsb-ratio",
562 .data = &sysctl_tsb_ratio,
563 .maxlen = sizeof (int),
564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800566 },
567#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#ifdef __hppa__
569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "soft-power",
571 .data = &pwrsw_enabled,
572 .maxlen = sizeof (int),
573 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800574 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530576#endif
577#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "unaligned-trap",
580 .data = &unaligned_enabled,
581 .maxlen = sizeof (int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585#endif
586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .procname = "ctrl-alt-del",
588 .data = &C_A_D,
589 .maxlen = sizeof(int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400593#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200594 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200595 .procname = "ftrace_enabled",
596 .data = &ftrace_enabled,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800599 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200600 },
601#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500602#ifdef CONFIG_STACK_TRACER
603 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500604 .procname = "stack_tracer_enabled",
605 .data = &stack_tracer_enabled,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500609 },
610#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400611#ifdef CONFIG_TRACING
612 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100613 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400614 .data = &ftrace_dump_on_oops,
615 .maxlen = sizeof(int),
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400618 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400619 {
620 .procname = "traceoff_on_warning",
621 .data = &__disable_trace_on_warning,
622 .maxlen = sizeof(__disable_trace_on_warning),
623 .mode = 0644,
624 .proc_handler = proc_dointvec,
625 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400626#endif
Kees Cook79847542014-01-23 15:55:59 -0800627#ifdef CONFIG_KEXEC
628 {
629 .procname = "kexec_load_disabled",
630 .data = &kexec_load_disabled,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 /* only handle a transition from default "0" to "1" */
634 .proc_handler = proc_dointvec_minmax,
635 .extra1 = &one,
636 .extra2 = &one,
637 },
638#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200639#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .procname = "modprobe",
642 .data = &modprobe_path,
643 .maxlen = KMOD_PATH_LEN,
644 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800645 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 },
Kees Cook3d433212009-04-02 15:49:29 -0700647 {
Kees Cook3d433212009-04-02 15:49:29 -0700648 .procname = "modules_disabled",
649 .data = &modules_disabled,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700654 .extra1 = &one,
655 .extra2 = &one,
656 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700658#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100661 .data = &uevent_helper,
662 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800664 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 },
Michael Marineau86d56132014-04-10 14:09:31 -0700666#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#ifdef CONFIG_CHR_DEV_SG
668 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 .procname = "sg-big-buff",
670 .data = &sg_big_buff,
671 .maxlen = sizeof (int),
672 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800673 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 },
675#endif
676#ifdef CONFIG_BSD_PROCESS_ACCT
677 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 .procname = "acct",
679 .data = &acct_parm,
680 .maxlen = 3*sizeof(int),
681 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800682 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
684#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#ifdef CONFIG_MAGIC_SYSRQ
686 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800688 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .maxlen = sizeof (int),
690 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700691 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
693#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700694#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700697 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .maxlen = sizeof (int),
699 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700702#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .procname = "threads-max",
705 .data = &max_threads,
706 .maxlen = sizeof(int),
707 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800708 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 },
710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 .procname = "random",
712 .mode = 0555,
713 .child = random_table,
714 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 {
Eric Paris17f60a72011-04-01 17:07:50 -0400716 .procname = "usermodehelper",
717 .mode = 0555,
718 .child = usermodehelper_table,
719 },
720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "overflowuid",
722 .data = &overflowuid,
723 .maxlen = sizeof(int),
724 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800725 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .extra1 = &minolduid,
727 .extra2 = &maxolduid,
728 },
729 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .procname = "overflowgid",
731 .data = &overflowgid,
732 .maxlen = sizeof(int),
733 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800734 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 .extra1 = &minolduid,
736 .extra2 = &maxolduid,
737 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800738#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#ifdef CONFIG_MATHEMU
740 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 .procname = "ieee_emulation_warnings",
742 .data = &sysctl_ieee_emulation_warnings,
743 .maxlen = sizeof(int),
744 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800745 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 },
747#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200750 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 .maxlen = sizeof(int),
752 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800753 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 },
755#endif
756 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 .procname = "pid_max",
758 .data = &pid_max,
759 .maxlen = sizeof (int),
760 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800761 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 .extra1 = &pid_max_min,
763 .extra2 = &pid_max_max,
764 },
765 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 .procname = "panic_on_oops",
767 .data = &panic_on_oops,
768 .maxlen = sizeof(int),
769 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800770 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800772#if defined CONFIG_PRINTK
773 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800774 .procname = "printk",
775 .data = &console_loglevel,
776 .maxlen = 4*sizeof(int),
777 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800778 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800779 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700782 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .maxlen = sizeof(int),
784 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800785 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 },
787 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700789 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .maxlen = sizeof(int),
791 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 },
Dave Youngaf913222009-09-22 16:43:33 -0700794 {
Dave Youngaf913222009-09-22 16:43:33 -0700795 .procname = "printk_delay",
796 .data = &printk_delay_msec,
797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700800 .extra1 = &zero,
801 .extra2 = &ten_thousand,
802 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800804 .procname = "dmesg_restrict",
805 .data = &dmesg_restrict,
806 .maxlen = sizeof(int),
807 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700808 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800809 .extra1 = &zero,
810 .extra2 = &one,
811 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800812 {
813 .procname = "kptr_restrict",
814 .data = &kptr_restrict,
815 .maxlen = sizeof(int),
816 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700817 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800818 .extra1 = &zero,
819 .extra2 = &two,
820 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800821#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800822 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 .procname = "ngroups_max",
824 .data = &ngroups_max,
825 .maxlen = sizeof (int),
826 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 },
Dan Ballard73efc032011-10-31 17:11:20 -0700829 {
830 .procname = "cap_last_cap",
831 .data = (void *)&cap_last_cap,
832 .maxlen = sizeof(int),
833 .mode = 0444,
834 .proc_handler = proc_dointvec,
835 },
Don Zickus58687ac2010-05-07 17:11:44 -0400836#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500837 {
Don Zickus58687ac2010-05-07 17:11:44 -0400838 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200839 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500840 .maxlen = sizeof (int),
841 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700842 .proc_handler = proc_dowatchdog,
843 .extra1 = &zero,
844 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400845 },
846 {
847 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700848 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400849 .maxlen = sizeof(int),
850 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700851 .proc_handler = proc_dowatchdog,
Li Zefana6572f82013-05-17 10:31:04 +0800852 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400853 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500854 },
Don Zickus2508ce12010-05-07 17:11:46 -0400855 {
856 .procname = "softlockup_panic",
857 .data = &softlockup_panic,
858 .maxlen = sizeof(int),
859 .mode = 0644,
860 .proc_handler = proc_dointvec_minmax,
861 .extra1 = &zero,
862 .extra2 = &one,
863 },
Don Zickus5dc30552010-11-29 17:07:17 -0500864 {
865 .procname = "nmi_watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200866 .data = &watchdog_user_enabled,
Don Zickus5dc30552010-11-29 17:07:17 -0500867 .maxlen = sizeof (int),
868 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700869 .proc_handler = proc_dowatchdog,
870 .extra1 = &zero,
871 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500872 },
873#endif
874#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
875 {
876 .procname = "unknown_nmi_panic",
877 .data = &unknown_nmi_panic,
878 .maxlen = sizeof (int),
879 .mode = 0644,
880 .proc_handler = proc_dointvec,
881 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500882#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883#if defined(CONFIG_X86)
884 {
Don Zickus8da5add2006-09-26 10:52:27 +0200885 .procname = "panic_on_unrecovered_nmi",
886 .data = &panic_on_unrecovered_nmi,
887 .maxlen = sizeof(int),
888 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800889 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200890 },
891 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700892 .procname = "panic_on_io_nmi",
893 .data = &panic_on_io_nmi,
894 .maxlen = sizeof(int),
895 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800896 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700897 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900898#ifdef CONFIG_DEBUG_STACKOVERFLOW
899 {
900 .procname = "panic_on_stackoverflow",
901 .data = &sysctl_panic_on_stackoverflow,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = proc_dointvec,
905 },
906#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700907 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 .procname = "bootloader_type",
909 .data = &bootloader_type,
910 .maxlen = sizeof (int),
911 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800912 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100914 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700915 .procname = "bootloader_version",
916 .data = &bootloader_version,
917 .maxlen = sizeof (int),
918 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800919 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700920 },
921 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100922 .procname = "kstack_depth_to_print",
923 .data = &kstack_depth_to_print,
924 .maxlen = sizeof(int),
925 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800926 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100927 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100928 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100929 .procname = "io_delay_type",
930 .data = &io_delay_type,
931 .maxlen = sizeof(int),
932 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800933 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100934 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800936#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .procname = "randomize_va_space",
939 .data = &randomize_va_space,
940 .maxlen = sizeof(int),
941 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800942 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800944#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800945#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700946 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700947 .procname = "spin_retry",
948 .data = &spin_retry,
949 .maxlen = sizeof (int),
950 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700952 },
953#endif
Len Brown673d5b42007-07-28 03:33:16 -0400954#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800955 {
Pavel Machekc255d842006-02-20 18:27:58 -0800956 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700957 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800958 .maxlen = sizeof (unsigned long),
959 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800960 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800961 },
962#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530963#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800964 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800965 .procname = "ignore-unaligned-usertrap",
966 .data = &no_unaligned_warning,
967 .maxlen = sizeof (int),
968 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800969 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800970 },
Vineet Guptab6fca722013-01-09 20:06:28 +0530971#endif
972#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800973 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800974 .procname = "unaligned-dump-stack",
975 .data = &unaligned_dump_stack,
976 .maxlen = sizeof (int),
977 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800978 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800979 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800980#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800981#ifdef CONFIG_DETECT_HUNG_TASK
982 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800983 .procname = "hung_task_panic",
984 .data = &sysctl_hung_task_panic,
985 .maxlen = sizeof(int),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800988 .extra1 = &zero,
989 .extra2 = &one,
990 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100991 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100992 .procname = "hung_task_check_count",
993 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +0800994 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100995 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +0800996 .proc_handler = proc_dointvec_minmax,
997 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100998 },
999 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001000 .procname = "hung_task_timeout_secs",
1001 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001002 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001003 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001004 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001005 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001006 },
1007 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001008 .procname = "hung_task_warnings",
1009 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001010 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001011 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001012 .proc_handler = proc_dointvec_minmax,
1013 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001014 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001015#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001016#ifdef CONFIG_COMPAT
1017 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001018 .procname = "compat-log",
1019 .data = &compat_log,
1020 .maxlen = sizeof (int),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001023 },
1024#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001025#ifdef CONFIG_RT_MUTEXES
1026 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001027 .procname = "max_lock_depth",
1028 .data = &max_lock_depth,
1029 .maxlen = sizeof(int),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001032 },
1033#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001034 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001035 .procname = "poweroff_cmd",
1036 .data = &poweroff_cmd,
1037 .maxlen = POWEROFF_CMD_PATH_LEN,
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001040 },
David Howells0b77f5b2008-04-29 01:01:32 -07001041#ifdef CONFIG_KEYS
1042 {
David Howells0b77f5b2008-04-29 01:01:32 -07001043 .procname = "keys",
1044 .mode = 0555,
1045 .child = key_sysctls,
1046 },
1047#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001048#ifdef CONFIG_RCU_TORTURE_TEST
1049 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001050 .procname = "rcutorture_runnable",
1051 .data = &rcutorture_runnable,
1052 .maxlen = sizeof(int),
1053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001055 },
1056#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001057#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001058 /*
1059 * User-space scripts rely on the existence of this file
1060 * as a feature check for perf_events being enabled.
1061 *
1062 * So it's an ABI, do not remove!
1063 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001064 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001065 .procname = "perf_event_paranoid",
1066 .data = &sysctl_perf_event_paranoid,
1067 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001068 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001069 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001070 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001071 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001072 .procname = "perf_event_mlock_kb",
1073 .data = &sysctl_perf_event_mlock,
1074 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001075 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001076 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001077 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001078 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001079 .procname = "perf_event_max_sample_rate",
1080 .data = &sysctl_perf_event_sample_rate,
1081 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001082 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001083 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001084 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001085 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001086 {
1087 .procname = "perf_cpu_time_max_percent",
1088 .data = &sysctl_perf_cpu_time_max_percent,
1089 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1090 .mode = 0644,
1091 .proc_handler = perf_cpu_time_max_percent_handler,
1092 .extra1 = &zero,
1093 .extra2 = &one_hundred,
1094 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001095#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001096#ifdef CONFIG_KMEMCHECK
1097 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001098 .procname = "kmemcheck",
1099 .data = &kmemcheck_enabled,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001102 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001103 },
1104#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001105 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106};
1107
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001108static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .procname = "overcommit_memory",
1111 .data = &sysctl_overcommit_memory,
1112 .maxlen = sizeof(sysctl_overcommit_memory),
1113 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001114 .proc_handler = proc_dointvec_minmax,
1115 .extra1 = &zero,
1116 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 },
1118 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001119 .procname = "panic_on_oom",
1120 .data = &sysctl_panic_on_oom,
1121 .maxlen = sizeof(sysctl_panic_on_oom),
1122 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001123 .proc_handler = proc_dointvec_minmax,
1124 .extra1 = &zero,
1125 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001126 },
1127 {
David Rientjesfe071d72007-10-16 23:25:56 -07001128 .procname = "oom_kill_allocating_task",
1129 .data = &sysctl_oom_kill_allocating_task,
1130 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1131 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001132 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001133 },
1134 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001135 .procname = "oom_dump_tasks",
1136 .data = &sysctl_oom_dump_tasks,
1137 .maxlen = sizeof(sysctl_oom_dump_tasks),
1138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001140 },
1141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .procname = "overcommit_ratio",
1143 .data = &sysctl_overcommit_ratio,
1144 .maxlen = sizeof(sysctl_overcommit_ratio),
1145 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001146 .proc_handler = overcommit_ratio_handler,
1147 },
1148 {
1149 .procname = "overcommit_kbytes",
1150 .data = &sysctl_overcommit_kbytes,
1151 .maxlen = sizeof(sysctl_overcommit_kbytes),
1152 .mode = 0644,
1153 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 },
1155 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 .procname = "page-cluster",
1157 .data = &page_cluster,
1158 .maxlen = sizeof(int),
1159 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001160 .proc_handler = proc_dointvec_minmax,
1161 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 },
1163 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 .procname = "dirty_background_ratio",
1165 .data = &dirty_background_ratio,
1166 .maxlen = sizeof(dirty_background_ratio),
1167 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001168 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 .extra1 = &zero,
1170 .extra2 = &one_hundred,
1171 },
1172 {
David Rientjes2da02992009-01-06 14:39:31 -08001173 .procname = "dirty_background_bytes",
1174 .data = &dirty_background_bytes,
1175 .maxlen = sizeof(dirty_background_bytes),
1176 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001177 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001178 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001179 },
1180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .procname = "dirty_ratio",
1182 .data = &vm_dirty_ratio,
1183 .maxlen = sizeof(vm_dirty_ratio),
1184 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001185 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 .extra1 = &zero,
1187 .extra2 = &one_hundred,
1188 },
1189 {
David Rientjes2da02992009-01-06 14:39:31 -08001190 .procname = "dirty_bytes",
1191 .data = &vm_dirty_bytes,
1192 .maxlen = sizeof(vm_dirty_bytes),
1193 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001194 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001195 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001196 },
1197 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001199 .data = &dirty_writeback_interval,
1200 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001202 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 },
1204 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001206 .data = &dirty_expire_interval,
1207 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001209 .proc_handler = proc_dointvec_minmax,
1210 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 },
1212 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001213 .procname = "nr_pdflush_threads",
1214 .mode = 0444 /* read-only */,
1215 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 },
1217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .procname = "swappiness",
1219 .data = &vm_swappiness,
1220 .maxlen = sizeof(vm_swappiness),
1221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001222 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .extra1 = &zero,
1224 .extra2 = &one_hundred,
1225 },
1226#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001227 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001229 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 .maxlen = sizeof(unsigned long),
1231 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001232 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 .extra1 = (void *)&hugetlb_zero,
1234 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001235 },
1236#ifdef CONFIG_NUMA
1237 {
1238 .procname = "nr_hugepages_mempolicy",
1239 .data = NULL,
1240 .maxlen = sizeof(unsigned long),
1241 .mode = 0644,
1242 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1243 .extra1 = (void *)&hugetlb_zero,
1244 .extra2 = (void *)&hugetlb_infinity,
1245 },
1246#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 .procname = "hugetlb_shm_group",
1249 .data = &sysctl_hugetlb_shm_group,
1250 .maxlen = sizeof(gid_t),
1251 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001252 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 },
Mel Gorman396faf02007-07-17 04:03:13 -07001254 {
Mel Gorman396faf02007-07-17 04:03:13 -07001255 .procname = "hugepages_treat_as_movable",
1256 .data = &hugepages_treat_as_movable,
1257 .maxlen = sizeof(int),
1258 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001259 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001260 },
Adam Litke54f9f802007-10-16 01:26:20 -07001261 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001262 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001263 .data = NULL,
1264 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001265 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001266 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001267 .extra1 = (void *)&hugetlb_zero,
1268 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270#endif
1271 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 .procname = "lowmem_reserve_ratio",
1273 .data = &sysctl_lowmem_reserve_ratio,
1274 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1275 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001276 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 },
1278 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001279 .procname = "drop_caches",
1280 .data = &sysctl_drop_caches,
1281 .maxlen = sizeof(int),
1282 .mode = 0644,
1283 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001284 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001285 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001286 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001287#ifdef CONFIG_COMPACTION
1288 {
1289 .procname = "compact_memory",
1290 .data = &sysctl_compact_memory,
1291 .maxlen = sizeof(int),
1292 .mode = 0200,
1293 .proc_handler = sysctl_compaction_handler,
1294 },
Mel Gorman5e771902010-05-24 14:32:31 -07001295 {
1296 .procname = "extfrag_threshold",
1297 .data = &sysctl_extfrag_threshold,
1298 .maxlen = sizeof(int),
1299 .mode = 0644,
1300 .proc_handler = sysctl_extfrag_handler,
1301 .extra1 = &min_extfrag_threshold,
1302 .extra2 = &max_extfrag_threshold,
1303 },
1304
Mel Gorman76ab0f52010-05-24 14:32:28 -07001305#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001306 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 .procname = "min_free_kbytes",
1308 .data = &min_free_kbytes,
1309 .maxlen = sizeof(min_free_kbytes),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 .extra1 = &zero,
1313 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001314 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001315 .procname = "percpu_pagelist_fraction",
1316 .data = &percpu_pagelist_fraction,
1317 .maxlen = sizeof(percpu_pagelist_fraction),
1318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001319 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001320 .extra1 = &min_percpu_pagelist_fract,
1321 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322#ifdef CONFIG_MMU
1323 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 .procname = "max_map_count",
1325 .data = &sysctl_max_map_count,
1326 .maxlen = sizeof(sysctl_max_map_count),
1327 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001328 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001329 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001331#else
1332 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001333 .procname = "nr_trim_pages",
1334 .data = &sysctl_nr_trim_pages,
1335 .maxlen = sizeof(sysctl_nr_trim_pages),
1336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001337 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001338 .extra1 = &zero,
1339 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340#endif
1341 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 .procname = "laptop_mode",
1343 .data = &laptop_mode,
1344 .maxlen = sizeof(laptop_mode),
1345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001346 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 },
1348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 .procname = "block_dump",
1350 .data = &block_dump,
1351 .maxlen = sizeof(block_dump),
1352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .extra1 = &zero,
1355 },
1356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .procname = "vfs_cache_pressure",
1358 .data = &sysctl_vfs_cache_pressure,
1359 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1360 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001361 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .extra1 = &zero,
1363 },
1364#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1365 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .procname = "legacy_va_layout",
1367 .data = &sysctl_legacy_va_layout,
1368 .maxlen = sizeof(sysctl_legacy_va_layout),
1369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001370 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .extra1 = &zero,
1372 },
1373#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001374#ifdef CONFIG_NUMA
1375 {
Christoph Lameter17436602006-01-18 17:42:32 -08001376 .procname = "zone_reclaim_mode",
1377 .data = &zone_reclaim_mode,
1378 .maxlen = sizeof(zone_reclaim_mode),
1379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001380 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001381 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001382 },
Christoph Lameter96146342006-07-03 00:24:13 -07001383 {
Christoph Lameter96146342006-07-03 00:24:13 -07001384 .procname = "min_unmapped_ratio",
1385 .data = &sysctl_min_unmapped_ratio,
1386 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001388 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001389 .extra1 = &zero,
1390 .extra2 = &one_hundred,
1391 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001392 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001393 .procname = "min_slab_ratio",
1394 .data = &sysctl_min_slab_ratio,
1395 .maxlen = sizeof(sysctl_min_slab_ratio),
1396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001398 .extra1 = &zero,
1399 .extra2 = &one_hundred,
1400 },
Christoph Lameter17436602006-01-18 17:42:32 -08001401#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001402#ifdef CONFIG_SMP
1403 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001404 .procname = "stat_interval",
1405 .data = &sysctl_stat_interval,
1406 .maxlen = sizeof(sysctl_stat_interval),
1407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001408 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001409 },
1410#endif
David Howells6e141542009-12-15 19:27:45 +00001411#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001412 {
Eric Parised032182007-06-28 15:55:21 -04001413 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001414 .data = &dac_mmap_min_addr,
1415 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001417 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001418 },
David Howells6e141542009-12-15 19:27:45 +00001419#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001420#ifdef CONFIG_NUMA
1421 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001422 .procname = "numa_zonelist_order",
1423 .data = &numa_zonelist_order,
1424 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001426 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001427 },
1428#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001429#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001430 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001431 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001432 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001433#ifdef CONFIG_X86_32
1434 .data = &vdso32_enabled,
1435 .maxlen = sizeof(vdso32_enabled),
1436#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001437 .data = &vdso_enabled,
1438 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001439#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001442 .extra1 = &zero,
1443 },
1444#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001445#ifdef CONFIG_HIGHMEM
1446 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001447 .procname = "highmem_is_dirtyable",
1448 .data = &vm_highmem_is_dirtyable,
1449 .maxlen = sizeof(vm_highmem_is_dirtyable),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001452 .extra1 = &zero,
1453 .extra2 = &one,
1454 },
1455#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001456 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001457 .procname = "scan_unevictable_pages",
1458 .data = &scan_unevictable_pages,
1459 .maxlen = sizeof(scan_unevictable_pages),
1460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001461 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001462 },
Andi Kleen6a460792009-09-16 11:50:15 +02001463#ifdef CONFIG_MEMORY_FAILURE
1464 {
Andi Kleen6a460792009-09-16 11:50:15 +02001465 .procname = "memory_failure_early_kill",
1466 .data = &sysctl_memory_failure_early_kill,
1467 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001469 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001470 .extra1 = &zero,
1471 .extra2 = &one,
1472 },
1473 {
Andi Kleen6a460792009-09-16 11:50:15 +02001474 .procname = "memory_failure_recovery",
1475 .data = &sysctl_memory_failure_recovery,
1476 .maxlen = sizeof(sysctl_memory_failure_recovery),
1477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001478 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001479 .extra1 = &zero,
1480 .extra2 = &one,
1481 },
1482#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001483 {
1484 .procname = "user_reserve_kbytes",
1485 .data = &sysctl_user_reserve_kbytes,
1486 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1487 .mode = 0644,
1488 .proc_handler = proc_doulongvec_minmax,
1489 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001490 {
1491 .procname = "admin_reserve_kbytes",
1492 .data = &sysctl_admin_reserve_kbytes,
1493 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1494 .mode = 0644,
1495 .proc_handler = proc_doulongvec_minmax,
1496 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001497 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498};
1499
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001500#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001501static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001502 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001503};
1504#endif
1505
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001506static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 .procname = "inode-nr",
1509 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001510 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001512 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 },
1514 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 .procname = "inode-state",
1516 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001517 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001519 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 },
1521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 .procname = "file-nr",
1523 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001524 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001526 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 },
1528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 .procname = "file-max",
1530 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001531 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001533 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 },
1535 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001536 .procname = "nr_open",
1537 .data = &sysctl_nr_open,
1538 .maxlen = sizeof(int),
1539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001540 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001541 .extra1 = &sysctl_nr_open_min,
1542 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001543 },
1544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 .procname = "dentry-state",
1546 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001547 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001549 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 },
1551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 .procname = "overflowuid",
1553 .data = &fs_overflowuid,
1554 .maxlen = sizeof(int),
1555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 .extra1 = &minolduid,
1558 .extra2 = &maxolduid,
1559 },
1560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 .procname = "overflowgid",
1562 .data = &fs_overflowgid,
1563 .maxlen = sizeof(int),
1564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001565 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 .extra1 = &minolduid,
1567 .extra2 = &maxolduid,
1568 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001569#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 .procname = "leases-enable",
1572 .data = &leases_enable,
1573 .maxlen = sizeof(int),
1574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001575 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001577#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578#ifdef CONFIG_DNOTIFY
1579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 .procname = "dir-notify-enable",
1581 .data = &dir_notify_enable,
1582 .maxlen = sizeof(int),
1583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001584 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 },
1586#endif
1587#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001588#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 .procname = "lease-break-time",
1591 .data = &lease_break_time,
1592 .maxlen = sizeof(int),
1593 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001594 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001596#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001597#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 .procname = "aio-nr",
1600 .data = &aio_nr,
1601 .maxlen = sizeof(aio_nr),
1602 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001603 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 },
1605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 .procname = "aio-max-nr",
1607 .data = &aio_max_nr,
1608 .maxlen = sizeof(aio_max_nr),
1609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001610 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001612#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001613#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001614 {
Robert Love0399cb02005-07-13 12:38:18 -04001615 .procname = "inotify",
1616 .mode = 0555,
1617 .child = inotify_table,
1618 },
1619#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001620#ifdef CONFIG_EPOLL
1621 {
1622 .procname = "epoll",
1623 .mode = 0555,
1624 .child = epoll_table,
1625 },
1626#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001628 {
Kees Cook800179c2012-07-25 17:29:07 -07001629 .procname = "protected_symlinks",
1630 .data = &sysctl_protected_symlinks,
1631 .maxlen = sizeof(int),
1632 .mode = 0600,
1633 .proc_handler = proc_dointvec_minmax,
1634 .extra1 = &zero,
1635 .extra2 = &one,
1636 },
1637 {
1638 .procname = "protected_hardlinks",
1639 .data = &sysctl_protected_hardlinks,
1640 .maxlen = sizeof(int),
1641 .mode = 0600,
1642 .proc_handler = proc_dointvec_minmax,
1643 .extra1 = &zero,
1644 .extra2 = &one,
1645 },
1646 {
Alan Coxd6e71142005-06-23 00:09:43 -07001647 .procname = "suid_dumpable",
1648 .data = &suid_dumpable,
1649 .maxlen = sizeof(int),
1650 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001651 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001652 .extra1 = &zero,
1653 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001654 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001655#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1656 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001657 .procname = "binfmt_misc",
1658 .mode = 0555,
1659 .child = binfmt_misc_table,
1660 },
1661#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001662 {
Jens Axboeff9da692010-06-03 14:54:39 +02001663 .procname = "pipe-max-size",
1664 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001665 .maxlen = sizeof(int),
1666 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001667 .proc_handler = &pipe_proc_fn,
1668 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001669 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001670 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671};
1672
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001673static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001674#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001675 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001676 .procname = "exception-trace",
1677 .data = &show_unhandled_signals,
1678 .maxlen = sizeof(int),
1679 .mode = 0644,
1680 .proc_handler = proc_dointvec
1681 },
1682#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001683#if defined(CONFIG_OPTPROBES)
1684 {
1685 .procname = "kprobes-optimization",
1686 .data = &sysctl_kprobes_optimization,
1687 .maxlen = sizeof(int),
1688 .mode = 0644,
1689 .proc_handler = proc_kprobes_optimization_handler,
1690 .extra1 = &zero,
1691 .extra2 = &one,
1692 },
1693#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001694 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695};
1696
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001697static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001698 { }
Robert Love0eeca282005-07-12 17:06:03 -04001699};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001701int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001702{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001703 struct ctl_table_header *hdr;
1704
1705 hdr = register_sysctl_table(sysctl_base_table);
1706 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001707 return 0;
1708}
1709
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001710#endif /* CONFIG_SYSCTL */
1711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712/*
1713 * /proc/sys support
1714 */
1715
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001716#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Kees Cookf8808302014-06-06 14:37:17 -07001718static int _proc_do_string(char *data, int maxlen, int write,
1719 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001720 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001721{
1722 size_t len;
1723 char __user *p;
1724 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001725
1726 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001727 *lenp = 0;
1728 return 0;
1729 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001730
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001731 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001732 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1733 /* Only continue writes not past the end of buffer. */
1734 len = strlen(data);
1735 if (len > maxlen - 1)
1736 len = maxlen - 1;
1737
1738 if (*ppos > len)
1739 return 0;
1740 len = *ppos;
1741 } else {
1742 /* Start writing from beginning of buffer. */
1743 len = 0;
1744 }
1745
Kees Cook2ca9bb42014-06-06 14:37:18 -07001746 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001747 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001748 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001749 if (get_user(c, p++))
1750 return -EFAULT;
1751 if (c == 0 || c == '\n')
1752 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001753 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001754 }
Kees Cookf8808302014-06-06 14:37:17 -07001755 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001756 } else {
1757 len = strlen(data);
1758 if (len > maxlen)
1759 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001760
1761 if (*ppos > len) {
1762 *lenp = 0;
1763 return 0;
1764 }
1765
1766 data += *ppos;
1767 len -= *ppos;
1768
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001769 if (len > *lenp)
1770 len = *lenp;
1771 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001772 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001773 return -EFAULT;
1774 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001775 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001776 return -EFAULT;
1777 len++;
1778 }
1779 *lenp = len;
1780 *ppos += len;
1781 }
1782 return 0;
1783}
1784
Kees Cookf4aacea2014-06-06 14:37:19 -07001785static void warn_sysctl_write(struct ctl_table *table)
1786{
1787 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1788 "This will not be supported in the future. To silence this\n"
1789 "warning, set kernel.sysctl_writes_strict = -1\n",
1790 current->comm, table->procname);
1791}
1792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793/**
1794 * proc_dostring - read a string sysctl
1795 * @table: the sysctl table
1796 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 * @buffer: the user buffer
1798 * @lenp: the size of the user buffer
1799 * @ppos: file position
1800 *
1801 * Reads/writes a string from/to the user buffer. If the kernel
1802 * buffer provided is not large enough to hold the string, the
1803 * string is truncated. The copied string is %NULL-terminated.
1804 * If the string is being read by the user process, it is copied
1805 * and a newline '\n' is added. It is truncated if the buffer is
1806 * not large enough.
1807 *
1808 * Returns 0 on success.
1809 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001810int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 void __user *buffer, size_t *lenp, loff_t *ppos)
1812{
Kees Cookf4aacea2014-06-06 14:37:19 -07001813 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1814 warn_sysctl_write(table);
1815
Kees Cookf8808302014-06-06 14:37:17 -07001816 return _proc_do_string((char *)(table->data), table->maxlen, write,
1817 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818}
1819
Amerigo Wang00b7c332010-05-05 00:26:45 +00001820static size_t proc_skip_spaces(char **buf)
1821{
1822 size_t ret;
1823 char *tmp = skip_spaces(*buf);
1824 ret = tmp - *buf;
1825 *buf = tmp;
1826 return ret;
1827}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001829static void proc_skip_char(char **buf, size_t *size, const char v)
1830{
1831 while (*size) {
1832 if (**buf != v)
1833 break;
1834 (*size)--;
1835 (*buf)++;
1836 }
1837}
1838
Amerigo Wang00b7c332010-05-05 00:26:45 +00001839#define TMPBUFLEN 22
1840/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001841 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001842 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001843 * @buf: a kernel buffer
1844 * @size: size of the kernel buffer
1845 * @val: this is where the number will be stored
1846 * @neg: set to %TRUE if number is negative
1847 * @perm_tr: a vector which contains the allowed trailers
1848 * @perm_tr_len: size of the perm_tr vector
1849 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001850 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001851 * In case of success %0 is returned and @buf and @size are updated with
1852 * the amount of bytes read. If @tr is non-NULL and a trailing
1853 * character exists (size is non-zero after returning from this
1854 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001855 */
1856static int proc_get_long(char **buf, size_t *size,
1857 unsigned long *val, bool *neg,
1858 const char *perm_tr, unsigned perm_tr_len, char *tr)
1859{
1860 int len;
1861 char *p, tmp[TMPBUFLEN];
1862
1863 if (!*size)
1864 return -EINVAL;
1865
1866 len = *size;
1867 if (len > TMPBUFLEN - 1)
1868 len = TMPBUFLEN - 1;
1869
1870 memcpy(tmp, *buf, len);
1871
1872 tmp[len] = 0;
1873 p = tmp;
1874 if (*p == '-' && *size > 1) {
1875 *neg = true;
1876 p++;
1877 } else
1878 *neg = false;
1879 if (!isdigit(*p))
1880 return -EINVAL;
1881
1882 *val = simple_strtoul(p, &p, 0);
1883
1884 len = p - tmp;
1885
1886 /* We don't know if the next char is whitespace thus we may accept
1887 * invalid integers (e.g. 1234...a) or two integers instead of one
1888 * (e.g. 123...1). So lets not allow such large numbers. */
1889 if (len == TMPBUFLEN - 1)
1890 return -EINVAL;
1891
1892 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1893 return -EINVAL;
1894
1895 if (tr && (len < *size))
1896 *tr = *p;
1897
1898 *buf += len;
1899 *size -= len;
1900
1901 return 0;
1902}
1903
1904/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001905 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001906 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001907 * @buf: the user buffer
1908 * @size: the size of the user buffer
1909 * @val: the integer to be converted
1910 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001911 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001912 * In case of success %0 is returned and @buf and @size are updated with
1913 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001914 */
1915static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1916 bool neg)
1917{
1918 int len;
1919 char tmp[TMPBUFLEN], *p = tmp;
1920
1921 sprintf(p, "%s%lu", neg ? "-" : "", val);
1922 len = strlen(tmp);
1923 if (len > *size)
1924 len = *size;
1925 if (copy_to_user(*buf, tmp, len))
1926 return -EFAULT;
1927 *size -= len;
1928 *buf += len;
1929 return 0;
1930}
1931#undef TMPBUFLEN
1932
1933static int proc_put_char(void __user **buf, size_t *size, char c)
1934{
1935 if (*size) {
1936 char __user **buffer = (char __user **)buf;
1937 if (put_user(c, *buffer))
1938 return -EFAULT;
1939 (*size)--, (*buffer)++;
1940 *buf = *buffer;
1941 }
1942 return 0;
1943}
1944
1945static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 int *valp,
1947 int write, void *data)
1948{
1949 if (write) {
1950 *valp = *negp ? -*lvalp : *lvalp;
1951 } else {
1952 int val = *valp;
1953 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001954 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 *lvalp = (unsigned long)-val;
1956 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001957 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 *lvalp = (unsigned long)val;
1959 }
1960 }
1961 return 0;
1962}
1963
Amerigo Wang00b7c332010-05-05 00:26:45 +00001964static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1965
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001966static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001967 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001968 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001969 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 int write, void *data),
1971 void *data)
1972{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001973 int *i, vleft, first = 1, err = 0;
1974 unsigned long page = 0;
1975 size_t left;
1976 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Amerigo Wang00b7c332010-05-05 00:26:45 +00001978 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 *lenp = 0;
1980 return 0;
1981 }
1982
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001983 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 vleft = table->maxlen / sizeof(*i);
1985 left = *lenp;
1986
1987 if (!conv)
1988 conv = do_proc_dointvec_conv;
1989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001991 if (*ppos) {
1992 switch (sysctl_writes_strict) {
1993 case SYSCTL_WRITES_STRICT:
1994 goto out;
1995 case SYSCTL_WRITES_WARN:
1996 warn_sysctl_write(table);
1997 break;
1998 default:
1999 break;
2000 }
2001 }
2002
Amerigo Wang00b7c332010-05-05 00:26:45 +00002003 if (left > PAGE_SIZE - 1)
2004 left = PAGE_SIZE - 1;
2005 page = __get_free_page(GFP_TEMPORARY);
2006 kbuf = (char *) page;
2007 if (!kbuf)
2008 return -ENOMEM;
2009 if (copy_from_user(kbuf, buffer, left)) {
2010 err = -EFAULT;
2011 goto free;
2012 }
2013 kbuf[left] = 0;
2014 }
2015
2016 for (; left && vleft--; i++, first=0) {
2017 unsigned long lval;
2018 bool neg;
2019
2020 if (write) {
2021 left -= proc_skip_spaces(&kbuf);
2022
J. R. Okajima563b0462010-05-25 16:10:14 -07002023 if (!left)
2024 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002025 err = proc_get_long(&kbuf, &left, &lval, &neg,
2026 proc_wspace_sep,
2027 sizeof(proc_wspace_sep), NULL);
2028 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002030 if (conv(&neg, &lval, i, 1, data)) {
2031 err = -EINVAL;
2032 break;
2033 }
2034 } else {
2035 if (conv(&neg, &lval, i, 0, data)) {
2036 err = -EINVAL;
2037 break;
2038 }
2039 if (!first)
2040 err = proc_put_char(&buffer, &left, '\t');
2041 if (err)
2042 break;
2043 err = proc_put_long(&buffer, &left, lval, neg);
2044 if (err)
2045 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 }
2047 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002048
2049 if (!write && !first && left && !err)
2050 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002051 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002052 left -= proc_skip_spaces(&kbuf);
2053free:
2054 if (write) {
2055 free_page(page);
2056 if (first)
2057 return err ? : -EINVAL;
2058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002060out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002062 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063}
2064
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002065static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002066 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002067 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002068 int write, void *data),
2069 void *data)
2070{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002071 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002072 buffer, lenp, ppos, conv, data);
2073}
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075/**
2076 * proc_dointvec - read a vector of integers
2077 * @table: the sysctl table
2078 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 * @buffer: the user buffer
2080 * @lenp: the size of the user buffer
2081 * @ppos: file position
2082 *
2083 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2084 * values from/to the user buffer, treated as an ASCII string.
2085 *
2086 * Returns 0 on success.
2087 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002088int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 void __user *buffer, size_t *lenp, loff_t *ppos)
2090{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002091 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 NULL,NULL);
2093}
2094
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002095/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002096 * Taint values can only be increased
2097 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002098 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002099static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002100 void __user *buffer, size_t *lenp, loff_t *ppos)
2101{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002102 struct ctl_table t;
2103 unsigned long tmptaint = get_taint();
2104 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002105
Bastian Blank91fcd412007-04-23 14:41:14 -07002106 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002107 return -EPERM;
2108
Andi Kleen25ddbb12008-10-15 22:01:41 -07002109 t = *table;
2110 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002111 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002112 if (err < 0)
2113 return err;
2114
2115 if (write) {
2116 /*
2117 * Poor man's atomic or. Not worth adding a primitive
2118 * to everyone's atomic.h for this
2119 */
2120 int i;
2121 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2122 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302123 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002124 }
2125 }
2126
2127 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002128}
2129
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002130#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002131static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002132 void __user *buffer, size_t *lenp, loff_t *ppos)
2133{
2134 if (write && !capable(CAP_SYS_ADMIN))
2135 return -EPERM;
2136
2137 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2138}
2139#endif
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141struct do_proc_dointvec_minmax_conv_param {
2142 int *min;
2143 int *max;
2144};
2145
Amerigo Wang00b7c332010-05-05 00:26:45 +00002146static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2147 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 int write, void *data)
2149{
2150 struct do_proc_dointvec_minmax_conv_param *param = data;
2151 if (write) {
2152 int val = *negp ? -*lvalp : *lvalp;
2153 if ((param->min && *param->min > val) ||
2154 (param->max && *param->max < val))
2155 return -EINVAL;
2156 *valp = val;
2157 } else {
2158 int val = *valp;
2159 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 *lvalp = (unsigned long)-val;
2162 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002163 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 *lvalp = (unsigned long)val;
2165 }
2166 }
2167 return 0;
2168}
2169
2170/**
2171 * proc_dointvec_minmax - read a vector of integers with min/max values
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2177 *
2178 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2179 * values from/to the user buffer, treated as an ASCII string.
2180 *
2181 * This routine will ensure the values are within the range specified by
2182 * table->extra1 (min) and table->extra2 (max).
2183 *
2184 * Returns 0 on success.
2185 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002186int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 void __user *buffer, size_t *lenp, loff_t *ppos)
2188{
2189 struct do_proc_dointvec_minmax_conv_param param = {
2190 .min = (int *) table->extra1,
2191 .max = (int *) table->extra2,
2192 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002193 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 do_proc_dointvec_minmax_conv, &param);
2195}
2196
Kees Cook54b50192012-07-30 14:39:18 -07002197static void validate_coredump_safety(void)
2198{
Alex Kelly046d6622012-10-04 17:15:23 -07002199#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002200 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002201 core_pattern[0] != '/' && core_pattern[0] != '|') {
2202 printk(KERN_WARNING "Unsafe core_pattern used with "\
2203 "suid_dumpable=2. Pipe handler or fully qualified "\
2204 "core dump path required.\n");
2205 }
Alex Kelly046d6622012-10-04 17:15:23 -07002206#endif
Kees Cook54b50192012-07-30 14:39:18 -07002207}
2208
2209static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2210 void __user *buffer, size_t *lenp, loff_t *ppos)
2211{
2212 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2213 if (!error)
2214 validate_coredump_safety();
2215 return error;
2216}
2217
Alex Kelly046d6622012-10-04 17:15:23 -07002218#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002219static int proc_dostring_coredump(struct ctl_table *table, int write,
2220 void __user *buffer, size_t *lenp, loff_t *ppos)
2221{
2222 int error = proc_dostring(table, write, buffer, lenp, ppos);
2223 if (!error)
2224 validate_coredump_safety();
2225 return error;
2226}
Alex Kelly046d6622012-10-04 17:15:23 -07002227#endif
Kees Cook54b50192012-07-30 14:39:18 -07002228
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002229static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 void __user *buffer,
2231 size_t *lenp, loff_t *ppos,
2232 unsigned long convmul,
2233 unsigned long convdiv)
2234{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002235 unsigned long *i, *min, *max;
2236 int vleft, first = 1, err = 0;
2237 unsigned long page = 0;
2238 size_t left;
2239 char *kbuf;
2240
2241 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 *lenp = 0;
2243 return 0;
2244 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002245
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002246 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 min = (unsigned long *) table->extra1;
2248 max = (unsigned long *) table->extra2;
2249 vleft = table->maxlen / sizeof(unsigned long);
2250 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002251
2252 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002253 if (*ppos) {
2254 switch (sysctl_writes_strict) {
2255 case SYSCTL_WRITES_STRICT:
2256 goto out;
2257 case SYSCTL_WRITES_WARN:
2258 warn_sysctl_write(table);
2259 break;
2260 default:
2261 break;
2262 }
2263 }
2264
Amerigo Wang00b7c332010-05-05 00:26:45 +00002265 if (left > PAGE_SIZE - 1)
2266 left = PAGE_SIZE - 1;
2267 page = __get_free_page(GFP_TEMPORARY);
2268 kbuf = (char *) page;
2269 if (!kbuf)
2270 return -ENOMEM;
2271 if (copy_from_user(kbuf, buffer, left)) {
2272 err = -EFAULT;
2273 goto free;
2274 }
2275 kbuf[left] = 0;
2276 }
2277
Eric Dumazet27b3d802010-10-07 12:59:29 -07002278 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002279 unsigned long val;
2280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002282 bool neg;
2283
2284 left -= proc_skip_spaces(&kbuf);
2285
2286 err = proc_get_long(&kbuf, &left, &val, &neg,
2287 proc_wspace_sep,
2288 sizeof(proc_wspace_sep), NULL);
2289 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 break;
2291 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 continue;
2293 if ((min && val < *min) || (max && val > *max))
2294 continue;
2295 *i = val;
2296 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002297 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002298 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002299 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002300 if (err)
2301 break;
2302 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 err = proc_put_long(&buffer, &left, val, false);
2304 if (err)
2305 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 }
2307 }
2308
Amerigo Wang00b7c332010-05-05 00:26:45 +00002309 if (!write && !first && left && !err)
2310 err = proc_put_char(&buffer, &left, '\n');
2311 if (write && !err)
2312 left -= proc_skip_spaces(&kbuf);
2313free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002315 free_page(page);
2316 if (first)
2317 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002320out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002325static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002326 void __user *buffer,
2327 size_t *lenp, loff_t *ppos,
2328 unsigned long convmul,
2329 unsigned long convdiv)
2330{
2331 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002332 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002333}
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/**
2336 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2337 * @table: the sysctl table
2338 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 * @buffer: the user buffer
2340 * @lenp: the size of the user buffer
2341 * @ppos: file position
2342 *
2343 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2344 * values from/to the user buffer, treated as an ASCII string.
2345 *
2346 * This routine will ensure the values are within the range specified by
2347 * table->extra1 (min) and table->extra2 (max).
2348 *
2349 * Returns 0 on success.
2350 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002351int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 void __user *buffer, size_t *lenp, loff_t *ppos)
2353{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002354 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
2357/**
2358 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2359 * @table: the sysctl table
2360 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 * @buffer: the user buffer
2362 * @lenp: the size of the user buffer
2363 * @ppos: file position
2364 *
2365 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2366 * values from/to the user buffer, treated as an ASCII string. The values
2367 * are treated as milliseconds, and converted to jiffies when they are stored.
2368 *
2369 * This routine will ensure the values are within the range specified by
2370 * table->extra1 (min) and table->extra2 (max).
2371 *
2372 * Returns 0 on success.
2373 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002374int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 void __user *buffer,
2376 size_t *lenp, loff_t *ppos)
2377{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002378 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 lenp, ppos, HZ, 1000l);
2380}
2381
2382
Amerigo Wang00b7c332010-05-05 00:26:45 +00002383static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 int *valp,
2385 int write, void *data)
2386{
2387 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002388 if (*lvalp > LONG_MAX / HZ)
2389 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2391 } else {
2392 int val = *valp;
2393 unsigned long lval;
2394 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002395 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 lval = (unsigned long)-val;
2397 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002398 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 lval = (unsigned long)val;
2400 }
2401 *lvalp = lval / HZ;
2402 }
2403 return 0;
2404}
2405
Amerigo Wang00b7c332010-05-05 00:26:45 +00002406static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 int *valp,
2408 int write, void *data)
2409{
2410 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002411 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2412 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2414 } else {
2415 int val = *valp;
2416 unsigned long lval;
2417 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002418 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 lval = (unsigned long)-val;
2420 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002421 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 lval = (unsigned long)val;
2423 }
2424 *lvalp = jiffies_to_clock_t(lval);
2425 }
2426 return 0;
2427}
2428
Amerigo Wang00b7c332010-05-05 00:26:45 +00002429static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 int *valp,
2431 int write, void *data)
2432{
2433 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002434 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2435
2436 if (jif > INT_MAX)
2437 return 1;
2438 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 } else {
2440 int val = *valp;
2441 unsigned long lval;
2442 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002443 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 lval = (unsigned long)-val;
2445 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002446 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 lval = (unsigned long)val;
2448 }
2449 *lvalp = jiffies_to_msecs(lval);
2450 }
2451 return 0;
2452}
2453
2454/**
2455 * proc_dointvec_jiffies - read a vector of integers as seconds
2456 * @table: the sysctl table
2457 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 * @buffer: the user buffer
2459 * @lenp: the size of the user buffer
2460 * @ppos: file position
2461 *
2462 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2463 * values from/to the user buffer, treated as an ASCII string.
2464 * The values read are assumed to be in seconds, and are converted into
2465 * jiffies.
2466 *
2467 * Returns 0 on success.
2468 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002469int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 void __user *buffer, size_t *lenp, loff_t *ppos)
2471{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002472 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 do_proc_dointvec_jiffies_conv,NULL);
2474}
2475
2476/**
2477 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2478 * @table: the sysctl table
2479 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 * @buffer: the user buffer
2481 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002482 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 *
2484 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2485 * values from/to the user buffer, treated as an ASCII string.
2486 * The values read are assumed to be in 1/USER_HZ seconds, and
2487 * are converted into jiffies.
2488 *
2489 * Returns 0 on success.
2490 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002491int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 void __user *buffer, size_t *lenp, loff_t *ppos)
2493{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002494 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 do_proc_dointvec_userhz_jiffies_conv,NULL);
2496}
2497
2498/**
2499 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2500 * @table: the sysctl table
2501 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 * @buffer: the user buffer
2503 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002504 * @ppos: file position
2505 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 *
2507 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2508 * values from/to the user buffer, treated as an ASCII string.
2509 * The values read are assumed to be in 1/1000 seconds, and
2510 * are converted into jiffies.
2511 *
2512 * Returns 0 on success.
2513 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002514int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 void __user *buffer, size_t *lenp, loff_t *ppos)
2516{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002517 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 do_proc_dointvec_ms_jiffies_conv, NULL);
2519}
2520
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002521static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002522 void __user *buffer, size_t *lenp, loff_t *ppos)
2523{
2524 struct pid *new_pid;
2525 pid_t tmp;
2526 int r;
2527
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002528 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002529
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002530 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002531 lenp, ppos, NULL, NULL);
2532 if (r || !write)
2533 return r;
2534
2535 new_pid = find_get_pid(tmp);
2536 if (!new_pid)
2537 return -ESRCH;
2538
2539 put_pid(xchg(&cad_pid, new_pid));
2540 return 0;
2541}
2542
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002543/**
2544 * proc_do_large_bitmap - read/write from/to a large bitmap
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2550 *
2551 * The bitmap is stored at table->data and the bitmap length (in bits)
2552 * in table->maxlen.
2553 *
2554 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2555 * large bitmaps may be represented in a compact manner. Writing into
2556 * the file will clear the bitmap then update it with the given input.
2557 *
2558 * Returns 0 on success.
2559 */
2560int proc_do_large_bitmap(struct ctl_table *table, int write,
2561 void __user *buffer, size_t *lenp, loff_t *ppos)
2562{
2563 int err = 0;
2564 bool first = 1;
2565 size_t left = *lenp;
2566 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002567 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002568 unsigned long *tmp_bitmap = NULL;
2569 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2570
WANG Cong122ff242014-05-12 16:04:53 -07002571 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002572 *lenp = 0;
2573 return 0;
2574 }
2575
2576 if (write) {
2577 unsigned long page = 0;
2578 char *kbuf;
2579
2580 if (left > PAGE_SIZE - 1)
2581 left = PAGE_SIZE - 1;
2582
2583 page = __get_free_page(GFP_TEMPORARY);
2584 kbuf = (char *) page;
2585 if (!kbuf)
2586 return -ENOMEM;
2587 if (copy_from_user(kbuf, buffer, left)) {
2588 free_page(page);
2589 return -EFAULT;
2590 }
2591 kbuf[left] = 0;
2592
2593 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2594 GFP_KERNEL);
2595 if (!tmp_bitmap) {
2596 free_page(page);
2597 return -ENOMEM;
2598 }
2599 proc_skip_char(&kbuf, &left, '\n');
2600 while (!err && left) {
2601 unsigned long val_a, val_b;
2602 bool neg;
2603
2604 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2605 sizeof(tr_a), &c);
2606 if (err)
2607 break;
2608 if (val_a >= bitmap_len || neg) {
2609 err = -EINVAL;
2610 break;
2611 }
2612
2613 val_b = val_a;
2614 if (left) {
2615 kbuf++;
2616 left--;
2617 }
2618
2619 if (c == '-') {
2620 err = proc_get_long(&kbuf, &left, &val_b,
2621 &neg, tr_b, sizeof(tr_b),
2622 &c);
2623 if (err)
2624 break;
2625 if (val_b >= bitmap_len || neg ||
2626 val_a > val_b) {
2627 err = -EINVAL;
2628 break;
2629 }
2630 if (left) {
2631 kbuf++;
2632 left--;
2633 }
2634 }
2635
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002636 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002637 first = 0;
2638 proc_skip_char(&kbuf, &left, '\n');
2639 }
2640 free_page(page);
2641 } else {
2642 unsigned long bit_a, bit_b = 0;
2643
2644 while (left) {
2645 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2646 if (bit_a >= bitmap_len)
2647 break;
2648 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2649 bit_a + 1) - 1;
2650
2651 if (!first) {
2652 err = proc_put_char(&buffer, &left, ',');
2653 if (err)
2654 break;
2655 }
2656 err = proc_put_long(&buffer, &left, bit_a, false);
2657 if (err)
2658 break;
2659 if (bit_a != bit_b) {
2660 err = proc_put_char(&buffer, &left, '-');
2661 if (err)
2662 break;
2663 err = proc_put_long(&buffer, &left, bit_b, false);
2664 if (err)
2665 break;
2666 }
2667
2668 first = 0; bit_b++;
2669 }
2670 if (!err)
2671 err = proc_put_char(&buffer, &left, '\n');
2672 }
2673
2674 if (!err) {
2675 if (write) {
2676 if (*ppos)
2677 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2678 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002679 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002680 }
2681 kfree(tmp_bitmap);
2682 *lenp -= left;
2683 *ppos += *lenp;
2684 return 0;
2685 } else {
2686 kfree(tmp_bitmap);
2687 return err;
2688 }
2689}
2690
Jovi Zhang55610502011-01-12 17:00:45 -08002691#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002693int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 void __user *buffer, size_t *lenp, loff_t *ppos)
2695{
2696 return -ENOSYS;
2697}
2698
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002699int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 void __user *buffer, size_t *lenp, loff_t *ppos)
2701{
2702 return -ENOSYS;
2703}
2704
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002705int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 void __user *buffer, size_t *lenp, loff_t *ppos)
2707{
2708 return -ENOSYS;
2709}
2710
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 void __user *buffer, size_t *lenp, loff_t *ppos)
2713{
2714 return -ENOSYS;
2715}
2716
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002717int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 void __user *buffer, size_t *lenp, loff_t *ppos)
2719{
2720 return -ENOSYS;
2721}
2722
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 void __user *buffer, size_t *lenp, loff_t *ppos)
2725{
2726 return -ENOSYS;
2727}
2728
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002729int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 void __user *buffer, size_t *lenp, loff_t *ppos)
2731{
2732 return -ENOSYS;
2733}
2734
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002735int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 void __user *buffer,
2737 size_t *lenp, loff_t *ppos)
2738{
2739 return -ENOSYS;
2740}
2741
2742
Jovi Zhang55610502011-01-12 17:00:45 -08002743#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745/*
2746 * No sense putting this after each symbol definition, twice,
2747 * exception granted :-)
2748 */
2749EXPORT_SYMBOL(proc_dointvec);
2750EXPORT_SYMBOL(proc_dointvec_jiffies);
2751EXPORT_SYMBOL(proc_dointvec_minmax);
2752EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2753EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2754EXPORT_SYMBOL(proc_dostring);
2755EXPORT_SYMBOL(proc_doulongvec_minmax);
2756EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);