blob: c3eee4c6d6c1733593f2ca6fd9ac761649258865 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#include <asm/uaccess.h>
69#include <asm/processor.h>
70
Andi Kleen29cbc782006-09-30 01:47:55 +020071#ifdef CONFIG_X86
72#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010073#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010074#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020075#endif
David Howellsd550bbd2012-03-28 18:30:03 +010076#ifdef CONFIG_SPARC
77#include <asm/setup.h>
78#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080079#ifdef CONFIG_BSD_PROCESS_ACCT
80#include <linux/acct.h>
81#endif
Dave Young4f0e0562010-03-10 15:24:09 -080082#ifdef CONFIG_RT_MUTEXES
83#include <linux/rtmutex.h>
84#endif
Dave Young2edf5e42010-03-10 15:24:10 -080085#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
86#include <linux/lockdep.h>
87#endif
Dave Young15485a42010-03-10 15:24:07 -080088#ifdef CONFIG_CHR_DEV_SG
89#include <scsi/sg.h>
90#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020091
Don Zickus58687ac2010-05-07 17:11:44 -040092#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050093#include <linux/nmi.h>
94#endif
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#if defined(CONFIG_SYSCTL)
97
98/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -070099extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700100#ifdef CONFIG_COREDUMP
101extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700103extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700104#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800107extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200108extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100109extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400110extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000111#ifndef CONFIG_MMU
112extern int sysctl_nr_trim_pages;
113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400116#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int sixty = 60;
118#endif
119
Aaron Tomlin270750db2014-01-20 17:34:13 +0000120static int __maybe_unused neg_one = -1;
121
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700123static int __maybe_unused one = 1;
124static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700125static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800126static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700127static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700128#ifdef CONFIG_PRINTK
129static int ten_thousand = 10000;
130#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700131
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700132/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
133static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
136static int maxolduid = 65535;
137static int minolduid;
138
139static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700140static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Liu Hua80df2842014-04-07 15:38:57 -0700142/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
143#ifdef CONFIG_DETECT_HUNG_TASK
144static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
145#endif
146
Dave Youngd14f1722010-02-25 20:28:57 -0500147#ifdef CONFIG_INOTIFY_USER
148#include <linux/inotify.h>
149#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700150#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152
153#ifdef __hppa__
154extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530155#endif
156
157#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158extern int unaligned_enabled;
159#endif
160
Jes Sorensend2b176e2006-02-28 09:42:23 -0800161#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800162extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800163#endif
164
Vineet Guptab6fca722013-01-09 20:06:28 +0530165#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
166extern int no_unaligned_warning;
167#endif
168
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700169#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700170
171#define SYSCTL_WRITES_LEGACY -1
172#define SYSCTL_WRITES_WARN 0
173#define SYSCTL_WRITES_STRICT 1
174
175static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
176
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700177static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700178 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700179static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800180 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700181#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700182
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700183#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700184static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700185 void __user *buffer, size_t *lenp, loff_t *ppos);
186#endif
187
Kees Cook54b50192012-07-30 14:39:18 -0700188static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
189 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700190#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700191static int proc_dostring_coredump(struct ctl_table *table, int write,
192 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700193#endif
Kees Cook54b50192012-07-30 14:39:18 -0700194
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700195#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800196/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100197static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700198
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700199static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700200 void __user *buffer, size_t *lenp,
201 loff_t *ppos)
202{
203 int error;
204
205 error = proc_dointvec(table, write, buffer, lenp, ppos);
206 if (error)
207 return error;
208
209 if (write)
210 sysrq_toggle_support(__sysrq_enabled);
211
212 return 0;
213}
214
215#endif
216
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700217static struct ctl_table kern_table[];
218static struct ctl_table vm_table[];
219static struct ctl_table fs_table[];
220static struct ctl_table debug_table[];
221static struct ctl_table dev_table[];
222extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800223#ifdef CONFIG_EPOLL
224extern struct ctl_table epoll_table[];
225#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
228int sysctl_legacy_va_layout;
229#endif
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231/* The default sysctl tables: */
232
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800233static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .procname = "kernel",
236 .mode = 0555,
237 .child = kern_table,
238 },
239 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .procname = "vm",
241 .mode = 0555,
242 .child = vm_table,
243 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .procname = "fs",
246 .mode = 0555,
247 .child = fs_table,
248 },
249 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .procname = "debug",
251 .mode = 0555,
252 .child = debug_table,
253 },
254 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .procname = "dev",
256 .mode = 0555,
257 .child = dev_table,
258 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700259 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100263static int min_sched_granularity_ns = 100000; /* 100 usecs */
264static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
265static int min_wakeup_granularity_ns; /* 0 usecs */
266static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200267#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100268static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
269static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200270#endif /* CONFIG_SMP */
271#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200272
Mel Gorman5e771902010-05-24 14:32:31 -0700273#ifdef CONFIG_COMPACTION
274static int min_extfrag_threshold;
275static int max_extfrag_threshold = 1000;
276#endif
277
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700278static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200279 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800284 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200285 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286#ifdef CONFIG_SCHED_DEBUG
287 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100288 .procname = "sched_min_granularity_ns",
289 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200290 .maxlen = sizeof(unsigned int),
291 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800292 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100293 .extra1 = &min_sched_granularity_ns,
294 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200295 },
296 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200297 .procname = "sched_latency_ns",
298 .data = &sysctl_sched_latency,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800301 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200302 .extra1 = &min_sched_granularity_ns,
303 .extra2 = &max_sched_granularity_ns,
304 },
305 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200306 .procname = "sched_wakeup_granularity_ns",
307 .data = &sysctl_sched_wakeup_granularity,
308 .maxlen = sizeof(unsigned int),
309 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800310 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200311 .extra1 = &min_wakeup_granularity_ns,
312 .extra2 = &max_wakeup_granularity_ns,
313 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200314#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200315 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100316 .procname = "sched_tunable_scaling",
317 .data = &sysctl_sched_tunable_scaling,
318 .maxlen = sizeof(enum sched_tunable_scaling),
319 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800320 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100321 .extra1 = &min_sched_tunable_scaling,
322 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200323 },
324 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900325 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200326 .data = &sysctl_sched_migration_cost,
327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800329 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200330 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100331 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100332 .procname = "sched_nr_migrate",
333 .data = &sysctl_sched_nr_migrate,
334 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100335 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800336 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100337 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530338 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900339 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200340 .data = &sysctl_sched_time_avg,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800343 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200344 },
345 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900346 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800347 .data = &sysctl_sched_shares_window,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
350 .proc_handler = proc_dointvec,
351 },
352 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530353 .procname = "timer_migration",
354 .data = &sysctl_timer_migration,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800357 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530358 .extra1 = &zero,
359 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530360 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200361#endif /* CONFIG_SMP */
362#ifdef CONFIG_NUMA_BALANCING
363 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200364 .procname = "numa_balancing_scan_delay_ms",
365 .data = &sysctl_numa_balancing_scan_delay,
366 .maxlen = sizeof(unsigned int),
367 .mode = 0644,
368 .proc_handler = proc_dointvec,
369 },
370 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200371 .procname = "numa_balancing_scan_period_min_ms",
372 .data = &sysctl_numa_balancing_scan_period_min,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec,
376 },
377 {
378 .procname = "numa_balancing_scan_period_max_ms",
379 .data = &sysctl_numa_balancing_scan_period_max,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec,
383 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200384 {
385 .procname = "numa_balancing_scan_size_mb",
386 .data = &sysctl_numa_balancing_scan_size,
387 .maxlen = sizeof(unsigned int),
388 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400389 .proc_handler = proc_dointvec_minmax,
390 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200391 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100392 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800393 .procname = "numa_balancing",
394 .data = NULL, /* filled in by handler */
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
397 .proc_handler = sysctl_numa_balancing,
398 .extra1 = &zero,
399 .extra2 = &one,
400 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200401#endif /* CONFIG_NUMA_BALANCING */
402#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200403 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100404 .procname = "sched_rt_period_us",
405 .data = &sysctl_sched_rt_period,
406 .maxlen = sizeof(unsigned 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 },
410 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100411 .procname = "sched_rt_runtime_us",
412 .data = &sysctl_sched_rt_runtime,
413 .maxlen = sizeof(int),
414 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800415 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100416 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600417 {
418 .procname = "sched_rr_timeslice_ms",
419 .data = &sched_rr_timeslice,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = sched_rr_handler,
423 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100424#ifdef CONFIG_SCHED_AUTOGROUP
425 {
426 .procname = "sched_autogroup_enabled",
427 .data = &sysctl_sched_autogroup_enabled,
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800430 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100431 .extra1 = &zero,
432 .extra2 = &one,
433 },
434#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700435#ifdef CONFIG_CFS_BANDWIDTH
436 {
437 .procname = "sched_cfs_bandwidth_slice_us",
438 .data = &sysctl_sched_cfs_bandwidth_slice,
439 .maxlen = sizeof(unsigned int),
440 .mode = 0644,
441 .proc_handler = proc_dointvec_minmax,
442 .extra1 = &one,
443 },
444#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700445#ifdef CONFIG_PROVE_LOCKING
446 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700447 .procname = "prove_locking",
448 .data = &prove_locking,
449 .maxlen = sizeof(int),
450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800451 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700452 },
453#endif
454#ifdef CONFIG_LOCK_STAT
455 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700456 .procname = "lock_stat",
457 .data = &lock_stat,
458 .maxlen = sizeof(int),
459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800460 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700461 },
462#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "panic",
465 .data = &panic_timeout,
466 .maxlen = sizeof(int),
467 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800468 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
Alex Kelly046d6622012-10-04 17:15:23 -0700470#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .procname = "core_uses_pid",
473 .data = &core_uses_pid,
474 .maxlen = sizeof(int),
475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800476 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
478 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .procname = "core_pattern",
480 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700481 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700483 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 },
Neil Hormana2939802009-09-23 15:56:56 -0700485 {
Neil Hormana2939802009-09-23 15:56:56 -0700486 .procname = "core_pipe_limit",
487 .data = &core_pipe_limit,
488 .maxlen = sizeof(unsigned int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700491 },
Alex Kelly046d6622012-10-04 17:15:23 -0700492#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800493#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700496 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700500 {
501 .procname = "sysctl_writes_strict",
502 .data = &sysctl_writes_strict,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = proc_dointvec_minmax,
506 .extra1 = &neg_one,
507 .extra2 = &one,
508 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800509#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100510#ifdef CONFIG_LATENCYTOP
511 {
512 .procname = "latencytop",
513 .data = &latencytop_enabled,
514 .maxlen = sizeof(int),
515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800516 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100517 },
518#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#ifdef CONFIG_BLK_DEV_INITRD
520 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .procname = "real-root-dev",
522 .data = &real_root_dev,
523 .maxlen = sizeof(int),
524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800525 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 },
527#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700528 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700529 .procname = "print-fatal-signals",
530 .data = &print_fatal_signals,
531 .maxlen = sizeof(int),
532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800533 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700534 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700535#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 .procname = "reboot-cmd",
538 .data = reboot_command,
539 .maxlen = 256,
540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 },
543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "stop-a",
545 .data = &stop_a_enabled,
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 .procname = "scons-poweroff",
552 .data = &scons_pwroff,
553 .maxlen = sizeof (int),
554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800555 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 },
557#endif
David S. Miller08714202008-11-16 23:49:24 -0800558#ifdef CONFIG_SPARC64
559 {
David S. Miller08714202008-11-16 23:49:24 -0800560 .procname = "tsb-ratio",
561 .data = &sysctl_tsb_ratio,
562 .maxlen = sizeof (int),
563 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800564 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800565 },
566#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#ifdef __hppa__
568 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 .procname = "soft-power",
570 .data = &pwrsw_enabled,
571 .maxlen = sizeof (int),
572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800573 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530575#endif
576#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 .procname = "unaligned-trap",
579 .data = &unaligned_enabled,
580 .maxlen = sizeof (int),
581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800582 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 },
584#endif
585 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .procname = "ctrl-alt-del",
587 .data = &C_A_D,
588 .maxlen = sizeof(int),
589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800590 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400592#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200593 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200594 .procname = "ftrace_enabled",
595 .data = &ftrace_enabled,
596 .maxlen = sizeof(int),
597 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800598 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200599 },
600#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500601#ifdef CONFIG_STACK_TRACER
602 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500603 .procname = "stack_tracer_enabled",
604 .data = &stack_tracer_enabled,
605 .maxlen = sizeof(int),
606 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800607 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500608 },
609#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400610#ifdef CONFIG_TRACING
611 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100612 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400613 .data = &ftrace_dump_on_oops,
614 .maxlen = sizeof(int),
615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800616 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400617 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400618 {
619 .procname = "traceoff_on_warning",
620 .data = &__disable_trace_on_warning,
621 .maxlen = sizeof(__disable_trace_on_warning),
622 .mode = 0644,
623 .proc_handler = proc_dointvec,
624 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500625 {
626 .procname = "tracepoint_printk",
627 .data = &tracepoint_printk,
628 .maxlen = sizeof(tracepoint_printk),
629 .mode = 0644,
630 .proc_handler = proc_dointvec,
631 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400632#endif
Kees Cook79847542014-01-23 15:55:59 -0800633#ifdef CONFIG_KEXEC
634 {
635 .procname = "kexec_load_disabled",
636 .data = &kexec_load_disabled,
637 .maxlen = sizeof(int),
638 .mode = 0644,
639 /* only handle a transition from default "0" to "1" */
640 .proc_handler = proc_dointvec_minmax,
641 .extra1 = &one,
642 .extra2 = &one,
643 },
644#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200645#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .procname = "modprobe",
648 .data = &modprobe_path,
649 .maxlen = KMOD_PATH_LEN,
650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 },
Kees Cook3d433212009-04-02 15:49:29 -0700653 {
Kees Cook3d433212009-04-02 15:49:29 -0700654 .procname = "modules_disabled",
655 .data = &modules_disabled,
656 .maxlen = sizeof(int),
657 .mode = 0644,
658 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800659 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700660 .extra1 = &one,
661 .extra2 = &one,
662 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700664#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100667 .data = &uevent_helper,
668 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800670 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 },
Michael Marineau86d56132014-04-10 14:09:31 -0700672#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#ifdef CONFIG_CHR_DEV_SG
674 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 .procname = "sg-big-buff",
676 .data = &sg_big_buff,
677 .maxlen = sizeof (int),
678 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800679 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 },
681#endif
682#ifdef CONFIG_BSD_PROCESS_ACCT
683 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 .procname = "acct",
685 .data = &acct_parm,
686 .maxlen = 3*sizeof(int),
687 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800688 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 },
690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#ifdef CONFIG_MAGIC_SYSRQ
692 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800694 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .maxlen = sizeof (int),
696 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700697 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 },
699#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700700#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700703 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .maxlen = sizeof (int),
705 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800706 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700708#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700711 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 .maxlen = sizeof(int),
713 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700714 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 },
716 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .procname = "random",
718 .mode = 0555,
719 .child = random_table,
720 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 {
Eric Paris17f60a72011-04-01 17:07:50 -0400722 .procname = "usermodehelper",
723 .mode = 0555,
724 .child = usermodehelper_table,
725 },
726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .procname = "overflowuid",
728 .data = &overflowuid,
729 .maxlen = sizeof(int),
730 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800731 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .extra1 = &minolduid,
733 .extra2 = &maxolduid,
734 },
735 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .procname = "overflowgid",
737 .data = &overflowgid,
738 .maxlen = sizeof(int),
739 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800740 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 .extra1 = &minolduid,
742 .extra2 = &maxolduid,
743 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800744#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#ifdef CONFIG_MATHEMU
746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 .procname = "ieee_emulation_warnings",
748 .data = &sysctl_ieee_emulation_warnings,
749 .maxlen = sizeof(int),
750 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800751 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 },
753#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200756 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 .maxlen = sizeof(int),
758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800759 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 },
761#endif
762 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 .procname = "pid_max",
764 .data = &pid_max,
765 .maxlen = sizeof (int),
766 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800767 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 .extra1 = &pid_max_min,
769 .extra2 = &pid_max_max,
770 },
771 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 .procname = "panic_on_oops",
773 .data = &panic_on_oops,
774 .maxlen = sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800778#if defined CONFIG_PRINTK
779 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800780 .procname = "printk",
781 .data = &console_loglevel,
782 .maxlen = 4*sizeof(int),
783 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800785 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700788 .data = &printk_ratelimit_state.interval,
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_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 },
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700795 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 },
Dave Youngaf913222009-09-22 16:43:33 -0700800 {
Dave Youngaf913222009-09-22 16:43:33 -0700801 .procname = "printk_delay",
802 .data = &printk_delay_msec,
803 .maxlen = sizeof(int),
804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800805 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700806 .extra1 = &zero,
807 .extra2 = &ten_thousand,
808 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800810 .procname = "dmesg_restrict",
811 .data = &dmesg_restrict,
812 .maxlen = sizeof(int),
813 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700814 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800815 .extra1 = &zero,
816 .extra2 = &one,
817 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800818 {
819 .procname = "kptr_restrict",
820 .data = &kptr_restrict,
821 .maxlen = sizeof(int),
822 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700823 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800824 .extra1 = &zero,
825 .extra2 = &two,
826 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800827#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800828 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 .procname = "ngroups_max",
830 .data = &ngroups_max,
831 .maxlen = sizeof (int),
832 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 },
Dan Ballard73efc032011-10-31 17:11:20 -0700835 {
836 .procname = "cap_last_cap",
837 .data = (void *)&cap_last_cap,
838 .maxlen = sizeof(int),
839 .mode = 0444,
840 .proc_handler = proc_dointvec,
841 },
Don Zickus58687ac2010-05-07 17:11:44 -0400842#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500843 {
Don Zickus58687ac2010-05-07 17:11:44 -0400844 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200845 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500846 .maxlen = sizeof (int),
847 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700848 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700849 .extra1 = &zero,
850 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400851 },
852 {
853 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700854 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400855 .maxlen = sizeof(int),
856 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700857 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800858 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400859 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500860 },
Don Zickus2508ce12010-05-07 17:11:46 -0400861 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700862 .procname = "nmi_watchdog",
863 .data = &nmi_watchdog_enabled,
864 .maxlen = sizeof (int),
865 .mode = 0644,
866 .proc_handler = proc_nmi_watchdog,
867 .extra1 = &zero,
868#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
869 .extra2 = &one,
870#else
871 .extra2 = &zero,
872#endif
873 },
874 {
875 .procname = "soft_watchdog",
876 .data = &soft_watchdog_enabled,
877 .maxlen = sizeof (int),
878 .mode = 0644,
879 .proc_handler = proc_soft_watchdog,
880 .extra1 = &zero,
881 .extra2 = &one,
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 },
Aaron Tomlined235872014-06-23 13:22:05 -0700892#ifdef CONFIG_SMP
893 {
894 .procname = "softlockup_all_cpu_backtrace",
895 .data = &sysctl_softlockup_all_cpu_backtrace,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = proc_dointvec_minmax,
899 .extra1 = &zero,
900 .extra2 = &one,
901 },
902#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500903#endif
904#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
905 {
906 .procname = "unknown_nmi_panic",
907 .data = &unknown_nmi_panic,
908 .maxlen = sizeof (int),
909 .mode = 0644,
910 .proc_handler = proc_dointvec,
911 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500912#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913#if defined(CONFIG_X86)
914 {
Don Zickus8da5add2006-09-26 10:52:27 +0200915 .procname = "panic_on_unrecovered_nmi",
916 .data = &panic_on_unrecovered_nmi,
917 .maxlen = sizeof(int),
918 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800919 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200920 },
921 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700922 .procname = "panic_on_io_nmi",
923 .data = &panic_on_io_nmi,
924 .maxlen = sizeof(int),
925 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800926 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700927 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900928#ifdef CONFIG_DEBUG_STACKOVERFLOW
929 {
930 .procname = "panic_on_stackoverflow",
931 .data = &sysctl_panic_on_stackoverflow,
932 .maxlen = sizeof(int),
933 .mode = 0644,
934 .proc_handler = proc_dointvec,
935 },
936#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700937 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .procname = "bootloader_type",
939 .data = &bootloader_type,
940 .maxlen = sizeof (int),
941 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800942 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100944 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700945 .procname = "bootloader_version",
946 .data = &bootloader_version,
947 .maxlen = sizeof (int),
948 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800949 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700950 },
951 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100952 .procname = "kstack_depth_to_print",
953 .data = &kstack_depth_to_print,
954 .maxlen = sizeof(int),
955 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800956 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100957 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100958 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100959 .procname = "io_delay_type",
960 .data = &io_delay_type,
961 .maxlen = sizeof(int),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100964 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800966#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 .procname = "randomize_va_space",
969 .data = &randomize_va_space,
970 .maxlen = sizeof(int),
971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800974#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800975#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700976 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700977 .procname = "spin_retry",
978 .data = &spin_retry,
979 .maxlen = sizeof (int),
980 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800981 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700982 },
983#endif
Len Brown673d5b42007-07-28 03:33:16 -0400984#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800985 {
Pavel Machekc255d842006-02-20 18:27:58 -0800986 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700987 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800988 .maxlen = sizeof (unsigned long),
989 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800990 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800991 },
992#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530993#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800994 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800995 .procname = "ignore-unaligned-usertrap",
996 .data = &no_unaligned_warning,
997 .maxlen = sizeof (int),
998 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800999 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001000 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301001#endif
1002#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001003 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001004 .procname = "unaligned-dump-stack",
1005 .data = &unaligned_dump_stack,
1006 .maxlen = sizeof (int),
1007 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001008 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001009 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001010#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001011#ifdef CONFIG_DETECT_HUNG_TASK
1012 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001013 .procname = "hung_task_panic",
1014 .data = &sysctl_hung_task_panic,
1015 .maxlen = sizeof(int),
1016 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001017 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001018 .extra1 = &zero,
1019 .extra2 = &one,
1020 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001021 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001022 .procname = "hung_task_check_count",
1023 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001024 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001025 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001026 .proc_handler = proc_dointvec_minmax,
1027 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001028 },
1029 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001030 .procname = "hung_task_timeout_secs",
1031 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001032 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001033 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001034 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001035 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001036 },
1037 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001038 .procname = "hung_task_warnings",
1039 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001040 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001041 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001042 .proc_handler = proc_dointvec_minmax,
1043 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001044 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001045#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001046#ifdef CONFIG_COMPAT
1047 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001048 .procname = "compat-log",
1049 .data = &compat_log,
1050 .maxlen = sizeof (int),
1051 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001052 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001053 },
1054#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -07001055#ifdef CONFIG_RT_MUTEXES
1056 {
Ingo Molnar23f78d42006-06-27 02:54:53 -07001057 .procname = "max_lock_depth",
1058 .data = &max_lock_depth,
1059 .maxlen = sizeof(int),
1060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -07001062 },
1063#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001064 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001065 .procname = "poweroff_cmd",
1066 .data = &poweroff_cmd,
1067 .maxlen = POWEROFF_CMD_PATH_LEN,
1068 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001069 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001070 },
David Howells0b77f5b2008-04-29 01:01:32 -07001071#ifdef CONFIG_KEYS
1072 {
David Howells0b77f5b2008-04-29 01:01:32 -07001073 .procname = "keys",
1074 .mode = 0555,
1075 .child = key_sysctls,
1076 },
1077#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001078#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001079 /*
1080 * User-space scripts rely on the existence of this file
1081 * as a feature check for perf_events being enabled.
1082 *
1083 * So it's an ABI, do not remove!
1084 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001085 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001086 .procname = "perf_event_paranoid",
1087 .data = &sysctl_perf_event_paranoid,
1088 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001089 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001090 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001091 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001092 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001093 .procname = "perf_event_mlock_kb",
1094 .data = &sysctl_perf_event_mlock,
1095 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001096 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001097 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001098 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001099 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001100 .procname = "perf_event_max_sample_rate",
1101 .data = &sysctl_perf_event_sample_rate,
1102 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001103 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001104 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001105 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001106 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001107 {
1108 .procname = "perf_cpu_time_max_percent",
1109 .data = &sysctl_perf_cpu_time_max_percent,
1110 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1111 .mode = 0644,
1112 .proc_handler = perf_cpu_time_max_percent_handler,
1113 .extra1 = &zero,
1114 .extra2 = &one_hundred,
1115 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001116#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001117#ifdef CONFIG_KMEMCHECK
1118 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001119 .procname = "kmemcheck",
1120 .data = &kmemcheck_enabled,
1121 .maxlen = sizeof(int),
1122 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001123 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001124 },
1125#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001126 {
1127 .procname = "panic_on_warn",
1128 .data = &panic_on_warn,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
1131 .proc_handler = proc_dointvec_minmax,
1132 .extra1 = &zero,
1133 .extra2 = &one,
1134 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001135 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136};
1137
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001138static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 .procname = "overcommit_memory",
1141 .data = &sysctl_overcommit_memory,
1142 .maxlen = sizeof(sysctl_overcommit_memory),
1143 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001144 .proc_handler = proc_dointvec_minmax,
1145 .extra1 = &zero,
1146 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 },
1148 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001149 .procname = "panic_on_oom",
1150 .data = &sysctl_panic_on_oom,
1151 .maxlen = sizeof(sysctl_panic_on_oom),
1152 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001153 .proc_handler = proc_dointvec_minmax,
1154 .extra1 = &zero,
1155 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001156 },
1157 {
David Rientjesfe071d72007-10-16 23:25:56 -07001158 .procname = "oom_kill_allocating_task",
1159 .data = &sysctl_oom_kill_allocating_task,
1160 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1161 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001162 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001163 },
1164 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001165 .procname = "oom_dump_tasks",
1166 .data = &sysctl_oom_dump_tasks,
1167 .maxlen = sizeof(sysctl_oom_dump_tasks),
1168 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001169 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001170 },
1171 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 .procname = "overcommit_ratio",
1173 .data = &sysctl_overcommit_ratio,
1174 .maxlen = sizeof(sysctl_overcommit_ratio),
1175 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001176 .proc_handler = overcommit_ratio_handler,
1177 },
1178 {
1179 .procname = "overcommit_kbytes",
1180 .data = &sysctl_overcommit_kbytes,
1181 .maxlen = sizeof(sysctl_overcommit_kbytes),
1182 .mode = 0644,
1183 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 },
1185 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 .procname = "page-cluster",
1187 .data = &page_cluster,
1188 .maxlen = sizeof(int),
1189 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001190 .proc_handler = proc_dointvec_minmax,
1191 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 },
1193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .procname = "dirty_background_ratio",
1195 .data = &dirty_background_ratio,
1196 .maxlen = sizeof(dirty_background_ratio),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 .extra1 = &zero,
1200 .extra2 = &one_hundred,
1201 },
1202 {
David Rientjes2da02992009-01-06 14:39:31 -08001203 .procname = "dirty_background_bytes",
1204 .data = &dirty_background_bytes,
1205 .maxlen = sizeof(dirty_background_bytes),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001208 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001209 },
1210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .procname = "dirty_ratio",
1212 .data = &vm_dirty_ratio,
1213 .maxlen = sizeof(vm_dirty_ratio),
1214 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001215 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .extra1 = &zero,
1217 .extra2 = &one_hundred,
1218 },
1219 {
David Rientjes2da02992009-01-06 14:39:31 -08001220 .procname = "dirty_bytes",
1221 .data = &vm_dirty_bytes,
1222 .maxlen = sizeof(vm_dirty_bytes),
1223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001224 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001225 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001226 },
1227 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001229 .data = &dirty_writeback_interval,
1230 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001232 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 },
1234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001236 .data = &dirty_expire_interval,
1237 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001239 .proc_handler = proc_dointvec_minmax,
1240 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 },
1242 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001243 .procname = "dirtytime_expire_seconds",
1244 .data = &dirtytime_expire_interval,
1245 .maxlen = sizeof(dirty_expire_interval),
1246 .mode = 0644,
1247 .proc_handler = dirtytime_interval_handler,
1248 .extra1 = &zero,
1249 },
1250 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001251 .procname = "nr_pdflush_threads",
1252 .mode = 0444 /* read-only */,
1253 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 },
1255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 .procname = "swappiness",
1257 .data = &vm_swappiness,
1258 .maxlen = sizeof(vm_swappiness),
1259 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001260 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 .extra1 = &zero,
1262 .extra2 = &one_hundred,
1263 },
1264#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001265 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001267 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .maxlen = sizeof(unsigned long),
1269 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001270 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001271 },
1272#ifdef CONFIG_NUMA
1273 {
1274 .procname = "nr_hugepages_mempolicy",
1275 .data = NULL,
1276 .maxlen = sizeof(unsigned long),
1277 .mode = 0644,
1278 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001279 },
1280#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 .procname = "hugetlb_shm_group",
1283 .data = &sysctl_hugetlb_shm_group,
1284 .maxlen = sizeof(gid_t),
1285 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001286 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 },
Mel Gorman396faf02007-07-17 04:03:13 -07001288 {
Mel Gorman396faf02007-07-17 04:03:13 -07001289 .procname = "hugepages_treat_as_movable",
1290 .data = &hugepages_treat_as_movable,
1291 .maxlen = sizeof(int),
1292 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001293 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001294 },
Adam Litke54f9f802007-10-16 01:26:20 -07001295 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001296 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001297 .data = NULL,
1298 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001301 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302#endif
1303 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 .procname = "lowmem_reserve_ratio",
1305 .data = &sysctl_lowmem_reserve_ratio,
1306 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1307 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001308 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 },
1310 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001311 .procname = "drop_caches",
1312 .data = &sysctl_drop_caches,
1313 .maxlen = sizeof(int),
1314 .mode = 0644,
1315 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001316 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001317 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001318 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001319#ifdef CONFIG_COMPACTION
1320 {
1321 .procname = "compact_memory",
1322 .data = &sysctl_compact_memory,
1323 .maxlen = sizeof(int),
1324 .mode = 0200,
1325 .proc_handler = sysctl_compaction_handler,
1326 },
Mel Gorman5e771902010-05-24 14:32:31 -07001327 {
1328 .procname = "extfrag_threshold",
1329 .data = &sysctl_extfrag_threshold,
1330 .maxlen = sizeof(int),
1331 .mode = 0644,
1332 .proc_handler = sysctl_extfrag_handler,
1333 .extra1 = &min_extfrag_threshold,
1334 .extra2 = &max_extfrag_threshold,
1335 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001336 {
1337 .procname = "compact_unevictable_allowed",
1338 .data = &sysctl_compact_unevictable_allowed,
1339 .maxlen = sizeof(int),
1340 .mode = 0644,
1341 .proc_handler = proc_dointvec,
1342 .extra1 = &zero,
1343 .extra2 = &one,
1344 },
Mel Gorman5e771902010-05-24 14:32:31 -07001345
Mel Gorman76ab0f52010-05-24 14:32:28 -07001346#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .procname = "min_free_kbytes",
1349 .data = &min_free_kbytes,
1350 .maxlen = sizeof(min_free_kbytes),
1351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 .extra1 = &zero,
1354 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001355 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001356 .procname = "percpu_pagelist_fraction",
1357 .data = &percpu_pagelist_fraction,
1358 .maxlen = sizeof(percpu_pagelist_fraction),
1359 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001360 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001361 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001362 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363#ifdef CONFIG_MMU
1364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 .procname = "max_map_count",
1366 .data = &sysctl_max_map_count,
1367 .maxlen = sizeof(sysctl_max_map_count),
1368 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001369 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001370 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001372#else
1373 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001374 .procname = "nr_trim_pages",
1375 .data = &sysctl_nr_trim_pages,
1376 .maxlen = sizeof(sysctl_nr_trim_pages),
1377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001378 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001379 .extra1 = &zero,
1380 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381#endif
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "laptop_mode",
1384 .data = &laptop_mode,
1385 .maxlen = sizeof(laptop_mode),
1386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "block_dump",
1391 .data = &block_dump,
1392 .maxlen = sizeof(block_dump),
1393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .extra1 = &zero,
1396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "vfs_cache_pressure",
1399 .data = &sysctl_vfs_cache_pressure,
1400 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001402 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .extra1 = &zero,
1404 },
1405#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 .procname = "legacy_va_layout",
1408 .data = &sysctl_legacy_va_layout,
1409 .maxlen = sizeof(sysctl_legacy_va_layout),
1410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001411 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .extra1 = &zero,
1413 },
1414#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001415#ifdef CONFIG_NUMA
1416 {
Christoph Lameter17436602006-01-18 17:42:32 -08001417 .procname = "zone_reclaim_mode",
1418 .data = &zone_reclaim_mode,
1419 .maxlen = sizeof(zone_reclaim_mode),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001422 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001423 },
Christoph Lameter96146342006-07-03 00:24:13 -07001424 {
Christoph Lameter96146342006-07-03 00:24:13 -07001425 .procname = "min_unmapped_ratio",
1426 .data = &sysctl_min_unmapped_ratio,
1427 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001430 .extra1 = &zero,
1431 .extra2 = &one_hundred,
1432 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001433 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001434 .procname = "min_slab_ratio",
1435 .data = &sysctl_min_slab_ratio,
1436 .maxlen = sizeof(sysctl_min_slab_ratio),
1437 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001438 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001439 .extra1 = &zero,
1440 .extra2 = &one_hundred,
1441 },
Christoph Lameter17436602006-01-18 17:42:32 -08001442#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001443#ifdef CONFIG_SMP
1444 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001445 .procname = "stat_interval",
1446 .data = &sysctl_stat_interval,
1447 .maxlen = sizeof(sysctl_stat_interval),
1448 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001449 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001450 },
1451#endif
David Howells6e141542009-12-15 19:27:45 +00001452#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001453 {
Eric Parised032182007-06-28 15:55:21 -04001454 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001455 .data = &dac_mmap_min_addr,
1456 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001458 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001459 },
David Howells6e141542009-12-15 19:27:45 +00001460#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001461#ifdef CONFIG_NUMA
1462 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001463 .procname = "numa_zonelist_order",
1464 .data = &numa_zonelist_order,
1465 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001467 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001468 },
1469#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001470#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001471 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001472 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001473 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001474#ifdef CONFIG_X86_32
1475 .data = &vdso32_enabled,
1476 .maxlen = sizeof(vdso32_enabled),
1477#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001478 .data = &vdso_enabled,
1479 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001480#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001482 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001483 .extra1 = &zero,
1484 },
1485#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001486#ifdef CONFIG_HIGHMEM
1487 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001488 .procname = "highmem_is_dirtyable",
1489 .data = &vm_highmem_is_dirtyable,
1490 .maxlen = sizeof(vm_highmem_is_dirtyable),
1491 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001492 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001493 .extra1 = &zero,
1494 .extra2 = &one,
1495 },
1496#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001497#ifdef CONFIG_MEMORY_FAILURE
1498 {
Andi Kleen6a460792009-09-16 11:50:15 +02001499 .procname = "memory_failure_early_kill",
1500 .data = &sysctl_memory_failure_early_kill,
1501 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001503 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001504 .extra1 = &zero,
1505 .extra2 = &one,
1506 },
1507 {
Andi Kleen6a460792009-09-16 11:50:15 +02001508 .procname = "memory_failure_recovery",
1509 .data = &sysctl_memory_failure_recovery,
1510 .maxlen = sizeof(sysctl_memory_failure_recovery),
1511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001512 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001513 .extra1 = &zero,
1514 .extra2 = &one,
1515 },
1516#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001517 {
1518 .procname = "user_reserve_kbytes",
1519 .data = &sysctl_user_reserve_kbytes,
1520 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1521 .mode = 0644,
1522 .proc_handler = proc_doulongvec_minmax,
1523 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001524 {
1525 .procname = "admin_reserve_kbytes",
1526 .data = &sysctl_admin_reserve_kbytes,
1527 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1528 .mode = 0644,
1529 .proc_handler = proc_doulongvec_minmax,
1530 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001531 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532};
1533
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001534static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 .procname = "inode-nr",
1537 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001538 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001540 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 },
1542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 .procname = "inode-state",
1544 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001545 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001547 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 },
1549 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 .procname = "file-nr",
1551 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001552 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001554 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 },
1556 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 .procname = "file-max",
1558 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001559 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001561 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 },
1563 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001564 .procname = "nr_open",
1565 .data = &sysctl_nr_open,
1566 .maxlen = sizeof(int),
1567 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001568 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001569 .extra1 = &sysctl_nr_open_min,
1570 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001571 },
1572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 .procname = "dentry-state",
1574 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001575 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001577 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 },
1579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 .procname = "overflowuid",
1581 .data = &fs_overflowuid,
1582 .maxlen = sizeof(int),
1583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001584 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 .extra1 = &minolduid,
1586 .extra2 = &maxolduid,
1587 },
1588 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 .procname = "overflowgid",
1590 .data = &fs_overflowgid,
1591 .maxlen = sizeof(int),
1592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001593 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 .extra1 = &minolduid,
1595 .extra2 = &maxolduid,
1596 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001597#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 .procname = "leases-enable",
1600 .data = &leases_enable,
1601 .maxlen = sizeof(int),
1602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001603 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001605#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606#ifdef CONFIG_DNOTIFY
1607 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 .procname = "dir-notify-enable",
1609 .data = &dir_notify_enable,
1610 .maxlen = sizeof(int),
1611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001612 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 },
1614#endif
1615#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001616#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 .procname = "lease-break-time",
1619 .data = &lease_break_time,
1620 .maxlen = sizeof(int),
1621 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001622 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001624#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001625#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 .procname = "aio-nr",
1628 .data = &aio_nr,
1629 .maxlen = sizeof(aio_nr),
1630 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001631 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 },
1633 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 .procname = "aio-max-nr",
1635 .data = &aio_max_nr,
1636 .maxlen = sizeof(aio_max_nr),
1637 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001638 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001640#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001641#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001642 {
Robert Love0399cb02005-07-13 12:38:18 -04001643 .procname = "inotify",
1644 .mode = 0555,
1645 .child = inotify_table,
1646 },
1647#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001648#ifdef CONFIG_EPOLL
1649 {
1650 .procname = "epoll",
1651 .mode = 0555,
1652 .child = epoll_table,
1653 },
1654#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001656 {
Kees Cook800179c2012-07-25 17:29:07 -07001657 .procname = "protected_symlinks",
1658 .data = &sysctl_protected_symlinks,
1659 .maxlen = sizeof(int),
1660 .mode = 0600,
1661 .proc_handler = proc_dointvec_minmax,
1662 .extra1 = &zero,
1663 .extra2 = &one,
1664 },
1665 {
1666 .procname = "protected_hardlinks",
1667 .data = &sysctl_protected_hardlinks,
1668 .maxlen = sizeof(int),
1669 .mode = 0600,
1670 .proc_handler = proc_dointvec_minmax,
1671 .extra1 = &zero,
1672 .extra2 = &one,
1673 },
1674 {
Alan Coxd6e71142005-06-23 00:09:43 -07001675 .procname = "suid_dumpable",
1676 .data = &suid_dumpable,
1677 .maxlen = sizeof(int),
1678 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001679 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001680 .extra1 = &zero,
1681 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001682 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001683#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1684 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001685 .procname = "binfmt_misc",
1686 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001687 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001688 },
1689#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001690 {
Jens Axboeff9da692010-06-03 14:54:39 +02001691 .procname = "pipe-max-size",
1692 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001693 .maxlen = sizeof(int),
1694 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001695 .proc_handler = &pipe_proc_fn,
1696 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001697 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001698 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699};
1700
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001701static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001702#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001703 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001704 .procname = "exception-trace",
1705 .data = &show_unhandled_signals,
1706 .maxlen = sizeof(int),
1707 .mode = 0644,
1708 .proc_handler = proc_dointvec
1709 },
1710#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001711#if defined(CONFIG_OPTPROBES)
1712 {
1713 .procname = "kprobes-optimization",
1714 .data = &sysctl_kprobes_optimization,
1715 .maxlen = sizeof(int),
1716 .mode = 0644,
1717 .proc_handler = proc_kprobes_optimization_handler,
1718 .extra1 = &zero,
1719 .extra2 = &one,
1720 },
1721#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001722 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723};
1724
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001725static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001726 { }
Robert Love0eeca282005-07-12 17:06:03 -04001727};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001729int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001730{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001731 struct ctl_table_header *hdr;
1732
1733 hdr = register_sysctl_table(sysctl_base_table);
1734 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001735 return 0;
1736}
1737
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001738#endif /* CONFIG_SYSCTL */
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740/*
1741 * /proc/sys support
1742 */
1743
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001744#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
Kees Cookf8808302014-06-06 14:37:17 -07001746static int _proc_do_string(char *data, int maxlen, int write,
1747 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001748 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001749{
1750 size_t len;
1751 char __user *p;
1752 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001753
1754 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001755 *lenp = 0;
1756 return 0;
1757 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001758
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001759 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001760 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1761 /* Only continue writes not past the end of buffer. */
1762 len = strlen(data);
1763 if (len > maxlen - 1)
1764 len = maxlen - 1;
1765
1766 if (*ppos > len)
1767 return 0;
1768 len = *ppos;
1769 } else {
1770 /* Start writing from beginning of buffer. */
1771 len = 0;
1772 }
1773
Kees Cook2ca9bb42014-06-06 14:37:18 -07001774 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001775 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001776 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001777 if (get_user(c, p++))
1778 return -EFAULT;
1779 if (c == 0 || c == '\n')
1780 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001781 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001782 }
Kees Cookf8808302014-06-06 14:37:17 -07001783 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001784 } else {
1785 len = strlen(data);
1786 if (len > maxlen)
1787 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001788
1789 if (*ppos > len) {
1790 *lenp = 0;
1791 return 0;
1792 }
1793
1794 data += *ppos;
1795 len -= *ppos;
1796
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001797 if (len > *lenp)
1798 len = *lenp;
1799 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001800 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001801 return -EFAULT;
1802 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001803 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001804 return -EFAULT;
1805 len++;
1806 }
1807 *lenp = len;
1808 *ppos += len;
1809 }
1810 return 0;
1811}
1812
Kees Cookf4aacea2014-06-06 14:37:19 -07001813static void warn_sysctl_write(struct ctl_table *table)
1814{
1815 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1816 "This will not be supported in the future. To silence this\n"
1817 "warning, set kernel.sysctl_writes_strict = -1\n",
1818 current->comm, table->procname);
1819}
1820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821/**
1822 * proc_dostring - read a string sysctl
1823 * @table: the sysctl table
1824 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 * @buffer: the user buffer
1826 * @lenp: the size of the user buffer
1827 * @ppos: file position
1828 *
1829 * Reads/writes a string from/to the user buffer. If the kernel
1830 * buffer provided is not large enough to hold the string, the
1831 * string is truncated. The copied string is %NULL-terminated.
1832 * If the string is being read by the user process, it is copied
1833 * and a newline '\n' is added. It is truncated if the buffer is
1834 * not large enough.
1835 *
1836 * Returns 0 on success.
1837 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001838int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 void __user *buffer, size_t *lenp, loff_t *ppos)
1840{
Kees Cookf4aacea2014-06-06 14:37:19 -07001841 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1842 warn_sysctl_write(table);
1843
Kees Cookf8808302014-06-06 14:37:17 -07001844 return _proc_do_string((char *)(table->data), table->maxlen, write,
1845 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
Amerigo Wang00b7c332010-05-05 00:26:45 +00001848static size_t proc_skip_spaces(char **buf)
1849{
1850 size_t ret;
1851 char *tmp = skip_spaces(*buf);
1852 ret = tmp - *buf;
1853 *buf = tmp;
1854 return ret;
1855}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001857static void proc_skip_char(char **buf, size_t *size, const char v)
1858{
1859 while (*size) {
1860 if (**buf != v)
1861 break;
1862 (*size)--;
1863 (*buf)++;
1864 }
1865}
1866
Amerigo Wang00b7c332010-05-05 00:26:45 +00001867#define TMPBUFLEN 22
1868/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001869 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001870 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001871 * @buf: a kernel buffer
1872 * @size: size of the kernel buffer
1873 * @val: this is where the number will be stored
1874 * @neg: set to %TRUE if number is negative
1875 * @perm_tr: a vector which contains the allowed trailers
1876 * @perm_tr_len: size of the perm_tr vector
1877 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001878 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001879 * In case of success %0 is returned and @buf and @size are updated with
1880 * the amount of bytes read. If @tr is non-NULL and a trailing
1881 * character exists (size is non-zero after returning from this
1882 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001883 */
1884static int proc_get_long(char **buf, size_t *size,
1885 unsigned long *val, bool *neg,
1886 const char *perm_tr, unsigned perm_tr_len, char *tr)
1887{
1888 int len;
1889 char *p, tmp[TMPBUFLEN];
1890
1891 if (!*size)
1892 return -EINVAL;
1893
1894 len = *size;
1895 if (len > TMPBUFLEN - 1)
1896 len = TMPBUFLEN - 1;
1897
1898 memcpy(tmp, *buf, len);
1899
1900 tmp[len] = 0;
1901 p = tmp;
1902 if (*p == '-' && *size > 1) {
1903 *neg = true;
1904 p++;
1905 } else
1906 *neg = false;
1907 if (!isdigit(*p))
1908 return -EINVAL;
1909
1910 *val = simple_strtoul(p, &p, 0);
1911
1912 len = p - tmp;
1913
1914 /* We don't know if the next char is whitespace thus we may accept
1915 * invalid integers (e.g. 1234...a) or two integers instead of one
1916 * (e.g. 123...1). So lets not allow such large numbers. */
1917 if (len == TMPBUFLEN - 1)
1918 return -EINVAL;
1919
1920 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1921 return -EINVAL;
1922
1923 if (tr && (len < *size))
1924 *tr = *p;
1925
1926 *buf += len;
1927 *size -= len;
1928
1929 return 0;
1930}
1931
1932/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001933 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001934 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001935 * @buf: the user buffer
1936 * @size: the size of the user buffer
1937 * @val: the integer to be converted
1938 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001939 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001940 * In case of success %0 is returned and @buf and @size are updated with
1941 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001942 */
1943static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1944 bool neg)
1945{
1946 int len;
1947 char tmp[TMPBUFLEN], *p = tmp;
1948
1949 sprintf(p, "%s%lu", neg ? "-" : "", val);
1950 len = strlen(tmp);
1951 if (len > *size)
1952 len = *size;
1953 if (copy_to_user(*buf, tmp, len))
1954 return -EFAULT;
1955 *size -= len;
1956 *buf += len;
1957 return 0;
1958}
1959#undef TMPBUFLEN
1960
1961static int proc_put_char(void __user **buf, size_t *size, char c)
1962{
1963 if (*size) {
1964 char __user **buffer = (char __user **)buf;
1965 if (put_user(c, *buffer))
1966 return -EFAULT;
1967 (*size)--, (*buffer)++;
1968 *buf = *buffer;
1969 }
1970 return 0;
1971}
1972
1973static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 int *valp,
1975 int write, void *data)
1976{
1977 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07001978 if (*negp) {
1979 if (*lvalp > (unsigned long) INT_MAX + 1)
1980 return -EINVAL;
1981 *valp = -*lvalp;
1982 } else {
1983 if (*lvalp > (unsigned long) INT_MAX)
1984 return -EINVAL;
1985 *valp = *lvalp;
1986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 } else {
1988 int val = *valp;
1989 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001990 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 *lvalp = (unsigned long)-val;
1992 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001993 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 *lvalp = (unsigned long)val;
1995 }
1996 }
1997 return 0;
1998}
1999
Amerigo Wang00b7c332010-05-05 00:26:45 +00002000static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2001
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002002static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002003 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002004 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002005 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 int write, void *data),
2007 void *data)
2008{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002009 int *i, vleft, first = 1, err = 0;
2010 unsigned long page = 0;
2011 size_t left;
2012 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
Amerigo Wang00b7c332010-05-05 00:26:45 +00002014 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 *lenp = 0;
2016 return 0;
2017 }
2018
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002019 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 vleft = table->maxlen / sizeof(*i);
2021 left = *lenp;
2022
2023 if (!conv)
2024 conv = do_proc_dointvec_conv;
2025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002027 if (*ppos) {
2028 switch (sysctl_writes_strict) {
2029 case SYSCTL_WRITES_STRICT:
2030 goto out;
2031 case SYSCTL_WRITES_WARN:
2032 warn_sysctl_write(table);
2033 break;
2034 default:
2035 break;
2036 }
2037 }
2038
Amerigo Wang00b7c332010-05-05 00:26:45 +00002039 if (left > PAGE_SIZE - 1)
2040 left = PAGE_SIZE - 1;
2041 page = __get_free_page(GFP_TEMPORARY);
2042 kbuf = (char *) page;
2043 if (!kbuf)
2044 return -ENOMEM;
2045 if (copy_from_user(kbuf, buffer, left)) {
2046 err = -EFAULT;
2047 goto free;
2048 }
2049 kbuf[left] = 0;
2050 }
2051
2052 for (; left && vleft--; i++, first=0) {
2053 unsigned long lval;
2054 bool neg;
2055
2056 if (write) {
2057 left -= proc_skip_spaces(&kbuf);
2058
J. R. Okajima563b0462010-05-25 16:10:14 -07002059 if (!left)
2060 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002061 err = proc_get_long(&kbuf, &left, &lval, &neg,
2062 proc_wspace_sep,
2063 sizeof(proc_wspace_sep), NULL);
2064 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002066 if (conv(&neg, &lval, i, 1, data)) {
2067 err = -EINVAL;
2068 break;
2069 }
2070 } else {
2071 if (conv(&neg, &lval, i, 0, data)) {
2072 err = -EINVAL;
2073 break;
2074 }
2075 if (!first)
2076 err = proc_put_char(&buffer, &left, '\t');
2077 if (err)
2078 break;
2079 err = proc_put_long(&buffer, &left, lval, neg);
2080 if (err)
2081 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 }
2083 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002084
2085 if (!write && !first && left && !err)
2086 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002087 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002088 left -= proc_skip_spaces(&kbuf);
2089free:
2090 if (write) {
2091 free_page(page);
2092 if (first)
2093 return err ? : -EINVAL;
2094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002096out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002098 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002101static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002102 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002103 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002104 int write, void *data),
2105 void *data)
2106{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002107 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002108 buffer, lenp, ppos, conv, data);
2109}
2110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111/**
2112 * proc_dointvec - read a vector of integers
2113 * @table: the sysctl table
2114 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 * @buffer: the user buffer
2116 * @lenp: the size of the user buffer
2117 * @ppos: file position
2118 *
2119 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2120 * values from/to the user buffer, treated as an ASCII string.
2121 *
2122 * Returns 0 on success.
2123 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002124int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 void __user *buffer, size_t *lenp, loff_t *ppos)
2126{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002127 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 NULL,NULL);
2129}
2130
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002131/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002132 * Taint values can only be increased
2133 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002134 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002135static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002136 void __user *buffer, size_t *lenp, loff_t *ppos)
2137{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002138 struct ctl_table t;
2139 unsigned long tmptaint = get_taint();
2140 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002141
Bastian Blank91fcd412007-04-23 14:41:14 -07002142 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002143 return -EPERM;
2144
Andi Kleen25ddbb12008-10-15 22:01:41 -07002145 t = *table;
2146 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002147 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002148 if (err < 0)
2149 return err;
2150
2151 if (write) {
2152 /*
2153 * Poor man's atomic or. Not worth adding a primitive
2154 * to everyone's atomic.h for this
2155 */
2156 int i;
2157 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2158 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302159 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002160 }
2161 }
2162
2163 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002164}
2165
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002166#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002167static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002168 void __user *buffer, size_t *lenp, loff_t *ppos)
2169{
2170 if (write && !capable(CAP_SYS_ADMIN))
2171 return -EPERM;
2172
2173 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2174}
2175#endif
2176
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177struct do_proc_dointvec_minmax_conv_param {
2178 int *min;
2179 int *max;
2180};
2181
Amerigo Wang00b7c332010-05-05 00:26:45 +00002182static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2183 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 int write, void *data)
2185{
2186 struct do_proc_dointvec_minmax_conv_param *param = data;
2187 if (write) {
2188 int val = *negp ? -*lvalp : *lvalp;
2189 if ((param->min && *param->min > val) ||
2190 (param->max && *param->max < val))
2191 return -EINVAL;
2192 *valp = val;
2193 } else {
2194 int val = *valp;
2195 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 *lvalp = (unsigned long)-val;
2198 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002199 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 *lvalp = (unsigned long)val;
2201 }
2202 }
2203 return 0;
2204}
2205
2206/**
2207 * proc_dointvec_minmax - read a vector of integers with min/max values
2208 * @table: the sysctl table
2209 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2213 *
2214 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2215 * values from/to the user buffer, treated as an ASCII string.
2216 *
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2219 *
2220 * Returns 0 on success.
2221 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002222int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 void __user *buffer, size_t *lenp, loff_t *ppos)
2224{
2225 struct do_proc_dointvec_minmax_conv_param param = {
2226 .min = (int *) table->extra1,
2227 .max = (int *) table->extra2,
2228 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002229 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 do_proc_dointvec_minmax_conv, &param);
2231}
2232
Kees Cook54b50192012-07-30 14:39:18 -07002233static void validate_coredump_safety(void)
2234{
Alex Kelly046d6622012-10-04 17:15:23 -07002235#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002236 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002237 core_pattern[0] != '/' && core_pattern[0] != '|') {
2238 printk(KERN_WARNING "Unsafe core_pattern used with "\
2239 "suid_dumpable=2. Pipe handler or fully qualified "\
2240 "core dump path required.\n");
2241 }
Alex Kelly046d6622012-10-04 17:15:23 -07002242#endif
Kees Cook54b50192012-07-30 14:39:18 -07002243}
2244
2245static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2247{
2248 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2249 if (!error)
2250 validate_coredump_safety();
2251 return error;
2252}
2253
Alex Kelly046d6622012-10-04 17:15:23 -07002254#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002255static int proc_dostring_coredump(struct ctl_table *table, int write,
2256 void __user *buffer, size_t *lenp, loff_t *ppos)
2257{
2258 int error = proc_dostring(table, write, buffer, lenp, ppos);
2259 if (!error)
2260 validate_coredump_safety();
2261 return error;
2262}
Alex Kelly046d6622012-10-04 17:15:23 -07002263#endif
Kees Cook54b50192012-07-30 14:39:18 -07002264
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002265static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 void __user *buffer,
2267 size_t *lenp, loff_t *ppos,
2268 unsigned long convmul,
2269 unsigned long convdiv)
2270{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271 unsigned long *i, *min, *max;
2272 int vleft, first = 1, err = 0;
2273 unsigned long page = 0;
2274 size_t left;
2275 char *kbuf;
2276
2277 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 *lenp = 0;
2279 return 0;
2280 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002282 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 min = (unsigned long *) table->extra1;
2284 max = (unsigned long *) table->extra2;
2285 vleft = table->maxlen / sizeof(unsigned long);
2286 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287
2288 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002289 if (*ppos) {
2290 switch (sysctl_writes_strict) {
2291 case SYSCTL_WRITES_STRICT:
2292 goto out;
2293 case SYSCTL_WRITES_WARN:
2294 warn_sysctl_write(table);
2295 break;
2296 default:
2297 break;
2298 }
2299 }
2300
Amerigo Wang00b7c332010-05-05 00:26:45 +00002301 if (left > PAGE_SIZE - 1)
2302 left = PAGE_SIZE - 1;
2303 page = __get_free_page(GFP_TEMPORARY);
2304 kbuf = (char *) page;
2305 if (!kbuf)
2306 return -ENOMEM;
2307 if (copy_from_user(kbuf, buffer, left)) {
2308 err = -EFAULT;
2309 goto free;
2310 }
2311 kbuf[left] = 0;
2312 }
2313
Eric Dumazet27b3d802010-10-07 12:59:29 -07002314 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002315 unsigned long val;
2316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 bool neg;
2319
2320 left -= proc_skip_spaces(&kbuf);
2321
2322 err = proc_get_long(&kbuf, &left, &val, &neg,
2323 proc_wspace_sep,
2324 sizeof(proc_wspace_sep), NULL);
2325 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 break;
2327 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 continue;
2329 if ((min && val < *min) || (max && val > *max))
2330 continue;
2331 *i = val;
2332 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002333 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002334 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002335 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002336 if (err)
2337 break;
2338 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 err = proc_put_long(&buffer, &left, val, false);
2340 if (err)
2341 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
2343 }
2344
Amerigo Wang00b7c332010-05-05 00:26:45 +00002345 if (!write && !first && left && !err)
2346 err = proc_put_char(&buffer, &left, '\n');
2347 if (write && !err)
2348 left -= proc_skip_spaces(&kbuf);
2349free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002351 free_page(page);
2352 if (first)
2353 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002356out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359}
2360
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002361static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002362 void __user *buffer,
2363 size_t *lenp, loff_t *ppos,
2364 unsigned long convmul,
2365 unsigned long convdiv)
2366{
2367 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002369}
2370
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371/**
2372 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2378 *
2379 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2380 * values from/to the user buffer, treated as an ASCII string.
2381 *
2382 * This routine will ensure the values are within the range specified by
2383 * table->extra1 (min) and table->extra2 (max).
2384 *
2385 * Returns 0 on success.
2386 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002387int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 void __user *buffer, size_t *lenp, loff_t *ppos)
2389{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002390 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391}
2392
2393/**
2394 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2395 * @table: the sysctl table
2396 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 * @buffer: the user buffer
2398 * @lenp: the size of the user buffer
2399 * @ppos: file position
2400 *
2401 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2402 * values from/to the user buffer, treated as an ASCII string. The values
2403 * are treated as milliseconds, and converted to jiffies when they are stored.
2404 *
2405 * This routine will ensure the values are within the range specified by
2406 * table->extra1 (min) and table->extra2 (max).
2407 *
2408 * Returns 0 on success.
2409 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002410int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 void __user *buffer,
2412 size_t *lenp, loff_t *ppos)
2413{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002414 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 lenp, ppos, HZ, 1000l);
2416}
2417
2418
Amerigo Wang00b7c332010-05-05 00:26:45 +00002419static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 int *valp,
2421 int write, void *data)
2422{
2423 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002424 if (*lvalp > LONG_MAX / HZ)
2425 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2427 } else {
2428 int val = *valp;
2429 unsigned long lval;
2430 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002431 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 lval = (unsigned long)-val;
2433 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002434 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 lval = (unsigned long)val;
2436 }
2437 *lvalp = lval / HZ;
2438 }
2439 return 0;
2440}
2441
Amerigo Wang00b7c332010-05-05 00:26:45 +00002442static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 int *valp,
2444 int write, void *data)
2445{
2446 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002447 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2448 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2450 } else {
2451 int val = *valp;
2452 unsigned long lval;
2453 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002454 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 lval = (unsigned long)-val;
2456 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002457 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 lval = (unsigned long)val;
2459 }
2460 *lvalp = jiffies_to_clock_t(lval);
2461 }
2462 return 0;
2463}
2464
Amerigo Wang00b7c332010-05-05 00:26:45 +00002465static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 int *valp,
2467 int write, void *data)
2468{
2469 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002470 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2471
2472 if (jif > INT_MAX)
2473 return 1;
2474 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 } else {
2476 int val = *valp;
2477 unsigned long lval;
2478 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002479 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 lval = (unsigned long)-val;
2481 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002482 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 lval = (unsigned long)val;
2484 }
2485 *lvalp = jiffies_to_msecs(lval);
2486 }
2487 return 0;
2488}
2489
2490/**
2491 * proc_dointvec_jiffies - read a vector of integers as seconds
2492 * @table: the sysctl table
2493 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2497 *
2498 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2499 * values from/to the user buffer, treated as an ASCII string.
2500 * The values read are assumed to be in seconds, and are converted into
2501 * jiffies.
2502 *
2503 * Returns 0 on success.
2504 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002505int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 void __user *buffer, size_t *lenp, loff_t *ppos)
2507{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002508 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 do_proc_dointvec_jiffies_conv,NULL);
2510}
2511
2512/**
2513 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2514 * @table: the sysctl table
2515 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 * @buffer: the user buffer
2517 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002518 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 *
2520 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2521 * values from/to the user buffer, treated as an ASCII string.
2522 * The values read are assumed to be in 1/USER_HZ seconds, and
2523 * are converted into jiffies.
2524 *
2525 * Returns 0 on success.
2526 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002527int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 void __user *buffer, size_t *lenp, loff_t *ppos)
2529{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002530 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 do_proc_dointvec_userhz_jiffies_conv,NULL);
2532}
2533
2534/**
2535 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2536 * @table: the sysctl table
2537 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 * @buffer: the user buffer
2539 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002540 * @ppos: file position
2541 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 *
2543 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2544 * values from/to the user buffer, treated as an ASCII string.
2545 * The values read are assumed to be in 1/1000 seconds, and
2546 * are converted into jiffies.
2547 *
2548 * Returns 0 on success.
2549 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002550int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 void __user *buffer, size_t *lenp, loff_t *ppos)
2552{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002553 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 do_proc_dointvec_ms_jiffies_conv, NULL);
2555}
2556
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002557static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002558 void __user *buffer, size_t *lenp, loff_t *ppos)
2559{
2560 struct pid *new_pid;
2561 pid_t tmp;
2562 int r;
2563
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002564 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002565
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002566 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002567 lenp, ppos, NULL, NULL);
2568 if (r || !write)
2569 return r;
2570
2571 new_pid = find_get_pid(tmp);
2572 if (!new_pid)
2573 return -ESRCH;
2574
2575 put_pid(xchg(&cad_pid, new_pid));
2576 return 0;
2577}
2578
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002579/**
2580 * proc_do_large_bitmap - read/write from/to a large bitmap
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
2583 * @buffer: the user buffer
2584 * @lenp: the size of the user buffer
2585 * @ppos: file position
2586 *
2587 * The bitmap is stored at table->data and the bitmap length (in bits)
2588 * in table->maxlen.
2589 *
2590 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2591 * large bitmaps may be represented in a compact manner. Writing into
2592 * the file will clear the bitmap then update it with the given input.
2593 *
2594 * Returns 0 on success.
2595 */
2596int proc_do_large_bitmap(struct ctl_table *table, int write,
2597 void __user *buffer, size_t *lenp, loff_t *ppos)
2598{
2599 int err = 0;
2600 bool first = 1;
2601 size_t left = *lenp;
2602 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002603 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002604 unsigned long *tmp_bitmap = NULL;
2605 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2606
WANG Cong122ff242014-05-12 16:04:53 -07002607 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002608 *lenp = 0;
2609 return 0;
2610 }
2611
2612 if (write) {
2613 unsigned long page = 0;
2614 char *kbuf;
2615
2616 if (left > PAGE_SIZE - 1)
2617 left = PAGE_SIZE - 1;
2618
2619 page = __get_free_page(GFP_TEMPORARY);
2620 kbuf = (char *) page;
2621 if (!kbuf)
2622 return -ENOMEM;
2623 if (copy_from_user(kbuf, buffer, left)) {
2624 free_page(page);
2625 return -EFAULT;
2626 }
2627 kbuf[left] = 0;
2628
2629 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2630 GFP_KERNEL);
2631 if (!tmp_bitmap) {
2632 free_page(page);
2633 return -ENOMEM;
2634 }
2635 proc_skip_char(&kbuf, &left, '\n');
2636 while (!err && left) {
2637 unsigned long val_a, val_b;
2638 bool neg;
2639
2640 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2641 sizeof(tr_a), &c);
2642 if (err)
2643 break;
2644 if (val_a >= bitmap_len || neg) {
2645 err = -EINVAL;
2646 break;
2647 }
2648
2649 val_b = val_a;
2650 if (left) {
2651 kbuf++;
2652 left--;
2653 }
2654
2655 if (c == '-') {
2656 err = proc_get_long(&kbuf, &left, &val_b,
2657 &neg, tr_b, sizeof(tr_b),
2658 &c);
2659 if (err)
2660 break;
2661 if (val_b >= bitmap_len || neg ||
2662 val_a > val_b) {
2663 err = -EINVAL;
2664 break;
2665 }
2666 if (left) {
2667 kbuf++;
2668 left--;
2669 }
2670 }
2671
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002672 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002673 first = 0;
2674 proc_skip_char(&kbuf, &left, '\n');
2675 }
2676 free_page(page);
2677 } else {
2678 unsigned long bit_a, bit_b = 0;
2679
2680 while (left) {
2681 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2682 if (bit_a >= bitmap_len)
2683 break;
2684 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2685 bit_a + 1) - 1;
2686
2687 if (!first) {
2688 err = proc_put_char(&buffer, &left, ',');
2689 if (err)
2690 break;
2691 }
2692 err = proc_put_long(&buffer, &left, bit_a, false);
2693 if (err)
2694 break;
2695 if (bit_a != bit_b) {
2696 err = proc_put_char(&buffer, &left, '-');
2697 if (err)
2698 break;
2699 err = proc_put_long(&buffer, &left, bit_b, false);
2700 if (err)
2701 break;
2702 }
2703
2704 first = 0; bit_b++;
2705 }
2706 if (!err)
2707 err = proc_put_char(&buffer, &left, '\n');
2708 }
2709
2710 if (!err) {
2711 if (write) {
2712 if (*ppos)
2713 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2714 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002715 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002716 }
2717 kfree(tmp_bitmap);
2718 *lenp -= left;
2719 *ppos += *lenp;
2720 return 0;
2721 } else {
2722 kfree(tmp_bitmap);
2723 return err;
2724 }
2725}
2726
Jovi Zhang55610502011-01-12 17:00:45 -08002727#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002729int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 void __user *buffer, size_t *lenp, loff_t *ppos)
2731{
2732 return -ENOSYS;
2733}
2734
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 void __user *buffer, size_t *lenp, loff_t *ppos)
2737{
2738 return -ENOSYS;
2739}
2740
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002741int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 void __user *buffer, size_t *lenp, loff_t *ppos)
2743{
2744 return -ENOSYS;
2745}
2746
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002747int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 void __user *buffer, size_t *lenp, loff_t *ppos)
2749{
2750 return -ENOSYS;
2751}
2752
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002753int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 void __user *buffer, size_t *lenp, loff_t *ppos)
2755{
2756 return -ENOSYS;
2757}
2758
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002759int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 void __user *buffer, size_t *lenp, loff_t *ppos)
2761{
2762 return -ENOSYS;
2763}
2764
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002765int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 void __user *buffer, size_t *lenp, loff_t *ppos)
2767{
2768 return -ENOSYS;
2769}
2770
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002771int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 void __user *buffer,
2773 size_t *lenp, loff_t *ppos)
2774{
2775 return -ENOSYS;
2776}
2777
2778
Jovi Zhang55610502011-01-12 17:00:45 -08002779#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781/*
2782 * No sense putting this after each symbol definition, twice,
2783 * exception granted :-)
2784 */
2785EXPORT_SYMBOL(proc_dointvec);
2786EXPORT_SYMBOL(proc_dointvec_jiffies);
2787EXPORT_SYMBOL(proc_dointvec_minmax);
2788EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2789EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2790EXPORT_SYMBOL(proc_dostring);
2791EXPORT_SYMBOL(proc_doulongvec_minmax);
2792EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);