blob: 42b7fc2860c15a2748e4d8209d29a28179d059e0 [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>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#include <asm/uaccess.h>
69#include <asm/processor.h>
70
Andi Kleen29cbc782006-09-30 01:47:55 +020071#ifdef CONFIG_X86
72#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010073#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010074#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020075#endif
David Howellsd550bbd2012-03-28 18:30:03 +010076#ifdef CONFIG_SPARC
77#include <asm/setup.h>
78#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080079#ifdef CONFIG_BSD_PROCESS_ACCT
80#include <linux/acct.h>
81#endif
Dave Young4f0e0562010-03-10 15:24:09 -080082#ifdef CONFIG_RT_MUTEXES
83#include <linux/rtmutex.h>
84#endif
Dave Young2edf5e42010-03-10 15:24:10 -080085#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
86#include <linux/lockdep.h>
87#endif
Dave Young15485a42010-03-10 15:24:07 -080088#ifdef CONFIG_CHR_DEV_SG
89#include <scsi/sg.h>
90#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020091
Don Zickus58687ac2010-05-07 17:11:44 -040092#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050093#include <linux/nmi.h>
94#endif
95
Eric W. Biederman7058cb02007-10-18 03:05:58 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#if defined(CONFIG_SYSCTL)
98
99/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100extern int max_threads;
Alan Coxd6e71142005-06-23 00:09:43 -0700101extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700102#ifdef CONFIG_COREDUMP
103extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700105extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200110extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400112extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700130#ifdef CONFIG_PRINTK
131static int ten_thousand = 10000;
132#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700133
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700134/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138static int maxolduid = 65535;
139static int minolduid;
140
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 Zijlstra4b96a29b2012-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,
Kirill Tkhai64192652014-10-16 14:39:37 +0400391 .proc_handler = proc_dointvec_minmax,
392 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200393 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100394 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800395 .procname = "numa_balancing",
396 .data = NULL, /* filled in by handler */
397 .maxlen = sizeof(unsigned int),
398 .mode = 0644,
399 .proc_handler = sysctl_numa_balancing,
400 .extra1 = &zero,
401 .extra2 = &one,
402 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200403#endif /* CONFIG_NUMA_BALANCING */
404#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200405 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100406 .procname = "sched_rt_period_us",
407 .data = &sysctl_sched_rt_period,
408 .maxlen = sizeof(unsigned int),
409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800410 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100411 },
412 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100413 .procname = "sched_rt_runtime_us",
414 .data = &sysctl_sched_rt_runtime,
415 .maxlen = sizeof(int),
416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800417 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100418 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600419 {
420 .procname = "sched_rr_timeslice_ms",
421 .data = &sched_rr_timeslice,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = sched_rr_handler,
425 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100426#ifdef CONFIG_SCHED_AUTOGROUP
427 {
428 .procname = "sched_autogroup_enabled",
429 .data = &sysctl_sched_autogroup_enabled,
430 .maxlen = sizeof(unsigned int),
431 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800432 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100433 .extra1 = &zero,
434 .extra2 = &one,
435 },
436#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700437#ifdef CONFIG_CFS_BANDWIDTH
438 {
439 .procname = "sched_cfs_bandwidth_slice_us",
440 .data = &sysctl_sched_cfs_bandwidth_slice,
441 .maxlen = sizeof(unsigned int),
442 .mode = 0644,
443 .proc_handler = proc_dointvec_minmax,
444 .extra1 = &one,
445 },
446#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700447#ifdef CONFIG_PROVE_LOCKING
448 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700449 .procname = "prove_locking",
450 .data = &prove_locking,
451 .maxlen = sizeof(int),
452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800453 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700454 },
455#endif
456#ifdef CONFIG_LOCK_STAT
457 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700458 .procname = "lock_stat",
459 .data = &lock_stat,
460 .maxlen = sizeof(int),
461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800462 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700463 },
464#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200465 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .procname = "panic",
467 .data = &panic_timeout,
468 .maxlen = sizeof(int),
469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800470 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 },
Alex Kelly046d6622012-10-04 17:15:23 -0700472#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "core_uses_pid",
475 .data = &core_uses_pid,
476 .maxlen = sizeof(int),
477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800478 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 .procname = "core_pattern",
482 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700483 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700485 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
Neil Hormana2939802009-09-23 15:56:56 -0700487 {
Neil Hormana2939802009-09-23 15:56:56 -0700488 .procname = "core_pipe_limit",
489 .data = &core_pipe_limit,
490 .maxlen = sizeof(unsigned int),
491 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800492 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700493 },
Alex Kelly046d6622012-10-04 17:15:23 -0700494#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800495#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700498 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800500 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700502 {
503 .procname = "sysctl_writes_strict",
504 .data = &sysctl_writes_strict,
505 .maxlen = sizeof(int),
506 .mode = 0644,
507 .proc_handler = proc_dointvec_minmax,
508 .extra1 = &neg_one,
509 .extra2 = &one,
510 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800511#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100512#ifdef CONFIG_LATENCYTOP
513 {
514 .procname = "latencytop",
515 .data = &latencytop_enabled,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100519 },
520#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#ifdef CONFIG_BLK_DEV_INITRD
522 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .procname = "real-root-dev",
524 .data = &real_root_dev,
525 .maxlen = sizeof(int),
526 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800527 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 },
529#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700530 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700531 .procname = "print-fatal-signals",
532 .data = &print_fatal_signals,
533 .maxlen = sizeof(int),
534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800535 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700536 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700537#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "reboot-cmd",
540 .data = reboot_command,
541 .maxlen = 256,
542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800543 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 },
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "stop-a",
547 .data = &stop_a_enabled,
548 .maxlen = sizeof (int),
549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 .procname = "scons-poweroff",
554 .data = &scons_pwroff,
555 .maxlen = sizeof (int),
556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800557 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 },
559#endif
David S. Miller08714202008-11-16 23:49:24 -0800560#ifdef CONFIG_SPARC64
561 {
David S. Miller08714202008-11-16 23:49:24 -0800562 .procname = "tsb-ratio",
563 .data = &sysctl_tsb_ratio,
564 .maxlen = sizeof (int),
565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800567 },
568#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#ifdef __hppa__
570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "soft-power",
572 .data = &pwrsw_enabled,
573 .maxlen = sizeof (int),
574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800575 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530577#endif
578#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "unaligned-trap",
581 .data = &unaligned_enabled,
582 .maxlen = sizeof (int),
583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800584 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
586#endif
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "ctrl-alt-del",
589 .data = &C_A_D,
590 .maxlen = sizeof(int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400594#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200595 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200596 .procname = "ftrace_enabled",
597 .data = &ftrace_enabled,
598 .maxlen = sizeof(int),
599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800600 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200601 },
602#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500603#ifdef CONFIG_STACK_TRACER
604 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500605 .procname = "stack_tracer_enabled",
606 .data = &stack_tracer_enabled,
607 .maxlen = sizeof(int),
608 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800609 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500610 },
611#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400612#ifdef CONFIG_TRACING
613 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100614 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400615 .data = &ftrace_dump_on_oops,
616 .maxlen = sizeof(int),
617 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800618 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400619 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400620 {
621 .procname = "traceoff_on_warning",
622 .data = &__disable_trace_on_warning,
623 .maxlen = sizeof(__disable_trace_on_warning),
624 .mode = 0644,
625 .proc_handler = proc_dointvec,
626 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500627 {
628 .procname = "tracepoint_printk",
629 .data = &tracepoint_printk,
630 .maxlen = sizeof(tracepoint_printk),
631 .mode = 0644,
632 .proc_handler = proc_dointvec,
633 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400634#endif
Kees Cook79847542014-01-23 15:55:59 -0800635#ifdef CONFIG_KEXEC
636 {
637 .procname = "kexec_load_disabled",
638 .data = &kexec_load_disabled,
639 .maxlen = sizeof(int),
640 .mode = 0644,
641 /* only handle a transition from default "0" to "1" */
642 .proc_handler = proc_dointvec_minmax,
643 .extra1 = &one,
644 .extra2 = &one,
645 },
646#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200647#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .procname = "modprobe",
650 .data = &modprobe_path,
651 .maxlen = KMOD_PATH_LEN,
652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
Kees Cook3d433212009-04-02 15:49:29 -0700655 {
Kees Cook3d433212009-04-02 15:49:29 -0700656 .procname = "modules_disabled",
657 .data = &modules_disabled,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800661 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700662 .extra1 = &one,
663 .extra2 = &one,
664 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700666#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100669 .data = &uevent_helper,
670 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
Michael Marineau86d56132014-04-10 14:09:31 -0700674#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#ifdef CONFIG_CHR_DEV_SG
676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .procname = "sg-big-buff",
678 .data = &sg_big_buff,
679 .maxlen = sizeof (int),
680 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 },
683#endif
684#ifdef CONFIG_BSD_PROCESS_ACCT
685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "acct",
687 .data = &acct_parm,
688 .maxlen = 3*sizeof(int),
689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800690 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
692#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#ifdef CONFIG_MAGIC_SYSRQ
694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800696 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .maxlen = sizeof (int),
698 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700699 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 },
701#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700702#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700705 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 .maxlen = sizeof (int),
707 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800708 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700710#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 .procname = "threads-max",
713 .data = &max_threads,
714 .maxlen = sizeof(int),
715 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800716 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 },
718 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .procname = "random",
720 .mode = 0555,
721 .child = random_table,
722 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 {
Eric Paris17f60a72011-04-01 17:07:50 -0400724 .procname = "usermodehelper",
725 .mode = 0555,
726 .child = usermodehelper_table,
727 },
728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .procname = "overflowuid",
730 .data = &overflowuid,
731 .maxlen = sizeof(int),
732 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800733 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .extra1 = &minolduid,
735 .extra2 = &maxolduid,
736 },
737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .procname = "overflowgid",
739 .data = &overflowgid,
740 .maxlen = sizeof(int),
741 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800742 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .extra1 = &minolduid,
744 .extra2 = &maxolduid,
745 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800746#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747#ifdef CONFIG_MATHEMU
748 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .procname = "ieee_emulation_warnings",
750 .data = &sysctl_ieee_emulation_warnings,
751 .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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200758 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 .maxlen = sizeof(int),
760 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800761 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 },
763#endif
764 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 .procname = "pid_max",
766 .data = &pid_max,
767 .maxlen = sizeof (int),
768 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800769 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .extra1 = &pid_max_min,
771 .extra2 = &pid_max_max,
772 },
773 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 .procname = "panic_on_oops",
775 .data = &panic_on_oops,
776 .maxlen = sizeof(int),
777 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800778 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800780#if defined CONFIG_PRINTK
781 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800782 .procname = "printk",
783 .data = &console_loglevel,
784 .maxlen = 4*sizeof(int),
785 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800786 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800787 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700790 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .maxlen = sizeof(int),
792 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800793 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 },
795 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700797 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .maxlen = sizeof(int),
799 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800800 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 },
Dave Youngaf913222009-09-22 16:43:33 -0700802 {
Dave Youngaf913222009-09-22 16:43:33 -0700803 .procname = "printk_delay",
804 .data = &printk_delay_msec,
805 .maxlen = sizeof(int),
806 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800807 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700808 .extra1 = &zero,
809 .extra2 = &ten_thousand,
810 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800812 .procname = "dmesg_restrict",
813 .data = &dmesg_restrict,
814 .maxlen = sizeof(int),
815 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700816 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800817 .extra1 = &zero,
818 .extra2 = &one,
819 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800820 {
821 .procname = "kptr_restrict",
822 .data = &kptr_restrict,
823 .maxlen = sizeof(int),
824 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700825 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800826 .extra1 = &zero,
827 .extra2 = &two,
828 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800829#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800830 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 .procname = "ngroups_max",
832 .data = &ngroups_max,
833 .maxlen = sizeof (int),
834 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800835 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 },
Dan Ballard73efc032011-10-31 17:11:20 -0700837 {
838 .procname = "cap_last_cap",
839 .data = (void *)&cap_last_cap,
840 .maxlen = sizeof(int),
841 .mode = 0444,
842 .proc_handler = proc_dointvec,
843 },
Don Zickus58687ac2010-05-07 17:11:44 -0400844#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500845 {
Don Zickus58687ac2010-05-07 17:11:44 -0400846 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200847 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500848 .maxlen = sizeof (int),
849 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700850 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700851 .extra1 = &zero,
852 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400853 },
854 {
855 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700856 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400857 .maxlen = sizeof(int),
858 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700859 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800860 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400861 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500862 },
Don Zickus2508ce12010-05-07 17:11:46 -0400863 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700864 .procname = "nmi_watchdog",
865 .data = &nmi_watchdog_enabled,
866 .maxlen = sizeof (int),
867 .mode = 0644,
868 .proc_handler = proc_nmi_watchdog,
869 .extra1 = &zero,
870#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
871 .extra2 = &one,
872#else
873 .extra2 = &zero,
874#endif
875 },
876 {
877 .procname = "soft_watchdog",
878 .data = &soft_watchdog_enabled,
879 .maxlen = sizeof (int),
880 .mode = 0644,
881 .proc_handler = proc_soft_watchdog,
882 .extra1 = &zero,
883 .extra2 = &one,
884 },
885 {
Don Zickus2508ce12010-05-07 17:11:46 -0400886 .procname = "softlockup_panic",
887 .data = &softlockup_panic,
888 .maxlen = sizeof(int),
889 .mode = 0644,
890 .proc_handler = proc_dointvec_minmax,
891 .extra1 = &zero,
892 .extra2 = &one,
893 },
Aaron Tomlined235872014-06-23 13:22:05 -0700894#ifdef CONFIG_SMP
895 {
896 .procname = "softlockup_all_cpu_backtrace",
897 .data = &sysctl_softlockup_all_cpu_backtrace,
898 .maxlen = sizeof(int),
899 .mode = 0644,
900 .proc_handler = proc_dointvec_minmax,
901 .extra1 = &zero,
902 .extra2 = &one,
903 },
904#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500905#endif
906#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
907 {
908 .procname = "unknown_nmi_panic",
909 .data = &unknown_nmi_panic,
910 .maxlen = sizeof (int),
911 .mode = 0644,
912 .proc_handler = proc_dointvec,
913 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500914#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915#if defined(CONFIG_X86)
916 {
Don Zickus8da5add2006-09-26 10:52:27 +0200917 .procname = "panic_on_unrecovered_nmi",
918 .data = &panic_on_unrecovered_nmi,
919 .maxlen = sizeof(int),
920 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800921 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200922 },
923 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700924 .procname = "panic_on_io_nmi",
925 .data = &panic_on_io_nmi,
926 .maxlen = sizeof(int),
927 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800928 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700929 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900930#ifdef CONFIG_DEBUG_STACKOVERFLOW
931 {
932 .procname = "panic_on_stackoverflow",
933 .data = &sysctl_panic_on_stackoverflow,
934 .maxlen = sizeof(int),
935 .mode = 0644,
936 .proc_handler = proc_dointvec,
937 },
938#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700939 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 .procname = "bootloader_type",
941 .data = &bootloader_type,
942 .maxlen = sizeof (int),
943 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100946 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700947 .procname = "bootloader_version",
948 .data = &bootloader_version,
949 .maxlen = sizeof (int),
950 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700952 },
953 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100954 .procname = "kstack_depth_to_print",
955 .data = &kstack_depth_to_print,
956 .maxlen = sizeof(int),
957 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800958 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100959 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100960 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100961 .procname = "io_delay_type",
962 .data = &io_delay_type,
963 .maxlen = sizeof(int),
964 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800965 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100966 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800968#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 .procname = "randomize_va_space",
971 .data = &randomize_va_space,
972 .maxlen = sizeof(int),
973 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800974 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800976#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800977#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700978 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700979 .procname = "spin_retry",
980 .data = &spin_retry,
981 .maxlen = sizeof (int),
982 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800983 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700984 },
985#endif
Len Brown673d5b42007-07-28 03:33:16 -0400986#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800987 {
Pavel Machekc255d842006-02-20 18:27:58 -0800988 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700989 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800990 .maxlen = sizeof (unsigned long),
991 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800992 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800993 },
994#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530995#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800996 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800997 .procname = "ignore-unaligned-usertrap",
998 .data = &no_unaligned_warning,
999 .maxlen = sizeof (int),
1000 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001001 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001002 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301003#endif
1004#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001005 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001006 .procname = "unaligned-dump-stack",
1007 .data = &unaligned_dump_stack,
1008 .maxlen = sizeof (int),
1009 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001010 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001011 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001012#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001013#ifdef CONFIG_DETECT_HUNG_TASK
1014 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001015 .procname = "hung_task_panic",
1016 .data = &sysctl_hung_task_panic,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001020 .extra1 = &zero,
1021 .extra2 = &one,
1022 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001023 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001024 .procname = "hung_task_check_count",
1025 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001026 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001027 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001028 .proc_handler = proc_dointvec_minmax,
1029 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001030 },
1031 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001032 .procname = "hung_task_timeout_secs",
1033 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001034 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001035 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001036 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001037 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001038 },
1039 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001040 .procname = "hung_task_warnings",
1041 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001042 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001043 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001044 .proc_handler = proc_dointvec_minmax,
1045 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001046 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001047#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001048#ifdef CONFIG_COMPAT
1049 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001050 .procname = "compat-log",
1051 .data = &compat_log,
1052 .maxlen = sizeof (int),
1053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001055 },
1056#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001057#ifdef CONFIG_RT_MUTEXES
1058 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001059 .procname = "max_lock_depth",
1060 .data = &max_lock_depth,
1061 .maxlen = sizeof(int),
1062 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001064 },
1065#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001066 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001067 .procname = "poweroff_cmd",
1068 .data = &poweroff_cmd,
1069 .maxlen = POWEROFF_CMD_PATH_LEN,
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001072 },
David Howells0b77f5b2008-04-29 01:01:32 -07001073#ifdef CONFIG_KEYS
1074 {
David Howells0b77f5b2008-04-29 01:01:32 -07001075 .procname = "keys",
1076 .mode = 0555,
1077 .child = key_sysctls,
1078 },
1079#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001080#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001081 /*
1082 * User-space scripts rely on the existence of this file
1083 * as a feature check for perf_events being enabled.
1084 *
1085 * So it's an ABI, do not remove!
1086 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001087 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001088 .procname = "perf_event_paranoid",
1089 .data = &sysctl_perf_event_paranoid,
1090 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001091 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001092 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001093 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001094 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001095 .procname = "perf_event_mlock_kb",
1096 .data = &sysctl_perf_event_mlock,
1097 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001098 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001099 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001100 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001101 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001102 .procname = "perf_event_max_sample_rate",
1103 .data = &sysctl_perf_event_sample_rate,
1104 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001105 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001106 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001107 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001108 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001109 {
1110 .procname = "perf_cpu_time_max_percent",
1111 .data = &sysctl_perf_cpu_time_max_percent,
1112 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1113 .mode = 0644,
1114 .proc_handler = perf_cpu_time_max_percent_handler,
1115 .extra1 = &zero,
1116 .extra2 = &one_hundred,
1117 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001118#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001119#ifdef CONFIG_KMEMCHECK
1120 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001121 .procname = "kmemcheck",
1122 .data = &kmemcheck_enabled,
1123 .maxlen = sizeof(int),
1124 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001125 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001126 },
1127#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001128 {
1129 .procname = "panic_on_warn",
1130 .data = &panic_on_warn,
1131 .maxlen = sizeof(int),
1132 .mode = 0644,
1133 .proc_handler = proc_dointvec_minmax,
1134 .extra1 = &zero,
1135 .extra2 = &one,
1136 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001137 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138};
1139
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001140static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .procname = "overcommit_memory",
1143 .data = &sysctl_overcommit_memory,
1144 .maxlen = sizeof(sysctl_overcommit_memory),
1145 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001146 .proc_handler = proc_dointvec_minmax,
1147 .extra1 = &zero,
1148 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 },
1150 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001151 .procname = "panic_on_oom",
1152 .data = &sysctl_panic_on_oom,
1153 .maxlen = sizeof(sysctl_panic_on_oom),
1154 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001155 .proc_handler = proc_dointvec_minmax,
1156 .extra1 = &zero,
1157 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001158 },
1159 {
David Rientjesfe071d72007-10-16 23:25:56 -07001160 .procname = "oom_kill_allocating_task",
1161 .data = &sysctl_oom_kill_allocating_task,
1162 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1163 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001164 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001165 },
1166 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001167 .procname = "oom_dump_tasks",
1168 .data = &sysctl_oom_dump_tasks,
1169 .maxlen = sizeof(sysctl_oom_dump_tasks),
1170 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001171 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001172 },
1173 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 .procname = "overcommit_ratio",
1175 .data = &sysctl_overcommit_ratio,
1176 .maxlen = sizeof(sysctl_overcommit_ratio),
1177 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001178 .proc_handler = overcommit_ratio_handler,
1179 },
1180 {
1181 .procname = "overcommit_kbytes",
1182 .data = &sysctl_overcommit_kbytes,
1183 .maxlen = sizeof(sysctl_overcommit_kbytes),
1184 .mode = 0644,
1185 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 },
1187 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 .procname = "page-cluster",
1189 .data = &page_cluster,
1190 .maxlen = sizeof(int),
1191 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001192 .proc_handler = proc_dointvec_minmax,
1193 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 },
1195 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 .procname = "dirty_background_ratio",
1197 .data = &dirty_background_ratio,
1198 .maxlen = sizeof(dirty_background_ratio),
1199 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001200 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 .extra1 = &zero,
1202 .extra2 = &one_hundred,
1203 },
1204 {
David Rientjes2da02992009-01-06 14:39:31 -08001205 .procname = "dirty_background_bytes",
1206 .data = &dirty_background_bytes,
1207 .maxlen = sizeof(dirty_background_bytes),
1208 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001209 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001210 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001211 },
1212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 .procname = "dirty_ratio",
1214 .data = &vm_dirty_ratio,
1215 .maxlen = sizeof(vm_dirty_ratio),
1216 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001217 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .extra1 = &zero,
1219 .extra2 = &one_hundred,
1220 },
1221 {
David Rientjes2da02992009-01-06 14:39:31 -08001222 .procname = "dirty_bytes",
1223 .data = &vm_dirty_bytes,
1224 .maxlen = sizeof(vm_dirty_bytes),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001227 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001228 },
1229 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001231 .data = &dirty_writeback_interval,
1232 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 },
1236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001238 .data = &dirty_expire_interval,
1239 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001241 .proc_handler = proc_dointvec_minmax,
1242 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 },
1244 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001245 .procname = "dirtytime_expire_seconds",
1246 .data = &dirtytime_expire_interval,
1247 .maxlen = sizeof(dirty_expire_interval),
1248 .mode = 0644,
1249 .proc_handler = dirtytime_interval_handler,
1250 .extra1 = &zero,
1251 },
1252 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001253 .procname = "nr_pdflush_threads",
1254 .mode = 0444 /* read-only */,
1255 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 },
1257 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 .procname = "swappiness",
1259 .data = &vm_swappiness,
1260 .maxlen = sizeof(vm_swappiness),
1261 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 .extra1 = &zero,
1264 .extra2 = &one_hundred,
1265 },
1266#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001269 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 .maxlen = sizeof(unsigned long),
1271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001273 },
1274#ifdef CONFIG_NUMA
1275 {
1276 .procname = "nr_hugepages_mempolicy",
1277 .data = NULL,
1278 .maxlen = sizeof(unsigned long),
1279 .mode = 0644,
1280 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001281 },
1282#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 .procname = "hugetlb_shm_group",
1285 .data = &sysctl_hugetlb_shm_group,
1286 .maxlen = sizeof(gid_t),
1287 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001288 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 },
Mel Gorman396faf02007-07-17 04:03:13 -07001290 {
Mel Gorman396faf02007-07-17 04:03:13 -07001291 .procname = "hugepages_treat_as_movable",
1292 .data = &hugepages_treat_as_movable,
1293 .maxlen = sizeof(int),
1294 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001295 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001296 },
Adam Litke54f9f802007-10-16 01:26:20 -07001297 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001298 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001299 .data = NULL,
1300 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001303 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304#endif
1305 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .procname = "lowmem_reserve_ratio",
1307 .data = &sysctl_lowmem_reserve_ratio,
1308 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 },
1312 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001313 .procname = "drop_caches",
1314 .data = &sysctl_drop_caches,
1315 .maxlen = sizeof(int),
1316 .mode = 0644,
1317 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001318 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001319 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001320 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001321#ifdef CONFIG_COMPACTION
1322 {
1323 .procname = "compact_memory",
1324 .data = &sysctl_compact_memory,
1325 .maxlen = sizeof(int),
1326 .mode = 0200,
1327 .proc_handler = sysctl_compaction_handler,
1328 },
Mel Gorman5e771902010-05-24 14:32:31 -07001329 {
1330 .procname = "extfrag_threshold",
1331 .data = &sysctl_extfrag_threshold,
1332 .maxlen = sizeof(int),
1333 .mode = 0644,
1334 .proc_handler = sysctl_extfrag_handler,
1335 .extra1 = &min_extfrag_threshold,
1336 .extra2 = &max_extfrag_threshold,
1337 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001338 {
1339 .procname = "compact_unevictable_allowed",
1340 .data = &sysctl_compact_unevictable_allowed,
1341 .maxlen = sizeof(int),
1342 .mode = 0644,
1343 .proc_handler = proc_dointvec,
1344 .extra1 = &zero,
1345 .extra2 = &one,
1346 },
Mel Gorman5e771902010-05-24 14:32:31 -07001347
Mel Gorman76ab0f52010-05-24 14:32:28 -07001348#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .procname = "min_free_kbytes",
1351 .data = &min_free_kbytes,
1352 .maxlen = sizeof(min_free_kbytes),
1353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001354 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .extra1 = &zero,
1356 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001357 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001358 .procname = "percpu_pagelist_fraction",
1359 .data = &percpu_pagelist_fraction,
1360 .maxlen = sizeof(percpu_pagelist_fraction),
1361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001362 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001363 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001364 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365#ifdef CONFIG_MMU
1366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .procname = "max_map_count",
1368 .data = &sysctl_max_map_count,
1369 .maxlen = sizeof(sysctl_max_map_count),
1370 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001371 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001372 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001374#else
1375 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001376 .procname = "nr_trim_pages",
1377 .data = &sysctl_nr_trim_pages,
1378 .maxlen = sizeof(sysctl_nr_trim_pages),
1379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001380 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001381 .extra1 = &zero,
1382 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383#endif
1384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .procname = "laptop_mode",
1386 .data = &laptop_mode,
1387 .maxlen = sizeof(laptop_mode),
1388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001389 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 },
1391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .procname = "block_dump",
1393 .data = &block_dump,
1394 .maxlen = sizeof(block_dump),
1395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001396 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 .extra1 = &zero,
1398 },
1399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .procname = "vfs_cache_pressure",
1401 .data = &sysctl_vfs_cache_pressure,
1402 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001404 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 .extra1 = &zero,
1406 },
1407#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 .procname = "legacy_va_layout",
1410 .data = &sysctl_legacy_va_layout,
1411 .maxlen = sizeof(sysctl_legacy_va_layout),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .extra1 = &zero,
1415 },
1416#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001417#ifdef CONFIG_NUMA
1418 {
Christoph Lameter17436602006-01-18 17:42:32 -08001419 .procname = "zone_reclaim_mode",
1420 .data = &zone_reclaim_mode,
1421 .maxlen = sizeof(zone_reclaim_mode),
1422 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001423 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001424 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001425 },
Christoph Lameter96146342006-07-03 00:24:13 -07001426 {
Christoph Lameter96146342006-07-03 00:24:13 -07001427 .procname = "min_unmapped_ratio",
1428 .data = &sysctl_min_unmapped_ratio,
1429 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001432 .extra1 = &zero,
1433 .extra2 = &one_hundred,
1434 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001435 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001436 .procname = "min_slab_ratio",
1437 .data = &sysctl_min_slab_ratio,
1438 .maxlen = sizeof(sysctl_min_slab_ratio),
1439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001440 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001441 .extra1 = &zero,
1442 .extra2 = &one_hundred,
1443 },
Christoph Lameter17436602006-01-18 17:42:32 -08001444#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001445#ifdef CONFIG_SMP
1446 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001447 .procname = "stat_interval",
1448 .data = &sysctl_stat_interval,
1449 .maxlen = sizeof(sysctl_stat_interval),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001452 },
1453#endif
David Howells6e141542009-12-15 19:27:45 +00001454#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001455 {
Eric Parised032182007-06-28 15:55:21 -04001456 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001457 .data = &dac_mmap_min_addr,
1458 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001461 },
David Howells6e141542009-12-15 19:27:45 +00001462#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001463#ifdef CONFIG_NUMA
1464 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001465 .procname = "numa_zonelist_order",
1466 .data = &numa_zonelist_order,
1467 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001469 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001470 },
1471#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001472#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001473 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001474 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001475 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001476#ifdef CONFIG_X86_32
1477 .data = &vdso32_enabled,
1478 .maxlen = sizeof(vdso32_enabled),
1479#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001480 .data = &vdso_enabled,
1481 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001482#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001484 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001485 .extra1 = &zero,
1486 },
1487#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001488#ifdef CONFIG_HIGHMEM
1489 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001490 .procname = "highmem_is_dirtyable",
1491 .data = &vm_highmem_is_dirtyable,
1492 .maxlen = sizeof(vm_highmem_is_dirtyable),
1493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001494 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001495 .extra1 = &zero,
1496 .extra2 = &one,
1497 },
1498#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001499#ifdef CONFIG_MEMORY_FAILURE
1500 {
Andi Kleen6a460792009-09-16 11:50:15 +02001501 .procname = "memory_failure_early_kill",
1502 .data = &sysctl_memory_failure_early_kill,
1503 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001505 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001506 .extra1 = &zero,
1507 .extra2 = &one,
1508 },
1509 {
Andi Kleen6a460792009-09-16 11:50:15 +02001510 .procname = "memory_failure_recovery",
1511 .data = &sysctl_memory_failure_recovery,
1512 .maxlen = sizeof(sysctl_memory_failure_recovery),
1513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001514 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001515 .extra1 = &zero,
1516 .extra2 = &one,
1517 },
1518#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001519 {
1520 .procname = "user_reserve_kbytes",
1521 .data = &sysctl_user_reserve_kbytes,
1522 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1523 .mode = 0644,
1524 .proc_handler = proc_doulongvec_minmax,
1525 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001526 {
1527 .procname = "admin_reserve_kbytes",
1528 .data = &sysctl_admin_reserve_kbytes,
1529 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1530 .mode = 0644,
1531 .proc_handler = proc_doulongvec_minmax,
1532 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001533 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534};
1535
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001536#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001537static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001538 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001539};
1540#endif
1541
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001542static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 .procname = "inode-nr",
1545 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001546 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001548 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 },
1550 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 .procname = "inode-state",
1552 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001553 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001555 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 },
1557 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 .procname = "file-nr",
1559 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001560 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001562 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 },
1564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 .procname = "file-max",
1566 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001567 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001569 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 },
1571 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001572 .procname = "nr_open",
1573 .data = &sysctl_nr_open,
1574 .maxlen = sizeof(int),
1575 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001576 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001577 .extra1 = &sysctl_nr_open_min,
1578 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001579 },
1580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 .procname = "dentry-state",
1582 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001583 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001585 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 },
1587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 .procname = "overflowuid",
1589 .data = &fs_overflowuid,
1590 .maxlen = sizeof(int),
1591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001592 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 .extra1 = &minolduid,
1594 .extra2 = &maxolduid,
1595 },
1596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 .procname = "overflowgid",
1598 .data = &fs_overflowgid,
1599 .maxlen = sizeof(int),
1600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001601 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 .extra1 = &minolduid,
1603 .extra2 = &maxolduid,
1604 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001605#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 .procname = "leases-enable",
1608 .data = &leases_enable,
1609 .maxlen = sizeof(int),
1610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001611 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614#ifdef CONFIG_DNOTIFY
1615 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 .procname = "dir-notify-enable",
1617 .data = &dir_notify_enable,
1618 .maxlen = sizeof(int),
1619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001620 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 },
1622#endif
1623#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001624#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 .procname = "lease-break-time",
1627 .data = &lease_break_time,
1628 .maxlen = sizeof(int),
1629 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001630 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001632#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001633#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 .procname = "aio-nr",
1636 .data = &aio_nr,
1637 .maxlen = sizeof(aio_nr),
1638 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001639 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 },
1641 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 .procname = "aio-max-nr",
1643 .data = &aio_max_nr,
1644 .maxlen = sizeof(aio_max_nr),
1645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001646 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001648#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001649#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001650 {
Robert Love0399cb02005-07-13 12:38:18 -04001651 .procname = "inotify",
1652 .mode = 0555,
1653 .child = inotify_table,
1654 },
1655#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001656#ifdef CONFIG_EPOLL
1657 {
1658 .procname = "epoll",
1659 .mode = 0555,
1660 .child = epoll_table,
1661 },
1662#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001664 {
Kees Cook800179c2012-07-25 17:29:07 -07001665 .procname = "protected_symlinks",
1666 .data = &sysctl_protected_symlinks,
1667 .maxlen = sizeof(int),
1668 .mode = 0600,
1669 .proc_handler = proc_dointvec_minmax,
1670 .extra1 = &zero,
1671 .extra2 = &one,
1672 },
1673 {
1674 .procname = "protected_hardlinks",
1675 .data = &sysctl_protected_hardlinks,
1676 .maxlen = sizeof(int),
1677 .mode = 0600,
1678 .proc_handler = proc_dointvec_minmax,
1679 .extra1 = &zero,
1680 .extra2 = &one,
1681 },
1682 {
Alan Coxd6e71142005-06-23 00:09:43 -07001683 .procname = "suid_dumpable",
1684 .data = &suid_dumpable,
1685 .maxlen = sizeof(int),
1686 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001687 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001688 .extra1 = &zero,
1689 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001690 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001691#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1692 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001693 .procname = "binfmt_misc",
1694 .mode = 0555,
1695 .child = binfmt_misc_table,
1696 },
1697#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001698 {
Jens Axboeff9da692010-06-03 14:54:39 +02001699 .procname = "pipe-max-size",
1700 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001701 .maxlen = sizeof(int),
1702 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001703 .proc_handler = &pipe_proc_fn,
1704 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001705 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001706 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707};
1708
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001709static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001710#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001711 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001712 .procname = "exception-trace",
1713 .data = &show_unhandled_signals,
1714 .maxlen = sizeof(int),
1715 .mode = 0644,
1716 .proc_handler = proc_dointvec
1717 },
1718#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001719#if defined(CONFIG_OPTPROBES)
1720 {
1721 .procname = "kprobes-optimization",
1722 .data = &sysctl_kprobes_optimization,
1723 .maxlen = sizeof(int),
1724 .mode = 0644,
1725 .proc_handler = proc_kprobes_optimization_handler,
1726 .extra1 = &zero,
1727 .extra2 = &one,
1728 },
1729#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001730 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731};
1732
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001733static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001734 { }
Robert Love0eeca282005-07-12 17:06:03 -04001735};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001737int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001738{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001739 struct ctl_table_header *hdr;
1740
1741 hdr = register_sysctl_table(sysctl_base_table);
1742 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001743 return 0;
1744}
1745
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001746#endif /* CONFIG_SYSCTL */
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748/*
1749 * /proc/sys support
1750 */
1751
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001752#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753
Kees Cookf8808302014-06-06 14:37:17 -07001754static int _proc_do_string(char *data, int maxlen, int write,
1755 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001756 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001757{
1758 size_t len;
1759 char __user *p;
1760 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001761
1762 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001763 *lenp = 0;
1764 return 0;
1765 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001766
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001767 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001768 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1769 /* Only continue writes not past the end of buffer. */
1770 len = strlen(data);
1771 if (len > maxlen - 1)
1772 len = maxlen - 1;
1773
1774 if (*ppos > len)
1775 return 0;
1776 len = *ppos;
1777 } else {
1778 /* Start writing from beginning of buffer. */
1779 len = 0;
1780 }
1781
Kees Cook2ca9bb42014-06-06 14:37:18 -07001782 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001783 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001784 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001785 if (get_user(c, p++))
1786 return -EFAULT;
1787 if (c == 0 || c == '\n')
1788 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001789 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001790 }
Kees Cookf8808302014-06-06 14:37:17 -07001791 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001792 } else {
1793 len = strlen(data);
1794 if (len > maxlen)
1795 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001796
1797 if (*ppos > len) {
1798 *lenp = 0;
1799 return 0;
1800 }
1801
1802 data += *ppos;
1803 len -= *ppos;
1804
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001805 if (len > *lenp)
1806 len = *lenp;
1807 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001808 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001809 return -EFAULT;
1810 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001811 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001812 return -EFAULT;
1813 len++;
1814 }
1815 *lenp = len;
1816 *ppos += len;
1817 }
1818 return 0;
1819}
1820
Kees Cookf4aacea2014-06-06 14:37:19 -07001821static void warn_sysctl_write(struct ctl_table *table)
1822{
1823 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1824 "This will not be supported in the future. To silence this\n"
1825 "warning, set kernel.sysctl_writes_strict = -1\n",
1826 current->comm, table->procname);
1827}
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829/**
1830 * proc_dostring - read a string sysctl
1831 * @table: the sysctl table
1832 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 * @buffer: the user buffer
1834 * @lenp: the size of the user buffer
1835 * @ppos: file position
1836 *
1837 * Reads/writes a string from/to the user buffer. If the kernel
1838 * buffer provided is not large enough to hold the string, the
1839 * string is truncated. The copied string is %NULL-terminated.
1840 * If the string is being read by the user process, it is copied
1841 * and a newline '\n' is added. It is truncated if the buffer is
1842 * not large enough.
1843 *
1844 * Returns 0 on success.
1845 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001846int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 void __user *buffer, size_t *lenp, loff_t *ppos)
1848{
Kees Cookf4aacea2014-06-06 14:37:19 -07001849 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1850 warn_sysctl_write(table);
1851
Kees Cookf8808302014-06-06 14:37:17 -07001852 return _proc_do_string((char *)(table->data), table->maxlen, write,
1853 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
Amerigo Wang00b7c332010-05-05 00:26:45 +00001856static size_t proc_skip_spaces(char **buf)
1857{
1858 size_t ret;
1859 char *tmp = skip_spaces(*buf);
1860 ret = tmp - *buf;
1861 *buf = tmp;
1862 return ret;
1863}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001865static void proc_skip_char(char **buf, size_t *size, const char v)
1866{
1867 while (*size) {
1868 if (**buf != v)
1869 break;
1870 (*size)--;
1871 (*buf)++;
1872 }
1873}
1874
Amerigo Wang00b7c332010-05-05 00:26:45 +00001875#define TMPBUFLEN 22
1876/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001877 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001878 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001879 * @buf: a kernel buffer
1880 * @size: size of the kernel buffer
1881 * @val: this is where the number will be stored
1882 * @neg: set to %TRUE if number is negative
1883 * @perm_tr: a vector which contains the allowed trailers
1884 * @perm_tr_len: size of the perm_tr vector
1885 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001886 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001887 * In case of success %0 is returned and @buf and @size are updated with
1888 * the amount of bytes read. If @tr is non-NULL and a trailing
1889 * character exists (size is non-zero after returning from this
1890 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001891 */
1892static int proc_get_long(char **buf, size_t *size,
1893 unsigned long *val, bool *neg,
1894 const char *perm_tr, unsigned perm_tr_len, char *tr)
1895{
1896 int len;
1897 char *p, tmp[TMPBUFLEN];
1898
1899 if (!*size)
1900 return -EINVAL;
1901
1902 len = *size;
1903 if (len > TMPBUFLEN - 1)
1904 len = TMPBUFLEN - 1;
1905
1906 memcpy(tmp, *buf, len);
1907
1908 tmp[len] = 0;
1909 p = tmp;
1910 if (*p == '-' && *size > 1) {
1911 *neg = true;
1912 p++;
1913 } else
1914 *neg = false;
1915 if (!isdigit(*p))
1916 return -EINVAL;
1917
1918 *val = simple_strtoul(p, &p, 0);
1919
1920 len = p - tmp;
1921
1922 /* We don't know if the next char is whitespace thus we may accept
1923 * invalid integers (e.g. 1234...a) or two integers instead of one
1924 * (e.g. 123...1). So lets not allow such large numbers. */
1925 if (len == TMPBUFLEN - 1)
1926 return -EINVAL;
1927
1928 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1929 return -EINVAL;
1930
1931 if (tr && (len < *size))
1932 *tr = *p;
1933
1934 *buf += len;
1935 *size -= len;
1936
1937 return 0;
1938}
1939
1940/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001941 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001942 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001943 * @buf: the user buffer
1944 * @size: the size of the user buffer
1945 * @val: the integer to be converted
1946 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001947 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001948 * In case of success %0 is returned and @buf and @size are updated with
1949 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001950 */
1951static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1952 bool neg)
1953{
1954 int len;
1955 char tmp[TMPBUFLEN], *p = tmp;
1956
1957 sprintf(p, "%s%lu", neg ? "-" : "", val);
1958 len = strlen(tmp);
1959 if (len > *size)
1960 len = *size;
1961 if (copy_to_user(*buf, tmp, len))
1962 return -EFAULT;
1963 *size -= len;
1964 *buf += len;
1965 return 0;
1966}
1967#undef TMPBUFLEN
1968
1969static int proc_put_char(void __user **buf, size_t *size, char c)
1970{
1971 if (*size) {
1972 char __user **buffer = (char __user **)buf;
1973 if (put_user(c, *buffer))
1974 return -EFAULT;
1975 (*size)--, (*buffer)++;
1976 *buf = *buffer;
1977 }
1978 return 0;
1979}
1980
1981static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 int *valp,
1983 int write, void *data)
1984{
1985 if (write) {
1986 *valp = *negp ? -*lvalp : *lvalp;
1987 } else {
1988 int val = *valp;
1989 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001990 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 *lvalp = (unsigned long)-val;
1992 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001993 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 *lvalp = (unsigned long)val;
1995 }
1996 }
1997 return 0;
1998}
1999
Amerigo Wang00b7c332010-05-05 00:26:45 +00002000static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2001
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002002static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002003 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002004 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002005 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 int write, void *data),
2007 void *data)
2008{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002009 int *i, vleft, first = 1, err = 0;
2010 unsigned long page = 0;
2011 size_t left;
2012 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Amerigo Wang00b7c332010-05-05 00:26:45 +00002014 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 *lenp = 0;
2016 return 0;
2017 }
2018
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002019 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 vleft = table->maxlen / sizeof(*i);
2021 left = *lenp;
2022
2023 if (!conv)
2024 conv = do_proc_dointvec_conv;
2025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002027 if (*ppos) {
2028 switch (sysctl_writes_strict) {
2029 case SYSCTL_WRITES_STRICT:
2030 goto out;
2031 case SYSCTL_WRITES_WARN:
2032 warn_sysctl_write(table);
2033 break;
2034 default:
2035 break;
2036 }
2037 }
2038
Amerigo Wang00b7c332010-05-05 00:26:45 +00002039 if (left > PAGE_SIZE - 1)
2040 left = PAGE_SIZE - 1;
2041 page = __get_free_page(GFP_TEMPORARY);
2042 kbuf = (char *) page;
2043 if (!kbuf)
2044 return -ENOMEM;
2045 if (copy_from_user(kbuf, buffer, left)) {
2046 err = -EFAULT;
2047 goto free;
2048 }
2049 kbuf[left] = 0;
2050 }
2051
2052 for (; left && vleft--; i++, first=0) {
2053 unsigned long lval;
2054 bool neg;
2055
2056 if (write) {
2057 left -= proc_skip_spaces(&kbuf);
2058
J. R. Okajima563b0462010-05-25 16:10:14 -07002059 if (!left)
2060 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002061 err = proc_get_long(&kbuf, &left, &lval, &neg,
2062 proc_wspace_sep,
2063 sizeof(proc_wspace_sep), NULL);
2064 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002066 if (conv(&neg, &lval, i, 1, data)) {
2067 err = -EINVAL;
2068 break;
2069 }
2070 } else {
2071 if (conv(&neg, &lval, i, 0, data)) {
2072 err = -EINVAL;
2073 break;
2074 }
2075 if (!first)
2076 err = proc_put_char(&buffer, &left, '\t');
2077 if (err)
2078 break;
2079 err = proc_put_long(&buffer, &left, lval, neg);
2080 if (err)
2081 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 }
2083 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002084
2085 if (!write && !first && left && !err)
2086 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002087 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002088 left -= proc_skip_spaces(&kbuf);
2089free:
2090 if (write) {
2091 free_page(page);
2092 if (first)
2093 return err ? : -EINVAL;
2094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002096out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002098 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002101static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002102 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002103 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002104 int write, void *data),
2105 void *data)
2106{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002107 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002108 buffer, lenp, ppos, conv, data);
2109}
2110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111/**
2112 * proc_dointvec - read a vector of integers
2113 * @table: the sysctl table
2114 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 * @buffer: the user buffer
2116 * @lenp: the size of the user buffer
2117 * @ppos: file position
2118 *
2119 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2120 * values from/to the user buffer, treated as an ASCII string.
2121 *
2122 * Returns 0 on success.
2123 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002124int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 void __user *buffer, size_t *lenp, loff_t *ppos)
2126{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002127 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 NULL,NULL);
2129}
2130
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002131/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002132 * Taint values can only be increased
2133 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002134 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002135static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002136 void __user *buffer, size_t *lenp, loff_t *ppos)
2137{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002138 struct ctl_table t;
2139 unsigned long tmptaint = get_taint();
2140 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002141
Bastian Blank91fcd412007-04-23 14:41:14 -07002142 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002143 return -EPERM;
2144
Andi Kleen25ddbb12008-10-15 22:01:41 -07002145 t = *table;
2146 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002147 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002148 if (err < 0)
2149 return err;
2150
2151 if (write) {
2152 /*
2153 * Poor man's atomic or. Not worth adding a primitive
2154 * to everyone's atomic.h for this
2155 */
2156 int i;
2157 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2158 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302159 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002160 }
2161 }
2162
2163 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002164}
2165
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002166#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002167static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002168 void __user *buffer, size_t *lenp, loff_t *ppos)
2169{
2170 if (write && !capable(CAP_SYS_ADMIN))
2171 return -EPERM;
2172
2173 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2174}
2175#endif
2176
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177struct do_proc_dointvec_minmax_conv_param {
2178 int *min;
2179 int *max;
2180};
2181
Amerigo Wang00b7c332010-05-05 00:26:45 +00002182static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2183 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 int write, void *data)
2185{
2186 struct do_proc_dointvec_minmax_conv_param *param = data;
2187 if (write) {
2188 int val = *negp ? -*lvalp : *lvalp;
2189 if ((param->min && *param->min > val) ||
2190 (param->max && *param->max < val))
2191 return -EINVAL;
2192 *valp = val;
2193 } else {
2194 int val = *valp;
2195 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 *lvalp = (unsigned long)-val;
2198 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002199 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 *lvalp = (unsigned long)val;
2201 }
2202 }
2203 return 0;
2204}
2205
2206/**
2207 * proc_dointvec_minmax - read a vector of integers with min/max values
2208 * @table: the sysctl table
2209 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2213 *
2214 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2215 * values from/to the user buffer, treated as an ASCII string.
2216 *
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2219 *
2220 * Returns 0 on success.
2221 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002222int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 void __user *buffer, size_t *lenp, loff_t *ppos)
2224{
2225 struct do_proc_dointvec_minmax_conv_param param = {
2226 .min = (int *) table->extra1,
2227 .max = (int *) table->extra2,
2228 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002229 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 do_proc_dointvec_minmax_conv, &param);
2231}
2232
Kees Cook54b50192012-07-30 14:39:18 -07002233static void validate_coredump_safety(void)
2234{
Alex Kelly046d6622012-10-04 17:15:23 -07002235#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002236 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002237 core_pattern[0] != '/' && core_pattern[0] != '|') {
2238 printk(KERN_WARNING "Unsafe core_pattern used with "\
2239 "suid_dumpable=2. Pipe handler or fully qualified "\
2240 "core dump path required.\n");
2241 }
Alex Kelly046d6622012-10-04 17:15:23 -07002242#endif
Kees Cook54b50192012-07-30 14:39:18 -07002243}
2244
2245static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2247{
2248 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2249 if (!error)
2250 validate_coredump_safety();
2251 return error;
2252}
2253
Alex Kelly046d6622012-10-04 17:15:23 -07002254#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002255static int proc_dostring_coredump(struct ctl_table *table, int write,
2256 void __user *buffer, size_t *lenp, loff_t *ppos)
2257{
2258 int error = proc_dostring(table, write, buffer, lenp, ppos);
2259 if (!error)
2260 validate_coredump_safety();
2261 return error;
2262}
Alex Kelly046d6622012-10-04 17:15:23 -07002263#endif
Kees Cook54b50192012-07-30 14:39:18 -07002264
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002265static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 void __user *buffer,
2267 size_t *lenp, loff_t *ppos,
2268 unsigned long convmul,
2269 unsigned long convdiv)
2270{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271 unsigned long *i, *min, *max;
2272 int vleft, first = 1, err = 0;
2273 unsigned long page = 0;
2274 size_t left;
2275 char *kbuf;
2276
2277 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 *lenp = 0;
2279 return 0;
2280 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002282 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 min = (unsigned long *) table->extra1;
2284 max = (unsigned long *) table->extra2;
2285 vleft = table->maxlen / sizeof(unsigned long);
2286 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287
2288 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002289 if (*ppos) {
2290 switch (sysctl_writes_strict) {
2291 case SYSCTL_WRITES_STRICT:
2292 goto out;
2293 case SYSCTL_WRITES_WARN:
2294 warn_sysctl_write(table);
2295 break;
2296 default:
2297 break;
2298 }
2299 }
2300
Amerigo Wang00b7c332010-05-05 00:26:45 +00002301 if (left > PAGE_SIZE - 1)
2302 left = PAGE_SIZE - 1;
2303 page = __get_free_page(GFP_TEMPORARY);
2304 kbuf = (char *) page;
2305 if (!kbuf)
2306 return -ENOMEM;
2307 if (copy_from_user(kbuf, buffer, left)) {
2308 err = -EFAULT;
2309 goto free;
2310 }
2311 kbuf[left] = 0;
2312 }
2313
Eric Dumazet27b3d802010-10-07 12:59:29 -07002314 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002315 unsigned long val;
2316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 bool neg;
2319
2320 left -= proc_skip_spaces(&kbuf);
2321
2322 err = proc_get_long(&kbuf, &left, &val, &neg,
2323 proc_wspace_sep,
2324 sizeof(proc_wspace_sep), NULL);
2325 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 break;
2327 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 continue;
2329 if ((min && val < *min) || (max && val > *max))
2330 continue;
2331 *i = val;
2332 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002333 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002334 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002335 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002336 if (err)
2337 break;
2338 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 err = proc_put_long(&buffer, &left, val, false);
2340 if (err)
2341 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
2343 }
2344
Amerigo Wang00b7c332010-05-05 00:26:45 +00002345 if (!write && !first && left && !err)
2346 err = proc_put_char(&buffer, &left, '\n');
2347 if (write && !err)
2348 left -= proc_skip_spaces(&kbuf);
2349free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002351 free_page(page);
2352 if (first)
2353 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002356out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359}
2360
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002361static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002362 void __user *buffer,
2363 size_t *lenp, loff_t *ppos,
2364 unsigned long convmul,
2365 unsigned long convdiv)
2366{
2367 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002369}
2370
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371/**
2372 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2378 *
2379 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2380 * values from/to the user buffer, treated as an ASCII string.
2381 *
2382 * This routine will ensure the values are within the range specified by
2383 * table->extra1 (min) and table->extra2 (max).
2384 *
2385 * Returns 0 on success.
2386 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002387int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 void __user *buffer, size_t *lenp, loff_t *ppos)
2389{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002390 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391}
2392
2393/**
2394 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2395 * @table: the sysctl table
2396 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 * @buffer: the user buffer
2398 * @lenp: the size of the user buffer
2399 * @ppos: file position
2400 *
2401 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2402 * values from/to the user buffer, treated as an ASCII string. The values
2403 * are treated as milliseconds, and converted to jiffies when they are stored.
2404 *
2405 * This routine will ensure the values are within the range specified by
2406 * table->extra1 (min) and table->extra2 (max).
2407 *
2408 * Returns 0 on success.
2409 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002410int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 void __user *buffer,
2412 size_t *lenp, loff_t *ppos)
2413{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002414 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 lenp, ppos, HZ, 1000l);
2416}
2417
2418
Amerigo Wang00b7c332010-05-05 00:26:45 +00002419static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 int *valp,
2421 int write, void *data)
2422{
2423 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002424 if (*lvalp > LONG_MAX / HZ)
2425 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2427 } else {
2428 int val = *valp;
2429 unsigned long lval;
2430 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002431 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 lval = (unsigned long)-val;
2433 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002434 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 lval = (unsigned long)val;
2436 }
2437 *lvalp = lval / HZ;
2438 }
2439 return 0;
2440}
2441
Amerigo Wang00b7c332010-05-05 00:26:45 +00002442static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 int *valp,
2444 int write, void *data)
2445{
2446 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002447 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2448 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2450 } else {
2451 int val = *valp;
2452 unsigned long lval;
2453 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002454 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 lval = (unsigned long)-val;
2456 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002457 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 lval = (unsigned long)val;
2459 }
2460 *lvalp = jiffies_to_clock_t(lval);
2461 }
2462 return 0;
2463}
2464
Amerigo Wang00b7c332010-05-05 00:26:45 +00002465static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 int *valp,
2467 int write, void *data)
2468{
2469 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002470 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2471
2472 if (jif > INT_MAX)
2473 return 1;
2474 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 } else {
2476 int val = *valp;
2477 unsigned long lval;
2478 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002479 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 lval = (unsigned long)-val;
2481 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002482 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 lval = (unsigned long)val;
2484 }
2485 *lvalp = jiffies_to_msecs(lval);
2486 }
2487 return 0;
2488}
2489
2490/**
2491 * proc_dointvec_jiffies - read a vector of integers as seconds
2492 * @table: the sysctl table
2493 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2497 *
2498 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2499 * values from/to the user buffer, treated as an ASCII string.
2500 * The values read are assumed to be in seconds, and are converted into
2501 * jiffies.
2502 *
2503 * Returns 0 on success.
2504 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002505int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 void __user *buffer, size_t *lenp, loff_t *ppos)
2507{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002508 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 do_proc_dointvec_jiffies_conv,NULL);
2510}
2511
2512/**
2513 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2514 * @table: the sysctl table
2515 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 * @buffer: the user buffer
2517 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002518 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 *
2520 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2521 * values from/to the user buffer, treated as an ASCII string.
2522 * The values read are assumed to be in 1/USER_HZ seconds, and
2523 * are converted into jiffies.
2524 *
2525 * Returns 0 on success.
2526 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002527int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 void __user *buffer, size_t *lenp, loff_t *ppos)
2529{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002530 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 do_proc_dointvec_userhz_jiffies_conv,NULL);
2532}
2533
2534/**
2535 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2536 * @table: the sysctl table
2537 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 * @buffer: the user buffer
2539 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002540 * @ppos: file position
2541 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 *
2543 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2544 * values from/to the user buffer, treated as an ASCII string.
2545 * The values read are assumed to be in 1/1000 seconds, and
2546 * are converted into jiffies.
2547 *
2548 * Returns 0 on success.
2549 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002550int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 void __user *buffer, size_t *lenp, loff_t *ppos)
2552{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002553 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 do_proc_dointvec_ms_jiffies_conv, NULL);
2555}
2556
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002557static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002558 void __user *buffer, size_t *lenp, loff_t *ppos)
2559{
2560 struct pid *new_pid;
2561 pid_t tmp;
2562 int r;
2563
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002564 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002565
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002566 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002567 lenp, ppos, NULL, NULL);
2568 if (r || !write)
2569 return r;
2570
2571 new_pid = find_get_pid(tmp);
2572 if (!new_pid)
2573 return -ESRCH;
2574
2575 put_pid(xchg(&cad_pid, new_pid));
2576 return 0;
2577}
2578
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002579/**
2580 * proc_do_large_bitmap - read/write from/to a large bitmap
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
2583 * @buffer: the user buffer
2584 * @lenp: the size of the user buffer
2585 * @ppos: file position
2586 *
2587 * The bitmap is stored at table->data and the bitmap length (in bits)
2588 * in table->maxlen.
2589 *
2590 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2591 * large bitmaps may be represented in a compact manner. Writing into
2592 * the file will clear the bitmap then update it with the given input.
2593 *
2594 * Returns 0 on success.
2595 */
2596int proc_do_large_bitmap(struct ctl_table *table, int write,
2597 void __user *buffer, size_t *lenp, loff_t *ppos)
2598{
2599 int err = 0;
2600 bool first = 1;
2601 size_t left = *lenp;
2602 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002603 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002604 unsigned long *tmp_bitmap = NULL;
2605 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2606
WANG Cong122ff242014-05-12 16:04:53 -07002607 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002608 *lenp = 0;
2609 return 0;
2610 }
2611
2612 if (write) {
2613 unsigned long page = 0;
2614 char *kbuf;
2615
2616 if (left > PAGE_SIZE - 1)
2617 left = PAGE_SIZE - 1;
2618
2619 page = __get_free_page(GFP_TEMPORARY);
2620 kbuf = (char *) page;
2621 if (!kbuf)
2622 return -ENOMEM;
2623 if (copy_from_user(kbuf, buffer, left)) {
2624 free_page(page);
2625 return -EFAULT;
2626 }
2627 kbuf[left] = 0;
2628
2629 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2630 GFP_KERNEL);
2631 if (!tmp_bitmap) {
2632 free_page(page);
2633 return -ENOMEM;
2634 }
2635 proc_skip_char(&kbuf, &left, '\n');
2636 while (!err && left) {
2637 unsigned long val_a, val_b;
2638 bool neg;
2639
2640 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2641 sizeof(tr_a), &c);
2642 if (err)
2643 break;
2644 if (val_a >= bitmap_len || neg) {
2645 err = -EINVAL;
2646 break;
2647 }
2648
2649 val_b = val_a;
2650 if (left) {
2651 kbuf++;
2652 left--;
2653 }
2654
2655 if (c == '-') {
2656 err = proc_get_long(&kbuf, &left, &val_b,
2657 &neg, tr_b, sizeof(tr_b),
2658 &c);
2659 if (err)
2660 break;
2661 if (val_b >= bitmap_len || neg ||
2662 val_a > val_b) {
2663 err = -EINVAL;
2664 break;
2665 }
2666 if (left) {
2667 kbuf++;
2668 left--;
2669 }
2670 }
2671
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002672 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002673 first = 0;
2674 proc_skip_char(&kbuf, &left, '\n');
2675 }
2676 free_page(page);
2677 } else {
2678 unsigned long bit_a, bit_b = 0;
2679
2680 while (left) {
2681 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2682 if (bit_a >= bitmap_len)
2683 break;
2684 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2685 bit_a + 1) - 1;
2686
2687 if (!first) {
2688 err = proc_put_char(&buffer, &left, ',');
2689 if (err)
2690 break;
2691 }
2692 err = proc_put_long(&buffer, &left, bit_a, false);
2693 if (err)
2694 break;
2695 if (bit_a != bit_b) {
2696 err = proc_put_char(&buffer, &left, '-');
2697 if (err)
2698 break;
2699 err = proc_put_long(&buffer, &left, bit_b, false);
2700 if (err)
2701 break;
2702 }
2703
2704 first = 0; bit_b++;
2705 }
2706 if (!err)
2707 err = proc_put_char(&buffer, &left, '\n');
2708 }
2709
2710 if (!err) {
2711 if (write) {
2712 if (*ppos)
2713 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2714 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002715 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002716 }
2717 kfree(tmp_bitmap);
2718 *lenp -= left;
2719 *ppos += *lenp;
2720 return 0;
2721 } else {
2722 kfree(tmp_bitmap);
2723 return err;
2724 }
2725}
2726
Jovi Zhang55610502011-01-12 17:00:45 -08002727#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002729int proc_dostring(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
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 void __user *buffer, size_t *lenp, loff_t *ppos)
2737{
2738 return -ENOSYS;
2739}
2740
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002741int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 void __user *buffer, size_t *lenp, loff_t *ppos)
2743{
2744 return -ENOSYS;
2745}
2746
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002747int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 void __user *buffer, size_t *lenp, loff_t *ppos)
2749{
2750 return -ENOSYS;
2751}
2752
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002753int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 void __user *buffer, size_t *lenp, loff_t *ppos)
2755{
2756 return -ENOSYS;
2757}
2758
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002759int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 void __user *buffer, size_t *lenp, loff_t *ppos)
2761{
2762 return -ENOSYS;
2763}
2764
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002765int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 void __user *buffer, size_t *lenp, loff_t *ppos)
2767{
2768 return -ENOSYS;
2769}
2770
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002771int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 void __user *buffer,
2773 size_t *lenp, loff_t *ppos)
2774{
2775 return -ENOSYS;
2776}
2777
2778
Jovi Zhang55610502011-01-12 17:00:45 -08002779#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781/*
2782 * No sense putting this after each symbol definition, twice,
2783 * exception granted :-)
2784 */
2785EXPORT_SYMBOL(proc_dointvec);
2786EXPORT_SYMBOL(proc_dointvec_jiffies);
2787EXPORT_SYMBOL(proc_dointvec_minmax);
2788EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2789EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2790EXPORT_SYMBOL(proc_dostring);
2791EXPORT_SYMBOL(proc_doulongvec_minmax);
2792EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);