blob: 81fe3bde9feefd9f4946d0c00faab936e54fff67 [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>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include <asm/uaccess.h>
70#include <asm/processor.h>
71
Andi Kleen29cbc782006-09-30 01:47:55 +020072#ifdef CONFIG_X86
73#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010074#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010075#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020076#endif
David Howellsd550bbd2012-03-28 18:30:03 +010077#ifdef CONFIG_SPARC
78#include <asm/setup.h>
79#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080080#ifdef CONFIG_BSD_PROCESS_ACCT
81#include <linux/acct.h>
82#endif
Dave Young4f0e0562010-03-10 15:24:09 -080083#ifdef CONFIG_RT_MUTEXES
84#include <linux/rtmutex.h>
85#endif
Dave Young2edf5e42010-03-10 15:24:10 -080086#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
87#include <linux/lockdep.h>
88#endif
Dave Young15485a42010-03-10 15:24:07 -080089#ifdef CONFIG_CHR_DEV_SG
90#include <scsi/sg.h>
91#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020092
Don Zickus58687ac2010-05-07 17:11:44 -040093#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050094#include <linux/nmi.h>
95#endif
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#if defined(CONFIG_SYSCTL)
98
99/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700100extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700104extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max;
Rik van Rielf8ade362011-09-01 15:26:50 -0400107extern int extra_free_kbytes;
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 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200354#endif /* CONFIG_SMP */
355#ifdef CONFIG_NUMA_BALANCING
356 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200357 .procname = "numa_balancing_scan_delay_ms",
358 .data = &sysctl_numa_balancing_scan_delay,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
361 .proc_handler = proc_dointvec,
362 },
363 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200364 .procname = "numa_balancing_scan_period_min_ms",
365 .data = &sysctl_numa_balancing_scan_period_min,
366 .maxlen = sizeof(unsigned int),
367 .mode = 0644,
368 .proc_handler = proc_dointvec,
369 },
370 {
371 .procname = "numa_balancing_scan_period_max_ms",
372 .data = &sysctl_numa_balancing_scan_period_max,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec,
376 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200377 {
378 .procname = "numa_balancing_scan_size_mb",
379 .data = &sysctl_numa_balancing_scan_size,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400382 .proc_handler = proc_dointvec_minmax,
383 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200384 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100385 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800386 .procname = "numa_balancing",
387 .data = NULL, /* filled in by handler */
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = sysctl_numa_balancing,
391 .extra1 = &zero,
392 .extra2 = &one,
393 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200394#endif /* CONFIG_NUMA_BALANCING */
395#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200396 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100397 .procname = "sched_rt_period_us",
398 .data = &sysctl_sched_rt_period,
399 .maxlen = sizeof(unsigned int),
400 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800401 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100402 },
403 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100404 .procname = "sched_rt_runtime_us",
405 .data = &sysctl_sched_rt_runtime,
406 .maxlen = sizeof(int),
407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800408 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100409 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600410 {
411 .procname = "sched_rr_timeslice_ms",
412 .data = &sched_rr_timeslice,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = sched_rr_handler,
416 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100417#ifdef CONFIG_SCHED_AUTOGROUP
418 {
419 .procname = "sched_autogroup_enabled",
420 .data = &sysctl_sched_autogroup_enabled,
421 .maxlen = sizeof(unsigned int),
422 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800423 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100424 .extra1 = &zero,
425 .extra2 = &one,
426 },
427#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700428#ifdef CONFIG_CFS_BANDWIDTH
429 {
430 .procname = "sched_cfs_bandwidth_slice_us",
431 .data = &sysctl_sched_cfs_bandwidth_slice,
432 .maxlen = sizeof(unsigned int),
433 .mode = 0644,
434 .proc_handler = proc_dointvec_minmax,
435 .extra1 = &one,
436 },
437#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700438#ifdef CONFIG_PROVE_LOCKING
439 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700440 .procname = "prove_locking",
441 .data = &prove_locking,
442 .maxlen = sizeof(int),
443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800444 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700445 },
446#endif
447#ifdef CONFIG_LOCK_STAT
448 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700449 .procname = "lock_stat",
450 .data = &lock_stat,
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
Ingo Molnar77e54a12007-07-09 18:52:00 +0200456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "panic",
458 .data = &panic_timeout,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
Alex Kelly046d6622012-10-04 17:15:23 -0700463#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "core_uses_pid",
466 .data = &core_uses_pid,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800469 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 },
471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .procname = "core_pattern",
473 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700474 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700476 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
Neil Hormana2939802009-09-23 15:56:56 -0700478 {
Neil Hormana2939802009-09-23 15:56:56 -0700479 .procname = "core_pipe_limit",
480 .data = &core_pipe_limit,
481 .maxlen = sizeof(unsigned int),
482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800483 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700484 },
Alex Kelly046d6622012-10-04 17:15:23 -0700485#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800486#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700489 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700493 {
494 .procname = "sysctl_writes_strict",
495 .data = &sysctl_writes_strict,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = proc_dointvec_minmax,
499 .extra1 = &neg_one,
500 .extra2 = &one,
501 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800502#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100503#ifdef CONFIG_LATENCYTOP
504 {
505 .procname = "latencytop",
506 .data = &latencytop_enabled,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800509 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100510 },
511#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#ifdef CONFIG_BLK_DEV_INITRD
513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .procname = "real-root-dev",
515 .data = &real_root_dev,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
520#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700521 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700522 .procname = "print-fatal-signals",
523 .data = &print_fatal_signals,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700527 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700528#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 .procname = "reboot-cmd",
531 .data = reboot_command,
532 .maxlen = 256,
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 },
536 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 .procname = "stop-a",
538 .data = &stop_a_enabled,
539 .maxlen = sizeof (int),
540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 },
543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "scons-poweroff",
545 .data = &scons_pwroff,
546 .maxlen = sizeof (int),
547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 },
550#endif
David S. Miller08714202008-11-16 23:49:24 -0800551#ifdef CONFIG_SPARC64
552 {
David S. Miller08714202008-11-16 23:49:24 -0800553 .procname = "tsb-ratio",
554 .data = &sysctl_tsb_ratio,
555 .maxlen = sizeof (int),
556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800557 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800558 },
559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#ifdef __hppa__
561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "soft-power",
563 .data = &pwrsw_enabled,
564 .maxlen = sizeof (int),
565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530568#endif
569#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "unaligned-trap",
572 .data = &unaligned_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 },
577#endif
578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "ctrl-alt-del",
580 .data = &C_A_D,
581 .maxlen = sizeof(int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400585#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200586 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200587 .procname = "ftrace_enabled",
588 .data = &ftrace_enabled,
589 .maxlen = sizeof(int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200592 },
593#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500594#ifdef CONFIG_STACK_TRACER
595 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500596 .procname = "stack_tracer_enabled",
597 .data = &stack_tracer_enabled,
598 .maxlen = sizeof(int),
599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800600 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500601 },
602#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400603#ifdef CONFIG_TRACING
604 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100605 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400606 .data = &ftrace_dump_on_oops,
607 .maxlen = sizeof(int),
608 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800609 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400610 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400611 {
612 .procname = "traceoff_on_warning",
613 .data = &__disable_trace_on_warning,
614 .maxlen = sizeof(__disable_trace_on_warning),
615 .mode = 0644,
616 .proc_handler = proc_dointvec,
617 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500618 {
619 .procname = "tracepoint_printk",
620 .data = &tracepoint_printk,
621 .maxlen = sizeof(tracepoint_printk),
622 .mode = 0644,
623 .proc_handler = proc_dointvec,
624 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400625#endif
Dave Young2965faa2015-09-09 15:38:55 -0700626#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800627 {
628 .procname = "kexec_load_disabled",
629 .data = &kexec_load_disabled,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 /* only handle a transition from default "0" to "1" */
633 .proc_handler = proc_dointvec_minmax,
634 .extra1 = &one,
635 .extra2 = &one,
636 },
637#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200638#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .procname = "modprobe",
641 .data = &modprobe_path,
642 .maxlen = KMOD_PATH_LEN,
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 },
Kees Cook3d433212009-04-02 15:49:29 -0700646 {
Kees Cook3d433212009-04-02 15:49:29 -0700647 .procname = "modules_disabled",
648 .data = &modules_disabled,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700653 .extra1 = &one,
654 .extra2 = &one,
655 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700657#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100660 .data = &uevent_helper,
661 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800663 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 },
Michael Marineau86d56132014-04-10 14:09:31 -0700665#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666#ifdef CONFIG_CHR_DEV_SG
667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "sg-big-buff",
669 .data = &sg_big_buff,
670 .maxlen = sizeof (int),
671 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
674#endif
675#ifdef CONFIG_BSD_PROCESS_ACCT
676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .procname = "acct",
678 .data = &acct_parm,
679 .maxlen = 3*sizeof(int),
680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 },
683#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684#ifdef CONFIG_MAGIC_SYSRQ
685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800687 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof (int),
689 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700690 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
692#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700693#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700696 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .maxlen = sizeof (int),
698 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800699 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700701#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700704 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .maxlen = sizeof(int),
706 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700707 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 },
709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "random",
711 .mode = 0555,
712 .child = random_table,
713 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 {
Eric Paris17f60a72011-04-01 17:07:50 -0400715 .procname = "usermodehelper",
716 .mode = 0555,
717 .child = usermodehelper_table,
718 },
719 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .procname = "overflowuid",
721 .data = &overflowuid,
722 .maxlen = sizeof(int),
723 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800724 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .extra1 = &minolduid,
726 .extra2 = &maxolduid,
727 },
728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .procname = "overflowgid",
730 .data = &overflowgid,
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 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800737#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738#ifdef CONFIG_MATHEMU
739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .procname = "ieee_emulation_warnings",
741 .data = &sysctl_ieee_emulation_warnings,
742 .maxlen = sizeof(int),
743 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800744 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 },
746#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200749 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .maxlen = sizeof(int),
751 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800752 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 },
754#endif
755 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 .procname = "pid_max",
757 .data = &pid_max,
758 .maxlen = sizeof (int),
759 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800760 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .extra1 = &pid_max_min,
762 .extra2 = &pid_max_max,
763 },
764 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 .procname = "panic_on_oops",
766 .data = &panic_on_oops,
767 .maxlen = sizeof(int),
768 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800769 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800771#if defined CONFIG_PRINTK
772 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800773 .procname = "printk",
774 .data = &console_loglevel,
775 .maxlen = 4*sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800778 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700781 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .maxlen = sizeof(int),
783 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 },
786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700788 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .maxlen = sizeof(int),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 },
Dave Youngaf913222009-09-22 16:43:33 -0700793 {
Dave Youngaf913222009-09-22 16:43:33 -0700794 .procname = "printk_delay",
795 .data = &printk_delay_msec,
796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700799 .extra1 = &zero,
800 .extra2 = &ten_thousand,
801 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800803 .procname = "dmesg_restrict",
804 .data = &dmesg_restrict,
805 .maxlen = sizeof(int),
806 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700807 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800808 .extra1 = &zero,
809 .extra2 = &one,
810 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800811 {
812 .procname = "kptr_restrict",
813 .data = &kptr_restrict,
814 .maxlen = sizeof(int),
815 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700816 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800817 .extra1 = &zero,
818 .extra2 = &two,
819 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800820#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800821 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 .procname = "ngroups_max",
823 .data = &ngroups_max,
824 .maxlen = sizeof (int),
825 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 },
Dan Ballard73efc032011-10-31 17:11:20 -0700828 {
829 .procname = "cap_last_cap",
830 .data = (void *)&cap_last_cap,
831 .maxlen = sizeof(int),
832 .mode = 0444,
833 .proc_handler = proc_dointvec,
834 },
Don Zickus58687ac2010-05-07 17:11:44 -0400835#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500836 {
Don Zickus58687ac2010-05-07 17:11:44 -0400837 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200838 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500839 .maxlen = sizeof (int),
840 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700841 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700842 .extra1 = &zero,
843 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400844 },
845 {
846 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700847 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400848 .maxlen = sizeof(int),
849 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700850 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800851 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400852 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500853 },
Don Zickus2508ce12010-05-07 17:11:46 -0400854 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700855 .procname = "nmi_watchdog",
856 .data = &nmi_watchdog_enabled,
857 .maxlen = sizeof (int),
858 .mode = 0644,
859 .proc_handler = proc_nmi_watchdog,
860 .extra1 = &zero,
861#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
862 .extra2 = &one,
863#else
864 .extra2 = &zero,
865#endif
866 },
867 {
868 .procname = "soft_watchdog",
869 .data = &soft_watchdog_enabled,
870 .maxlen = sizeof (int),
871 .mode = 0644,
872 .proc_handler = proc_soft_watchdog,
873 .extra1 = &zero,
874 .extra2 = &one,
875 },
876 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700877 .procname = "watchdog_cpumask",
878 .data = &watchdog_cpumask_bits,
879 .maxlen = NR_CPUS,
880 .mode = 0644,
881 .proc_handler = proc_watchdog_cpumask,
882 },
883 {
Don Zickus2508ce12010-05-07 17:11:46 -0400884 .procname = "softlockup_panic",
885 .data = &softlockup_panic,
886 .maxlen = sizeof(int),
887 .mode = 0644,
888 .proc_handler = proc_dointvec_minmax,
889 .extra1 = &zero,
890 .extra2 = &one,
891 },
Don Zickusac1f5912015-11-05 18:44:44 -0800892#ifdef CONFIG_HARDLOCKUP_DETECTOR
893 {
894 .procname = "hardlockup_panic",
895 .data = &hardlockup_panic,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = proc_dointvec_minmax,
899 .extra1 = &zero,
900 .extra2 = &one,
901 },
902#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700903#ifdef CONFIG_SMP
904 {
905 .procname = "softlockup_all_cpu_backtrace",
906 .data = &sysctl_softlockup_all_cpu_backtrace,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = proc_dointvec_minmax,
910 .extra1 = &zero,
911 .extra2 = &one,
912 },
Jiri Kosina55537872015-11-05 18:44:41 -0800913 {
914 .procname = "hardlockup_all_cpu_backtrace",
915 .data = &sysctl_hardlockup_all_cpu_backtrace,
916 .maxlen = sizeof(int),
917 .mode = 0644,
918 .proc_handler = proc_dointvec_minmax,
919 .extra1 = &zero,
920 .extra2 = &one,
921 },
Aaron Tomlined235872014-06-23 13:22:05 -0700922#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500923#endif
924#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
925 {
926 .procname = "unknown_nmi_panic",
927 .data = &unknown_nmi_panic,
928 .maxlen = sizeof (int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
931 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500932#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933#if defined(CONFIG_X86)
934 {
Don Zickus8da5add2006-09-26 10:52:27 +0200935 .procname = "panic_on_unrecovered_nmi",
936 .data = &panic_on_unrecovered_nmi,
937 .maxlen = sizeof(int),
938 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800939 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200940 },
941 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700942 .procname = "panic_on_io_nmi",
943 .data = &panic_on_io_nmi,
944 .maxlen = sizeof(int),
945 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800946 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700947 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900948#ifdef CONFIG_DEBUG_STACKOVERFLOW
949 {
950 .procname = "panic_on_stackoverflow",
951 .data = &sysctl_panic_on_stackoverflow,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec,
955 },
956#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700957 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 .procname = "bootloader_type",
959 .data = &bootloader_type,
960 .maxlen = sizeof (int),
961 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800962 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100964 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700965 .procname = "bootloader_version",
966 .data = &bootloader_version,
967 .maxlen = sizeof (int),
968 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800969 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700970 },
971 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100972 .procname = "kstack_depth_to_print",
973 .data = &kstack_depth_to_print,
974 .maxlen = sizeof(int),
975 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800976 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100977 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100978 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100979 .procname = "io_delay_type",
980 .data = &io_delay_type,
981 .maxlen = sizeof(int),
982 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800983 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800986#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .procname = "randomize_va_space",
989 .data = &randomize_va_space,
990 .maxlen = sizeof(int),
991 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800992 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800994#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800995#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700996 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700997 .procname = "spin_retry",
998 .data = &spin_retry,
999 .maxlen = sizeof (int),
1000 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001001 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001002 },
1003#endif
Len Brown673d5b42007-07-28 03:33:16 -04001004#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001005 {
Pavel Machekc255d842006-02-20 18:27:58 -08001006 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001007 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001008 .maxlen = sizeof (unsigned long),
1009 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001010 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001011 },
1012#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301013#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001014 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001015 .procname = "ignore-unaligned-usertrap",
1016 .data = &no_unaligned_warning,
1017 .maxlen = sizeof (int),
1018 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001020 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301021#endif
1022#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001023 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001024 .procname = "unaligned-dump-stack",
1025 .data = &unaligned_dump_stack,
1026 .maxlen = sizeof (int),
1027 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001028 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001029 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001030#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001031#ifdef CONFIG_DETECT_HUNG_TASK
1032 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001033 .procname = "hung_task_panic",
1034 .data = &sysctl_hung_task_panic,
1035 .maxlen = sizeof(int),
1036 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001037 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001038 .extra1 = &zero,
1039 .extra2 = &one,
1040 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001041 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001042 .procname = "hung_task_check_count",
1043 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001044 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001045 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001046 .proc_handler = proc_dointvec_minmax,
1047 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001048 },
1049 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001050 .procname = "hung_task_timeout_secs",
1051 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001052 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001055 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001056 },
1057 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001058 .procname = "hung_task_warnings",
1059 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001060 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001061 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001062 .proc_handler = proc_dointvec_minmax,
1063 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001064 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001065#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001066#ifdef CONFIG_COMPAT
1067 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001068 .procname = "compat-log",
1069 .data = &compat_log,
1070 .maxlen = sizeof (int),
1071 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001072 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001073 },
1074#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -07001075#ifdef CONFIG_RT_MUTEXES
1076 {
Ingo Molnar23f78d42006-06-27 02:54:53 -07001077 .procname = "max_lock_depth",
1078 .data = &max_lock_depth,
1079 .maxlen = sizeof(int),
1080 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001081 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -07001082 },
1083#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001084 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001085 .procname = "poweroff_cmd",
1086 .data = &poweroff_cmd,
1087 .maxlen = POWEROFF_CMD_PATH_LEN,
1088 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001089 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001090 },
David Howells0b77f5b2008-04-29 01:01:32 -07001091#ifdef CONFIG_KEYS
1092 {
David Howells0b77f5b2008-04-29 01:01:32 -07001093 .procname = "keys",
1094 .mode = 0555,
1095 .child = key_sysctls,
1096 },
1097#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001098#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001099 /*
1100 * User-space scripts rely on the existence of this file
1101 * as a feature check for perf_events being enabled.
1102 *
1103 * So it's an ABI, do not remove!
1104 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001105 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001106 .procname = "perf_event_paranoid",
1107 .data = &sysctl_perf_event_paranoid,
1108 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001109 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001110 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001111 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001112 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001113 .procname = "perf_event_mlock_kb",
1114 .data = &sysctl_perf_event_mlock,
1115 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001116 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001117 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001118 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001119 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001120 .procname = "perf_event_max_sample_rate",
1121 .data = &sysctl_perf_event_sample_rate,
1122 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001123 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001124 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001125 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001126 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001127 {
1128 .procname = "perf_cpu_time_max_percent",
1129 .data = &sysctl_perf_cpu_time_max_percent,
1130 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1131 .mode = 0644,
1132 .proc_handler = perf_cpu_time_max_percent_handler,
1133 .extra1 = &zero,
1134 .extra2 = &one_hundred,
1135 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001136#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001137#ifdef CONFIG_KMEMCHECK
1138 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001139 .procname = "kmemcheck",
1140 .data = &kmemcheck_enabled,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001143 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001144 },
1145#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001146 {
1147 .procname = "panic_on_warn",
1148 .data = &panic_on_warn,
1149 .maxlen = sizeof(int),
1150 .mode = 0644,
1151 .proc_handler = proc_dointvec_minmax,
1152 .extra1 = &zero,
1153 .extra2 = &one,
1154 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001155#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1156 {
1157 .procname = "timer_migration",
1158 .data = &sysctl_timer_migration,
1159 .maxlen = sizeof(unsigned int),
1160 .mode = 0644,
1161 .proc_handler = timer_migration_handler,
1162 },
1163#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001164#ifdef CONFIG_BPF_SYSCALL
1165 {
1166 .procname = "unprivileged_bpf_disabled",
1167 .data = &sysctl_unprivileged_bpf_disabled,
1168 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1169 .mode = 0644,
1170 /* only handle a transition from default "0" to "1" */
1171 .proc_handler = proc_dointvec_minmax,
1172 .extra1 = &one,
1173 .extra2 = &one,
1174 },
1175#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001176 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177};
1178
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001179static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .procname = "overcommit_memory",
1182 .data = &sysctl_overcommit_memory,
1183 .maxlen = sizeof(sysctl_overcommit_memory),
1184 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001185 .proc_handler = proc_dointvec_minmax,
1186 .extra1 = &zero,
1187 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 },
1189 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001190 .procname = "panic_on_oom",
1191 .data = &sysctl_panic_on_oom,
1192 .maxlen = sizeof(sysctl_panic_on_oom),
1193 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001194 .proc_handler = proc_dointvec_minmax,
1195 .extra1 = &zero,
1196 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001197 },
1198 {
David Rientjesfe071d72007-10-16 23:25:56 -07001199 .procname = "oom_kill_allocating_task",
1200 .data = &sysctl_oom_kill_allocating_task,
1201 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1202 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001203 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001204 },
1205 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001206 .procname = "oom_dump_tasks",
1207 .data = &sysctl_oom_dump_tasks,
1208 .maxlen = sizeof(sysctl_oom_dump_tasks),
1209 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001210 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001211 },
1212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 .procname = "overcommit_ratio",
1214 .data = &sysctl_overcommit_ratio,
1215 .maxlen = sizeof(sysctl_overcommit_ratio),
1216 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001217 .proc_handler = overcommit_ratio_handler,
1218 },
1219 {
1220 .procname = "overcommit_kbytes",
1221 .data = &sysctl_overcommit_kbytes,
1222 .maxlen = sizeof(sysctl_overcommit_kbytes),
1223 .mode = 0644,
1224 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 },
1226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .procname = "page-cluster",
1228 .data = &page_cluster,
1229 .maxlen = sizeof(int),
1230 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001231 .proc_handler = proc_dointvec_minmax,
1232 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 },
1234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 .procname = "dirty_background_ratio",
1236 .data = &dirty_background_ratio,
1237 .maxlen = sizeof(dirty_background_ratio),
1238 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001239 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 .extra1 = &zero,
1241 .extra2 = &one_hundred,
1242 },
1243 {
David Rientjes2da02992009-01-06 14:39:31 -08001244 .procname = "dirty_background_bytes",
1245 .data = &dirty_background_bytes,
1246 .maxlen = sizeof(dirty_background_bytes),
1247 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001248 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001249 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001250 },
1251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 .procname = "dirty_ratio",
1253 .data = &vm_dirty_ratio,
1254 .maxlen = sizeof(vm_dirty_ratio),
1255 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001256 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 .extra1 = &zero,
1258 .extra2 = &one_hundred,
1259 },
1260 {
David Rientjes2da02992009-01-06 14:39:31 -08001261 .procname = "dirty_bytes",
1262 .data = &vm_dirty_bytes,
1263 .maxlen = sizeof(vm_dirty_bytes),
1264 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001265 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001266 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001267 },
1268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001270 .data = &dirty_writeback_interval,
1271 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001273 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 },
1275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001277 .data = &dirty_expire_interval,
1278 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001280 .proc_handler = proc_dointvec_minmax,
1281 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 },
1283 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001284 .procname = "dirtytime_expire_seconds",
1285 .data = &dirtytime_expire_interval,
1286 .maxlen = sizeof(dirty_expire_interval),
1287 .mode = 0644,
1288 .proc_handler = dirtytime_interval_handler,
1289 .extra1 = &zero,
1290 },
1291 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001292 .procname = "nr_pdflush_threads",
1293 .mode = 0444 /* read-only */,
1294 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 },
1296 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 .procname = "swappiness",
1298 .data = &vm_swappiness,
1299 .maxlen = sizeof(vm_swappiness),
1300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 .extra1 = &zero,
1303 .extra2 = &one_hundred,
1304 },
1305#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001306 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001308 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 .maxlen = sizeof(unsigned long),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001312 },
1313#ifdef CONFIG_NUMA
1314 {
1315 .procname = "nr_hugepages_mempolicy",
1316 .data = NULL,
1317 .maxlen = sizeof(unsigned long),
1318 .mode = 0644,
1319 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001320 },
1321#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .procname = "hugetlb_shm_group",
1324 .data = &sysctl_hugetlb_shm_group,
1325 .maxlen = sizeof(gid_t),
1326 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001327 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 },
Mel Gorman396faf02007-07-17 04:03:13 -07001329 {
Mel Gorman396faf02007-07-17 04:03:13 -07001330 .procname = "hugepages_treat_as_movable",
1331 .data = &hugepages_treat_as_movable,
1332 .maxlen = sizeof(int),
1333 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001334 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001335 },
Adam Litke54f9f802007-10-16 01:26:20 -07001336 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001337 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001338 .data = NULL,
1339 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001341 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001342 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343#endif
1344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "lowmem_reserve_ratio",
1346 .data = &sysctl_lowmem_reserve_ratio,
1347 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 },
1351 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001352 .procname = "drop_caches",
1353 .data = &sysctl_drop_caches,
1354 .maxlen = sizeof(int),
1355 .mode = 0644,
1356 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001357 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001358 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001359 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001360#ifdef CONFIG_COMPACTION
1361 {
1362 .procname = "compact_memory",
1363 .data = &sysctl_compact_memory,
1364 .maxlen = sizeof(int),
1365 .mode = 0200,
1366 .proc_handler = sysctl_compaction_handler,
1367 },
Mel Gorman5e771902010-05-24 14:32:31 -07001368 {
1369 .procname = "extfrag_threshold",
1370 .data = &sysctl_extfrag_threshold,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = sysctl_extfrag_handler,
1374 .extra1 = &min_extfrag_threshold,
1375 .extra2 = &max_extfrag_threshold,
1376 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001377 {
1378 .procname = "compact_unevictable_allowed",
1379 .data = &sysctl_compact_unevictable_allowed,
1380 .maxlen = sizeof(int),
1381 .mode = 0644,
1382 .proc_handler = proc_dointvec,
1383 .extra1 = &zero,
1384 .extra2 = &one,
1385 },
Mel Gorman5e771902010-05-24 14:32:31 -07001386
Mel Gorman76ab0f52010-05-24 14:32:28 -07001387#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001388 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 .procname = "min_free_kbytes",
1390 .data = &min_free_kbytes,
1391 .maxlen = sizeof(min_free_kbytes),
1392 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001393 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .extra1 = &zero,
1395 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001396 {
Rik van Rielf8ade362011-09-01 15:26:50 -04001397 .procname = "extra_free_kbytes",
1398 .data = &extra_free_kbytes,
1399 .maxlen = sizeof(extra_free_kbytes),
1400 .mode = 0644,
1401 .proc_handler = min_free_kbytes_sysctl_handler,
1402 .extra1 = &zero,
1403 },
1404 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001405 .procname = "percpu_pagelist_fraction",
1406 .data = &percpu_pagelist_fraction,
1407 .maxlen = sizeof(percpu_pagelist_fraction),
1408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001409 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001410 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001411 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412#ifdef CONFIG_MMU
1413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .procname = "max_map_count",
1415 .data = &sysctl_max_map_count,
1416 .maxlen = sizeof(sysctl_max_map_count),
1417 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001418 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001419 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001421#else
1422 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001423 .procname = "nr_trim_pages",
1424 .data = &sysctl_nr_trim_pages,
1425 .maxlen = sizeof(sysctl_nr_trim_pages),
1426 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001427 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001428 .extra1 = &zero,
1429 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430#endif
1431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .procname = "laptop_mode",
1433 .data = &laptop_mode,
1434 .maxlen = sizeof(laptop_mode),
1435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 },
1438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 .procname = "block_dump",
1440 .data = &block_dump,
1441 .maxlen = sizeof(block_dump),
1442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001443 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 .extra1 = &zero,
1445 },
1446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .procname = "vfs_cache_pressure",
1448 .data = &sysctl_vfs_cache_pressure,
1449 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 .extra1 = &zero,
1453 },
1454#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .procname = "legacy_va_layout",
1457 .data = &sysctl_legacy_va_layout,
1458 .maxlen = sizeof(sysctl_legacy_va_layout),
1459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 .extra1 = &zero,
1462 },
1463#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001464#ifdef CONFIG_NUMA
1465 {
Christoph Lameter17436602006-01-18 17:42:32 -08001466 .procname = "zone_reclaim_mode",
1467 .data = &zone_reclaim_mode,
1468 .maxlen = sizeof(zone_reclaim_mode),
1469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001470 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001471 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001472 },
Christoph Lameter96146342006-07-03 00:24:13 -07001473 {
Christoph Lameter96146342006-07-03 00:24:13 -07001474 .procname = "min_unmapped_ratio",
1475 .data = &sysctl_min_unmapped_ratio,
1476 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001478 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001479 .extra1 = &zero,
1480 .extra2 = &one_hundred,
1481 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001482 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001483 .procname = "min_slab_ratio",
1484 .data = &sysctl_min_slab_ratio,
1485 .maxlen = sizeof(sysctl_min_slab_ratio),
1486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001487 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001488 .extra1 = &zero,
1489 .extra2 = &one_hundred,
1490 },
Christoph Lameter17436602006-01-18 17:42:32 -08001491#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001492#ifdef CONFIG_SMP
1493 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001494 .procname = "stat_interval",
1495 .data = &sysctl_stat_interval,
1496 .maxlen = sizeof(sysctl_stat_interval),
1497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001498 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001499 },
1500#endif
David Howells6e141542009-12-15 19:27:45 +00001501#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001502 {
Eric Parised032182007-06-28 15:55:21 -04001503 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001504 .data = &dac_mmap_min_addr,
1505 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001506 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001507 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001508 },
David Howells6e141542009-12-15 19:27:45 +00001509#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001510#ifdef CONFIG_NUMA
1511 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001512 .procname = "numa_zonelist_order",
1513 .data = &numa_zonelist_order,
1514 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001516 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001517 },
1518#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001519#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001520 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001521 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001522 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001523#ifdef CONFIG_X86_32
1524 .data = &vdso32_enabled,
1525 .maxlen = sizeof(vdso32_enabled),
1526#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001527 .data = &vdso_enabled,
1528 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001529#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001531 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001532 .extra1 = &zero,
1533 },
1534#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001535#ifdef CONFIG_HIGHMEM
1536 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001537 .procname = "highmem_is_dirtyable",
1538 .data = &vm_highmem_is_dirtyable,
1539 .maxlen = sizeof(vm_highmem_is_dirtyable),
1540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001541 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001542 .extra1 = &zero,
1543 .extra2 = &one,
1544 },
1545#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001546#ifdef CONFIG_MEMORY_FAILURE
1547 {
Andi Kleen6a460792009-09-16 11:50:15 +02001548 .procname = "memory_failure_early_kill",
1549 .data = &sysctl_memory_failure_early_kill,
1550 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001552 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001553 .extra1 = &zero,
1554 .extra2 = &one,
1555 },
1556 {
Andi Kleen6a460792009-09-16 11:50:15 +02001557 .procname = "memory_failure_recovery",
1558 .data = &sysctl_memory_failure_recovery,
1559 .maxlen = sizeof(sysctl_memory_failure_recovery),
1560 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001561 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001562 .extra1 = &zero,
1563 .extra2 = &one,
1564 },
1565#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001566 {
1567 .procname = "user_reserve_kbytes",
1568 .data = &sysctl_user_reserve_kbytes,
1569 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1570 .mode = 0644,
1571 .proc_handler = proc_doulongvec_minmax,
1572 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001573 {
1574 .procname = "admin_reserve_kbytes",
1575 .data = &sysctl_admin_reserve_kbytes,
1576 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1577 .mode = 0644,
1578 .proc_handler = proc_doulongvec_minmax,
1579 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001580 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581};
1582
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001583static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 .procname = "inode-nr",
1586 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001587 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001589 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 },
1591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 .procname = "inode-state",
1593 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001594 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001596 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 },
1598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 .procname = "file-nr",
1600 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001601 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001603 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 },
1605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 .procname = "file-max",
1607 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001608 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001610 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 },
1612 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001613 .procname = "nr_open",
1614 .data = &sysctl_nr_open,
1615 .maxlen = sizeof(int),
1616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001617 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001618 .extra1 = &sysctl_nr_open_min,
1619 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001620 },
1621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 .procname = "dentry-state",
1623 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001624 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001626 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 },
1628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 .procname = "overflowuid",
1630 .data = &fs_overflowuid,
1631 .maxlen = sizeof(int),
1632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001633 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 .extra1 = &minolduid,
1635 .extra2 = &maxolduid,
1636 },
1637 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 .procname = "overflowgid",
1639 .data = &fs_overflowgid,
1640 .maxlen = sizeof(int),
1641 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001642 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 .extra1 = &minolduid,
1644 .extra2 = &maxolduid,
1645 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001646#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 .procname = "leases-enable",
1649 .data = &leases_enable,
1650 .maxlen = sizeof(int),
1651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001652 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001654#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655#ifdef CONFIG_DNOTIFY
1656 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 .procname = "dir-notify-enable",
1658 .data = &dir_notify_enable,
1659 .maxlen = sizeof(int),
1660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001661 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 },
1663#endif
1664#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001665#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 .procname = "lease-break-time",
1668 .data = &lease_break_time,
1669 .maxlen = sizeof(int),
1670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001671 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001673#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001674#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 .procname = "aio-nr",
1677 .data = &aio_nr,
1678 .maxlen = sizeof(aio_nr),
1679 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001680 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 },
1682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 .procname = "aio-max-nr",
1684 .data = &aio_max_nr,
1685 .maxlen = sizeof(aio_max_nr),
1686 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001687 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001689#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001690#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001691 {
Robert Love0399cb02005-07-13 12:38:18 -04001692 .procname = "inotify",
1693 .mode = 0555,
1694 .child = inotify_table,
1695 },
1696#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001697#ifdef CONFIG_EPOLL
1698 {
1699 .procname = "epoll",
1700 .mode = 0555,
1701 .child = epoll_table,
1702 },
1703#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001705 {
Kees Cook800179c2012-07-25 17:29:07 -07001706 .procname = "protected_symlinks",
1707 .data = &sysctl_protected_symlinks,
1708 .maxlen = sizeof(int),
1709 .mode = 0600,
1710 .proc_handler = proc_dointvec_minmax,
1711 .extra1 = &zero,
1712 .extra2 = &one,
1713 },
1714 {
1715 .procname = "protected_hardlinks",
1716 .data = &sysctl_protected_hardlinks,
1717 .maxlen = sizeof(int),
1718 .mode = 0600,
1719 .proc_handler = proc_dointvec_minmax,
1720 .extra1 = &zero,
1721 .extra2 = &one,
1722 },
1723 {
Alan Coxd6e71142005-06-23 00:09:43 -07001724 .procname = "suid_dumpable",
1725 .data = &suid_dumpable,
1726 .maxlen = sizeof(int),
1727 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001728 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001729 .extra1 = &zero,
1730 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001731 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001732#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1733 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001734 .procname = "binfmt_misc",
1735 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001736 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001737 },
1738#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001739 {
Jens Axboeff9da692010-06-03 14:54:39 +02001740 .procname = "pipe-max-size",
1741 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001742 .maxlen = sizeof(int),
1743 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001744 .proc_handler = &pipe_proc_fn,
1745 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001746 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001747 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748};
1749
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001750static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001751#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001752 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001753 .procname = "exception-trace",
1754 .data = &show_unhandled_signals,
1755 .maxlen = sizeof(int),
1756 .mode = 0644,
1757 .proc_handler = proc_dointvec
1758 },
1759#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001760#if defined(CONFIG_OPTPROBES)
1761 {
1762 .procname = "kprobes-optimization",
1763 .data = &sysctl_kprobes_optimization,
1764 .maxlen = sizeof(int),
1765 .mode = 0644,
1766 .proc_handler = proc_kprobes_optimization_handler,
1767 .extra1 = &zero,
1768 .extra2 = &one,
1769 },
1770#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001771 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772};
1773
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001774static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001775 { }
Robert Love0eeca282005-07-12 17:06:03 -04001776};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001778int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001779{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001780 struct ctl_table_header *hdr;
1781
1782 hdr = register_sysctl_table(sysctl_base_table);
1783 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001784 return 0;
1785}
1786
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001787#endif /* CONFIG_SYSCTL */
1788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789/*
1790 * /proc/sys support
1791 */
1792
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001793#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Kees Cookf8808302014-06-06 14:37:17 -07001795static int _proc_do_string(char *data, int maxlen, int write,
1796 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001797 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001798{
1799 size_t len;
1800 char __user *p;
1801 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001802
1803 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001804 *lenp = 0;
1805 return 0;
1806 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001807
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001808 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001809 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1810 /* Only continue writes not past the end of buffer. */
1811 len = strlen(data);
1812 if (len > maxlen - 1)
1813 len = maxlen - 1;
1814
1815 if (*ppos > len)
1816 return 0;
1817 len = *ppos;
1818 } else {
1819 /* Start writing from beginning of buffer. */
1820 len = 0;
1821 }
1822
Kees Cook2ca9bb42014-06-06 14:37:18 -07001823 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001824 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001825 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001826 if (get_user(c, p++))
1827 return -EFAULT;
1828 if (c == 0 || c == '\n')
1829 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001830 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001831 }
Kees Cookf8808302014-06-06 14:37:17 -07001832 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001833 } else {
1834 len = strlen(data);
1835 if (len > maxlen)
1836 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001837
1838 if (*ppos > len) {
1839 *lenp = 0;
1840 return 0;
1841 }
1842
1843 data += *ppos;
1844 len -= *ppos;
1845
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846 if (len > *lenp)
1847 len = *lenp;
1848 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001849 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001850 return -EFAULT;
1851 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001852 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001853 return -EFAULT;
1854 len++;
1855 }
1856 *lenp = len;
1857 *ppos += len;
1858 }
1859 return 0;
1860}
1861
Kees Cookf4aacea2014-06-06 14:37:19 -07001862static void warn_sysctl_write(struct ctl_table *table)
1863{
1864 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1865 "This will not be supported in the future. To silence this\n"
1866 "warning, set kernel.sysctl_writes_strict = -1\n",
1867 current->comm, table->procname);
1868}
1869
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870/**
1871 * proc_dostring - read a string sysctl
1872 * @table: the sysctl table
1873 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 * @buffer: the user buffer
1875 * @lenp: the size of the user buffer
1876 * @ppos: file position
1877 *
1878 * Reads/writes a string from/to the user buffer. If the kernel
1879 * buffer provided is not large enough to hold the string, the
1880 * string is truncated. The copied string is %NULL-terminated.
1881 * If the string is being read by the user process, it is copied
1882 * and a newline '\n' is added. It is truncated if the buffer is
1883 * not large enough.
1884 *
1885 * Returns 0 on success.
1886 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001887int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 void __user *buffer, size_t *lenp, loff_t *ppos)
1889{
Kees Cookf4aacea2014-06-06 14:37:19 -07001890 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1891 warn_sysctl_write(table);
1892
Kees Cookf8808302014-06-06 14:37:17 -07001893 return _proc_do_string((char *)(table->data), table->maxlen, write,
1894 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895}
1896
Amerigo Wang00b7c332010-05-05 00:26:45 +00001897static size_t proc_skip_spaces(char **buf)
1898{
1899 size_t ret;
1900 char *tmp = skip_spaces(*buf);
1901 ret = tmp - *buf;
1902 *buf = tmp;
1903 return ret;
1904}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001906static void proc_skip_char(char **buf, size_t *size, const char v)
1907{
1908 while (*size) {
1909 if (**buf != v)
1910 break;
1911 (*size)--;
1912 (*buf)++;
1913 }
1914}
1915
Amerigo Wang00b7c332010-05-05 00:26:45 +00001916#define TMPBUFLEN 22
1917/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001918 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001919 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001920 * @buf: a kernel buffer
1921 * @size: size of the kernel buffer
1922 * @val: this is where the number will be stored
1923 * @neg: set to %TRUE if number is negative
1924 * @perm_tr: a vector which contains the allowed trailers
1925 * @perm_tr_len: size of the perm_tr vector
1926 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001927 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001928 * In case of success %0 is returned and @buf and @size are updated with
1929 * the amount of bytes read. If @tr is non-NULL and a trailing
1930 * character exists (size is non-zero after returning from this
1931 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001932 */
1933static int proc_get_long(char **buf, size_t *size,
1934 unsigned long *val, bool *neg,
1935 const char *perm_tr, unsigned perm_tr_len, char *tr)
1936{
1937 int len;
1938 char *p, tmp[TMPBUFLEN];
1939
1940 if (!*size)
1941 return -EINVAL;
1942
1943 len = *size;
1944 if (len > TMPBUFLEN - 1)
1945 len = TMPBUFLEN - 1;
1946
1947 memcpy(tmp, *buf, len);
1948
1949 tmp[len] = 0;
1950 p = tmp;
1951 if (*p == '-' && *size > 1) {
1952 *neg = true;
1953 p++;
1954 } else
1955 *neg = false;
1956 if (!isdigit(*p))
1957 return -EINVAL;
1958
1959 *val = simple_strtoul(p, &p, 0);
1960
1961 len = p - tmp;
1962
1963 /* We don't know if the next char is whitespace thus we may accept
1964 * invalid integers (e.g. 1234...a) or two integers instead of one
1965 * (e.g. 123...1). So lets not allow such large numbers. */
1966 if (len == TMPBUFLEN - 1)
1967 return -EINVAL;
1968
1969 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1970 return -EINVAL;
1971
1972 if (tr && (len < *size))
1973 *tr = *p;
1974
1975 *buf += len;
1976 *size -= len;
1977
1978 return 0;
1979}
1980
1981/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001982 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001983 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001984 * @buf: the user buffer
1985 * @size: the size of the user buffer
1986 * @val: the integer to be converted
1987 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001988 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001989 * In case of success %0 is returned and @buf and @size are updated with
1990 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001991 */
1992static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1993 bool neg)
1994{
1995 int len;
1996 char tmp[TMPBUFLEN], *p = tmp;
1997
1998 sprintf(p, "%s%lu", neg ? "-" : "", val);
1999 len = strlen(tmp);
2000 if (len > *size)
2001 len = *size;
2002 if (copy_to_user(*buf, tmp, len))
2003 return -EFAULT;
2004 *size -= len;
2005 *buf += len;
2006 return 0;
2007}
2008#undef TMPBUFLEN
2009
2010static int proc_put_char(void __user **buf, size_t *size, char c)
2011{
2012 if (*size) {
2013 char __user **buffer = (char __user **)buf;
2014 if (put_user(c, *buffer))
2015 return -EFAULT;
2016 (*size)--, (*buffer)++;
2017 *buf = *buffer;
2018 }
2019 return 0;
2020}
2021
2022static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 int *valp,
2024 int write, void *data)
2025{
2026 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002027 if (*negp) {
2028 if (*lvalp > (unsigned long) INT_MAX + 1)
2029 return -EINVAL;
2030 *valp = -*lvalp;
2031 } else {
2032 if (*lvalp > (unsigned long) INT_MAX)
2033 return -EINVAL;
2034 *valp = *lvalp;
2035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 } else {
2037 int val = *valp;
2038 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002039 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002040 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002042 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 *lvalp = (unsigned long)val;
2044 }
2045 }
2046 return 0;
2047}
2048
Amerigo Wang00b7c332010-05-05 00:26:45 +00002049static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2050
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002051static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002052 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002053 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002054 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 int write, void *data),
2056 void *data)
2057{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002058 int *i, vleft, first = 1, err = 0;
2059 unsigned long page = 0;
2060 size_t left;
2061 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Amerigo Wang00b7c332010-05-05 00:26:45 +00002063 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 *lenp = 0;
2065 return 0;
2066 }
2067
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002068 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 vleft = table->maxlen / sizeof(*i);
2070 left = *lenp;
2071
2072 if (!conv)
2073 conv = do_proc_dointvec_conv;
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002076 if (*ppos) {
2077 switch (sysctl_writes_strict) {
2078 case SYSCTL_WRITES_STRICT:
2079 goto out;
2080 case SYSCTL_WRITES_WARN:
2081 warn_sysctl_write(table);
2082 break;
2083 default:
2084 break;
2085 }
2086 }
2087
Amerigo Wang00b7c332010-05-05 00:26:45 +00002088 if (left > PAGE_SIZE - 1)
2089 left = PAGE_SIZE - 1;
2090 page = __get_free_page(GFP_TEMPORARY);
2091 kbuf = (char *) page;
2092 if (!kbuf)
2093 return -ENOMEM;
2094 if (copy_from_user(kbuf, buffer, left)) {
2095 err = -EFAULT;
2096 goto free;
2097 }
2098 kbuf[left] = 0;
2099 }
2100
2101 for (; left && vleft--; i++, first=0) {
2102 unsigned long lval;
2103 bool neg;
2104
2105 if (write) {
2106 left -= proc_skip_spaces(&kbuf);
2107
J. R. Okajima563b0462010-05-25 16:10:14 -07002108 if (!left)
2109 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002110 err = proc_get_long(&kbuf, &left, &lval, &neg,
2111 proc_wspace_sep,
2112 sizeof(proc_wspace_sep), NULL);
2113 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002115 if (conv(&neg, &lval, i, 1, data)) {
2116 err = -EINVAL;
2117 break;
2118 }
2119 } else {
2120 if (conv(&neg, &lval, i, 0, data)) {
2121 err = -EINVAL;
2122 break;
2123 }
2124 if (!first)
2125 err = proc_put_char(&buffer, &left, '\t');
2126 if (err)
2127 break;
2128 err = proc_put_long(&buffer, &left, lval, neg);
2129 if (err)
2130 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 }
2132 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002133
2134 if (!write && !first && left && !err)
2135 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002136 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002137 left -= proc_skip_spaces(&kbuf);
2138free:
2139 if (write) {
2140 free_page(page);
2141 if (first)
2142 return err ? : -EINVAL;
2143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002145out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002147 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002150static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002151 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002152 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002153 int write, void *data),
2154 void *data)
2155{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002156 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002157 buffer, lenp, ppos, conv, data);
2158}
2159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160/**
2161 * proc_dointvec - read a vector of integers
2162 * @table: the sysctl table
2163 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 * @buffer: the user buffer
2165 * @lenp: the size of the user buffer
2166 * @ppos: file position
2167 *
2168 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2169 * values from/to the user buffer, treated as an ASCII string.
2170 *
2171 * Returns 0 on success.
2172 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002173int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 void __user *buffer, size_t *lenp, loff_t *ppos)
2175{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002176 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 NULL,NULL);
2178}
2179
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002180/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002181 * Taint values can only be increased
2182 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002183 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002184static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002185 void __user *buffer, size_t *lenp, loff_t *ppos)
2186{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002187 struct ctl_table t;
2188 unsigned long tmptaint = get_taint();
2189 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002190
Bastian Blank91fcd412007-04-23 14:41:14 -07002191 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002192 return -EPERM;
2193
Andi Kleen25ddbb12008-10-15 22:01:41 -07002194 t = *table;
2195 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002196 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002197 if (err < 0)
2198 return err;
2199
2200 if (write) {
2201 /*
2202 * Poor man's atomic or. Not worth adding a primitive
2203 * to everyone's atomic.h for this
2204 */
2205 int i;
2206 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2207 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302208 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002209 }
2210 }
2211
2212 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002213}
2214
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002215#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002216static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002217 void __user *buffer, size_t *lenp, loff_t *ppos)
2218{
2219 if (write && !capable(CAP_SYS_ADMIN))
2220 return -EPERM;
2221
2222 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2223}
2224#endif
2225
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226struct do_proc_dointvec_minmax_conv_param {
2227 int *min;
2228 int *max;
2229};
2230
Amerigo Wang00b7c332010-05-05 00:26:45 +00002231static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2232 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 int write, void *data)
2234{
2235 struct do_proc_dointvec_minmax_conv_param *param = data;
2236 if (write) {
2237 int val = *negp ? -*lvalp : *lvalp;
2238 if ((param->min && *param->min > val) ||
2239 (param->max && *param->max < val))
2240 return -EINVAL;
2241 *valp = val;
2242 } else {
2243 int val = *valp;
2244 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002245 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002246 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002248 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 *lvalp = (unsigned long)val;
2250 }
2251 }
2252 return 0;
2253}
2254
2255/**
2256 * proc_dointvec_minmax - read a vector of integers with min/max values
2257 * @table: the sysctl table
2258 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 * @buffer: the user buffer
2260 * @lenp: the size of the user buffer
2261 * @ppos: file position
2262 *
2263 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2264 * values from/to the user buffer, treated as an ASCII string.
2265 *
2266 * This routine will ensure the values are within the range specified by
2267 * table->extra1 (min) and table->extra2 (max).
2268 *
2269 * Returns 0 on success.
2270 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002271int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 void __user *buffer, size_t *lenp, loff_t *ppos)
2273{
2274 struct do_proc_dointvec_minmax_conv_param param = {
2275 .min = (int *) table->extra1,
2276 .max = (int *) table->extra2,
2277 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002278 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 do_proc_dointvec_minmax_conv, &param);
2280}
2281
Kees Cook54b50192012-07-30 14:39:18 -07002282static void validate_coredump_safety(void)
2283{
Alex Kelly046d6622012-10-04 17:15:23 -07002284#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002285 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002286 core_pattern[0] != '/' && core_pattern[0] != '|') {
2287 printk(KERN_WARNING "Unsafe core_pattern used with "\
2288 "suid_dumpable=2. Pipe handler or fully qualified "\
2289 "core dump path required.\n");
2290 }
Alex Kelly046d6622012-10-04 17:15:23 -07002291#endif
Kees Cook54b50192012-07-30 14:39:18 -07002292}
2293
2294static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2296{
2297 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2298 if (!error)
2299 validate_coredump_safety();
2300 return error;
2301}
2302
Alex Kelly046d6622012-10-04 17:15:23 -07002303#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002304static int proc_dostring_coredump(struct ctl_table *table, int write,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2306{
2307 int error = proc_dostring(table, write, buffer, lenp, ppos);
2308 if (!error)
2309 validate_coredump_safety();
2310 return error;
2311}
Alex Kelly046d6622012-10-04 17:15:23 -07002312#endif
Kees Cook54b50192012-07-30 14:39:18 -07002313
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002314static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 void __user *buffer,
2316 size_t *lenp, loff_t *ppos,
2317 unsigned long convmul,
2318 unsigned long convdiv)
2319{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002320 unsigned long *i, *min, *max;
2321 int vleft, first = 1, err = 0;
2322 unsigned long page = 0;
2323 size_t left;
2324 char *kbuf;
2325
2326 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 *lenp = 0;
2328 return 0;
2329 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002331 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 min = (unsigned long *) table->extra1;
2333 max = (unsigned long *) table->extra2;
2334 vleft = table->maxlen / sizeof(unsigned long);
2335 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002336
2337 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002338 if (*ppos) {
2339 switch (sysctl_writes_strict) {
2340 case SYSCTL_WRITES_STRICT:
2341 goto out;
2342 case SYSCTL_WRITES_WARN:
2343 warn_sysctl_write(table);
2344 break;
2345 default:
2346 break;
2347 }
2348 }
2349
Amerigo Wang00b7c332010-05-05 00:26:45 +00002350 if (left > PAGE_SIZE - 1)
2351 left = PAGE_SIZE - 1;
2352 page = __get_free_page(GFP_TEMPORARY);
2353 kbuf = (char *) page;
2354 if (!kbuf)
2355 return -ENOMEM;
2356 if (copy_from_user(kbuf, buffer, left)) {
2357 err = -EFAULT;
2358 goto free;
2359 }
2360 kbuf[left] = 0;
2361 }
2362
Eric Dumazet27b3d802010-10-07 12:59:29 -07002363 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002364 unsigned long val;
2365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002367 bool neg;
2368
2369 left -= proc_skip_spaces(&kbuf);
2370
2371 err = proc_get_long(&kbuf, &left, &val, &neg,
2372 proc_wspace_sep,
2373 sizeof(proc_wspace_sep), NULL);
2374 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 break;
2376 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 continue;
2378 if ((min && val < *min) || (max && val > *max))
2379 continue;
2380 *i = val;
2381 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002382 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002383 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002384 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002385 if (err)
2386 break;
2387 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002388 err = proc_put_long(&buffer, &left, val, false);
2389 if (err)
2390 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 }
2392 }
2393
Amerigo Wang00b7c332010-05-05 00:26:45 +00002394 if (!write && !first && left && !err)
2395 err = proc_put_char(&buffer, &left, '\n');
2396 if (write && !err)
2397 left -= proc_skip_spaces(&kbuf);
2398free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002400 free_page(page);
2401 if (first)
2402 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002405out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002407 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002410static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002411 void __user *buffer,
2412 size_t *lenp, loff_t *ppos,
2413 unsigned long convmul,
2414 unsigned long convdiv)
2415{
2416 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002417 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002418}
2419
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420/**
2421 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2422 * @table: the sysctl table
2423 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 * @buffer: the user buffer
2425 * @lenp: the size of the user buffer
2426 * @ppos: file position
2427 *
2428 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2429 * values from/to the user buffer, treated as an ASCII string.
2430 *
2431 * This routine will ensure the values are within the range specified by
2432 * table->extra1 (min) and table->extra2 (max).
2433 *
2434 * Returns 0 on success.
2435 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002436int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002439 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440}
2441
2442/**
2443 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2449 *
2450 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2451 * values from/to the user buffer, treated as an ASCII string. The values
2452 * are treated as milliseconds, and converted to jiffies when they are stored.
2453 *
2454 * This routine will ensure the values are within the range specified by
2455 * table->extra1 (min) and table->extra2 (max).
2456 *
2457 * Returns 0 on success.
2458 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002459int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 void __user *buffer,
2461 size_t *lenp, loff_t *ppos)
2462{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002463 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 lenp, ppos, HZ, 1000l);
2465}
2466
2467
Amerigo Wang00b7c332010-05-05 00:26:45 +00002468static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 int *valp,
2470 int write, void *data)
2471{
2472 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002473 if (*lvalp > LONG_MAX / HZ)
2474 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2476 } else {
2477 int val = *valp;
2478 unsigned long lval;
2479 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002480 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002481 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002483 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 lval = (unsigned long)val;
2485 }
2486 *lvalp = lval / HZ;
2487 }
2488 return 0;
2489}
2490
Amerigo Wang00b7c332010-05-05 00:26:45 +00002491static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 int *valp,
2493 int write, void *data)
2494{
2495 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002496 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2497 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2499 } else {
2500 int val = *valp;
2501 unsigned long lval;
2502 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002503 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002504 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 lval = (unsigned long)val;
2508 }
2509 *lvalp = jiffies_to_clock_t(lval);
2510 }
2511 return 0;
2512}
2513
Amerigo Wang00b7c332010-05-05 00:26:45 +00002514static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 int *valp,
2516 int write, void *data)
2517{
2518 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002519 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2520
2521 if (jif > INT_MAX)
2522 return 1;
2523 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 } else {
2525 int val = *valp;
2526 unsigned long lval;
2527 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002529 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002531 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 lval = (unsigned long)val;
2533 }
2534 *lvalp = jiffies_to_msecs(lval);
2535 }
2536 return 0;
2537}
2538
2539/**
2540 * proc_dointvec_jiffies - read a vector of integers as seconds
2541 * @table: the sysctl table
2542 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 * @buffer: the user buffer
2544 * @lenp: the size of the user buffer
2545 * @ppos: file position
2546 *
2547 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2548 * values from/to the user buffer, treated as an ASCII string.
2549 * The values read are assumed to be in seconds, and are converted into
2550 * jiffies.
2551 *
2552 * Returns 0 on success.
2553 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002554int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 void __user *buffer, size_t *lenp, loff_t *ppos)
2556{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002557 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 do_proc_dointvec_jiffies_conv,NULL);
2559}
2560
2561/**
2562 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2563 * @table: the sysctl table
2564 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 * @buffer: the user buffer
2566 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002567 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 *
2569 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2570 * values from/to the user buffer, treated as an ASCII string.
2571 * The values read are assumed to be in 1/USER_HZ seconds, and
2572 * are converted into jiffies.
2573 *
2574 * Returns 0 on success.
2575 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 void __user *buffer, size_t *lenp, loff_t *ppos)
2578{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002579 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 do_proc_dointvec_userhz_jiffies_conv,NULL);
2581}
2582
2583/**
2584 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 * @buffer: the user buffer
2588 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002589 * @ppos: file position
2590 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 *
2592 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2593 * values from/to the user buffer, treated as an ASCII string.
2594 * The values read are assumed to be in 1/1000 seconds, and
2595 * are converted into jiffies.
2596 *
2597 * Returns 0 on success.
2598 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002599int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 void __user *buffer, size_t *lenp, loff_t *ppos)
2601{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002602 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 do_proc_dointvec_ms_jiffies_conv, NULL);
2604}
2605
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002606static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002607 void __user *buffer, size_t *lenp, loff_t *ppos)
2608{
2609 struct pid *new_pid;
2610 pid_t tmp;
2611 int r;
2612
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002613 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002614
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002615 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002616 lenp, ppos, NULL, NULL);
2617 if (r || !write)
2618 return r;
2619
2620 new_pid = find_get_pid(tmp);
2621 if (!new_pid)
2622 return -ESRCH;
2623
2624 put_pid(xchg(&cad_pid, new_pid));
2625 return 0;
2626}
2627
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002628/**
2629 * proc_do_large_bitmap - read/write from/to a large bitmap
2630 * @table: the sysctl table
2631 * @write: %TRUE if this is a write to the sysctl file
2632 * @buffer: the user buffer
2633 * @lenp: the size of the user buffer
2634 * @ppos: file position
2635 *
2636 * The bitmap is stored at table->data and the bitmap length (in bits)
2637 * in table->maxlen.
2638 *
2639 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2640 * large bitmaps may be represented in a compact manner. Writing into
2641 * the file will clear the bitmap then update it with the given input.
2642 *
2643 * Returns 0 on success.
2644 */
2645int proc_do_large_bitmap(struct ctl_table *table, int write,
2646 void __user *buffer, size_t *lenp, loff_t *ppos)
2647{
2648 int err = 0;
2649 bool first = 1;
2650 size_t left = *lenp;
2651 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002652 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002653 unsigned long *tmp_bitmap = NULL;
2654 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2655
WANG Cong122ff242014-05-12 16:04:53 -07002656 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002657 *lenp = 0;
2658 return 0;
2659 }
2660
2661 if (write) {
2662 unsigned long page = 0;
2663 char *kbuf;
2664
2665 if (left > PAGE_SIZE - 1)
2666 left = PAGE_SIZE - 1;
2667
2668 page = __get_free_page(GFP_TEMPORARY);
2669 kbuf = (char *) page;
2670 if (!kbuf)
2671 return -ENOMEM;
2672 if (copy_from_user(kbuf, buffer, left)) {
2673 free_page(page);
2674 return -EFAULT;
2675 }
2676 kbuf[left] = 0;
2677
2678 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2679 GFP_KERNEL);
2680 if (!tmp_bitmap) {
2681 free_page(page);
2682 return -ENOMEM;
2683 }
2684 proc_skip_char(&kbuf, &left, '\n');
2685 while (!err && left) {
2686 unsigned long val_a, val_b;
2687 bool neg;
2688
2689 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2690 sizeof(tr_a), &c);
2691 if (err)
2692 break;
2693 if (val_a >= bitmap_len || neg) {
2694 err = -EINVAL;
2695 break;
2696 }
2697
2698 val_b = val_a;
2699 if (left) {
2700 kbuf++;
2701 left--;
2702 }
2703
2704 if (c == '-') {
2705 err = proc_get_long(&kbuf, &left, &val_b,
2706 &neg, tr_b, sizeof(tr_b),
2707 &c);
2708 if (err)
2709 break;
2710 if (val_b >= bitmap_len || neg ||
2711 val_a > val_b) {
2712 err = -EINVAL;
2713 break;
2714 }
2715 if (left) {
2716 kbuf++;
2717 left--;
2718 }
2719 }
2720
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002721 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002722 first = 0;
2723 proc_skip_char(&kbuf, &left, '\n');
2724 }
2725 free_page(page);
2726 } else {
2727 unsigned long bit_a, bit_b = 0;
2728
2729 while (left) {
2730 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2731 if (bit_a >= bitmap_len)
2732 break;
2733 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2734 bit_a + 1) - 1;
2735
2736 if (!first) {
2737 err = proc_put_char(&buffer, &left, ',');
2738 if (err)
2739 break;
2740 }
2741 err = proc_put_long(&buffer, &left, bit_a, false);
2742 if (err)
2743 break;
2744 if (bit_a != bit_b) {
2745 err = proc_put_char(&buffer, &left, '-');
2746 if (err)
2747 break;
2748 err = proc_put_long(&buffer, &left, bit_b, false);
2749 if (err)
2750 break;
2751 }
2752
2753 first = 0; bit_b++;
2754 }
2755 if (!err)
2756 err = proc_put_char(&buffer, &left, '\n');
2757 }
2758
2759 if (!err) {
2760 if (write) {
2761 if (*ppos)
2762 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2763 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002764 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002765 }
2766 kfree(tmp_bitmap);
2767 *lenp -= left;
2768 *ppos += *lenp;
2769 return 0;
2770 } else {
2771 kfree(tmp_bitmap);
2772 return err;
2773 }
2774}
2775
Jovi Zhang55610502011-01-12 17:00:45 -08002776#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002778int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 void __user *buffer, size_t *lenp, loff_t *ppos)
2780{
2781 return -ENOSYS;
2782}
2783
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002784int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 void __user *buffer, size_t *lenp, loff_t *ppos)
2786{
2787 return -ENOSYS;
2788}
2789
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002790int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 void __user *buffer, size_t *lenp, loff_t *ppos)
2792{
2793 return -ENOSYS;
2794}
2795
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002796int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 void __user *buffer, size_t *lenp, loff_t *ppos)
2798{
2799 return -ENOSYS;
2800}
2801
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002802int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 void __user *buffer, size_t *lenp, loff_t *ppos)
2804{
2805 return -ENOSYS;
2806}
2807
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002808int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 void __user *buffer, size_t *lenp, loff_t *ppos)
2810{
2811 return -ENOSYS;
2812}
2813
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002814int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 void __user *buffer, size_t *lenp, loff_t *ppos)
2816{
2817 return -ENOSYS;
2818}
2819
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002820int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 void __user *buffer,
2822 size_t *lenp, loff_t *ppos)
2823{
2824 return -ENOSYS;
2825}
2826
2827
Jovi Zhang55610502011-01-12 17:00:45 -08002828#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830/*
2831 * No sense putting this after each symbol definition, twice,
2832 * exception granted :-)
2833 */
2834EXPORT_SYMBOL(proc_dointvec);
2835EXPORT_SYMBOL(proc_dointvec_jiffies);
2836EXPORT_SYMBOL(proc_dointvec_minmax);
2837EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2838EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2839EXPORT_SYMBOL(proc_dostring);
2840EXPORT_SYMBOL(proc_doulongvec_minmax);
2841EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);