blob: c0f63fae330d50c2a5a697fb1a9512fdba7a4bb6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050068#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#include <asm/uaccess.h>
71#include <asm/processor.h>
72
Andi Kleen29cbc782006-09-30 01:47:55 +020073#ifdef CONFIG_X86
74#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010075#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010076#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020077#endif
David Howellsd550bbd2012-03-28 18:30:03 +010078#ifdef CONFIG_SPARC
79#include <asm/setup.h>
80#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080081#ifdef CONFIG_BSD_PROCESS_ACCT
82#include <linux/acct.h>
83#endif
Dave Young4f0e0562010-03-10 15:24:09 -080084#ifdef CONFIG_RT_MUTEXES
85#include <linux/rtmutex.h>
86#endif
Dave Young2edf5e42010-03-10 15:24:10 -080087#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88#include <linux/lockdep.h>
89#endif
Dave Young15485a42010-03-10 15:24:07 -080090#ifdef CONFIG_CHR_DEV_SG
91#include <scsi/sg.h>
92#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020093
Don Zickus58687ac2010-05-07 17:11:44 -040094#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050095#include <linux/nmi.h>
96#endif
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#if defined(CONFIG_SYSCTL)
99
100/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700101extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700102#ifdef CONFIG_COREDUMP
103extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700105extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max;
Rik van Rieldbe0f612011-09-01 15:26:50 -0400108extern int extra_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300112extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700130static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700131#ifdef CONFIG_PRINTK
132static int ten_thousand = 10000;
133#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300134#ifdef CONFIG_PERF_EVENTS
135static int six_hundred_forty_kb = 640 * 1024;
136#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700137
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700138/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142static int maxolduid = 65535;
143static int minolduid;
144
145static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700146static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Liu Hua80df2842014-04-07 15:38:57 -0700148/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149#ifdef CONFIG_DETECT_HUNG_TASK
150static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
151#endif
152
Dave Youngd14f1722010-02-25 20:28:57 -0500153#ifdef CONFIG_INOTIFY_USER
154#include <linux/inotify.h>
155#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700156#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
159#ifdef __hppa__
160extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530161#endif
162
163#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164extern int unaligned_enabled;
165#endif
166
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800168extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800169#endif
170
Vineet Guptab6fca722013-01-09 20:06:28 +0530171#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172extern int no_unaligned_warning;
173#endif
174
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700175#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700176
177#define SYSCTL_WRITES_LEGACY -1
178#define SYSCTL_WRITES_WARN 0
179#define SYSCTL_WRITES_STRICT 1
180
Kees Cook41662f52016-01-20 15:00:45 -0800181static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700182
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700183static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700184 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700185static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800186 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700187#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700188
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700189#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700190static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700191 void __user *buffer, size_t *lenp, loff_t *ppos);
192#endif
193
Kees Cook54b50192012-07-30 14:39:18 -0700194static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700196#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700197static int proc_dostring_coredump(struct ctl_table *table, int write,
198 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700199#endif
Kees Cook54b50192012-07-30 14:39:18 -0700200
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700201#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800202/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100203static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700204
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700205static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700206 void __user *buffer, size_t *lenp,
207 loff_t *ppos)
208{
209 int error;
210
211 error = proc_dointvec(table, write, buffer, lenp, ppos);
212 if (error)
213 return error;
214
215 if (write)
216 sysrq_toggle_support(__sysrq_enabled);
217
218 return 0;
219}
220
221#endif
222
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700223static struct ctl_table kern_table[];
224static struct ctl_table vm_table[];
225static struct ctl_table fs_table[];
226static struct ctl_table debug_table[];
227static struct ctl_table dev_table[];
228extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800229#ifdef CONFIG_EPOLL
230extern struct ctl_table epoll_table[];
231#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234int sysctl_legacy_va_layout;
235#endif
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/* The default sysctl tables: */
238
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800239static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .procname = "kernel",
242 .mode = 0555,
243 .child = kern_table,
244 },
245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .procname = "vm",
247 .mode = 0555,
248 .child = vm_table,
249 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 .procname = "fs",
252 .mode = 0555,
253 .child = fs_table,
254 },
255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .procname = "debug",
257 .mode = 0555,
258 .child = debug_table,
259 },
260 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .procname = "dev",
262 .mode = 0555,
263 .child = dev_table,
264 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700265 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266};
267
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100269static int min_sched_granularity_ns = 100000; /* 100 usecs */
270static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
271static int min_wakeup_granularity_ns; /* 0 usecs */
272static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200273#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100274static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
275static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200276#endif /* CONFIG_SMP */
277#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278
Mel Gorman5e771902010-05-24 14:32:31 -0700279#ifdef CONFIG_COMPACTION
280static int min_extfrag_threshold;
281static int max_extfrag_threshold = 1000;
282#endif
283
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700284static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200285 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800290 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200291 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292#ifdef CONFIG_SCHED_DEBUG
293 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100294 .procname = "sched_min_granularity_ns",
295 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 },
302 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200303 .procname = "sched_latency_ns",
304 .data = &sysctl_sched_latency,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200308 .extra1 = &min_sched_granularity_ns,
309 .extra2 = &max_sched_granularity_ns,
310 },
311 {
Dietmar Eggemannea5a7f22017-01-13 13:51:24 +0000312 .procname = "sched_sync_hint_enable",
313 .data = &sysctl_sched_sync_hint_enable,
Juri Lelli1931b932016-07-29 14:04:11 +0100314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = proc_dointvec,
317 },
Srivatsa Vaddagiri26c21542016-05-31 09:08:38 -0700318#ifdef CONFIG_SCHED_WALT
319 {
320 .procname = "sched_use_walt_cpu_util",
321 .data = &sysctl_sched_use_walt_cpu_util,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
324 .proc_handler = proc_dointvec,
325 },
326 {
327 .procname = "sched_use_walt_task_util",
328 .data = &sysctl_sched_use_walt_task_util,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = proc_dointvec,
332 },
333 {
334 .procname = "sched_walt_init_task_load_pct",
335 .data = &sysctl_sched_walt_init_task_load_pct,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
338 .proc_handler = proc_dointvec,
339 },
Srinath Sridharan3a73c962016-07-22 13:21:15 +0100340 {
341 .procname = "sched_walt_cpu_high_irqload",
342 .data = &sysctl_sched_walt_cpu_high_irqload,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = proc_dointvec,
346 },
Srivatsa Vaddagiri26c21542016-05-31 09:08:38 -0700347#endif
Juri Lelli1931b932016-07-29 14:04:11 +0100348 {
Srinath Sridharanbf47bdd2016-07-14 09:57:29 +0100349 .procname = "sched_cstate_aware",
350 .data = &sysctl_sched_cstate_aware,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = proc_dointvec,
354 },
355 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200356 .procname = "sched_wakeup_granularity_ns",
357 .data = &sysctl_sched_wakeup_granularity,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800360 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200361 .extra1 = &min_wakeup_granularity_ns,
362 .extra2 = &max_wakeup_granularity_ns,
363 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200364#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200365 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100366 .procname = "sched_tunable_scaling",
367 .data = &sysctl_sched_tunable_scaling,
368 .maxlen = sizeof(enum sched_tunable_scaling),
369 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800370 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100371 .extra1 = &min_sched_tunable_scaling,
372 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200373 },
374 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900375 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200376 .data = &sysctl_sched_migration_cost,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800379 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200380 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100381 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100382 .procname = "sched_nr_migrate",
383 .data = &sysctl_sched_nr_migrate,
384 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100385 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800386 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100387 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530388 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900389 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200390 .data = &sysctl_sched_time_avg,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800393 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200394 },
395 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900396 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800397 .data = &sysctl_sched_shares_window,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = proc_dointvec,
401 },
Mel Gormancb251762016-02-05 09:08:36 +0000402#ifdef CONFIG_SCHEDSTATS
403 {
404 .procname = "sched_schedstats",
405 .data = NULL,
406 .maxlen = sizeof(unsigned int),
407 .mode = 0644,
408 .proc_handler = sysctl_schedstats,
409 .extra1 = &zero,
410 .extra2 = &one,
411 },
412#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200413#endif /* CONFIG_SMP */
414#ifdef CONFIG_NUMA_BALANCING
415 {
Peter Zijlstra4b96a29b2012-10-25 14:16:47 +0200416 .procname = "numa_balancing_scan_delay_ms",
417 .data = &sysctl_numa_balancing_scan_delay,
418 .maxlen = sizeof(unsigned int),
419 .mode = 0644,
420 .proc_handler = proc_dointvec,
421 },
422 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200423 .procname = "numa_balancing_scan_period_min_ms",
424 .data = &sysctl_numa_balancing_scan_period_min,
425 .maxlen = sizeof(unsigned int),
426 .mode = 0644,
427 .proc_handler = proc_dointvec,
428 },
429 {
430 .procname = "numa_balancing_scan_period_max_ms",
431 .data = &sysctl_numa_balancing_scan_period_max,
432 .maxlen = sizeof(unsigned int),
433 .mode = 0644,
434 .proc_handler = proc_dointvec,
435 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200436 {
437 .procname = "numa_balancing_scan_size_mb",
438 .data = &sysctl_numa_balancing_scan_size,
439 .maxlen = sizeof(unsigned int),
440 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400441 .proc_handler = proc_dointvec_minmax,
442 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200443 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100444 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800445 .procname = "numa_balancing",
446 .data = NULL, /* filled in by handler */
447 .maxlen = sizeof(unsigned int),
448 .mode = 0644,
449 .proc_handler = sysctl_numa_balancing,
450 .extra1 = &zero,
451 .extra2 = &one,
452 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200453#endif /* CONFIG_NUMA_BALANCING */
454#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200455 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100456 .procname = "sched_rt_period_us",
457 .data = &sysctl_sched_rt_period,
458 .maxlen = sizeof(unsigned int),
459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800460 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100461 },
462 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100463 .procname = "sched_rt_runtime_us",
464 .data = &sysctl_sched_rt_runtime,
465 .maxlen = sizeof(int),
466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800467 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100468 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600469 {
470 .procname = "sched_rr_timeslice_ms",
471 .data = &sched_rr_timeslice,
472 .maxlen = sizeof(int),
473 .mode = 0644,
474 .proc_handler = sched_rr_handler,
475 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100476#ifdef CONFIG_SCHED_AUTOGROUP
477 {
478 .procname = "sched_autogroup_enabled",
479 .data = &sysctl_sched_autogroup_enabled,
480 .maxlen = sizeof(unsigned int),
481 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800482 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100483 .extra1 = &zero,
484 .extra2 = &one,
485 },
486#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700487#ifdef CONFIG_CFS_BANDWIDTH
488 {
489 .procname = "sched_cfs_bandwidth_slice_us",
490 .data = &sysctl_sched_cfs_bandwidth_slice,
491 .maxlen = sizeof(unsigned int),
492 .mode = 0644,
493 .proc_handler = proc_dointvec_minmax,
494 .extra1 = &one,
495 },
496#endif
Patrick Bellasi69fa4c72015-06-22 18:11:44 +0100497#ifdef CONFIG_SCHED_TUNE
498 {
499 .procname = "sched_cfs_boost",
500 .data = &sysctl_sched_cfs_boost,
501 .maxlen = sizeof(sysctl_sched_cfs_boost),
Patrick Bellasiae710302015-06-23 09:17:54 +0100502#ifdef CONFIG_CGROUP_SCHEDTUNE
503 .mode = 0444,
504#else
Patrick Bellasi69fa4c72015-06-22 18:11:44 +0100505 .mode = 0644,
Patrick Bellasiae710302015-06-23 09:17:54 +0100506#endif
Patrick Bellasi69fa4c72015-06-22 18:11:44 +0100507 .proc_handler = &sysctl_sched_cfs_boost_handler,
508 .extra1 = &zero,
509 .extra2 = &one_hundred,
510 },
511#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700512#ifdef CONFIG_PROVE_LOCKING
513 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700514 .procname = "prove_locking",
515 .data = &prove_locking,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700519 },
520#endif
521#ifdef CONFIG_LOCK_STAT
522 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700523 .procname = "lock_stat",
524 .data = &lock_stat,
525 .maxlen = sizeof(int),
526 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800527 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700528 },
529#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200530 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 .procname = "panic",
532 .data = &panic_timeout,
533 .maxlen = sizeof(int),
534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800535 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 },
Alex Kelly046d6622012-10-04 17:15:23 -0700537#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "core_uses_pid",
540 .data = &core_uses_pid,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800543 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 },
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "core_pattern",
547 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700548 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700550 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
Neil Hormana2939802009-09-23 15:56:56 -0700552 {
Neil Hormana2939802009-09-23 15:56:56 -0700553 .procname = "core_pipe_limit",
554 .data = &core_pipe_limit,
555 .maxlen = sizeof(unsigned int),
556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800557 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700558 },
Alex Kelly046d6622012-10-04 17:15:23 -0700559#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800560#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700563 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700567 {
568 .procname = "sysctl_writes_strict",
569 .data = &sysctl_writes_strict,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = proc_dointvec_minmax,
573 .extra1 = &neg_one,
574 .extra2 = &one,
575 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800576#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100577#ifdef CONFIG_LATENCYTOP
578 {
579 .procname = "latencytop",
580 .data = &latencytop_enabled,
581 .maxlen = sizeof(int),
582 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000583 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100584 },
585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#ifdef CONFIG_BLK_DEV_INITRD
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "real-root-dev",
589 .data = &real_root_dev,
590 .maxlen = sizeof(int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700595 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700596 .procname = "print-fatal-signals",
597 .data = &print_fatal_signals,
598 .maxlen = sizeof(int),
599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800600 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700601 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700602#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .procname = "reboot-cmd",
605 .data = reboot_command,
606 .maxlen = 256,
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 },
610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "stop-a",
612 .data = &stop_a_enabled,
613 .maxlen = sizeof (int),
614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800615 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 },
617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .procname = "scons-poweroff",
619 .data = &scons_pwroff,
620 .maxlen = sizeof (int),
621 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800622 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 },
624#endif
David S. Miller08714202008-11-16 23:49:24 -0800625#ifdef CONFIG_SPARC64
626 {
David S. Miller08714202008-11-16 23:49:24 -0800627 .procname = "tsb-ratio",
628 .data = &sysctl_tsb_ratio,
629 .maxlen = sizeof (int),
630 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800631 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800632 },
633#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#ifdef __hppa__
635 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .procname = "soft-power",
637 .data = &pwrsw_enabled,
638 .maxlen = sizeof (int),
639 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800640 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530642#endif
643#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .procname = "unaligned-trap",
646 .data = &unaligned_enabled,
647 .maxlen = sizeof (int),
648 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800649 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 },
651#endif
652 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .procname = "ctrl-alt-del",
654 .data = &C_A_D,
655 .maxlen = sizeof(int),
656 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800657 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400659#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200660 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200661 .procname = "ftrace_enabled",
662 .data = &ftrace_enabled,
663 .maxlen = sizeof(int),
664 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800665 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200666 },
667#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500668#ifdef CONFIG_STACK_TRACER
669 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500670 .procname = "stack_tracer_enabled",
671 .data = &stack_tracer_enabled,
672 .maxlen = sizeof(int),
673 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800674 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500675 },
676#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400677#ifdef CONFIG_TRACING
678 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100679 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400680 .data = &ftrace_dump_on_oops,
681 .maxlen = sizeof(int),
682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400684 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400685 {
686 .procname = "traceoff_on_warning",
687 .data = &__disable_trace_on_warning,
688 .maxlen = sizeof(__disable_trace_on_warning),
689 .mode = 0644,
690 .proc_handler = proc_dointvec,
691 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500692 {
693 .procname = "tracepoint_printk",
694 .data = &tracepoint_printk,
695 .maxlen = sizeof(tracepoint_printk),
696 .mode = 0644,
697 .proc_handler = proc_dointvec,
698 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400699#endif
Dave Young2965faa2015-09-09 15:38:55 -0700700#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800701 {
702 .procname = "kexec_load_disabled",
703 .data = &kexec_load_disabled,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 /* only handle a transition from default "0" to "1" */
707 .proc_handler = proc_dointvec_minmax,
708 .extra1 = &one,
709 .extra2 = &one,
710 },
711#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200712#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .procname = "modprobe",
715 .data = &modprobe_path,
716 .maxlen = KMOD_PATH_LEN,
717 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800718 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
Kees Cook3d433212009-04-02 15:49:29 -0700720 {
Kees Cook3d433212009-04-02 15:49:29 -0700721 .procname = "modules_disabled",
722 .data = &modules_disabled,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800726 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700727 .extra1 = &one,
728 .extra2 = &one,
729 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700731#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100734 .data = &uevent_helper,
735 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800737 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 },
Michael Marineau86d56132014-04-10 14:09:31 -0700739#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740#ifdef CONFIG_CHR_DEV_SG
741 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .procname = "sg-big-buff",
743 .data = &sg_big_buff,
744 .maxlen = sizeof (int),
745 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800746 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 },
748#endif
749#ifdef CONFIG_BSD_PROCESS_ACCT
750 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 .procname = "acct",
752 .data = &acct_parm,
753 .maxlen = 3*sizeof(int),
754 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800755 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 },
757#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758#ifdef CONFIG_MAGIC_SYSRQ
759 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800761 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 .maxlen = sizeof (int),
763 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700764 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 },
766#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700767#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700770 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 .maxlen = sizeof (int),
772 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700775#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700778 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .maxlen = sizeof(int),
780 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700781 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 },
783 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .procname = "random",
785 .mode = 0555,
786 .child = random_table,
787 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 {
Eric Paris17f60a72011-04-01 17:07:50 -0400789 .procname = "usermodehelper",
790 .mode = 0555,
791 .child = usermodehelper_table,
792 },
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .procname = "overflowuid",
795 .data = &overflowuid,
796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .extra1 = &minolduid,
800 .extra2 = &maxolduid,
801 },
802 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 .procname = "overflowgid",
804 .data = &overflowgid,
805 .maxlen = sizeof(int),
806 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800807 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .extra1 = &minolduid,
809 .extra2 = &maxolduid,
810 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800811#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812#ifdef CONFIG_MATHEMU
813 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 .procname = "ieee_emulation_warnings",
815 .data = &sysctl_ieee_emulation_warnings,
816 .maxlen = sizeof(int),
817 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800818 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 },
820#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200823 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 .maxlen = sizeof(int),
825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 },
828#endif
829 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .procname = "pid_max",
831 .data = &pid_max,
832 .maxlen = sizeof (int),
833 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800834 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 .extra1 = &pid_max_min,
836 .extra2 = &pid_max_max,
837 },
838 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 .procname = "panic_on_oops",
840 .data = &panic_on_oops,
841 .maxlen = sizeof(int),
842 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800843 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800845#if defined CONFIG_PRINTK
846 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800847 .procname = "printk",
848 .data = &console_loglevel,
849 .maxlen = 4*sizeof(int),
850 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800851 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800852 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700855 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 .maxlen = sizeof(int),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 },
860 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700862 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 .maxlen = sizeof(int),
864 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800865 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 },
Dave Youngaf913222009-09-22 16:43:33 -0700867 {
Dave Youngaf913222009-09-22 16:43:33 -0700868 .procname = "printk_delay",
869 .data = &printk_delay_msec,
870 .maxlen = sizeof(int),
871 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800872 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700873 .extra1 = &zero,
874 .extra2 = &ten_thousand,
875 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700877 .procname = "printk_devkmsg",
878 .data = devkmsg_log_str,
879 .maxlen = DEVKMSG_STR_MAX_SIZE,
880 .mode = 0644,
881 .proc_handler = devkmsg_sysctl_set_loglvl,
882 },
883 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800884 .procname = "dmesg_restrict",
885 .data = &dmesg_restrict,
886 .maxlen = sizeof(int),
887 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700888 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800889 .extra1 = &zero,
890 .extra2 = &one,
891 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800892 {
893 .procname = "kptr_restrict",
894 .data = &kptr_restrict,
895 .maxlen = sizeof(int),
896 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700897 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800898 .extra1 = &zero,
899 .extra2 = &two,
900 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800901#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800902 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 .procname = "ngroups_max",
904 .data = &ngroups_max,
905 .maxlen = sizeof (int),
906 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800907 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 },
Dan Ballard73efc032011-10-31 17:11:20 -0700909 {
910 .procname = "cap_last_cap",
911 .data = (void *)&cap_last_cap,
912 .maxlen = sizeof(int),
913 .mode = 0444,
914 .proc_handler = proc_dointvec,
915 },
Don Zickus58687ac2010-05-07 17:11:44 -0400916#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500917 {
Don Zickus58687ac2010-05-07 17:11:44 -0400918 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200919 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500920 .maxlen = sizeof (int),
921 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700922 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700923 .extra1 = &zero,
924 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400925 },
926 {
927 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700928 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400929 .maxlen = sizeof(int),
930 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700931 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800932 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400933 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500934 },
Don Zickus2508ce12010-05-07 17:11:46 -0400935 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700936 .procname = "nmi_watchdog",
937 .data = &nmi_watchdog_enabled,
938 .maxlen = sizeof (int),
939 .mode = 0644,
940 .proc_handler = proc_nmi_watchdog,
941 .extra1 = &zero,
942#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
943 .extra2 = &one,
944#else
945 .extra2 = &zero,
946#endif
947 },
948 {
949 .procname = "soft_watchdog",
950 .data = &soft_watchdog_enabled,
951 .maxlen = sizeof (int),
952 .mode = 0644,
953 .proc_handler = proc_soft_watchdog,
954 .extra1 = &zero,
955 .extra2 = &one,
956 },
957 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700958 .procname = "watchdog_cpumask",
959 .data = &watchdog_cpumask_bits,
960 .maxlen = NR_CPUS,
961 .mode = 0644,
962 .proc_handler = proc_watchdog_cpumask,
963 },
964 {
Don Zickus2508ce12010-05-07 17:11:46 -0400965 .procname = "softlockup_panic",
966 .data = &softlockup_panic,
967 .maxlen = sizeof(int),
968 .mode = 0644,
969 .proc_handler = proc_dointvec_minmax,
970 .extra1 = &zero,
971 .extra2 = &one,
972 },
Don Zickusac1f5912015-11-05 18:44:44 -0800973#ifdef CONFIG_HARDLOCKUP_DETECTOR
974 {
975 .procname = "hardlockup_panic",
976 .data = &hardlockup_panic,
977 .maxlen = sizeof(int),
978 .mode = 0644,
979 .proc_handler = proc_dointvec_minmax,
980 .extra1 = &zero,
981 .extra2 = &one,
982 },
983#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700984#ifdef CONFIG_SMP
985 {
986 .procname = "softlockup_all_cpu_backtrace",
987 .data = &sysctl_softlockup_all_cpu_backtrace,
988 .maxlen = sizeof(int),
989 .mode = 0644,
990 .proc_handler = proc_dointvec_minmax,
991 .extra1 = &zero,
992 .extra2 = &one,
993 },
Jiri Kosina55537872015-11-05 18:44:41 -0800994 {
995 .procname = "hardlockup_all_cpu_backtrace",
996 .data = &sysctl_hardlockup_all_cpu_backtrace,
997 .maxlen = sizeof(int),
998 .mode = 0644,
999 .proc_handler = proc_dointvec_minmax,
1000 .extra1 = &zero,
1001 .extra2 = &one,
1002 },
Aaron Tomlined235872014-06-23 13:22:05 -07001003#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -05001004#endif
1005#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1006 {
1007 .procname = "unknown_nmi_panic",
1008 .data = &unknown_nmi_panic,
1009 .maxlen = sizeof (int),
1010 .mode = 0644,
1011 .proc_handler = proc_dointvec,
1012 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001013#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014#if defined(CONFIG_X86)
1015 {
Don Zickus8da5add2006-09-26 10:52:27 +02001016 .procname = "panic_on_unrecovered_nmi",
1017 .data = &panic_on_unrecovered_nmi,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001020 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001021 },
1022 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001023 .procname = "panic_on_io_nmi",
1024 .data = &panic_on_io_nmi,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001027 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001028 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001029#ifdef CONFIG_DEBUG_STACKOVERFLOW
1030 {
1031 .procname = "panic_on_stackoverflow",
1032 .data = &sysctl_panic_on_stackoverflow,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
1035 .proc_handler = proc_dointvec,
1036 },
1037#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001038 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .procname = "bootloader_type",
1040 .data = &bootloader_type,
1041 .maxlen = sizeof (int),
1042 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001043 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001045 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001046 .procname = "bootloader_version",
1047 .data = &bootloader_version,
1048 .maxlen = sizeof (int),
1049 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001050 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001051 },
1052 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001053 .procname = "kstack_depth_to_print",
1054 .data = &kstack_depth_to_print,
1055 .maxlen = sizeof(int),
1056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001058 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001059 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001060 .procname = "io_delay_type",
1061 .data = &io_delay_type,
1062 .maxlen = sizeof(int),
1063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001065 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001067#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 .procname = "randomize_va_space",
1070 .data = &randomize_va_space,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001073 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001075#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001076#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001077 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001078 .procname = "spin_retry",
1079 .data = &spin_retry,
1080 .maxlen = sizeof (int),
1081 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001082 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001083 },
1084#endif
Len Brown673d5b42007-07-28 03:33:16 -04001085#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001086 {
Pavel Machekc255d842006-02-20 18:27:58 -08001087 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001088 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001089 .maxlen = sizeof (unsigned long),
1090 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001091 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001092 },
1093#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301094#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001095 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001096 .procname = "ignore-unaligned-usertrap",
1097 .data = &no_unaligned_warning,
1098 .maxlen = sizeof (int),
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001101 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301102#endif
1103#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001104 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001105 .procname = "unaligned-dump-stack",
1106 .data = &unaligned_dump_stack,
1107 .maxlen = sizeof (int),
1108 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001109 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001110 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001111#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001112#ifdef CONFIG_DETECT_HUNG_TASK
1113 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001114 .procname = "hung_task_panic",
1115 .data = &sysctl_hung_task_panic,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001118 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001119 .extra1 = &zero,
1120 .extra2 = &one,
1121 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001122 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001123 .procname = "hung_task_check_count",
1124 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001125 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001126 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001127 .proc_handler = proc_dointvec_minmax,
1128 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001129 },
1130 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001131 .procname = "hung_task_timeout_secs",
1132 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001133 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001134 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001135 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001136 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001137 },
1138 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001139 .procname = "hung_task_warnings",
1140 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001141 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001142 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001143 .proc_handler = proc_dointvec_minmax,
1144 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001145 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001146#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001147#ifdef CONFIG_RT_MUTEXES
1148 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001149 .procname = "max_lock_depth",
1150 .data = &max_lock_depth,
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001153 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001154 },
1155#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001156 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001157 .procname = "poweroff_cmd",
1158 .data = &poweroff_cmd,
1159 .maxlen = POWEROFF_CMD_PATH_LEN,
1160 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001161 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001162 },
David Howells0b77f5b2008-04-29 01:01:32 -07001163#ifdef CONFIG_KEYS
1164 {
David Howells0b77f5b2008-04-29 01:01:32 -07001165 .procname = "keys",
1166 .mode = 0555,
1167 .child = key_sysctls,
1168 },
1169#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001170#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001171 /*
1172 * User-space scripts rely on the existence of this file
1173 * as a feature check for perf_events being enabled.
1174 *
1175 * So it's an ABI, do not remove!
1176 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001177 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001178 .procname = "perf_event_paranoid",
1179 .data = &sysctl_perf_event_paranoid,
1180 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001181 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001182 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001183 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001184 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001185 .procname = "perf_event_mlock_kb",
1186 .data = &sysctl_perf_event_mlock,
1187 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001189 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001190 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001191 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001192 .procname = "perf_event_max_sample_rate",
1193 .data = &sysctl_perf_event_sample_rate,
1194 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001195 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001196 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001197 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001198 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001199 {
1200 .procname = "perf_cpu_time_max_percent",
1201 .data = &sysctl_perf_cpu_time_max_percent,
1202 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1203 .mode = 0644,
1204 .proc_handler = perf_cpu_time_max_percent_handler,
1205 .extra1 = &zero,
1206 .extra2 = &one_hundred,
1207 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001208 {
1209 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001210 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001211 .maxlen = sizeof(sysctl_perf_event_max_stack),
1212 .mode = 0644,
1213 .proc_handler = perf_event_max_stack_handler,
1214 .extra1 = &zero,
1215 .extra2 = &six_hundred_forty_kb,
1216 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001217 {
1218 .procname = "perf_event_max_contexts_per_stack",
1219 .data = &sysctl_perf_event_max_contexts_per_stack,
1220 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1221 .mode = 0644,
1222 .proc_handler = perf_event_max_stack_handler,
1223 .extra1 = &zero,
1224 .extra2 = &one_thousand,
1225 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001226#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001227#ifdef CONFIG_KMEMCHECK
1228 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001229 .procname = "kmemcheck",
1230 .data = &kmemcheck_enabled,
1231 .maxlen = sizeof(int),
1232 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001233 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001234 },
1235#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001236 {
1237 .procname = "panic_on_warn",
1238 .data = &panic_on_warn,
1239 .maxlen = sizeof(int),
1240 .mode = 0644,
1241 .proc_handler = proc_dointvec_minmax,
1242 .extra1 = &zero,
1243 .extra2 = &one,
1244 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001245#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1246 {
1247 .procname = "timer_migration",
1248 .data = &sysctl_timer_migration,
1249 .maxlen = sizeof(unsigned int),
1250 .mode = 0644,
1251 .proc_handler = timer_migration_handler,
Myungho Jung4c000152017-04-19 15:24:50 -07001252 .extra1 = &zero,
1253 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001254 },
1255#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001256#ifdef CONFIG_BPF_SYSCALL
1257 {
1258 .procname = "unprivileged_bpf_disabled",
1259 .data = &sysctl_unprivileged_bpf_disabled,
1260 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1261 .mode = 0644,
1262 /* only handle a transition from default "0" to "1" */
1263 .proc_handler = proc_dointvec_minmax,
1264 .extra1 = &one,
1265 .extra2 = &one,
1266 },
1267#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001268#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1269 {
1270 .procname = "panic_on_rcu_stall",
1271 .data = &sysctl_panic_on_rcu_stall,
1272 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1273 .mode = 0644,
1274 .proc_handler = proc_dointvec_minmax,
1275 .extra1 = &zero,
1276 .extra2 = &one,
1277 },
1278#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001279 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280};
1281
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001282static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 .procname = "overcommit_memory",
1285 .data = &sysctl_overcommit_memory,
1286 .maxlen = sizeof(sysctl_overcommit_memory),
1287 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001288 .proc_handler = proc_dointvec_minmax,
1289 .extra1 = &zero,
1290 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 },
1292 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001293 .procname = "panic_on_oom",
1294 .data = &sysctl_panic_on_oom,
1295 .maxlen = sizeof(sysctl_panic_on_oom),
1296 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001297 .proc_handler = proc_dointvec_minmax,
1298 .extra1 = &zero,
1299 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001300 },
1301 {
David Rientjesfe071d72007-10-16 23:25:56 -07001302 .procname = "oom_kill_allocating_task",
1303 .data = &sysctl_oom_kill_allocating_task,
1304 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1305 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001306 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001307 },
1308 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001309 .procname = "oom_dump_tasks",
1310 .data = &sysctl_oom_dump_tasks,
1311 .maxlen = sizeof(sysctl_oom_dump_tasks),
1312 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001313 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001314 },
1315 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 .procname = "overcommit_ratio",
1317 .data = &sysctl_overcommit_ratio,
1318 .maxlen = sizeof(sysctl_overcommit_ratio),
1319 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001320 .proc_handler = overcommit_ratio_handler,
1321 },
1322 {
1323 .procname = "overcommit_kbytes",
1324 .data = &sysctl_overcommit_kbytes,
1325 .maxlen = sizeof(sysctl_overcommit_kbytes),
1326 .mode = 0644,
1327 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 },
1329 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 .procname = "page-cluster",
1331 .data = &page_cluster,
1332 .maxlen = sizeof(int),
1333 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001334 .proc_handler = proc_dointvec_minmax,
1335 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 },
1337 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 .procname = "dirty_background_ratio",
1339 .data = &dirty_background_ratio,
1340 .maxlen = sizeof(dirty_background_ratio),
1341 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001342 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 .extra1 = &zero,
1344 .extra2 = &one_hundred,
1345 },
1346 {
David Rientjes2da02992009-01-06 14:39:31 -08001347 .procname = "dirty_background_bytes",
1348 .data = &dirty_background_bytes,
1349 .maxlen = sizeof(dirty_background_bytes),
1350 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001351 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001352 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001353 },
1354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "dirty_ratio",
1356 .data = &vm_dirty_ratio,
1357 .maxlen = sizeof(vm_dirty_ratio),
1358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001359 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 .extra1 = &zero,
1361 .extra2 = &one_hundred,
1362 },
1363 {
David Rientjes2da02992009-01-06 14:39:31 -08001364 .procname = "dirty_bytes",
1365 .data = &vm_dirty_bytes,
1366 .maxlen = sizeof(vm_dirty_bytes),
1367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001368 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001369 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001370 },
1371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001373 .data = &dirty_writeback_interval,
1374 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001376 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 },
1378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001380 .data = &dirty_expire_interval,
1381 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001383 .proc_handler = proc_dointvec_minmax,
1384 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 },
1386 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001387 .procname = "dirtytime_expire_seconds",
1388 .data = &dirtytime_expire_interval,
1389 .maxlen = sizeof(dirty_expire_interval),
1390 .mode = 0644,
1391 .proc_handler = dirtytime_interval_handler,
1392 .extra1 = &zero,
1393 },
1394 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001395 .procname = "nr_pdflush_threads",
1396 .mode = 0444 /* read-only */,
1397 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 },
1399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .procname = "swappiness",
1401 .data = &vm_swappiness,
1402 .maxlen = sizeof(vm_swappiness),
1403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001404 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 .extra1 = &zero,
1406 .extra2 = &one_hundred,
1407 },
1408#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001411 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .maxlen = sizeof(unsigned long),
1413 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001414 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001415 },
1416#ifdef CONFIG_NUMA
1417 {
1418 .procname = "nr_hugepages_mempolicy",
1419 .data = NULL,
1420 .maxlen = sizeof(unsigned long),
1421 .mode = 0644,
1422 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001423 },
1424#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 .procname = "hugetlb_shm_group",
1427 .data = &sysctl_hugetlb_shm_group,
1428 .maxlen = sizeof(gid_t),
1429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001430 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 },
Mel Gorman396faf02007-07-17 04:03:13 -07001432 {
Mel Gorman396faf02007-07-17 04:03:13 -07001433 .procname = "hugepages_treat_as_movable",
1434 .data = &hugepages_treat_as_movable,
1435 .maxlen = sizeof(int),
1436 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001437 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001438 },
Adam Litke54f9f802007-10-16 01:26:20 -07001439 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001440 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001441 .data = NULL,
1442 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001444 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001445 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446#endif
1447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .procname = "lowmem_reserve_ratio",
1449 .data = &sysctl_lowmem_reserve_ratio,
1450 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001452 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 },
1454 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001455 .procname = "drop_caches",
1456 .data = &sysctl_drop_caches,
1457 .maxlen = sizeof(int),
1458 .mode = 0644,
1459 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001460 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001461 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001462 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001463#ifdef CONFIG_COMPACTION
1464 {
1465 .procname = "compact_memory",
1466 .data = &sysctl_compact_memory,
1467 .maxlen = sizeof(int),
1468 .mode = 0200,
1469 .proc_handler = sysctl_compaction_handler,
1470 },
Mel Gorman5e771902010-05-24 14:32:31 -07001471 {
1472 .procname = "extfrag_threshold",
1473 .data = &sysctl_extfrag_threshold,
1474 .maxlen = sizeof(int),
1475 .mode = 0644,
1476 .proc_handler = sysctl_extfrag_handler,
1477 .extra1 = &min_extfrag_threshold,
1478 .extra2 = &max_extfrag_threshold,
1479 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001480 {
1481 .procname = "compact_unevictable_allowed",
1482 .data = &sysctl_compact_unevictable_allowed,
1483 .maxlen = sizeof(int),
1484 .mode = 0644,
1485 .proc_handler = proc_dointvec,
1486 .extra1 = &zero,
1487 .extra2 = &one,
1488 },
Mel Gorman5e771902010-05-24 14:32:31 -07001489
Mel Gorman76ab0f52010-05-24 14:32:28 -07001490#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001491 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 .procname = "min_free_kbytes",
1493 .data = &min_free_kbytes,
1494 .maxlen = sizeof(min_free_kbytes),
1495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001496 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 .extra1 = &zero,
1498 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001499 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001500 .procname = "watermark_scale_factor",
1501 .data = &watermark_scale_factor,
1502 .maxlen = sizeof(watermark_scale_factor),
1503 .mode = 0644,
1504 .proc_handler = watermark_scale_factor_sysctl_handler,
1505 .extra1 = &one,
1506 .extra2 = &one_thousand,
1507 },
1508 {
Rik van Rieldbe0f612011-09-01 15:26:50 -04001509 .procname = "extra_free_kbytes",
1510 .data = &extra_free_kbytes,
1511 .maxlen = sizeof(extra_free_kbytes),
1512 .mode = 0644,
1513 .proc_handler = min_free_kbytes_sysctl_handler,
1514 .extra1 = &zero,
1515 },
1516 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001517 .procname = "percpu_pagelist_fraction",
1518 .data = &percpu_pagelist_fraction,
1519 .maxlen = sizeof(percpu_pagelist_fraction),
1520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001521 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001522 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001523 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524#ifdef CONFIG_MMU
1525 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 .procname = "max_map_count",
1527 .data = &sysctl_max_map_count,
1528 .maxlen = sizeof(sysctl_max_map_count),
1529 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001530 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001531 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001533#else
1534 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001535 .procname = "nr_trim_pages",
1536 .data = &sysctl_nr_trim_pages,
1537 .maxlen = sizeof(sysctl_nr_trim_pages),
1538 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001539 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001540 .extra1 = &zero,
1541 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542#endif
1543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 .procname = "laptop_mode",
1545 .data = &laptop_mode,
1546 .maxlen = sizeof(laptop_mode),
1547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001548 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 },
1550 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 .procname = "block_dump",
1552 .data = &block_dump,
1553 .maxlen = sizeof(block_dump),
1554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001555 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 .extra1 = &zero,
1557 },
1558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 .procname = "vfs_cache_pressure",
1560 .data = &sysctl_vfs_cache_pressure,
1561 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001563 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 .extra1 = &zero,
1565 },
1566#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1567 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 .procname = "legacy_va_layout",
1569 .data = &sysctl_legacy_va_layout,
1570 .maxlen = sizeof(sysctl_legacy_va_layout),
1571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001572 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 .extra1 = &zero,
1574 },
1575#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001576#ifdef CONFIG_NUMA
1577 {
Christoph Lameter17436602006-01-18 17:42:32 -08001578 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001579 .data = &node_reclaim_mode,
1580 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001582 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001583 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001584 },
Christoph Lameter96146342006-07-03 00:24:13 -07001585 {
Christoph Lameter96146342006-07-03 00:24:13 -07001586 .procname = "min_unmapped_ratio",
1587 .data = &sysctl_min_unmapped_ratio,
1588 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001590 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001591 .extra1 = &zero,
1592 .extra2 = &one_hundred,
1593 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001594 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001595 .procname = "min_slab_ratio",
1596 .data = &sysctl_min_slab_ratio,
1597 .maxlen = sizeof(sysctl_min_slab_ratio),
1598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001599 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001600 .extra1 = &zero,
1601 .extra2 = &one_hundred,
1602 },
Christoph Lameter17436602006-01-18 17:42:32 -08001603#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001604#ifdef CONFIG_SMP
1605 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001606 .procname = "stat_interval",
1607 .data = &sysctl_stat_interval,
1608 .maxlen = sizeof(sysctl_stat_interval),
1609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001610 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001611 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001612 {
1613 .procname = "stat_refresh",
1614 .data = NULL,
1615 .maxlen = 0,
1616 .mode = 0600,
1617 .proc_handler = vmstat_refresh,
1618 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001619#endif
David Howells6e141542009-12-15 19:27:45 +00001620#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001621 {
Eric Parised032182007-06-28 15:55:21 -04001622 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001623 .data = &dac_mmap_min_addr,
1624 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001626 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001627 },
David Howells6e141542009-12-15 19:27:45 +00001628#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001629#ifdef CONFIG_NUMA
1630 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001631 .procname = "numa_zonelist_order",
1632 .data = &numa_zonelist_order,
1633 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001635 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001636 },
1637#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001638#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001639 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001640 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001641 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001642#ifdef CONFIG_X86_32
1643 .data = &vdso32_enabled,
1644 .maxlen = sizeof(vdso32_enabled),
1645#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001646 .data = &vdso_enabled,
1647 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001648#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001649 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001650 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001651 .extra1 = &zero,
1652 },
1653#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001654#ifdef CONFIG_HIGHMEM
1655 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001656 .procname = "highmem_is_dirtyable",
1657 .data = &vm_highmem_is_dirtyable,
1658 .maxlen = sizeof(vm_highmem_is_dirtyable),
1659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001660 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001661 .extra1 = &zero,
1662 .extra2 = &one,
1663 },
1664#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001665#ifdef CONFIG_MEMORY_FAILURE
1666 {
Andi Kleen6a460792009-09-16 11:50:15 +02001667 .procname = "memory_failure_early_kill",
1668 .data = &sysctl_memory_failure_early_kill,
1669 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001671 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001672 .extra1 = &zero,
1673 .extra2 = &one,
1674 },
1675 {
Andi Kleen6a460792009-09-16 11:50:15 +02001676 .procname = "memory_failure_recovery",
1677 .data = &sysctl_memory_failure_recovery,
1678 .maxlen = sizeof(sysctl_memory_failure_recovery),
1679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001680 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001681 .extra1 = &zero,
1682 .extra2 = &one,
1683 },
1684#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001685 {
1686 .procname = "user_reserve_kbytes",
1687 .data = &sysctl_user_reserve_kbytes,
1688 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1689 .mode = 0644,
1690 .proc_handler = proc_doulongvec_minmax,
1691 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001692 {
1693 .procname = "admin_reserve_kbytes",
1694 .data = &sysctl_admin_reserve_kbytes,
1695 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1696 .mode = 0644,
1697 .proc_handler = proc_doulongvec_minmax,
1698 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001699#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1700 {
1701 .procname = "mmap_rnd_bits",
1702 .data = &mmap_rnd_bits,
1703 .maxlen = sizeof(mmap_rnd_bits),
1704 .mode = 0600,
1705 .proc_handler = proc_dointvec_minmax,
1706 .extra1 = (void *)&mmap_rnd_bits_min,
1707 .extra2 = (void *)&mmap_rnd_bits_max,
1708 },
1709#endif
1710#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1711 {
1712 .procname = "mmap_rnd_compat_bits",
1713 .data = &mmap_rnd_compat_bits,
1714 .maxlen = sizeof(mmap_rnd_compat_bits),
1715 .mode = 0600,
1716 .proc_handler = proc_dointvec_minmax,
1717 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1718 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1719 },
1720#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001721 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722};
1723
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001724static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 .procname = "inode-nr",
1727 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001728 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001730 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 },
1732 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 .procname = "inode-state",
1734 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001735 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001737 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 },
1739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 .procname = "file-nr",
1741 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001742 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001744 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 },
1746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 .procname = "file-max",
1748 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001749 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001751 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 },
1753 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001754 .procname = "nr_open",
1755 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001756 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001758 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001759 .extra1 = &sysctl_nr_open_min,
1760 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001761 },
1762 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 .procname = "dentry-state",
1764 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001765 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001767 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 },
1769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 .procname = "overflowuid",
1771 .data = &fs_overflowuid,
1772 .maxlen = sizeof(int),
1773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001774 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 .extra1 = &minolduid,
1776 .extra2 = &maxolduid,
1777 },
1778 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 .procname = "overflowgid",
1780 .data = &fs_overflowgid,
1781 .maxlen = sizeof(int),
1782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001783 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 .extra1 = &minolduid,
1785 .extra2 = &maxolduid,
1786 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001787#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 .procname = "leases-enable",
1790 .data = &leases_enable,
1791 .maxlen = sizeof(int),
1792 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001793 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001795#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796#ifdef CONFIG_DNOTIFY
1797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 .procname = "dir-notify-enable",
1799 .data = &dir_notify_enable,
1800 .maxlen = sizeof(int),
1801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001802 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 },
1804#endif
1805#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001806#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 .procname = "lease-break-time",
1809 .data = &lease_break_time,
1810 .maxlen = sizeof(int),
1811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001812 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001814#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001815#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 .procname = "aio-nr",
1818 .data = &aio_nr,
1819 .maxlen = sizeof(aio_nr),
1820 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001821 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 },
1823 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 .procname = "aio-max-nr",
1825 .data = &aio_max_nr,
1826 .maxlen = sizeof(aio_max_nr),
1827 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001828 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001830#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001831#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001832 {
Robert Love0399cb02005-07-13 12:38:18 -04001833 .procname = "inotify",
1834 .mode = 0555,
1835 .child = inotify_table,
1836 },
1837#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001838#ifdef CONFIG_EPOLL
1839 {
1840 .procname = "epoll",
1841 .mode = 0555,
1842 .child = epoll_table,
1843 },
1844#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001846 {
Kees Cook800179c2012-07-25 17:29:07 -07001847 .procname = "protected_symlinks",
1848 .data = &sysctl_protected_symlinks,
1849 .maxlen = sizeof(int),
1850 .mode = 0600,
1851 .proc_handler = proc_dointvec_minmax,
1852 .extra1 = &zero,
1853 .extra2 = &one,
1854 },
1855 {
1856 .procname = "protected_hardlinks",
1857 .data = &sysctl_protected_hardlinks,
1858 .maxlen = sizeof(int),
1859 .mode = 0600,
1860 .proc_handler = proc_dointvec_minmax,
1861 .extra1 = &zero,
1862 .extra2 = &one,
1863 },
1864 {
Alan Coxd6e71142005-06-23 00:09:43 -07001865 .procname = "suid_dumpable",
1866 .data = &suid_dumpable,
1867 .maxlen = sizeof(int),
1868 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001869 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001870 .extra1 = &zero,
1871 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001872 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001873#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1874 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001875 .procname = "binfmt_misc",
1876 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001877 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001878 },
1879#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001880 {
Jens Axboeff9da692010-06-03 14:54:39 +02001881 .procname = "pipe-max-size",
1882 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001883 .maxlen = sizeof(int),
1884 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001885 .proc_handler = &pipe_proc_fn,
1886 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001887 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001888 {
1889 .procname = "pipe-user-pages-hard",
1890 .data = &pipe_user_pages_hard,
1891 .maxlen = sizeof(pipe_user_pages_hard),
1892 .mode = 0644,
1893 .proc_handler = proc_doulongvec_minmax,
1894 },
1895 {
1896 .procname = "pipe-user-pages-soft",
1897 .data = &pipe_user_pages_soft,
1898 .maxlen = sizeof(pipe_user_pages_soft),
1899 .mode = 0644,
1900 .proc_handler = proc_doulongvec_minmax,
1901 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001902 {
1903 .procname = "mount-max",
1904 .data = &sysctl_mount_max,
1905 .maxlen = sizeof(unsigned int),
1906 .mode = 0644,
1907 .proc_handler = proc_dointvec_minmax,
1908 .extra1 = &one,
1909 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001910 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911};
1912
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001913static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001914#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001915 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001916 .procname = "exception-trace",
1917 .data = &show_unhandled_signals,
1918 .maxlen = sizeof(int),
1919 .mode = 0644,
1920 .proc_handler = proc_dointvec
1921 },
1922#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001923#if defined(CONFIG_OPTPROBES)
1924 {
1925 .procname = "kprobes-optimization",
1926 .data = &sysctl_kprobes_optimization,
1927 .maxlen = sizeof(int),
1928 .mode = 0644,
1929 .proc_handler = proc_kprobes_optimization_handler,
1930 .extra1 = &zero,
1931 .extra2 = &one,
1932 },
1933#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001934 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935};
1936
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001937static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001938 { }
Robert Love0eeca282005-07-12 17:06:03 -04001939};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001941int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001942{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001943 struct ctl_table_header *hdr;
1944
1945 hdr = register_sysctl_table(sysctl_base_table);
1946 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001947 return 0;
1948}
1949
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001950#endif /* CONFIG_SYSCTL */
1951
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952/*
1953 * /proc/sys support
1954 */
1955
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001956#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Kees Cookf8808302014-06-06 14:37:17 -07001958static int _proc_do_string(char *data, int maxlen, int write,
1959 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001960 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001961{
1962 size_t len;
1963 char __user *p;
1964 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001965
1966 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001967 *lenp = 0;
1968 return 0;
1969 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001970
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001971 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001972 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1973 /* Only continue writes not past the end of buffer. */
1974 len = strlen(data);
1975 if (len > maxlen - 1)
1976 len = maxlen - 1;
1977
1978 if (*ppos > len)
1979 return 0;
1980 len = *ppos;
1981 } else {
1982 /* Start writing from beginning of buffer. */
1983 len = 0;
1984 }
1985
Kees Cook2ca9bb42014-06-06 14:37:18 -07001986 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001987 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001988 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001989 if (get_user(c, p++))
1990 return -EFAULT;
1991 if (c == 0 || c == '\n')
1992 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001993 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001994 }
Kees Cookf8808302014-06-06 14:37:17 -07001995 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001996 } else {
1997 len = strlen(data);
1998 if (len > maxlen)
1999 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002000
2001 if (*ppos > len) {
2002 *lenp = 0;
2003 return 0;
2004 }
2005
2006 data += *ppos;
2007 len -= *ppos;
2008
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002009 if (len > *lenp)
2010 len = *lenp;
2011 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002012 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002013 return -EFAULT;
2014 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002015 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002016 return -EFAULT;
2017 len++;
2018 }
2019 *lenp = len;
2020 *ppos += len;
2021 }
2022 return 0;
2023}
2024
Kees Cookf4aacea2014-06-06 14:37:19 -07002025static void warn_sysctl_write(struct ctl_table *table)
2026{
2027 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2028 "This will not be supported in the future. To silence this\n"
2029 "warning, set kernel.sysctl_writes_strict = -1\n",
2030 current->comm, table->procname);
2031}
2032
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033/**
2034 * proc_dostring - read a string sysctl
2035 * @table: the sysctl table
2036 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 * @buffer: the user buffer
2038 * @lenp: the size of the user buffer
2039 * @ppos: file position
2040 *
2041 * Reads/writes a string from/to the user buffer. If the kernel
2042 * buffer provided is not large enough to hold the string, the
2043 * string is truncated. The copied string is %NULL-terminated.
2044 * If the string is being read by the user process, it is copied
2045 * and a newline '\n' is added. It is truncated if the buffer is
2046 * not large enough.
2047 *
2048 * Returns 0 on success.
2049 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002050int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 void __user *buffer, size_t *lenp, loff_t *ppos)
2052{
Kees Cookf4aacea2014-06-06 14:37:19 -07002053 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
2054 warn_sysctl_write(table);
2055
Kees Cookf8808302014-06-06 14:37:17 -07002056 return _proc_do_string((char *)(table->data), table->maxlen, write,
2057 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058}
2059
Amerigo Wang00b7c332010-05-05 00:26:45 +00002060static size_t proc_skip_spaces(char **buf)
2061{
2062 size_t ret;
2063 char *tmp = skip_spaces(*buf);
2064 ret = tmp - *buf;
2065 *buf = tmp;
2066 return ret;
2067}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002069static void proc_skip_char(char **buf, size_t *size, const char v)
2070{
2071 while (*size) {
2072 if (**buf != v)
2073 break;
2074 (*size)--;
2075 (*buf)++;
2076 }
2077}
2078
Amerigo Wang00b7c332010-05-05 00:26:45 +00002079#define TMPBUFLEN 22
2080/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002081 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002082 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002083 * @buf: a kernel buffer
2084 * @size: size of the kernel buffer
2085 * @val: this is where the number will be stored
2086 * @neg: set to %TRUE if number is negative
2087 * @perm_tr: a vector which contains the allowed trailers
2088 * @perm_tr_len: size of the perm_tr vector
2089 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002090 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002091 * In case of success %0 is returned and @buf and @size are updated with
2092 * the amount of bytes read. If @tr is non-NULL and a trailing
2093 * character exists (size is non-zero after returning from this
2094 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002095 */
2096static int proc_get_long(char **buf, size_t *size,
2097 unsigned long *val, bool *neg,
2098 const char *perm_tr, unsigned perm_tr_len, char *tr)
2099{
2100 int len;
2101 char *p, tmp[TMPBUFLEN];
2102
2103 if (!*size)
2104 return -EINVAL;
2105
2106 len = *size;
2107 if (len > TMPBUFLEN - 1)
2108 len = TMPBUFLEN - 1;
2109
2110 memcpy(tmp, *buf, len);
2111
2112 tmp[len] = 0;
2113 p = tmp;
2114 if (*p == '-' && *size > 1) {
2115 *neg = true;
2116 p++;
2117 } else
2118 *neg = false;
2119 if (!isdigit(*p))
2120 return -EINVAL;
2121
2122 *val = simple_strtoul(p, &p, 0);
2123
2124 len = p - tmp;
2125
2126 /* We don't know if the next char is whitespace thus we may accept
2127 * invalid integers (e.g. 1234...a) or two integers instead of one
2128 * (e.g. 123...1). So lets not allow such large numbers. */
2129 if (len == TMPBUFLEN - 1)
2130 return -EINVAL;
2131
2132 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2133 return -EINVAL;
2134
2135 if (tr && (len < *size))
2136 *tr = *p;
2137
2138 *buf += len;
2139 *size -= len;
2140
2141 return 0;
2142}
2143
2144/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002145 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002146 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002147 * @buf: the user buffer
2148 * @size: the size of the user buffer
2149 * @val: the integer to be converted
2150 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002151 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002152 * In case of success %0 is returned and @buf and @size are updated with
2153 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002154 */
2155static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2156 bool neg)
2157{
2158 int len;
2159 char tmp[TMPBUFLEN], *p = tmp;
2160
2161 sprintf(p, "%s%lu", neg ? "-" : "", val);
2162 len = strlen(tmp);
2163 if (len > *size)
2164 len = *size;
2165 if (copy_to_user(*buf, tmp, len))
2166 return -EFAULT;
2167 *size -= len;
2168 *buf += len;
2169 return 0;
2170}
2171#undef TMPBUFLEN
2172
2173static int proc_put_char(void __user **buf, size_t *size, char c)
2174{
2175 if (*size) {
2176 char __user **buffer = (char __user **)buf;
2177 if (put_user(c, *buffer))
2178 return -EFAULT;
2179 (*size)--, (*buffer)++;
2180 *buf = *buffer;
2181 }
2182 return 0;
2183}
2184
2185static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 int *valp,
2187 int write, void *data)
2188{
2189 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002190 if (*negp) {
2191 if (*lvalp > (unsigned long) INT_MAX + 1)
2192 return -EINVAL;
2193 *valp = -*lvalp;
2194 } else {
2195 if (*lvalp > (unsigned long) INT_MAX)
2196 return -EINVAL;
2197 *valp = *lvalp;
2198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 } else {
2200 int val = *valp;
2201 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002202 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002203 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002205 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 *lvalp = (unsigned long)val;
2207 }
2208 }
2209 return 0;
2210}
2211
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002212static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2213 int *valp,
2214 int write, void *data)
2215{
2216 if (write) {
2217 if (*negp)
2218 return -EINVAL;
Liping Zhang7bdacd32017-04-07 23:51:07 +08002219 if (*lvalp > UINT_MAX)
2220 return -EINVAL;
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002221 *valp = *lvalp;
2222 } else {
2223 unsigned int val = *valp;
Liping Zhang3a20c572017-04-07 23:51:06 +08002224 *negp = false;
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002225 *lvalp = (unsigned long)val;
2226 }
2227 return 0;
2228}
2229
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2231
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002232static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002233 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002234 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002235 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 int write, void *data),
2237 void *data)
2238{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002240 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002241 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Amerigo Wang00b7c332010-05-05 00:26:45 +00002243 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 *lenp = 0;
2245 return 0;
2246 }
2247
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002248 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 vleft = table->maxlen / sizeof(*i);
2250 left = *lenp;
2251
2252 if (!conv)
2253 conv = do_proc_dointvec_conv;
2254
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002256 if (*ppos) {
2257 switch (sysctl_writes_strict) {
2258 case SYSCTL_WRITES_STRICT:
2259 goto out;
2260 case SYSCTL_WRITES_WARN:
2261 warn_sysctl_write(table);
2262 break;
2263 default:
2264 break;
2265 }
2266 }
2267
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 if (left > PAGE_SIZE - 1)
2269 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002270 p = kbuf = memdup_user_nul(buffer, left);
2271 if (IS_ERR(kbuf))
2272 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 }
2274
2275 for (; left && vleft--; i++, first=0) {
2276 unsigned long lval;
2277 bool neg;
2278
2279 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002280 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281
J. R. Okajima563b0462010-05-25 16:10:14 -07002282 if (!left)
2283 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002284 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002285 proc_wspace_sep,
2286 sizeof(proc_wspace_sep), NULL);
2287 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002289 if (conv(&neg, &lval, i, 1, data)) {
2290 err = -EINVAL;
2291 break;
2292 }
2293 } else {
2294 if (conv(&neg, &lval, i, 0, data)) {
2295 err = -EINVAL;
2296 break;
2297 }
2298 if (!first)
2299 err = proc_put_char(&buffer, &left, '\t');
2300 if (err)
2301 break;
2302 err = proc_put_long(&buffer, &left, lval, neg);
2303 if (err)
2304 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 }
2306 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307
2308 if (!write && !first && left && !err)
2309 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002310 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002311 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002312 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002313 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002314 if (first)
2315 return err ? : -EINVAL;
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002318out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002320 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002323static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002324 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002326 int write, void *data),
2327 void *data)
2328{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002329 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002330 buffer, lenp, ppos, conv, data);
2331}
2332
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333/**
2334 * proc_dointvec - read a vector of integers
2335 * @table: the sysctl table
2336 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 * @buffer: the user buffer
2338 * @lenp: the size of the user buffer
2339 * @ppos: file position
2340 *
2341 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2342 * values from/to the user buffer, treated as an ASCII string.
2343 *
2344 * Returns 0 on success.
2345 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002346int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 void __user *buffer, size_t *lenp, loff_t *ppos)
2348{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002349 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2350}
2351
2352/**
2353 * proc_douintvec - read a vector of unsigned integers
2354 * @table: the sysctl table
2355 * @write: %TRUE if this is a write to the sysctl file
2356 * @buffer: the user buffer
2357 * @lenp: the size of the user buffer
2358 * @ppos: file position
2359 *
2360 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2361 * values from/to the user buffer, treated as an ASCII string.
2362 *
2363 * Returns 0 on success.
2364 */
2365int proc_douintvec(struct ctl_table *table, int write,
2366 void __user *buffer, size_t *lenp, loff_t *ppos)
2367{
2368 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2369 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370}
2371
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002373 * Taint values can only be increased
2374 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002375 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002376static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002377 void __user *buffer, size_t *lenp, loff_t *ppos)
2378{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002379 struct ctl_table t;
2380 unsigned long tmptaint = get_taint();
2381 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002382
Bastian Blank91fcd412007-04-23 14:41:14 -07002383 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002384 return -EPERM;
2385
Andi Kleen25ddbb12008-10-15 22:01:41 -07002386 t = *table;
2387 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002388 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002389 if (err < 0)
2390 return err;
2391
2392 if (write) {
2393 /*
2394 * Poor man's atomic or. Not worth adding a primitive
2395 * to everyone's atomic.h for this
2396 */
2397 int i;
2398 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2399 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302400 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002401 }
2402 }
2403
2404 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002405}
2406
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002407#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002408static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002409 void __user *buffer, size_t *lenp, loff_t *ppos)
2410{
2411 if (write && !capable(CAP_SYS_ADMIN))
2412 return -EPERM;
2413
2414 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2415}
2416#endif
2417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418struct do_proc_dointvec_minmax_conv_param {
2419 int *min;
2420 int *max;
2421};
2422
Amerigo Wang00b7c332010-05-05 00:26:45 +00002423static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2424 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 int write, void *data)
2426{
2427 struct do_proc_dointvec_minmax_conv_param *param = data;
2428 if (write) {
2429 int val = *negp ? -*lvalp : *lvalp;
2430 if ((param->min && *param->min > val) ||
2431 (param->max && *param->max < val))
2432 return -EINVAL;
2433 *valp = val;
2434 } else {
2435 int val = *valp;
2436 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002437 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002438 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002440 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 *lvalp = (unsigned long)val;
2442 }
2443 }
2444 return 0;
2445}
2446
2447/**
2448 * proc_dointvec_minmax - read a vector of integers with min/max values
2449 * @table: the sysctl table
2450 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 * @buffer: the user buffer
2452 * @lenp: the size of the user buffer
2453 * @ppos: file position
2454 *
2455 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2456 * values from/to the user buffer, treated as an ASCII string.
2457 *
2458 * This routine will ensure the values are within the range specified by
2459 * table->extra1 (min) and table->extra2 (max).
2460 *
2461 * Returns 0 on success.
2462 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002463int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 void __user *buffer, size_t *lenp, loff_t *ppos)
2465{
2466 struct do_proc_dointvec_minmax_conv_param param = {
2467 .min = (int *) table->extra1,
2468 .max = (int *) table->extra2,
2469 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002470 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 do_proc_dointvec_minmax_conv, &param);
2472}
2473
Kees Cook54b50192012-07-30 14:39:18 -07002474static void validate_coredump_safety(void)
2475{
Alex Kelly046d6622012-10-04 17:15:23 -07002476#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002477 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002478 core_pattern[0] != '/' && core_pattern[0] != '|') {
2479 printk(KERN_WARNING "Unsafe core_pattern used with "\
2480 "suid_dumpable=2. Pipe handler or fully qualified "\
2481 "core dump path required.\n");
2482 }
Alex Kelly046d6622012-10-04 17:15:23 -07002483#endif
Kees Cook54b50192012-07-30 14:39:18 -07002484}
2485
2486static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2488{
2489 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2490 if (!error)
2491 validate_coredump_safety();
2492 return error;
2493}
2494
Alex Kelly046d6622012-10-04 17:15:23 -07002495#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002496static int proc_dostring_coredump(struct ctl_table *table, int write,
2497 void __user *buffer, size_t *lenp, loff_t *ppos)
2498{
2499 int error = proc_dostring(table, write, buffer, lenp, ppos);
2500 if (!error)
2501 validate_coredump_safety();
2502 return error;
2503}
Alex Kelly046d6622012-10-04 17:15:23 -07002504#endif
Kees Cook54b50192012-07-30 14:39:18 -07002505
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002506static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 void __user *buffer,
2508 size_t *lenp, loff_t *ppos,
2509 unsigned long convmul,
2510 unsigned long convdiv)
2511{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002512 unsigned long *i, *min, *max;
2513 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002514 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002515 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002516
2517 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 *lenp = 0;
2519 return 0;
2520 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002521
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002522 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 min = (unsigned long *) table->extra1;
2524 max = (unsigned long *) table->extra2;
2525 vleft = table->maxlen / sizeof(unsigned long);
2526 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002527
2528 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002529 if (*ppos) {
2530 switch (sysctl_writes_strict) {
2531 case SYSCTL_WRITES_STRICT:
2532 goto out;
2533 case SYSCTL_WRITES_WARN:
2534 warn_sysctl_write(table);
2535 break;
2536 default:
2537 break;
2538 }
2539 }
2540
Amerigo Wang00b7c332010-05-05 00:26:45 +00002541 if (left > PAGE_SIZE - 1)
2542 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002543 p = kbuf = memdup_user_nul(buffer, left);
2544 if (IS_ERR(kbuf))
2545 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002546 }
2547
Eric Dumazet27b3d802010-10-07 12:59:29 -07002548 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002549 unsigned long val;
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002552 bool neg;
2553
Al Viro70f6cbb2015-12-24 00:13:10 -05002554 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002555
Al Viro70f6cbb2015-12-24 00:13:10 -05002556 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002557 proc_wspace_sep,
2558 sizeof(proc_wspace_sep), NULL);
2559 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 break;
2561 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 continue;
Eric Dumazet03707d62017-01-25 18:20:55 -08002563 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 if ((min && val < *min) || (max && val > *max))
2565 continue;
2566 *i = val;
2567 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002568 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002569 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002570 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002571 if (err)
2572 break;
2573 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002574 err = proc_put_long(&buffer, &left, val, false);
2575 if (err)
2576 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 }
2578 }
2579
Amerigo Wang00b7c332010-05-05 00:26:45 +00002580 if (!write && !first && left && !err)
2581 err = proc_put_char(&buffer, &left, '\n');
2582 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002583 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002585 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002586 if (first)
2587 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002590out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002592 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593}
2594
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002595static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002596 void __user *buffer,
2597 size_t *lenp, loff_t *ppos,
2598 unsigned long convmul,
2599 unsigned long convdiv)
2600{
2601 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002602 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002603}
2604
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605/**
2606 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2607 * @table: the sysctl table
2608 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
2611 * @ppos: file position
2612 *
2613 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2614 * values from/to the user buffer, treated as an ASCII string.
2615 *
2616 * This routine will ensure the values are within the range specified by
2617 * table->extra1 (min) and table->extra2 (max).
2618 *
2619 * Returns 0 on success.
2620 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002621int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 void __user *buffer, size_t *lenp, loff_t *ppos)
2623{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002624 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/**
2628 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2629 * @table: the sysctl table
2630 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
2633 * @ppos: file position
2634 *
2635 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2636 * values from/to the user buffer, treated as an ASCII string. The values
2637 * are treated as milliseconds, and converted to jiffies when they are stored.
2638 *
2639 * This routine will ensure the values are within the range specified by
2640 * table->extra1 (min) and table->extra2 (max).
2641 *
2642 * Returns 0 on success.
2643 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002644int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 void __user *buffer,
2646 size_t *lenp, loff_t *ppos)
2647{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002648 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 lenp, ppos, HZ, 1000l);
2650}
2651
2652
Amerigo Wang00b7c332010-05-05 00:26:45 +00002653static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 int *valp,
2655 int write, void *data)
2656{
2657 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002658 if (*lvalp > LONG_MAX / HZ)
2659 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2661 } else {
2662 int val = *valp;
2663 unsigned long lval;
2664 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002665 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002666 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002668 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 lval = (unsigned long)val;
2670 }
2671 *lvalp = lval / HZ;
2672 }
2673 return 0;
2674}
2675
Amerigo Wang00b7c332010-05-05 00:26:45 +00002676static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 int *valp,
2678 int write, void *data)
2679{
2680 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002681 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2682 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2684 } else {
2685 int val = *valp;
2686 unsigned long lval;
2687 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002688 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002689 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002691 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 lval = (unsigned long)val;
2693 }
2694 *lvalp = jiffies_to_clock_t(lval);
2695 }
2696 return 0;
2697}
2698
Amerigo Wang00b7c332010-05-05 00:26:45 +00002699static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 int *valp,
2701 int write, void *data)
2702{
2703 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002704 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2705
2706 if (jif > INT_MAX)
2707 return 1;
2708 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 } else {
2710 int val = *valp;
2711 unsigned long lval;
2712 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002713 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002714 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002716 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 lval = (unsigned long)val;
2718 }
2719 *lvalp = jiffies_to_msecs(lval);
2720 }
2721 return 0;
2722}
2723
2724/**
2725 * proc_dointvec_jiffies - read a vector of integers as seconds
2726 * @table: the sysctl table
2727 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 * @buffer: the user buffer
2729 * @lenp: the size of the user buffer
2730 * @ppos: file position
2731 *
2732 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2733 * values from/to the user buffer, treated as an ASCII string.
2734 * The values read are assumed to be in seconds, and are converted into
2735 * jiffies.
2736 *
2737 * Returns 0 on success.
2738 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002739int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 void __user *buffer, size_t *lenp, loff_t *ppos)
2741{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002742 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 do_proc_dointvec_jiffies_conv,NULL);
2744}
2745
2746/**
2747 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2748 * @table: the sysctl table
2749 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 * @buffer: the user buffer
2751 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002752 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 *
2754 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2755 * values from/to the user buffer, treated as an ASCII string.
2756 * The values read are assumed to be in 1/USER_HZ seconds, and
2757 * are converted into jiffies.
2758 *
2759 * Returns 0 on success.
2760 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002761int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 void __user *buffer, size_t *lenp, loff_t *ppos)
2763{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002764 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 do_proc_dointvec_userhz_jiffies_conv,NULL);
2766}
2767
2768/**
2769 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2770 * @table: the sysctl table
2771 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 * @buffer: the user buffer
2773 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002774 * @ppos: file position
2775 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 *
2777 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2778 * values from/to the user buffer, treated as an ASCII string.
2779 * The values read are assumed to be in 1/1000 seconds, and
2780 * are converted into jiffies.
2781 *
2782 * Returns 0 on success.
2783 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002784int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 void __user *buffer, size_t *lenp, loff_t *ppos)
2786{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002787 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 do_proc_dointvec_ms_jiffies_conv, NULL);
2789}
2790
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002791static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002792 void __user *buffer, size_t *lenp, loff_t *ppos)
2793{
2794 struct pid *new_pid;
2795 pid_t tmp;
2796 int r;
2797
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002798 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002799
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002800 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002801 lenp, ppos, NULL, NULL);
2802 if (r || !write)
2803 return r;
2804
2805 new_pid = find_get_pid(tmp);
2806 if (!new_pid)
2807 return -ESRCH;
2808
2809 put_pid(xchg(&cad_pid, new_pid));
2810 return 0;
2811}
2812
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002813/**
2814 * proc_do_large_bitmap - read/write from/to a large bitmap
2815 * @table: the sysctl table
2816 * @write: %TRUE if this is a write to the sysctl file
2817 * @buffer: the user buffer
2818 * @lenp: the size of the user buffer
2819 * @ppos: file position
2820 *
2821 * The bitmap is stored at table->data and the bitmap length (in bits)
2822 * in table->maxlen.
2823 *
2824 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2825 * large bitmaps may be represented in a compact manner. Writing into
2826 * the file will clear the bitmap then update it with the given input.
2827 *
2828 * Returns 0 on success.
2829 */
2830int proc_do_large_bitmap(struct ctl_table *table, int write,
2831 void __user *buffer, size_t *lenp, loff_t *ppos)
2832{
2833 int err = 0;
2834 bool first = 1;
2835 size_t left = *lenp;
2836 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002837 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002838 unsigned long *tmp_bitmap = NULL;
2839 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2840
WANG Cong122ff242014-05-12 16:04:53 -07002841 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002842 *lenp = 0;
2843 return 0;
2844 }
2845
2846 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002847 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002848
2849 if (left > PAGE_SIZE - 1)
2850 left = PAGE_SIZE - 1;
2851
Al Viro70f6cbb2015-12-24 00:13:10 -05002852 p = kbuf = memdup_user_nul(buffer, left);
2853 if (IS_ERR(kbuf))
2854 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002855
2856 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2857 GFP_KERNEL);
2858 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002859 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002860 return -ENOMEM;
2861 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002862 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002863 while (!err && left) {
2864 unsigned long val_a, val_b;
2865 bool neg;
2866
Al Viro70f6cbb2015-12-24 00:13:10 -05002867 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002868 sizeof(tr_a), &c);
2869 if (err)
2870 break;
2871 if (val_a >= bitmap_len || neg) {
2872 err = -EINVAL;
2873 break;
2874 }
2875
2876 val_b = val_a;
2877 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002878 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002879 left--;
2880 }
2881
2882 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05002883 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002884 &neg, tr_b, sizeof(tr_b),
2885 &c);
2886 if (err)
2887 break;
2888 if (val_b >= bitmap_len || neg ||
2889 val_a > val_b) {
2890 err = -EINVAL;
2891 break;
2892 }
2893 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002894 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002895 left--;
2896 }
2897 }
2898
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002899 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002900 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05002901 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002902 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002903 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002904 } else {
2905 unsigned long bit_a, bit_b = 0;
2906
2907 while (left) {
2908 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2909 if (bit_a >= bitmap_len)
2910 break;
2911 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2912 bit_a + 1) - 1;
2913
2914 if (!first) {
2915 err = proc_put_char(&buffer, &left, ',');
2916 if (err)
2917 break;
2918 }
2919 err = proc_put_long(&buffer, &left, bit_a, false);
2920 if (err)
2921 break;
2922 if (bit_a != bit_b) {
2923 err = proc_put_char(&buffer, &left, '-');
2924 if (err)
2925 break;
2926 err = proc_put_long(&buffer, &left, bit_b, false);
2927 if (err)
2928 break;
2929 }
2930
2931 first = 0; bit_b++;
2932 }
2933 if (!err)
2934 err = proc_put_char(&buffer, &left, '\n');
2935 }
2936
2937 if (!err) {
2938 if (write) {
2939 if (*ppos)
2940 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2941 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002942 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002943 }
2944 kfree(tmp_bitmap);
2945 *lenp -= left;
2946 *ppos += *lenp;
2947 return 0;
2948 } else {
2949 kfree(tmp_bitmap);
2950 return err;
2951 }
2952}
2953
Jovi Zhang55610502011-01-12 17:00:45 -08002954#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002956int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 void __user *buffer, size_t *lenp, loff_t *ppos)
2958{
2959 return -ENOSYS;
2960}
2961
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002962int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 void __user *buffer, size_t *lenp, loff_t *ppos)
2964{
2965 return -ENOSYS;
2966}
2967
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002968int proc_douintvec(struct ctl_table *table, int write,
2969 void __user *buffer, size_t *lenp, loff_t *ppos)
2970{
2971 return -ENOSYS;
2972}
2973
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002974int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 void __user *buffer, size_t *lenp, loff_t *ppos)
2976{
2977 return -ENOSYS;
2978}
2979
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002980int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 void __user *buffer, size_t *lenp, loff_t *ppos)
2982{
2983 return -ENOSYS;
2984}
2985
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002986int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 void __user *buffer, size_t *lenp, loff_t *ppos)
2988{
2989 return -ENOSYS;
2990}
2991
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002992int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 void __user *buffer, size_t *lenp, loff_t *ppos)
2994{
2995 return -ENOSYS;
2996}
2997
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002998int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 void __user *buffer, size_t *lenp, loff_t *ppos)
3000{
3001 return -ENOSYS;
3002}
3003
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003004int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 void __user *buffer,
3006 size_t *lenp, loff_t *ppos)
3007{
3008 return -ENOSYS;
3009}
3010
3011
Jovi Zhang55610502011-01-12 17:00:45 -08003012#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014/*
3015 * No sense putting this after each symbol definition, twice,
3016 * exception granted :-)
3017 */
3018EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003019EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020EXPORT_SYMBOL(proc_dointvec_jiffies);
3021EXPORT_SYMBOL(proc_dointvec_minmax);
3022EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3023EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3024EXPORT_SYMBOL(proc_dostring);
3025EXPORT_SYMBOL(proc_doulongvec_minmax);
3026EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);