blob: 8c0eabd418862bcaaebc7b01dcc3ea7ce4951a2b [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 Zijlstra4b96a292012-10-25 14:16:47 +0200366 .procname = "numa_balancing_scan_delay_ms",
367 .data = &sysctl_numa_balancing_scan_delay,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
371 },
372 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200373 .procname = "numa_balancing_scan_period_min_ms",
374 .data = &sysctl_numa_balancing_scan_period_min,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
378 },
379 {
380 .procname = "numa_balancing_scan_period_max_ms",
381 .data = &sysctl_numa_balancing_scan_period_max,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = proc_dointvec,
385 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200386 {
387 .procname = "numa_balancing_scan_size_mb",
388 .data = &sysctl_numa_balancing_scan_size,
389 .maxlen = sizeof(unsigned int),
390 .mode = 0644,
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 Rostedtf38f1d2a2008-12-16 23:06:40 -0500603#ifdef CONFIG_STACK_TRACER
604 {
Steven Rostedtf38f1d2a2008-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 Rostedtf38f1d2a2008-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 },
1338
Mel Gorman76ab0f52010-05-24 14:32:28 -07001339#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "min_free_kbytes",
1342 .data = &min_free_kbytes,
1343 .maxlen = sizeof(min_free_kbytes),
1344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001345 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 .extra1 = &zero,
1347 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001348 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001349 .procname = "percpu_pagelist_fraction",
1350 .data = &percpu_pagelist_fraction,
1351 .maxlen = sizeof(percpu_pagelist_fraction),
1352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001354 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001355 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356#ifdef CONFIG_MMU
1357 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 .procname = "max_map_count",
1359 .data = &sysctl_max_map_count,
1360 .maxlen = sizeof(sysctl_max_map_count),
1361 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001362 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001363 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001365#else
1366 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001367 .procname = "nr_trim_pages",
1368 .data = &sysctl_nr_trim_pages,
1369 .maxlen = sizeof(sysctl_nr_trim_pages),
1370 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001371 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001372 .extra1 = &zero,
1373 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374#endif
1375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .procname = "laptop_mode",
1377 .data = &laptop_mode,
1378 .maxlen = sizeof(laptop_mode),
1379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001380 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "block_dump",
1384 .data = &block_dump,
1385 .maxlen = sizeof(block_dump),
1386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .extra1 = &zero,
1389 },
1390 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 .procname = "vfs_cache_pressure",
1392 .data = &sysctl_vfs_cache_pressure,
1393 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001395 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 .extra1 = &zero,
1397 },
1398#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .procname = "legacy_va_layout",
1401 .data = &sysctl_legacy_va_layout,
1402 .maxlen = sizeof(sysctl_legacy_va_layout),
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#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001408#ifdef CONFIG_NUMA
1409 {
Christoph Lameter17436602006-01-18 17:42:32 -08001410 .procname = "zone_reclaim_mode",
1411 .data = &zone_reclaim_mode,
1412 .maxlen = sizeof(zone_reclaim_mode),
1413 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001414 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001415 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001416 },
Christoph Lameter96146342006-07-03 00:24:13 -07001417 {
Christoph Lameter96146342006-07-03 00:24:13 -07001418 .procname = "min_unmapped_ratio",
1419 .data = &sysctl_min_unmapped_ratio,
1420 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001423 .extra1 = &zero,
1424 .extra2 = &one_hundred,
1425 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001426 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001427 .procname = "min_slab_ratio",
1428 .data = &sysctl_min_slab_ratio,
1429 .maxlen = sizeof(sysctl_min_slab_ratio),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001432 .extra1 = &zero,
1433 .extra2 = &one_hundred,
1434 },
Christoph Lameter17436602006-01-18 17:42:32 -08001435#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001436#ifdef CONFIG_SMP
1437 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001438 .procname = "stat_interval",
1439 .data = &sysctl_stat_interval,
1440 .maxlen = sizeof(sysctl_stat_interval),
1441 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001442 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001443 },
1444#endif
David Howells6e141542009-12-15 19:27:45 +00001445#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001446 {
Eric Parised032182007-06-28 15:55:21 -04001447 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001448 .data = &dac_mmap_min_addr,
1449 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001452 },
David Howells6e141542009-12-15 19:27:45 +00001453#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001454#ifdef CONFIG_NUMA
1455 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001456 .procname = "numa_zonelist_order",
1457 .data = &numa_zonelist_order,
1458 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001461 },
1462#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001463#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001464 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001465 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001466 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001467#ifdef CONFIG_X86_32
1468 .data = &vdso32_enabled,
1469 .maxlen = sizeof(vdso32_enabled),
1470#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001471 .data = &vdso_enabled,
1472 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001473#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001474 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001475 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001476 .extra1 = &zero,
1477 },
1478#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001479#ifdef CONFIG_HIGHMEM
1480 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001481 .procname = "highmem_is_dirtyable",
1482 .data = &vm_highmem_is_dirtyable,
1483 .maxlen = sizeof(vm_highmem_is_dirtyable),
1484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001485 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001486 .extra1 = &zero,
1487 .extra2 = &one,
1488 },
1489#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001490#ifdef CONFIG_MEMORY_FAILURE
1491 {
Andi Kleen6a460792009-09-16 11:50:15 +02001492 .procname = "memory_failure_early_kill",
1493 .data = &sysctl_memory_failure_early_kill,
1494 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001496 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001497 .extra1 = &zero,
1498 .extra2 = &one,
1499 },
1500 {
Andi Kleen6a460792009-09-16 11:50:15 +02001501 .procname = "memory_failure_recovery",
1502 .data = &sysctl_memory_failure_recovery,
1503 .maxlen = sizeof(sysctl_memory_failure_recovery),
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#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001510 {
1511 .procname = "user_reserve_kbytes",
1512 .data = &sysctl_user_reserve_kbytes,
1513 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1514 .mode = 0644,
1515 .proc_handler = proc_doulongvec_minmax,
1516 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001517 {
1518 .procname = "admin_reserve_kbytes",
1519 .data = &sysctl_admin_reserve_kbytes,
1520 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1521 .mode = 0644,
1522 .proc_handler = proc_doulongvec_minmax,
1523 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001524 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525};
1526
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001527#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001528static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001529 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001530};
1531#endif
1532
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001533static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 .procname = "inode-nr",
1536 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001537 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001539 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 },
1541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 .procname = "inode-state",
1543 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001544 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001546 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 },
1548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 .procname = "file-nr",
1550 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001551 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001553 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 },
1555 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 .procname = "file-max",
1557 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001558 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001560 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 },
1562 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001563 .procname = "nr_open",
1564 .data = &sysctl_nr_open,
1565 .maxlen = sizeof(int),
1566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001567 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001568 .extra1 = &sysctl_nr_open_min,
1569 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001570 },
1571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 .procname = "dentry-state",
1573 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001574 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001576 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 },
1578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 .procname = "overflowuid",
1580 .data = &fs_overflowuid,
1581 .maxlen = sizeof(int),
1582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001583 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 .extra1 = &minolduid,
1585 .extra2 = &maxolduid,
1586 },
1587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 .procname = "overflowgid",
1589 .data = &fs_overflowgid,
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 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001596#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 .procname = "leases-enable",
1599 .data = &leases_enable,
1600 .maxlen = sizeof(int),
1601 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001602 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001604#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605#ifdef CONFIG_DNOTIFY
1606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 .procname = "dir-notify-enable",
1608 .data = &dir_notify_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 },
1613#endif
1614#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001615#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 .procname = "lease-break-time",
1618 .data = &lease_break_time,
1619 .maxlen = sizeof(int),
1620 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001621 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001623#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001624#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 .procname = "aio-nr",
1627 .data = &aio_nr,
1628 .maxlen = sizeof(aio_nr),
1629 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001630 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 },
1632 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 .procname = "aio-max-nr",
1634 .data = &aio_max_nr,
1635 .maxlen = sizeof(aio_max_nr),
1636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001637 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001639#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001640#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001641 {
Robert Love0399cb02005-07-13 12:38:18 -04001642 .procname = "inotify",
1643 .mode = 0555,
1644 .child = inotify_table,
1645 },
1646#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001647#ifdef CONFIG_EPOLL
1648 {
1649 .procname = "epoll",
1650 .mode = 0555,
1651 .child = epoll_table,
1652 },
1653#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001655 {
Kees Cook800179c2012-07-25 17:29:07 -07001656 .procname = "protected_symlinks",
1657 .data = &sysctl_protected_symlinks,
1658 .maxlen = sizeof(int),
1659 .mode = 0600,
1660 .proc_handler = proc_dointvec_minmax,
1661 .extra1 = &zero,
1662 .extra2 = &one,
1663 },
1664 {
1665 .procname = "protected_hardlinks",
1666 .data = &sysctl_protected_hardlinks,
1667 .maxlen = sizeof(int),
1668 .mode = 0600,
1669 .proc_handler = proc_dointvec_minmax,
1670 .extra1 = &zero,
1671 .extra2 = &one,
1672 },
1673 {
Alan Coxd6e71142005-06-23 00:09:43 -07001674 .procname = "suid_dumpable",
1675 .data = &suid_dumpable,
1676 .maxlen = sizeof(int),
1677 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001678 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001679 .extra1 = &zero,
1680 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001681 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001682#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1683 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001684 .procname = "binfmt_misc",
1685 .mode = 0555,
1686 .child = binfmt_misc_table,
1687 },
1688#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001689 {
Jens Axboeff9da692010-06-03 14:54:39 +02001690 .procname = "pipe-max-size",
1691 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001692 .maxlen = sizeof(int),
1693 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001694 .proc_handler = &pipe_proc_fn,
1695 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001696 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001697 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698};
1699
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001700static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001701#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001702 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001703 .procname = "exception-trace",
1704 .data = &show_unhandled_signals,
1705 .maxlen = sizeof(int),
1706 .mode = 0644,
1707 .proc_handler = proc_dointvec
1708 },
1709#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001710#if defined(CONFIG_OPTPROBES)
1711 {
1712 .procname = "kprobes-optimization",
1713 .data = &sysctl_kprobes_optimization,
1714 .maxlen = sizeof(int),
1715 .mode = 0644,
1716 .proc_handler = proc_kprobes_optimization_handler,
1717 .extra1 = &zero,
1718 .extra2 = &one,
1719 },
1720#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001721 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722};
1723
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001724static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001725 { }
Robert Love0eeca282005-07-12 17:06:03 -04001726};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001728int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001729{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001730 struct ctl_table_header *hdr;
1731
1732 hdr = register_sysctl_table(sysctl_base_table);
1733 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001734 return 0;
1735}
1736
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001737#endif /* CONFIG_SYSCTL */
1738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739/*
1740 * /proc/sys support
1741 */
1742
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001743#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Kees Cookf8808302014-06-06 14:37:17 -07001745static int _proc_do_string(char *data, int maxlen, int write,
1746 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001747 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001748{
1749 size_t len;
1750 char __user *p;
1751 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001752
1753 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001754 *lenp = 0;
1755 return 0;
1756 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001757
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001758 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001759 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1760 /* Only continue writes not past the end of buffer. */
1761 len = strlen(data);
1762 if (len > maxlen - 1)
1763 len = maxlen - 1;
1764
1765 if (*ppos > len)
1766 return 0;
1767 len = *ppos;
1768 } else {
1769 /* Start writing from beginning of buffer. */
1770 len = 0;
1771 }
1772
Kees Cook2ca9bb42014-06-06 14:37:18 -07001773 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001774 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001775 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001776 if (get_user(c, p++))
1777 return -EFAULT;
1778 if (c == 0 || c == '\n')
1779 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001780 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001781 }
Kees Cookf8808302014-06-06 14:37:17 -07001782 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001783 } else {
1784 len = strlen(data);
1785 if (len > maxlen)
1786 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001787
1788 if (*ppos > len) {
1789 *lenp = 0;
1790 return 0;
1791 }
1792
1793 data += *ppos;
1794 len -= *ppos;
1795
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001796 if (len > *lenp)
1797 len = *lenp;
1798 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001799 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001800 return -EFAULT;
1801 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001802 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001803 return -EFAULT;
1804 len++;
1805 }
1806 *lenp = len;
1807 *ppos += len;
1808 }
1809 return 0;
1810}
1811
Kees Cookf4aacea2014-06-06 14:37:19 -07001812static void warn_sysctl_write(struct ctl_table *table)
1813{
1814 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1815 "This will not be supported in the future. To silence this\n"
1816 "warning, set kernel.sysctl_writes_strict = -1\n",
1817 current->comm, table->procname);
1818}
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820/**
1821 * proc_dostring - read a string sysctl
1822 * @table: the sysctl table
1823 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 * @buffer: the user buffer
1825 * @lenp: the size of the user buffer
1826 * @ppos: file position
1827 *
1828 * Reads/writes a string from/to the user buffer. If the kernel
1829 * buffer provided is not large enough to hold the string, the
1830 * string is truncated. The copied string is %NULL-terminated.
1831 * If the string is being read by the user process, it is copied
1832 * and a newline '\n' is added. It is truncated if the buffer is
1833 * not large enough.
1834 *
1835 * Returns 0 on success.
1836 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001837int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 void __user *buffer, size_t *lenp, loff_t *ppos)
1839{
Kees Cookf4aacea2014-06-06 14:37:19 -07001840 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1841 warn_sysctl_write(table);
1842
Kees Cookf8808302014-06-06 14:37:17 -07001843 return _proc_do_string((char *)(table->data), table->maxlen, write,
1844 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
Amerigo Wang00b7c332010-05-05 00:26:45 +00001847static size_t proc_skip_spaces(char **buf)
1848{
1849 size_t ret;
1850 char *tmp = skip_spaces(*buf);
1851 ret = tmp - *buf;
1852 *buf = tmp;
1853 return ret;
1854}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001856static void proc_skip_char(char **buf, size_t *size, const char v)
1857{
1858 while (*size) {
1859 if (**buf != v)
1860 break;
1861 (*size)--;
1862 (*buf)++;
1863 }
1864}
1865
Amerigo Wang00b7c332010-05-05 00:26:45 +00001866#define TMPBUFLEN 22
1867/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001868 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001869 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001870 * @buf: a kernel buffer
1871 * @size: size of the kernel buffer
1872 * @val: this is where the number will be stored
1873 * @neg: set to %TRUE if number is negative
1874 * @perm_tr: a vector which contains the allowed trailers
1875 * @perm_tr_len: size of the perm_tr vector
1876 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001877 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001878 * In case of success %0 is returned and @buf and @size are updated with
1879 * the amount of bytes read. If @tr is non-NULL and a trailing
1880 * character exists (size is non-zero after returning from this
1881 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001882 */
1883static int proc_get_long(char **buf, size_t *size,
1884 unsigned long *val, bool *neg,
1885 const char *perm_tr, unsigned perm_tr_len, char *tr)
1886{
1887 int len;
1888 char *p, tmp[TMPBUFLEN];
1889
1890 if (!*size)
1891 return -EINVAL;
1892
1893 len = *size;
1894 if (len > TMPBUFLEN - 1)
1895 len = TMPBUFLEN - 1;
1896
1897 memcpy(tmp, *buf, len);
1898
1899 tmp[len] = 0;
1900 p = tmp;
1901 if (*p == '-' && *size > 1) {
1902 *neg = true;
1903 p++;
1904 } else
1905 *neg = false;
1906 if (!isdigit(*p))
1907 return -EINVAL;
1908
1909 *val = simple_strtoul(p, &p, 0);
1910
1911 len = p - tmp;
1912
1913 /* We don't know if the next char is whitespace thus we may accept
1914 * invalid integers (e.g. 1234...a) or two integers instead of one
1915 * (e.g. 123...1). So lets not allow such large numbers. */
1916 if (len == TMPBUFLEN - 1)
1917 return -EINVAL;
1918
1919 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1920 return -EINVAL;
1921
1922 if (tr && (len < *size))
1923 *tr = *p;
1924
1925 *buf += len;
1926 *size -= len;
1927
1928 return 0;
1929}
1930
1931/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001932 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001933 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001934 * @buf: the user buffer
1935 * @size: the size of the user buffer
1936 * @val: the integer to be converted
1937 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001938 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001939 * In case of success %0 is returned and @buf and @size are updated with
1940 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001941 */
1942static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1943 bool neg)
1944{
1945 int len;
1946 char tmp[TMPBUFLEN], *p = tmp;
1947
1948 sprintf(p, "%s%lu", neg ? "-" : "", val);
1949 len = strlen(tmp);
1950 if (len > *size)
1951 len = *size;
1952 if (copy_to_user(*buf, tmp, len))
1953 return -EFAULT;
1954 *size -= len;
1955 *buf += len;
1956 return 0;
1957}
1958#undef TMPBUFLEN
1959
1960static int proc_put_char(void __user **buf, size_t *size, char c)
1961{
1962 if (*size) {
1963 char __user **buffer = (char __user **)buf;
1964 if (put_user(c, *buffer))
1965 return -EFAULT;
1966 (*size)--, (*buffer)++;
1967 *buf = *buffer;
1968 }
1969 return 0;
1970}
1971
1972static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 int *valp,
1974 int write, void *data)
1975{
1976 if (write) {
1977 *valp = *negp ? -*lvalp : *lvalp;
1978 } else {
1979 int val = *valp;
1980 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001981 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 *lvalp = (unsigned long)-val;
1983 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001984 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 *lvalp = (unsigned long)val;
1986 }
1987 }
1988 return 0;
1989}
1990
Amerigo Wang00b7c332010-05-05 00:26:45 +00001991static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1992
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001993static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001994 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001995 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001996 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 int write, void *data),
1998 void *data)
1999{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002000 int *i, vleft, first = 1, err = 0;
2001 unsigned long page = 0;
2002 size_t left;
2003 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Amerigo Wang00b7c332010-05-05 00:26:45 +00002005 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 *lenp = 0;
2007 return 0;
2008 }
2009
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002010 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 vleft = table->maxlen / sizeof(*i);
2012 left = *lenp;
2013
2014 if (!conv)
2015 conv = do_proc_dointvec_conv;
2016
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002018 if (*ppos) {
2019 switch (sysctl_writes_strict) {
2020 case SYSCTL_WRITES_STRICT:
2021 goto out;
2022 case SYSCTL_WRITES_WARN:
2023 warn_sysctl_write(table);
2024 break;
2025 default:
2026 break;
2027 }
2028 }
2029
Amerigo Wang00b7c332010-05-05 00:26:45 +00002030 if (left > PAGE_SIZE - 1)
2031 left = PAGE_SIZE - 1;
2032 page = __get_free_page(GFP_TEMPORARY);
2033 kbuf = (char *) page;
2034 if (!kbuf)
2035 return -ENOMEM;
2036 if (copy_from_user(kbuf, buffer, left)) {
2037 err = -EFAULT;
2038 goto free;
2039 }
2040 kbuf[left] = 0;
2041 }
2042
2043 for (; left && vleft--; i++, first=0) {
2044 unsigned long lval;
2045 bool neg;
2046
2047 if (write) {
2048 left -= proc_skip_spaces(&kbuf);
2049
J. R. Okajima563b0462010-05-25 16:10:14 -07002050 if (!left)
2051 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002052 err = proc_get_long(&kbuf, &left, &lval, &neg,
2053 proc_wspace_sep,
2054 sizeof(proc_wspace_sep), NULL);
2055 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002057 if (conv(&neg, &lval, i, 1, data)) {
2058 err = -EINVAL;
2059 break;
2060 }
2061 } else {
2062 if (conv(&neg, &lval, i, 0, data)) {
2063 err = -EINVAL;
2064 break;
2065 }
2066 if (!first)
2067 err = proc_put_char(&buffer, &left, '\t');
2068 if (err)
2069 break;
2070 err = proc_put_long(&buffer, &left, lval, neg);
2071 if (err)
2072 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 }
2074 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002075
2076 if (!write && !first && left && !err)
2077 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002078 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002079 left -= proc_skip_spaces(&kbuf);
2080free:
2081 if (write) {
2082 free_page(page);
2083 if (first)
2084 return err ? : -EINVAL;
2085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002087out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002089 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002092static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002093 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002094 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002095 int write, void *data),
2096 void *data)
2097{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002098 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002099 buffer, lenp, ppos, conv, data);
2100}
2101
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102/**
2103 * proc_dointvec - read a vector of integers
2104 * @table: the sysctl table
2105 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 * @buffer: the user buffer
2107 * @lenp: the size of the user buffer
2108 * @ppos: file position
2109 *
2110 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2111 * values from/to the user buffer, treated as an ASCII string.
2112 *
2113 * Returns 0 on success.
2114 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002115int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 void __user *buffer, size_t *lenp, loff_t *ppos)
2117{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002118 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 NULL,NULL);
2120}
2121
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002122/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002123 * Taint values can only be increased
2124 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002125 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002126static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002127 void __user *buffer, size_t *lenp, loff_t *ppos)
2128{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002129 struct ctl_table t;
2130 unsigned long tmptaint = get_taint();
2131 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002132
Bastian Blank91fcd412007-04-23 14:41:14 -07002133 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002134 return -EPERM;
2135
Andi Kleen25ddbb12008-10-15 22:01:41 -07002136 t = *table;
2137 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002138 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002139 if (err < 0)
2140 return err;
2141
2142 if (write) {
2143 /*
2144 * Poor man's atomic or. Not worth adding a primitive
2145 * to everyone's atomic.h for this
2146 */
2147 int i;
2148 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2149 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302150 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002151 }
2152 }
2153
2154 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002155}
2156
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002157#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002158static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002159 void __user *buffer, size_t *lenp, loff_t *ppos)
2160{
2161 if (write && !capable(CAP_SYS_ADMIN))
2162 return -EPERM;
2163
2164 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2165}
2166#endif
2167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168struct do_proc_dointvec_minmax_conv_param {
2169 int *min;
2170 int *max;
2171};
2172
Amerigo Wang00b7c332010-05-05 00:26:45 +00002173static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2174 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 int write, void *data)
2176{
2177 struct do_proc_dointvec_minmax_conv_param *param = data;
2178 if (write) {
2179 int val = *negp ? -*lvalp : *lvalp;
2180 if ((param->min && *param->min > val) ||
2181 (param->max && *param->max < val))
2182 return -EINVAL;
2183 *valp = val;
2184 } else {
2185 int val = *valp;
2186 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002187 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 *lvalp = (unsigned long)-val;
2189 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002190 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 *lvalp = (unsigned long)val;
2192 }
2193 }
2194 return 0;
2195}
2196
2197/**
2198 * proc_dointvec_minmax - read a vector of integers with min/max values
2199 * @table: the sysctl table
2200 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 * @buffer: the user buffer
2202 * @lenp: the size of the user buffer
2203 * @ppos: file position
2204 *
2205 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2206 * values from/to the user buffer, treated as an ASCII string.
2207 *
2208 * This routine will ensure the values are within the range specified by
2209 * table->extra1 (min) and table->extra2 (max).
2210 *
2211 * Returns 0 on success.
2212 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002213int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 void __user *buffer, size_t *lenp, loff_t *ppos)
2215{
2216 struct do_proc_dointvec_minmax_conv_param param = {
2217 .min = (int *) table->extra1,
2218 .max = (int *) table->extra2,
2219 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002220 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 do_proc_dointvec_minmax_conv, &param);
2222}
2223
Kees Cook54b50192012-07-30 14:39:18 -07002224static void validate_coredump_safety(void)
2225{
Alex Kelly046d6622012-10-04 17:15:23 -07002226#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002227 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002228 core_pattern[0] != '/' && core_pattern[0] != '|') {
2229 printk(KERN_WARNING "Unsafe core_pattern used with "\
2230 "suid_dumpable=2. Pipe handler or fully qualified "\
2231 "core dump path required.\n");
2232 }
Alex Kelly046d6622012-10-04 17:15:23 -07002233#endif
Kees Cook54b50192012-07-30 14:39:18 -07002234}
2235
2236static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2237 void __user *buffer, size_t *lenp, loff_t *ppos)
2238{
2239 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2240 if (!error)
2241 validate_coredump_safety();
2242 return error;
2243}
2244
Alex Kelly046d6622012-10-04 17:15:23 -07002245#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002246static int proc_dostring_coredump(struct ctl_table *table, int write,
2247 void __user *buffer, size_t *lenp, loff_t *ppos)
2248{
2249 int error = proc_dostring(table, write, buffer, lenp, ppos);
2250 if (!error)
2251 validate_coredump_safety();
2252 return error;
2253}
Alex Kelly046d6622012-10-04 17:15:23 -07002254#endif
Kees Cook54b50192012-07-30 14:39:18 -07002255
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002256static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 void __user *buffer,
2258 size_t *lenp, loff_t *ppos,
2259 unsigned long convmul,
2260 unsigned long convdiv)
2261{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 unsigned long *i, *min, *max;
2263 int vleft, first = 1, err = 0;
2264 unsigned long page = 0;
2265 size_t left;
2266 char *kbuf;
2267
2268 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 *lenp = 0;
2270 return 0;
2271 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002272
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002273 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 min = (unsigned long *) table->extra1;
2275 max = (unsigned long *) table->extra2;
2276 vleft = table->maxlen / sizeof(unsigned long);
2277 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002278
2279 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002280 if (*ppos) {
2281 switch (sysctl_writes_strict) {
2282 case SYSCTL_WRITES_STRICT:
2283 goto out;
2284 case SYSCTL_WRITES_WARN:
2285 warn_sysctl_write(table);
2286 break;
2287 default:
2288 break;
2289 }
2290 }
2291
Amerigo Wang00b7c332010-05-05 00:26:45 +00002292 if (left > PAGE_SIZE - 1)
2293 left = PAGE_SIZE - 1;
2294 page = __get_free_page(GFP_TEMPORARY);
2295 kbuf = (char *) page;
2296 if (!kbuf)
2297 return -ENOMEM;
2298 if (copy_from_user(kbuf, buffer, left)) {
2299 err = -EFAULT;
2300 goto free;
2301 }
2302 kbuf[left] = 0;
2303 }
2304
Eric Dumazet27b3d802010-10-07 12:59:29 -07002305 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002306 unsigned long val;
2307
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002309 bool neg;
2310
2311 left -= proc_skip_spaces(&kbuf);
2312
2313 err = proc_get_long(&kbuf, &left, &val, &neg,
2314 proc_wspace_sep,
2315 sizeof(proc_wspace_sep), NULL);
2316 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 break;
2318 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 continue;
2320 if ((min && val < *min) || (max && val > *max))
2321 continue;
2322 *i = val;
2323 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002324 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002325 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002326 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002327 if (err)
2328 break;
2329 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330 err = proc_put_long(&buffer, &left, val, false);
2331 if (err)
2332 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 }
2334 }
2335
Amerigo Wang00b7c332010-05-05 00:26:45 +00002336 if (!write && !first && left && !err)
2337 err = proc_put_char(&buffer, &left, '\n');
2338 if (write && !err)
2339 left -= proc_skip_spaces(&kbuf);
2340free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002342 free_page(page);
2343 if (first)
2344 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002347out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002349 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350}
2351
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002352static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002353 void __user *buffer,
2354 size_t *lenp, loff_t *ppos,
2355 unsigned long convmul,
2356 unsigned long convdiv)
2357{
2358 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002359 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002360}
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362/**
2363 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2364 * @table: the sysctl table
2365 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 * @buffer: the user buffer
2367 * @lenp: the size of the user buffer
2368 * @ppos: file position
2369 *
2370 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2371 * values from/to the user buffer, treated as an ASCII string.
2372 *
2373 * This routine will ensure the values are within the range specified by
2374 * table->extra1 (min) and table->extra2 (max).
2375 *
2376 * Returns 0 on success.
2377 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002378int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 void __user *buffer, size_t *lenp, loff_t *ppos)
2380{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002381 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382}
2383
2384/**
2385 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2386 * @table: the sysctl table
2387 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 * @buffer: the user buffer
2389 * @lenp: the size of the user buffer
2390 * @ppos: file position
2391 *
2392 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2393 * values from/to the user buffer, treated as an ASCII string. The values
2394 * are treated as milliseconds, and converted to jiffies when they are stored.
2395 *
2396 * This routine will ensure the values are within the range specified by
2397 * table->extra1 (min) and table->extra2 (max).
2398 *
2399 * Returns 0 on success.
2400 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002401int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 void __user *buffer,
2403 size_t *lenp, loff_t *ppos)
2404{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002405 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 lenp, ppos, HZ, 1000l);
2407}
2408
2409
Amerigo Wang00b7c332010-05-05 00:26:45 +00002410static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 int *valp,
2412 int write, void *data)
2413{
2414 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002415 if (*lvalp > LONG_MAX / HZ)
2416 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2418 } else {
2419 int val = *valp;
2420 unsigned long lval;
2421 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002422 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 lval = (unsigned long)-val;
2424 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002425 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 lval = (unsigned long)val;
2427 }
2428 *lvalp = lval / HZ;
2429 }
2430 return 0;
2431}
2432
Amerigo Wang00b7c332010-05-05 00:26:45 +00002433static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 int *valp,
2435 int write, void *data)
2436{
2437 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002438 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2439 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2441 } else {
2442 int val = *valp;
2443 unsigned long lval;
2444 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002445 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 lval = (unsigned long)-val;
2447 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002448 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 lval = (unsigned long)val;
2450 }
2451 *lvalp = jiffies_to_clock_t(lval);
2452 }
2453 return 0;
2454}
2455
Amerigo Wang00b7c332010-05-05 00:26:45 +00002456static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 int *valp,
2458 int write, void *data)
2459{
2460 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002461 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2462
2463 if (jif > INT_MAX)
2464 return 1;
2465 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 } else {
2467 int val = *valp;
2468 unsigned long lval;
2469 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002470 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 lval = (unsigned long)-val;
2472 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002473 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 lval = (unsigned long)val;
2475 }
2476 *lvalp = jiffies_to_msecs(lval);
2477 }
2478 return 0;
2479}
2480
2481/**
2482 * proc_dointvec_jiffies - read a vector of integers as seconds
2483 * @table: the sysctl table
2484 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 * @buffer: the user buffer
2486 * @lenp: the size of the user buffer
2487 * @ppos: file position
2488 *
2489 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2490 * values from/to the user buffer, treated as an ASCII string.
2491 * The values read are assumed to be in seconds, and are converted into
2492 * jiffies.
2493 *
2494 * Returns 0 on success.
2495 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002496int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 void __user *buffer, size_t *lenp, loff_t *ppos)
2498{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002499 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 do_proc_dointvec_jiffies_conv,NULL);
2501}
2502
2503/**
2504 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2505 * @table: the sysctl table
2506 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 * @buffer: the user buffer
2508 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002509 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 *
2511 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2512 * values from/to the user buffer, treated as an ASCII string.
2513 * The values read are assumed to be in 1/USER_HZ seconds, and
2514 * are converted into jiffies.
2515 *
2516 * Returns 0 on success.
2517 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002518int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 void __user *buffer, size_t *lenp, loff_t *ppos)
2520{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002521 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 do_proc_dointvec_userhz_jiffies_conv,NULL);
2523}
2524
2525/**
2526 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 * @buffer: the user buffer
2530 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002531 * @ppos: file position
2532 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 *
2534 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2535 * values from/to the user buffer, treated as an ASCII string.
2536 * The values read are assumed to be in 1/1000 seconds, and
2537 * are converted into jiffies.
2538 *
2539 * Returns 0 on success.
2540 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002541int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 void __user *buffer, size_t *lenp, loff_t *ppos)
2543{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002544 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 do_proc_dointvec_ms_jiffies_conv, NULL);
2546}
2547
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002548static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002549 void __user *buffer, size_t *lenp, loff_t *ppos)
2550{
2551 struct pid *new_pid;
2552 pid_t tmp;
2553 int r;
2554
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002555 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002556
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002557 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002558 lenp, ppos, NULL, NULL);
2559 if (r || !write)
2560 return r;
2561
2562 new_pid = find_get_pid(tmp);
2563 if (!new_pid)
2564 return -ESRCH;
2565
2566 put_pid(xchg(&cad_pid, new_pid));
2567 return 0;
2568}
2569
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002570/**
2571 * proc_do_large_bitmap - read/write from/to a large bitmap
2572 * @table: the sysctl table
2573 * @write: %TRUE if this is a write to the sysctl file
2574 * @buffer: the user buffer
2575 * @lenp: the size of the user buffer
2576 * @ppos: file position
2577 *
2578 * The bitmap is stored at table->data and the bitmap length (in bits)
2579 * in table->maxlen.
2580 *
2581 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2582 * large bitmaps may be represented in a compact manner. Writing into
2583 * the file will clear the bitmap then update it with the given input.
2584 *
2585 * Returns 0 on success.
2586 */
2587int proc_do_large_bitmap(struct ctl_table *table, int write,
2588 void __user *buffer, size_t *lenp, loff_t *ppos)
2589{
2590 int err = 0;
2591 bool first = 1;
2592 size_t left = *lenp;
2593 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002594 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002595 unsigned long *tmp_bitmap = NULL;
2596 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2597
WANG Cong122ff242014-05-12 16:04:53 -07002598 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002599 *lenp = 0;
2600 return 0;
2601 }
2602
2603 if (write) {
2604 unsigned long page = 0;
2605 char *kbuf;
2606
2607 if (left > PAGE_SIZE - 1)
2608 left = PAGE_SIZE - 1;
2609
2610 page = __get_free_page(GFP_TEMPORARY);
2611 kbuf = (char *) page;
2612 if (!kbuf)
2613 return -ENOMEM;
2614 if (copy_from_user(kbuf, buffer, left)) {
2615 free_page(page);
2616 return -EFAULT;
2617 }
2618 kbuf[left] = 0;
2619
2620 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2621 GFP_KERNEL);
2622 if (!tmp_bitmap) {
2623 free_page(page);
2624 return -ENOMEM;
2625 }
2626 proc_skip_char(&kbuf, &left, '\n');
2627 while (!err && left) {
2628 unsigned long val_a, val_b;
2629 bool neg;
2630
2631 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2632 sizeof(tr_a), &c);
2633 if (err)
2634 break;
2635 if (val_a >= bitmap_len || neg) {
2636 err = -EINVAL;
2637 break;
2638 }
2639
2640 val_b = val_a;
2641 if (left) {
2642 kbuf++;
2643 left--;
2644 }
2645
2646 if (c == '-') {
2647 err = proc_get_long(&kbuf, &left, &val_b,
2648 &neg, tr_b, sizeof(tr_b),
2649 &c);
2650 if (err)
2651 break;
2652 if (val_b >= bitmap_len || neg ||
2653 val_a > val_b) {
2654 err = -EINVAL;
2655 break;
2656 }
2657 if (left) {
2658 kbuf++;
2659 left--;
2660 }
2661 }
2662
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002663 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002664 first = 0;
2665 proc_skip_char(&kbuf, &left, '\n');
2666 }
2667 free_page(page);
2668 } else {
2669 unsigned long bit_a, bit_b = 0;
2670
2671 while (left) {
2672 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2673 if (bit_a >= bitmap_len)
2674 break;
2675 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2676 bit_a + 1) - 1;
2677
2678 if (!first) {
2679 err = proc_put_char(&buffer, &left, ',');
2680 if (err)
2681 break;
2682 }
2683 err = proc_put_long(&buffer, &left, bit_a, false);
2684 if (err)
2685 break;
2686 if (bit_a != bit_b) {
2687 err = proc_put_char(&buffer, &left, '-');
2688 if (err)
2689 break;
2690 err = proc_put_long(&buffer, &left, bit_b, false);
2691 if (err)
2692 break;
2693 }
2694
2695 first = 0; bit_b++;
2696 }
2697 if (!err)
2698 err = proc_put_char(&buffer, &left, '\n');
2699 }
2700
2701 if (!err) {
2702 if (write) {
2703 if (*ppos)
2704 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2705 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002706 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002707 }
2708 kfree(tmp_bitmap);
2709 *lenp -= left;
2710 *ppos += *lenp;
2711 return 0;
2712 } else {
2713 kfree(tmp_bitmap);
2714 return err;
2715 }
2716}
2717
Jovi Zhang55610502011-01-12 17:00:45 -08002718#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002720int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 void __user *buffer, size_t *lenp, loff_t *ppos)
2722{
2723 return -ENOSYS;
2724}
2725
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002726int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 void __user *buffer, size_t *lenp, loff_t *ppos)
2728{
2729 return -ENOSYS;
2730}
2731
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002732int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 void __user *buffer, size_t *lenp, loff_t *ppos)
2734{
2735 return -ENOSYS;
2736}
2737
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002738int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 void __user *buffer, size_t *lenp, loff_t *ppos)
2740{
2741 return -ENOSYS;
2742}
2743
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002744int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 void __user *buffer, size_t *lenp, loff_t *ppos)
2746{
2747 return -ENOSYS;
2748}
2749
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002750int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 void __user *buffer, size_t *lenp, loff_t *ppos)
2752{
2753 return -ENOSYS;
2754}
2755
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002756int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 void __user *buffer, size_t *lenp, loff_t *ppos)
2758{
2759 return -ENOSYS;
2760}
2761
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002762int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 void __user *buffer,
2764 size_t *lenp, loff_t *ppos)
2765{
2766 return -ENOSYS;
2767}
2768
2769
Jovi Zhang55610502011-01-12 17:00:45 -08002770#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772/*
2773 * No sense putting this after each symbol definition, twice,
2774 * exception granted :-)
2775 */
2776EXPORT_SYMBOL(proc_dointvec);
2777EXPORT_SYMBOL(proc_dointvec_jiffies);
2778EXPORT_SYMBOL(proc_dointvec_minmax);
2779EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2780EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2781EXPORT_SYMBOL(proc_dostring);
2782EXPORT_SYMBOL(proc_doulongvec_minmax);
2783EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);