blob: 4a13a389e99b243a5e261d3b3a12b67e2e681c11 [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>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010065#include <linux/sched/coredump.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
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080070#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100110extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300111extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113extern int sysctl_nr_trim_pages;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400117#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int sixty = 60;
119#endif
120
Aaron Tomlin270750db2014-01-20 17:34:13 +0000121static int __maybe_unused neg_one = -1;
122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700126static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800127static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700129static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700130#ifdef CONFIG_PRINTK
131static int ten_thousand = 10000;
132#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300133#ifdef CONFIG_PERF_EVENTS
134static int six_hundred_forty_kb = 640 * 1024;
135#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700136
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700137/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141static int maxolduid = 65535;
142static int minolduid;
143
144static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700145static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Liu Hua80df2842014-04-07 15:38:57 -0700147/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
148#ifdef CONFIG_DETECT_HUNG_TASK
149static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
150#endif
151
Dave Youngd14f1722010-02-25 20:28:57 -0500152#ifdef CONFIG_INOTIFY_USER
153#include <linux/inotify.h>
154#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700155#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#endif
157
158#ifdef __hppa__
159extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530160#endif
161
162#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163extern int unaligned_enabled;
164#endif
165
Jes Sorensend2b176e2006-02-28 09:42:23 -0800166#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800167extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800168#endif
169
Vineet Guptab6fca722013-01-09 20:06:28 +0530170#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
171extern int no_unaligned_warning;
172#endif
173
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700174#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700175
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700176/**
177 * enum sysctl_writes_mode - supported sysctl write modes
178 *
179 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
180 * to be written, and multiple writes on the same sysctl file descriptor
181 * will rewrite the sysctl value, regardless of file position. No warning
182 * is issued when the initial position is not 0.
183 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
184 * not 0.
185 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
186 * file position 0 and the value must be fully contained in the buffer
187 * sent to the write syscall. If dealing with strings respect the file
188 * position, but restrict this to the max length of the buffer, anything
189 * passed the max lenght will be ignored. Multiple writes will append
190 * to the buffer.
191 *
192 * These write modes control how current file position affects the behavior of
193 * updating sysctl values through the proc interface on each write.
194 */
195enum sysctl_writes_mode {
196 SYSCTL_WRITES_LEGACY = -1,
197 SYSCTL_WRITES_WARN = 0,
198 SYSCTL_WRITES_STRICT = 1,
199};
Kees Cookf4aacea2014-06-06 14:37:19 -0700200
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700201static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700202
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700203static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700204 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700205static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800206 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700207#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700208
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700209#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700210static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700211 void __user *buffer, size_t *lenp, loff_t *ppos);
212#endif
213
Kees Cook54b50192012-07-30 14:39:18 -0700214static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
215 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700216#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700217static int proc_dostring_coredump(struct ctl_table *table, int write,
218 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700219#endif
Kees Cook54b50192012-07-30 14:39:18 -0700220
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700221#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800222/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100223static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700224
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700225static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700226 void __user *buffer, size_t *lenp,
227 loff_t *ppos)
228{
229 int error;
230
231 error = proc_dointvec(table, write, buffer, lenp, ppos);
232 if (error)
233 return error;
234
235 if (write)
236 sysrq_toggle_support(__sysrq_enabled);
237
238 return 0;
239}
240
241#endif
242
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700243static struct ctl_table kern_table[];
244static struct ctl_table vm_table[];
245static struct ctl_table fs_table[];
246static struct ctl_table debug_table[];
247static struct ctl_table dev_table[];
248extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800249#ifdef CONFIG_EPOLL
250extern struct ctl_table epoll_table[];
251#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
254int sysctl_legacy_va_layout;
255#endif
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/* The default sysctl tables: */
258
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800259static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .procname = "kernel",
262 .mode = 0555,
263 .child = kern_table,
264 },
265 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 .procname = "vm",
267 .mode = 0555,
268 .child = vm_table,
269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 .procname = "fs",
272 .mode = 0555,
273 .child = fs_table,
274 },
275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 .procname = "debug",
277 .mode = 0555,
278 .child = debug_table,
279 },
280 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 .procname = "dev",
282 .mode = 0555,
283 .child = dev_table,
284 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700285 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286};
287
Ingo Molnar77e54a12007-07-09 18:52:00 +0200288#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100289static int min_sched_granularity_ns = 100000; /* 100 usecs */
290static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
291static int min_wakeup_granularity_ns; /* 0 usecs */
292static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200293#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100294static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
295static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200296#endif /* CONFIG_SMP */
297#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200298
Mel Gorman5e771902010-05-24 14:32:31 -0700299#ifdef CONFIG_COMPACTION
300static int min_extfrag_threshold;
301static int max_extfrag_threshold = 1000;
302#endif
303
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700304static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200305 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200306 .procname = "sched_child_runs_first",
307 .data = &sysctl_sched_child_runs_first,
308 .maxlen = sizeof(unsigned int),
309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800310 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200311 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312#ifdef CONFIG_SCHED_DEBUG
313 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100314 .procname = "sched_min_granularity_ns",
315 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800318 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100319 .extra1 = &min_sched_granularity_ns,
320 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200321 },
322 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200323 .procname = "sched_latency_ns",
324 .data = &sysctl_sched_latency,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800327 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200328 .extra1 = &min_sched_granularity_ns,
329 .extra2 = &max_sched_granularity_ns,
330 },
331 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200332 .procname = "sched_wakeup_granularity_ns",
333 .data = &sysctl_sched_wakeup_granularity,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800336 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200337 .extra1 = &min_wakeup_granularity_ns,
338 .extra2 = &max_wakeup_granularity_ns,
339 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200340#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200341 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100342 .procname = "sched_tunable_scaling",
343 .data = &sysctl_sched_tunable_scaling,
344 .maxlen = sizeof(enum sched_tunable_scaling),
345 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800346 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100347 .extra1 = &min_sched_tunable_scaling,
348 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200349 },
350 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900351 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200352 .data = &sysctl_sched_migration_cost,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800355 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200356 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100357 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100358 .procname = "sched_nr_migrate",
359 .data = &sysctl_sched_nr_migrate,
360 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800362 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100363 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530364 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900365 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200366 .data = &sysctl_sched_time_avg,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
Ethan Zhao5ccba442017-09-04 13:59:34 +0800369 .proc_handler = proc_dointvec_minmax,
370 .extra1 = &one,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200371 },
Mel Gormancb251762016-02-05 09:08:36 +0000372#ifdef CONFIG_SCHEDSTATS
373 {
374 .procname = "sched_schedstats",
375 .data = NULL,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = sysctl_schedstats,
379 .extra1 = &zero,
380 .extra2 = &one,
381 },
382#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200383#endif /* CONFIG_SMP */
384#ifdef CONFIG_NUMA_BALANCING
385 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200386 .procname = "numa_balancing_scan_delay_ms",
387 .data = &sysctl_numa_balancing_scan_delay,
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = proc_dointvec,
391 },
392 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200393 .procname = "numa_balancing_scan_period_min_ms",
394 .data = &sysctl_numa_balancing_scan_period_min,
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
398 },
399 {
400 .procname = "numa_balancing_scan_period_max_ms",
401 .data = &sysctl_numa_balancing_scan_period_max,
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = proc_dointvec,
405 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200406 {
407 .procname = "numa_balancing_scan_size_mb",
408 .data = &sysctl_numa_balancing_scan_size,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400411 .proc_handler = proc_dointvec_minmax,
412 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200413 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100414 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800415 .procname = "numa_balancing",
416 .data = NULL, /* filled in by handler */
417 .maxlen = sizeof(unsigned int),
418 .mode = 0644,
419 .proc_handler = sysctl_numa_balancing,
420 .extra1 = &zero,
421 .extra2 = &one,
422 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200423#endif /* CONFIG_NUMA_BALANCING */
424#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200425 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100426 .procname = "sched_rt_period_us",
427 .data = &sysctl_sched_rt_period,
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800430 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100431 },
432 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100433 .procname = "sched_rt_runtime_us",
434 .data = &sysctl_sched_rt_runtime,
435 .maxlen = sizeof(int),
436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800437 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100438 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600439 {
440 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800441 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = sched_rr_handler,
445 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100446#ifdef CONFIG_SCHED_AUTOGROUP
447 {
448 .procname = "sched_autogroup_enabled",
449 .data = &sysctl_sched_autogroup_enabled,
450 .maxlen = sizeof(unsigned int),
451 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800452 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100453 .extra1 = &zero,
454 .extra2 = &one,
455 },
456#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700457#ifdef CONFIG_CFS_BANDWIDTH
458 {
459 .procname = "sched_cfs_bandwidth_slice_us",
460 .data = &sysctl_sched_cfs_bandwidth_slice,
461 .maxlen = sizeof(unsigned int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec_minmax,
464 .extra1 = &one,
465 },
466#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700467#ifdef CONFIG_PROVE_LOCKING
468 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700469 .procname = "prove_locking",
470 .data = &prove_locking,
471 .maxlen = sizeof(int),
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700474 },
475#endif
476#ifdef CONFIG_LOCK_STAT
477 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700478 .procname = "lock_stat",
479 .data = &lock_stat,
480 .maxlen = sizeof(int),
481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800482 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700483 },
484#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200485 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .procname = "panic",
487 .data = &panic_timeout,
488 .maxlen = sizeof(int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 },
Alex Kelly046d6622012-10-04 17:15:23 -0700492#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "core_uses_pid",
495 .data = &core_uses_pid,
496 .maxlen = sizeof(int),
497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "core_pattern",
502 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700503 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700505 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
Neil Hormana2939802009-09-23 15:56:56 -0700507 {
Neil Hormana2939802009-09-23 15:56:56 -0700508 .procname = "core_pipe_limit",
509 .data = &core_pipe_limit,
510 .maxlen = sizeof(unsigned int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700513 },
Alex Kelly046d6622012-10-04 17:15:23 -0700514#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800515#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700518 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700522 {
523 .procname = "sysctl_writes_strict",
524 .data = &sysctl_writes_strict,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = proc_dointvec_minmax,
528 .extra1 = &neg_one,
529 .extra2 = &one,
530 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800531#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100532#ifdef CONFIG_LATENCYTOP
533 {
534 .procname = "latencytop",
535 .data = &latencytop_enabled,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000538 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100539 },
540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#ifdef CONFIG_BLK_DEV_INITRD
542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 .procname = "real-root-dev",
544 .data = &real_root_dev,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800547 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 },
549#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700550 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700551 .procname = "print-fatal-signals",
552 .data = &print_fatal_signals,
553 .maxlen = sizeof(int),
554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800555 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700556 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700557#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .procname = "reboot-cmd",
560 .data = reboot_command,
561 .maxlen = 256,
562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800563 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 },
565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .procname = "stop-a",
567 .data = &stop_a_enabled,
568 .maxlen = sizeof (int),
569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800570 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 },
572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "scons-poweroff",
574 .data = &scons_pwroff,
575 .maxlen = sizeof (int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
579#endif
David S. Miller08714202008-11-16 23:49:24 -0800580#ifdef CONFIG_SPARC64
581 {
David S. Miller08714202008-11-16 23:49:24 -0800582 .procname = "tsb-ratio",
583 .data = &sysctl_tsb_ratio,
584 .maxlen = sizeof (int),
585 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800586 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800587 },
588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#ifdef __hppa__
590 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .procname = "soft-power",
592 .data = &pwrsw_enabled,
593 .maxlen = sizeof (int),
594 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800595 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530597#endif
598#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .procname = "unaligned-trap",
601 .data = &unaligned_enabled,
602 .maxlen = sizeof (int),
603 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800604 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 },
606#endif
607 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .procname = "ctrl-alt-del",
609 .data = &C_A_D,
610 .maxlen = sizeof(int),
611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800612 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400614#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200615 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200616 .procname = "ftrace_enabled",
617 .data = &ftrace_enabled,
618 .maxlen = sizeof(int),
619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800620 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200621 },
622#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500623#ifdef CONFIG_STACK_TRACER
624 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500625 .procname = "stack_tracer_enabled",
626 .data = &stack_tracer_enabled,
627 .maxlen = sizeof(int),
628 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800629 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500630 },
631#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400632#ifdef CONFIG_TRACING
633 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100634 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400635 .data = &ftrace_dump_on_oops,
636 .maxlen = sizeof(int),
637 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800638 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400639 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400640 {
641 .procname = "traceoff_on_warning",
642 .data = &__disable_trace_on_warning,
643 .maxlen = sizeof(__disable_trace_on_warning),
644 .mode = 0644,
645 .proc_handler = proc_dointvec,
646 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500647 {
648 .procname = "tracepoint_printk",
649 .data = &tracepoint_printk,
650 .maxlen = sizeof(tracepoint_printk),
651 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500652 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500653 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400654#endif
Dave Young2965faa2015-09-09 15:38:55 -0700655#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800656 {
657 .procname = "kexec_load_disabled",
658 .data = &kexec_load_disabled,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 /* only handle a transition from default "0" to "1" */
662 .proc_handler = proc_dointvec_minmax,
663 .extra1 = &one,
664 .extra2 = &one,
665 },
666#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200667#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 .procname = "modprobe",
670 .data = &modprobe_path,
671 .maxlen = KMOD_PATH_LEN,
672 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800673 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 },
Kees Cook3d433212009-04-02 15:49:29 -0700675 {
Kees Cook3d433212009-04-02 15:49:29 -0700676 .procname = "modules_disabled",
677 .data = &modules_disabled,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700682 .extra1 = &one,
683 .extra2 = &one,
684 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700686#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100689 .data = &uevent_helper,
690 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800692 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 },
Michael Marineau86d56132014-04-10 14:09:31 -0700694#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#ifdef CONFIG_CHR_DEV_SG
696 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .procname = "sg-big-buff",
698 .data = &sg_big_buff,
699 .maxlen = sizeof (int),
700 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800701 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 },
703#endif
704#ifdef CONFIG_BSD_PROCESS_ACCT
705 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 .procname = "acct",
707 .data = &acct_parm,
708 .maxlen = 3*sizeof(int),
709 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800710 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 },
712#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713#ifdef CONFIG_MAGIC_SYSRQ
714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800716 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .maxlen = sizeof (int),
718 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700719 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 },
721#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700722#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700725 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .maxlen = sizeof (int),
727 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800728 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700730#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700733 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .maxlen = sizeof(int),
735 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700736 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 },
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "random",
740 .mode = 0555,
741 .child = random_table,
742 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 {
Eric Paris17f60a72011-04-01 17:07:50 -0400744 .procname = "usermodehelper",
745 .mode = 0555,
746 .child = usermodehelper_table,
747 },
748 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .procname = "overflowuid",
750 .data = &overflowuid,
751 .maxlen = sizeof(int),
752 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800753 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 .extra1 = &minolduid,
755 .extra2 = &maxolduid,
756 },
757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .procname = "overflowgid",
759 .data = &overflowgid,
760 .maxlen = sizeof(int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 .extra1 = &minolduid,
764 .extra2 = &maxolduid,
765 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800766#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767#ifdef CONFIG_MATHEMU
768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .procname = "ieee_emulation_warnings",
770 .data = &sysctl_ieee_emulation_warnings,
771 .maxlen = sizeof(int),
772 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 },
775#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200778 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .maxlen = sizeof(int),
780 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800781 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 },
783#endif
784 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 .procname = "pid_max",
786 .data = &pid_max,
787 .maxlen = sizeof (int),
788 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800789 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .extra1 = &pid_max_min,
791 .extra2 = &pid_max_max,
792 },
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .procname = "panic_on_oops",
795 .data = &panic_on_oops,
796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800800#if defined CONFIG_PRINTK
801 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800802 .procname = "printk",
803 .data = &console_loglevel,
804 .maxlen = 4*sizeof(int),
805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800806 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800807 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700810 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .maxlen = sizeof(int),
812 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800813 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 },
815 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700817 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 .maxlen = sizeof(int),
819 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800820 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 },
Dave Youngaf913222009-09-22 16:43:33 -0700822 {
Dave Youngaf913222009-09-22 16:43:33 -0700823 .procname = "printk_delay",
824 .data = &printk_delay_msec,
825 .maxlen = sizeof(int),
826 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700828 .extra1 = &zero,
829 .extra2 = &ten_thousand,
830 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700832 .procname = "printk_devkmsg",
833 .data = devkmsg_log_str,
834 .maxlen = DEVKMSG_STR_MAX_SIZE,
835 .mode = 0644,
836 .proc_handler = devkmsg_sysctl_set_loglvl,
837 },
838 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800839 .procname = "dmesg_restrict",
840 .data = &dmesg_restrict,
841 .maxlen = sizeof(int),
842 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700843 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800844 .extra1 = &zero,
845 .extra2 = &one,
846 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800847 {
848 .procname = "kptr_restrict",
849 .data = &kptr_restrict,
850 .maxlen = sizeof(int),
851 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700852 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800853 .extra1 = &zero,
854 .extra2 = &two,
855 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800856#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800857 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 .procname = "ngroups_max",
859 .data = &ngroups_max,
860 .maxlen = sizeof (int),
861 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 },
Dan Ballard73efc032011-10-31 17:11:20 -0700864 {
865 .procname = "cap_last_cap",
866 .data = (void *)&cap_last_cap,
867 .maxlen = sizeof(int),
868 .mode = 0444,
869 .proc_handler = proc_dointvec,
870 },
Don Zickus58687ac2010-05-07 17:11:44 -0400871#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500872 {
Don Zickus58687ac2010-05-07 17:11:44 -0400873 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200874 .data = &watchdog_user_enabled,
875 .maxlen = sizeof(int),
876 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700877 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700878 .extra1 = &zero,
879 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400880 },
881 {
882 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700883 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400884 .maxlen = sizeof(int),
885 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700886 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800887 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400888 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500889 },
Don Zickus2508ce12010-05-07 17:11:46 -0400890 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700891 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200892 .data = &nmi_watchdog_user_enabled,
893 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200894 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700895 .proc_handler = proc_nmi_watchdog,
896 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700897 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700898 },
899 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700900 .procname = "watchdog_cpumask",
901 .data = &watchdog_cpumask_bits,
902 .maxlen = NR_CPUS,
903 .mode = 0644,
904 .proc_handler = proc_watchdog_cpumask,
905 },
906#ifdef CONFIG_SOFTLOCKUP_DETECTOR
907 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700908 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200909 .data = &soft_watchdog_user_enabled,
910 .maxlen = sizeof(int),
911 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700912 .proc_handler = proc_soft_watchdog,
913 .extra1 = &zero,
914 .extra2 = &one,
915 },
916 {
Don Zickus2508ce12010-05-07 17:11:46 -0400917 .procname = "softlockup_panic",
918 .data = &softlockup_panic,
919 .maxlen = sizeof(int),
920 .mode = 0644,
921 .proc_handler = proc_dointvec_minmax,
922 .extra1 = &zero,
923 .extra2 = &one,
924 },
Aaron Tomlined235872014-06-23 13:22:05 -0700925#ifdef CONFIG_SMP
926 {
927 .procname = "softlockup_all_cpu_backtrace",
928 .data = &sysctl_softlockup_all_cpu_backtrace,
929 .maxlen = sizeof(int),
930 .mode = 0644,
931 .proc_handler = proc_dointvec_minmax,
932 .extra1 = &zero,
933 .extra2 = &one,
934 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700935#endif /* CONFIG_SMP */
936#endif
937#ifdef CONFIG_HARDLOCKUP_DETECTOR
938 {
939 .procname = "hardlockup_panic",
940 .data = &hardlockup_panic,
941 .maxlen = sizeof(int),
942 .mode = 0644,
943 .proc_handler = proc_dointvec_minmax,
944 .extra1 = &zero,
945 .extra2 = &one,
946 },
947#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800948 {
949 .procname = "hardlockup_all_cpu_backtrace",
950 .data = &sysctl_hardlockup_all_cpu_backtrace,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec_minmax,
954 .extra1 = &zero,
955 .extra2 = &one,
956 },
Aaron Tomlined235872014-06-23 13:22:05 -0700957#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500958#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700959#endif
960
Don Zickus5dc30552010-11-29 17:07:17 -0500961#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
962 {
963 .procname = "unknown_nmi_panic",
964 .data = &unknown_nmi_panic,
965 .maxlen = sizeof (int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec,
968 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500969#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970#if defined(CONFIG_X86)
971 {
Don Zickus8da5add2006-09-26 10:52:27 +0200972 .procname = "panic_on_unrecovered_nmi",
973 .data = &panic_on_unrecovered_nmi,
974 .maxlen = sizeof(int),
975 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800976 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200977 },
978 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700979 .procname = "panic_on_io_nmi",
980 .data = &panic_on_io_nmi,
981 .maxlen = sizeof(int),
982 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800983 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700984 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900985#ifdef CONFIG_DEBUG_STACKOVERFLOW
986 {
987 .procname = "panic_on_stackoverflow",
988 .data = &sysctl_panic_on_stackoverflow,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = proc_dointvec,
992 },
993#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700994 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 .procname = "bootloader_type",
996 .data = &bootloader_type,
997 .maxlen = sizeof (int),
998 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800999 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001001 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001002 .procname = "bootloader_version",
1003 .data = &bootloader_version,
1004 .maxlen = sizeof (int),
1005 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001006 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001007 },
1008 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001009 .procname = "io_delay_type",
1010 .data = &io_delay_type,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001013 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001014 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001016#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .procname = "randomize_va_space",
1019 .data = &randomize_va_space,
1020 .maxlen = sizeof(int),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001024#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001025#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001026 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001027 .procname = "spin_retry",
1028 .data = &spin_retry,
1029 .maxlen = sizeof (int),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001032 },
1033#endif
Len Brown673d5b42007-07-28 03:33:16 -04001034#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001035 {
Pavel Machekc255d842006-02-20 18:27:58 -08001036 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001037 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001038 .maxlen = sizeof (unsigned long),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001041 },
1042#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301043#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001044 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001045 .procname = "ignore-unaligned-usertrap",
1046 .data = &no_unaligned_warning,
1047 .maxlen = sizeof (int),
1048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001050 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301051#endif
1052#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001053 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001054 .procname = "unaligned-dump-stack",
1055 .data = &unaligned_dump_stack,
1056 .maxlen = sizeof (int),
1057 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001058 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001059 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001060#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001061#ifdef CONFIG_DETECT_HUNG_TASK
1062 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001063 .procname = "hung_task_panic",
1064 .data = &sysctl_hung_task_panic,
1065 .maxlen = sizeof(int),
1066 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001067 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001068 .extra1 = &zero,
1069 .extra2 = &one,
1070 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001071 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001072 .procname = "hung_task_check_count",
1073 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001074 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001075 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001076 .proc_handler = proc_dointvec_minmax,
1077 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001078 },
1079 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001080 .procname = "hung_task_timeout_secs",
1081 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001082 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001083 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001084 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001085 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001086 },
1087 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001088 .procname = "hung_task_warnings",
1089 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001090 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001091 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001092 .proc_handler = proc_dointvec_minmax,
1093 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001094 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001095#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001096#ifdef CONFIG_RT_MUTEXES
1097 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001098 .procname = "max_lock_depth",
1099 .data = &max_lock_depth,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001102 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001103 },
1104#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001105 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001106 .procname = "poweroff_cmd",
1107 .data = &poweroff_cmd,
1108 .maxlen = POWEROFF_CMD_PATH_LEN,
1109 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001110 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001111 },
David Howells0b77f5b2008-04-29 01:01:32 -07001112#ifdef CONFIG_KEYS
1113 {
David Howells0b77f5b2008-04-29 01:01:32 -07001114 .procname = "keys",
1115 .mode = 0555,
1116 .child = key_sysctls,
1117 },
1118#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001119#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001120 /*
1121 * User-space scripts rely on the existence of this file
1122 * as a feature check for perf_events being enabled.
1123 *
1124 * So it's an ABI, do not remove!
1125 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001126 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001127 .procname = "perf_event_paranoid",
1128 .data = &sysctl_perf_event_paranoid,
1129 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001130 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001131 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001132 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001133 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001134 .procname = "perf_event_mlock_kb",
1135 .data = &sysctl_perf_event_mlock,
1136 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001137 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001138 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001139 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001140 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001141 .procname = "perf_event_max_sample_rate",
1142 .data = &sysctl_perf_event_sample_rate,
1143 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001144 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001145 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001146 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001147 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001148 {
1149 .procname = "perf_cpu_time_max_percent",
1150 .data = &sysctl_perf_cpu_time_max_percent,
1151 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1152 .mode = 0644,
1153 .proc_handler = perf_cpu_time_max_percent_handler,
1154 .extra1 = &zero,
1155 .extra2 = &one_hundred,
1156 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001157 {
1158 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001159 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001160 .maxlen = sizeof(sysctl_perf_event_max_stack),
1161 .mode = 0644,
1162 .proc_handler = perf_event_max_stack_handler,
1163 .extra1 = &zero,
1164 .extra2 = &six_hundred_forty_kb,
1165 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001166 {
1167 .procname = "perf_event_max_contexts_per_stack",
1168 .data = &sysctl_perf_event_max_contexts_per_stack,
1169 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1170 .mode = 0644,
1171 .proc_handler = perf_event_max_stack_handler,
1172 .extra1 = &zero,
1173 .extra2 = &one_thousand,
1174 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001175#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001176 {
1177 .procname = "panic_on_warn",
1178 .data = &panic_on_warn,
1179 .maxlen = sizeof(int),
1180 .mode = 0644,
1181 .proc_handler = proc_dointvec_minmax,
1182 .extra1 = &zero,
1183 .extra2 = &one,
1184 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001185#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1186 {
1187 .procname = "timer_migration",
1188 .data = &sysctl_timer_migration,
1189 .maxlen = sizeof(unsigned int),
1190 .mode = 0644,
1191 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001192 .extra1 = &zero,
1193 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001194 },
1195#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001196#ifdef CONFIG_BPF_SYSCALL
1197 {
1198 .procname = "unprivileged_bpf_disabled",
1199 .data = &sysctl_unprivileged_bpf_disabled,
1200 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1201 .mode = 0644,
1202 /* only handle a transition from default "0" to "1" */
1203 .proc_handler = proc_dointvec_minmax,
1204 .extra1 = &one,
1205 .extra2 = &one,
1206 },
1207#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001208#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1209 {
1210 .procname = "panic_on_rcu_stall",
1211 .data = &sysctl_panic_on_rcu_stall,
1212 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1213 .mode = 0644,
1214 .proc_handler = proc_dointvec_minmax,
1215 .extra1 = &zero,
1216 .extra2 = &one,
1217 },
1218#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001219 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220};
1221
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001222static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 .procname = "overcommit_memory",
1225 .data = &sysctl_overcommit_memory,
1226 .maxlen = sizeof(sysctl_overcommit_memory),
1227 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001228 .proc_handler = proc_dointvec_minmax,
1229 .extra1 = &zero,
1230 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 },
1232 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001233 .procname = "panic_on_oom",
1234 .data = &sysctl_panic_on_oom,
1235 .maxlen = sizeof(sysctl_panic_on_oom),
1236 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001237 .proc_handler = proc_dointvec_minmax,
1238 .extra1 = &zero,
1239 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001240 },
1241 {
David Rientjesfe071d72007-10-16 23:25:56 -07001242 .procname = "oom_kill_allocating_task",
1243 .data = &sysctl_oom_kill_allocating_task,
1244 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1245 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001246 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001247 },
1248 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001249 .procname = "oom_dump_tasks",
1250 .data = &sysctl_oom_dump_tasks,
1251 .maxlen = sizeof(sysctl_oom_dump_tasks),
1252 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001253 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001254 },
1255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 .procname = "overcommit_ratio",
1257 .data = &sysctl_overcommit_ratio,
1258 .maxlen = sizeof(sysctl_overcommit_ratio),
1259 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001260 .proc_handler = overcommit_ratio_handler,
1261 },
1262 {
1263 .procname = "overcommit_kbytes",
1264 .data = &sysctl_overcommit_kbytes,
1265 .maxlen = sizeof(sysctl_overcommit_kbytes),
1266 .mode = 0644,
1267 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 },
1269 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 .procname = "page-cluster",
1271 .data = &page_cluster,
1272 .maxlen = sizeof(int),
1273 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001274 .proc_handler = proc_dointvec_minmax,
1275 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 },
1277 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 .procname = "dirty_background_ratio",
1279 .data = &dirty_background_ratio,
1280 .maxlen = sizeof(dirty_background_ratio),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 .extra1 = &zero,
1284 .extra2 = &one_hundred,
1285 },
1286 {
David Rientjes2da02992009-01-06 14:39:31 -08001287 .procname = "dirty_background_bytes",
1288 .data = &dirty_background_bytes,
1289 .maxlen = sizeof(dirty_background_bytes),
1290 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001291 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001292 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001293 },
1294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 .procname = "dirty_ratio",
1296 .data = &vm_dirty_ratio,
1297 .maxlen = sizeof(vm_dirty_ratio),
1298 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001299 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 .extra1 = &zero,
1301 .extra2 = &one_hundred,
1302 },
1303 {
David Rientjes2da02992009-01-06 14:39:31 -08001304 .procname = "dirty_bytes",
1305 .data = &vm_dirty_bytes,
1306 .maxlen = sizeof(vm_dirty_bytes),
1307 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001308 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001309 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001310 },
1311 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001313 .data = &dirty_writeback_interval,
1314 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001316 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 },
1318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001320 .data = &dirty_expire_interval,
1321 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001323 .proc_handler = proc_dointvec_minmax,
1324 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 },
1326 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001327 .procname = "dirtytime_expire_seconds",
1328 .data = &dirtytime_expire_interval,
1329 .maxlen = sizeof(dirty_expire_interval),
1330 .mode = 0644,
1331 .proc_handler = dirtytime_interval_handler,
1332 .extra1 = &zero,
1333 },
1334 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 .procname = "swappiness",
1336 .data = &vm_swappiness,
1337 .maxlen = sizeof(vm_swappiness),
1338 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001339 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 .extra1 = &zero,
1341 .extra2 = &one_hundred,
1342 },
1343#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001346 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 .maxlen = sizeof(unsigned long),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001350 },
1351#ifdef CONFIG_NUMA
1352 {
1353 .procname = "nr_hugepages_mempolicy",
1354 .data = NULL,
1355 .maxlen = sizeof(unsigned long),
1356 .mode = 0644,
1357 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001358 },
Kemi Wang45180852017-11-15 17:38:22 -08001359 {
1360 .procname = "numa_stat",
1361 .data = &sysctl_vm_numa_stat,
1362 .maxlen = sizeof(int),
1363 .mode = 0644,
1364 .proc_handler = sysctl_vm_numa_stat_handler,
1365 .extra1 = &zero,
1366 .extra2 = &one,
1367 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001368#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 .procname = "hugetlb_shm_group",
1371 .data = &sysctl_hugetlb_shm_group,
1372 .maxlen = sizeof(gid_t),
1373 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001374 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 },
Mel Gorman396faf02007-07-17 04:03:13 -07001376 {
Mel Gorman396faf02007-07-17 04:03:13 -07001377 .procname = "hugepages_treat_as_movable",
1378 .data = &hugepages_treat_as_movable,
1379 .maxlen = sizeof(int),
1380 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001381 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001382 },
Adam Litke54f9f802007-10-16 01:26:20 -07001383 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001384 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001385 .data = NULL,
1386 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001388 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001389 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390#endif
1391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .procname = "lowmem_reserve_ratio",
1393 .data = &sysctl_lowmem_reserve_ratio,
1394 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001396 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 },
1398 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001399 .procname = "drop_caches",
1400 .data = &sysctl_drop_caches,
1401 .maxlen = sizeof(int),
1402 .mode = 0644,
1403 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001404 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001405 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001406 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001407#ifdef CONFIG_COMPACTION
1408 {
1409 .procname = "compact_memory",
1410 .data = &sysctl_compact_memory,
1411 .maxlen = sizeof(int),
1412 .mode = 0200,
1413 .proc_handler = sysctl_compaction_handler,
1414 },
Mel Gorman5e771902010-05-24 14:32:31 -07001415 {
1416 .procname = "extfrag_threshold",
1417 .data = &sysctl_extfrag_threshold,
1418 .maxlen = sizeof(int),
1419 .mode = 0644,
1420 .proc_handler = sysctl_extfrag_handler,
1421 .extra1 = &min_extfrag_threshold,
1422 .extra2 = &max_extfrag_threshold,
1423 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001424 {
1425 .procname = "compact_unevictable_allowed",
1426 .data = &sysctl_compact_unevictable_allowed,
1427 .maxlen = sizeof(int),
1428 .mode = 0644,
1429 .proc_handler = proc_dointvec,
1430 .extra1 = &zero,
1431 .extra2 = &one,
1432 },
Mel Gorman5e771902010-05-24 14:32:31 -07001433
Mel Gorman76ab0f52010-05-24 14:32:28 -07001434#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 .procname = "min_free_kbytes",
1437 .data = &min_free_kbytes,
1438 .maxlen = sizeof(min_free_kbytes),
1439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001440 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 .extra1 = &zero,
1442 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001443 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001444 .procname = "watermark_scale_factor",
1445 .data = &watermark_scale_factor,
1446 .maxlen = sizeof(watermark_scale_factor),
1447 .mode = 0644,
1448 .proc_handler = watermark_scale_factor_sysctl_handler,
1449 .extra1 = &one,
1450 .extra2 = &one_thousand,
1451 },
1452 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001453 .procname = "percpu_pagelist_fraction",
1454 .data = &percpu_pagelist_fraction,
1455 .maxlen = sizeof(percpu_pagelist_fraction),
1456 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001457 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001458 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001459 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460#ifdef CONFIG_MMU
1461 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 .procname = "max_map_count",
1463 .data = &sysctl_max_map_count,
1464 .maxlen = sizeof(sysctl_max_map_count),
1465 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001466 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001467 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001469#else
1470 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001471 .procname = "nr_trim_pages",
1472 .data = &sysctl_nr_trim_pages,
1473 .maxlen = sizeof(sysctl_nr_trim_pages),
1474 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001475 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001476 .extra1 = &zero,
1477 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478#endif
1479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 .procname = "laptop_mode",
1481 .data = &laptop_mode,
1482 .maxlen = sizeof(laptop_mode),
1483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001484 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 },
1486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 .procname = "block_dump",
1488 .data = &block_dump,
1489 .maxlen = sizeof(block_dump),
1490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001491 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 .extra1 = &zero,
1493 },
1494 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 .procname = "vfs_cache_pressure",
1496 .data = &sysctl_vfs_cache_pressure,
1497 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001499 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 .extra1 = &zero,
1501 },
1502#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 .procname = "legacy_va_layout",
1505 .data = &sysctl_legacy_va_layout,
1506 .maxlen = sizeof(sysctl_legacy_va_layout),
1507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001508 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 .extra1 = &zero,
1510 },
1511#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001512#ifdef CONFIG_NUMA
1513 {
Christoph Lameter17436602006-01-18 17:42:32 -08001514 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001515 .data = &node_reclaim_mode,
1516 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001518 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001519 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001520 },
Christoph Lameter96146342006-07-03 00:24:13 -07001521 {
Christoph Lameter96146342006-07-03 00:24:13 -07001522 .procname = "min_unmapped_ratio",
1523 .data = &sysctl_min_unmapped_ratio,
1524 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001526 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001527 .extra1 = &zero,
1528 .extra2 = &one_hundred,
1529 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001530 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001531 .procname = "min_slab_ratio",
1532 .data = &sysctl_min_slab_ratio,
1533 .maxlen = sizeof(sysctl_min_slab_ratio),
1534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001535 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001536 .extra1 = &zero,
1537 .extra2 = &one_hundred,
1538 },
Christoph Lameter17436602006-01-18 17:42:32 -08001539#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001540#ifdef CONFIG_SMP
1541 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001542 .procname = "stat_interval",
1543 .data = &sysctl_stat_interval,
1544 .maxlen = sizeof(sysctl_stat_interval),
1545 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001546 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001547 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001548 {
1549 .procname = "stat_refresh",
1550 .data = NULL,
1551 .maxlen = 0,
1552 .mode = 0600,
1553 .proc_handler = vmstat_refresh,
1554 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001555#endif
David Howells6e141542009-12-15 19:27:45 +00001556#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001557 {
Eric Parised032182007-06-28 15:55:21 -04001558 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001559 .data = &dac_mmap_min_addr,
1560 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001561 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001562 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001563 },
David Howells6e141542009-12-15 19:27:45 +00001564#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001565#ifdef CONFIG_NUMA
1566 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001567 .procname = "numa_zonelist_order",
1568 .data = &numa_zonelist_order,
1569 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1570 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001571 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001572 },
1573#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001574#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001575 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001576 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001577 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001578#ifdef CONFIG_X86_32
1579 .data = &vdso32_enabled,
1580 .maxlen = sizeof(vdso32_enabled),
1581#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001582 .data = &vdso_enabled,
1583 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001584#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001585 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001586 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001587 .extra1 = &zero,
1588 },
1589#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001590#ifdef CONFIG_HIGHMEM
1591 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001592 .procname = "highmem_is_dirtyable",
1593 .data = &vm_highmem_is_dirtyable,
1594 .maxlen = sizeof(vm_highmem_is_dirtyable),
1595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001596 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001597 .extra1 = &zero,
1598 .extra2 = &one,
1599 },
1600#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001601#ifdef CONFIG_MEMORY_FAILURE
1602 {
Andi Kleen6a460792009-09-16 11:50:15 +02001603 .procname = "memory_failure_early_kill",
1604 .data = &sysctl_memory_failure_early_kill,
1605 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1606 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001607 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001608 .extra1 = &zero,
1609 .extra2 = &one,
1610 },
1611 {
Andi Kleen6a460792009-09-16 11:50:15 +02001612 .procname = "memory_failure_recovery",
1613 .data = &sysctl_memory_failure_recovery,
1614 .maxlen = sizeof(sysctl_memory_failure_recovery),
1615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001616 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001617 .extra1 = &zero,
1618 .extra2 = &one,
1619 },
1620#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001621 {
1622 .procname = "user_reserve_kbytes",
1623 .data = &sysctl_user_reserve_kbytes,
1624 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1625 .mode = 0644,
1626 .proc_handler = proc_doulongvec_minmax,
1627 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001628 {
1629 .procname = "admin_reserve_kbytes",
1630 .data = &sysctl_admin_reserve_kbytes,
1631 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1632 .mode = 0644,
1633 .proc_handler = proc_doulongvec_minmax,
1634 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001635#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1636 {
1637 .procname = "mmap_rnd_bits",
1638 .data = &mmap_rnd_bits,
1639 .maxlen = sizeof(mmap_rnd_bits),
1640 .mode = 0600,
1641 .proc_handler = proc_dointvec_minmax,
1642 .extra1 = (void *)&mmap_rnd_bits_min,
1643 .extra2 = (void *)&mmap_rnd_bits_max,
1644 },
1645#endif
1646#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1647 {
1648 .procname = "mmap_rnd_compat_bits",
1649 .data = &mmap_rnd_compat_bits,
1650 .maxlen = sizeof(mmap_rnd_compat_bits),
1651 .mode = 0600,
1652 .proc_handler = proc_dointvec_minmax,
1653 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1654 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1655 },
1656#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001657 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658};
1659
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001660static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 .procname = "inode-nr",
1663 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001664 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001666 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 },
1668 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 .procname = "inode-state",
1670 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001671 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001673 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 },
1675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 .procname = "file-nr",
1677 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001678 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001680 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 },
1682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 .procname = "file-max",
1684 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001685 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001687 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 },
1689 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001690 .procname = "nr_open",
1691 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001692 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001693 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001694 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001695 .extra1 = &sysctl_nr_open_min,
1696 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001697 },
1698 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 .procname = "dentry-state",
1700 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001701 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001703 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 },
1705 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 .procname = "overflowuid",
1707 .data = &fs_overflowuid,
1708 .maxlen = sizeof(int),
1709 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001710 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 .extra1 = &minolduid,
1712 .extra2 = &maxolduid,
1713 },
1714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 .procname = "overflowgid",
1716 .data = &fs_overflowgid,
1717 .maxlen = sizeof(int),
1718 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001719 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 .extra1 = &minolduid,
1721 .extra2 = &maxolduid,
1722 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001723#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 .procname = "leases-enable",
1726 .data = &leases_enable,
1727 .maxlen = sizeof(int),
1728 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001729 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001731#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732#ifdef CONFIG_DNOTIFY
1733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .procname = "dir-notify-enable",
1735 .data = &dir_notify_enable,
1736 .maxlen = sizeof(int),
1737 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001738 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 },
1740#endif
1741#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001742#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 .procname = "lease-break-time",
1745 .data = &lease_break_time,
1746 .maxlen = sizeof(int),
1747 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001748 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001750#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001751#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .procname = "aio-nr",
1754 .data = &aio_nr,
1755 .maxlen = sizeof(aio_nr),
1756 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001757 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 },
1759 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 .procname = "aio-max-nr",
1761 .data = &aio_max_nr,
1762 .maxlen = sizeof(aio_max_nr),
1763 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001764 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001766#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001767#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001768 {
Robert Love0399cb02005-07-13 12:38:18 -04001769 .procname = "inotify",
1770 .mode = 0555,
1771 .child = inotify_table,
1772 },
1773#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001774#ifdef CONFIG_EPOLL
1775 {
1776 .procname = "epoll",
1777 .mode = 0555,
1778 .child = epoll_table,
1779 },
1780#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001782 {
Kees Cook800179c2012-07-25 17:29:07 -07001783 .procname = "protected_symlinks",
1784 .data = &sysctl_protected_symlinks,
1785 .maxlen = sizeof(int),
1786 .mode = 0600,
1787 .proc_handler = proc_dointvec_minmax,
1788 .extra1 = &zero,
1789 .extra2 = &one,
1790 },
1791 {
1792 .procname = "protected_hardlinks",
1793 .data = &sysctl_protected_hardlinks,
1794 .maxlen = sizeof(int),
1795 .mode = 0600,
1796 .proc_handler = proc_dointvec_minmax,
1797 .extra1 = &zero,
1798 .extra2 = &one,
1799 },
1800 {
Alan Coxd6e71142005-06-23 00:09:43 -07001801 .procname = "suid_dumpable",
1802 .data = &suid_dumpable,
1803 .maxlen = sizeof(int),
1804 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001805 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001806 .extra1 = &zero,
1807 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001808 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001809#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1810 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001811 .procname = "binfmt_misc",
1812 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001813 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001814 },
1815#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001816 {
Jens Axboeff9da692010-06-03 14:54:39 +02001817 .procname = "pipe-max-size",
1818 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001819 .maxlen = sizeof(int),
1820 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001821 .proc_handler = &pipe_proc_fn,
1822 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001823 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001824 {
1825 .procname = "pipe-user-pages-hard",
1826 .data = &pipe_user_pages_hard,
1827 .maxlen = sizeof(pipe_user_pages_hard),
1828 .mode = 0644,
1829 .proc_handler = proc_doulongvec_minmax,
1830 },
1831 {
1832 .procname = "pipe-user-pages-soft",
1833 .data = &pipe_user_pages_soft,
1834 .maxlen = sizeof(pipe_user_pages_soft),
1835 .mode = 0644,
1836 .proc_handler = proc_doulongvec_minmax,
1837 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001838 {
1839 .procname = "mount-max",
1840 .data = &sysctl_mount_max,
1841 .maxlen = sizeof(unsigned int),
1842 .mode = 0644,
1843 .proc_handler = proc_dointvec_minmax,
1844 .extra1 = &one,
1845 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001846 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847};
1848
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001849static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001850#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001851 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001852 .procname = "exception-trace",
1853 .data = &show_unhandled_signals,
1854 .maxlen = sizeof(int),
1855 .mode = 0644,
1856 .proc_handler = proc_dointvec
1857 },
1858#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001859#if defined(CONFIG_OPTPROBES)
1860 {
1861 .procname = "kprobes-optimization",
1862 .data = &sysctl_kprobes_optimization,
1863 .maxlen = sizeof(int),
1864 .mode = 0644,
1865 .proc_handler = proc_kprobes_optimization_handler,
1866 .extra1 = &zero,
1867 .extra2 = &one,
1868 },
1869#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001870 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871};
1872
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001873static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001874 { }
Robert Love0eeca282005-07-12 17:06:03 -04001875};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001877int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001878{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001879 struct ctl_table_header *hdr;
1880
1881 hdr = register_sysctl_table(sysctl_base_table);
1882 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001883 return 0;
1884}
1885
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001886#endif /* CONFIG_SYSCTL */
1887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888/*
1889 * /proc/sys support
1890 */
1891
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001892#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Kees Cookf8808302014-06-06 14:37:17 -07001894static int _proc_do_string(char *data, int maxlen, int write,
1895 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001896 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001897{
1898 size_t len;
1899 char __user *p;
1900 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001901
1902 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001903 *lenp = 0;
1904 return 0;
1905 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001906
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001907 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001908 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1909 /* Only continue writes not past the end of buffer. */
1910 len = strlen(data);
1911 if (len > maxlen - 1)
1912 len = maxlen - 1;
1913
1914 if (*ppos > len)
1915 return 0;
1916 len = *ppos;
1917 } else {
1918 /* Start writing from beginning of buffer. */
1919 len = 0;
1920 }
1921
Kees Cook2ca9bb42014-06-06 14:37:18 -07001922 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001923 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001924 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001925 if (get_user(c, p++))
1926 return -EFAULT;
1927 if (c == 0 || c == '\n')
1928 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001929 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001930 }
Kees Cookf8808302014-06-06 14:37:17 -07001931 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001932 } else {
1933 len = strlen(data);
1934 if (len > maxlen)
1935 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001936
1937 if (*ppos > len) {
1938 *lenp = 0;
1939 return 0;
1940 }
1941
1942 data += *ppos;
1943 len -= *ppos;
1944
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001945 if (len > *lenp)
1946 len = *lenp;
1947 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001948 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001949 return -EFAULT;
1950 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001951 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001952 return -EFAULT;
1953 len++;
1954 }
1955 *lenp = len;
1956 *ppos += len;
1957 }
1958 return 0;
1959}
1960
Kees Cookf4aacea2014-06-06 14:37:19 -07001961static void warn_sysctl_write(struct ctl_table *table)
1962{
1963 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1964 "This will not be supported in the future. To silence this\n"
1965 "warning, set kernel.sysctl_writes_strict = -1\n",
1966 current->comm, table->procname);
1967}
1968
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969/**
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001970 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1971 * @ppos: file position
1972 * @table: the sysctl table
1973 *
1974 * Returns true if the first position is non-zero and the sysctl_writes_strict
1975 * mode indicates this is not allowed for numeric input types. String proc
1976 * hadlers can ignore the return value.
1977 */
1978static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
1979 struct ctl_table *table)
1980{
1981 if (!*ppos)
1982 return false;
1983
1984 switch (sysctl_writes_strict) {
1985 case SYSCTL_WRITES_STRICT:
1986 return true;
1987 case SYSCTL_WRITES_WARN:
1988 warn_sysctl_write(table);
1989 return false;
1990 default:
1991 return false;
1992 }
1993}
1994
1995/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 * proc_dostring - read a string sysctl
1997 * @table: the sysctl table
1998 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 * @buffer: the user buffer
2000 * @lenp: the size of the user buffer
2001 * @ppos: file position
2002 *
2003 * Reads/writes a string from/to the user buffer. If the kernel
2004 * buffer provided is not large enough to hold the string, the
2005 * string is truncated. The copied string is %NULL-terminated.
2006 * If the string is being read by the user process, it is copied
2007 * and a newline '\n' is added. It is truncated if the buffer is
2008 * not large enough.
2009 *
2010 * Returns 0 on success.
2011 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002012int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 void __user *buffer, size_t *lenp, loff_t *ppos)
2014{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002015 if (write)
2016 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002017
Kees Cookf8808302014-06-06 14:37:17 -07002018 return _proc_do_string((char *)(table->data), table->maxlen, write,
2019 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
Amerigo Wang00b7c332010-05-05 00:26:45 +00002022static size_t proc_skip_spaces(char **buf)
2023{
2024 size_t ret;
2025 char *tmp = skip_spaces(*buf);
2026 ret = tmp - *buf;
2027 *buf = tmp;
2028 return ret;
2029}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002031static void proc_skip_char(char **buf, size_t *size, const char v)
2032{
2033 while (*size) {
2034 if (**buf != v)
2035 break;
2036 (*size)--;
2037 (*buf)++;
2038 }
2039}
2040
Amerigo Wang00b7c332010-05-05 00:26:45 +00002041#define TMPBUFLEN 22
2042/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002043 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002044 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002045 * @buf: a kernel buffer
2046 * @size: size of the kernel buffer
2047 * @val: this is where the number will be stored
2048 * @neg: set to %TRUE if number is negative
2049 * @perm_tr: a vector which contains the allowed trailers
2050 * @perm_tr_len: size of the perm_tr vector
2051 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002052 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002053 * In case of success %0 is returned and @buf and @size are updated with
2054 * the amount of bytes read. If @tr is non-NULL and a trailing
2055 * character exists (size is non-zero after returning from this
2056 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002057 */
2058static int proc_get_long(char **buf, size_t *size,
2059 unsigned long *val, bool *neg,
2060 const char *perm_tr, unsigned perm_tr_len, char *tr)
2061{
2062 int len;
2063 char *p, tmp[TMPBUFLEN];
2064
2065 if (!*size)
2066 return -EINVAL;
2067
2068 len = *size;
2069 if (len > TMPBUFLEN - 1)
2070 len = TMPBUFLEN - 1;
2071
2072 memcpy(tmp, *buf, len);
2073
2074 tmp[len] = 0;
2075 p = tmp;
2076 if (*p == '-' && *size > 1) {
2077 *neg = true;
2078 p++;
2079 } else
2080 *neg = false;
2081 if (!isdigit(*p))
2082 return -EINVAL;
2083
2084 *val = simple_strtoul(p, &p, 0);
2085
2086 len = p - tmp;
2087
2088 /* We don't know if the next char is whitespace thus we may accept
2089 * invalid integers (e.g. 1234...a) or two integers instead of one
2090 * (e.g. 123...1). So lets not allow such large numbers. */
2091 if (len == TMPBUFLEN - 1)
2092 return -EINVAL;
2093
2094 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2095 return -EINVAL;
2096
2097 if (tr && (len < *size))
2098 *tr = *p;
2099
2100 *buf += len;
2101 *size -= len;
2102
2103 return 0;
2104}
2105
2106/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002107 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002108 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002109 * @buf: the user buffer
2110 * @size: the size of the user buffer
2111 * @val: the integer to be converted
2112 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002113 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002114 * In case of success %0 is returned and @buf and @size are updated with
2115 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002116 */
2117static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2118 bool neg)
2119{
2120 int len;
2121 char tmp[TMPBUFLEN], *p = tmp;
2122
2123 sprintf(p, "%s%lu", neg ? "-" : "", val);
2124 len = strlen(tmp);
2125 if (len > *size)
2126 len = *size;
2127 if (copy_to_user(*buf, tmp, len))
2128 return -EFAULT;
2129 *size -= len;
2130 *buf += len;
2131 return 0;
2132}
2133#undef TMPBUFLEN
2134
2135static int proc_put_char(void __user **buf, size_t *size, char c)
2136{
2137 if (*size) {
2138 char __user **buffer = (char __user **)buf;
2139 if (put_user(c, *buffer))
2140 return -EFAULT;
2141 (*size)--, (*buffer)++;
2142 *buf = *buffer;
2143 }
2144 return 0;
2145}
2146
2147static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 int *valp,
2149 int write, void *data)
2150{
2151 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002152 if (*negp) {
2153 if (*lvalp > (unsigned long) INT_MAX + 1)
2154 return -EINVAL;
2155 *valp = -*lvalp;
2156 } else {
2157 if (*lvalp > (unsigned long) INT_MAX)
2158 return -EINVAL;
2159 *valp = *lvalp;
2160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 } else {
2162 int val = *valp;
2163 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002164 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002165 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002167 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 *lvalp = (unsigned long)val;
2169 }
2170 }
2171 return 0;
2172}
2173
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002174static int do_proc_douintvec_conv(unsigned long *lvalp,
2175 unsigned int *valp,
2176 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002177{
2178 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002179 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002180 return -EINVAL;
2181 *valp = *lvalp;
2182 } else {
2183 unsigned int val = *valp;
2184 *lvalp = (unsigned long)val;
2185 }
2186 return 0;
2187}
2188
Amerigo Wang00b7c332010-05-05 00:26:45 +00002189static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2190
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002191static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002192 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002193 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002194 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 int write, void *data),
2196 void *data)
2197{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002198 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002199 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002200 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Amerigo Wang00b7c332010-05-05 00:26:45 +00002202 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 *lenp = 0;
2204 return 0;
2205 }
2206
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002207 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 vleft = table->maxlen / sizeof(*i);
2209 left = *lenp;
2210
2211 if (!conv)
2212 conv = do_proc_dointvec_conv;
2213
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002215 if (proc_first_pos_non_zero_ignore(ppos, table))
2216 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002217
Amerigo Wang00b7c332010-05-05 00:26:45 +00002218 if (left > PAGE_SIZE - 1)
2219 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002220 p = kbuf = memdup_user_nul(buffer, left);
2221 if (IS_ERR(kbuf))
2222 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002223 }
2224
2225 for (; left && vleft--; i++, first=0) {
2226 unsigned long lval;
2227 bool neg;
2228
2229 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002230 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002231
J. R. Okajima563b0462010-05-25 16:10:14 -07002232 if (!left)
2233 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002234 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002235 proc_wspace_sep,
2236 sizeof(proc_wspace_sep), NULL);
2237 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 if (conv(&neg, &lval, i, 1, data)) {
2240 err = -EINVAL;
2241 break;
2242 }
2243 } else {
2244 if (conv(&neg, &lval, i, 0, data)) {
2245 err = -EINVAL;
2246 break;
2247 }
2248 if (!first)
2249 err = proc_put_char(&buffer, &left, '\t');
2250 if (err)
2251 break;
2252 err = proc_put_long(&buffer, &left, lval, neg);
2253 if (err)
2254 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 }
2256 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002257
2258 if (!write && !first && left && !err)
2259 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002260 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002261 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002263 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002264 if (first)
2265 return err ? : -EINVAL;
2266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002268out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002273static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002274 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002275 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002276 int write, void *data),
2277 void *data)
2278{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002279 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002280 buffer, lenp, ppos, conv, data);
2281}
2282
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002283static int do_proc_douintvec_w(unsigned int *tbl_data,
2284 struct ctl_table *table,
2285 void __user *buffer,
2286 size_t *lenp, loff_t *ppos,
2287 int (*conv)(unsigned long *lvalp,
2288 unsigned int *valp,
2289 int write, void *data),
2290 void *data)
2291{
2292 unsigned long lval;
2293 int err = 0;
2294 size_t left;
2295 bool neg;
2296 char *kbuf = NULL, *p;
2297
2298 left = *lenp;
2299
2300 if (proc_first_pos_non_zero_ignore(ppos, table))
2301 goto bail_early;
2302
2303 if (left > PAGE_SIZE - 1)
2304 left = PAGE_SIZE - 1;
2305
2306 p = kbuf = memdup_user_nul(buffer, left);
2307 if (IS_ERR(kbuf))
2308 return -EINVAL;
2309
2310 left -= proc_skip_spaces(&p);
2311 if (!left) {
2312 err = -EINVAL;
2313 goto out_free;
2314 }
2315
2316 err = proc_get_long(&p, &left, &lval, &neg,
2317 proc_wspace_sep,
2318 sizeof(proc_wspace_sep), NULL);
2319 if (err || neg) {
2320 err = -EINVAL;
2321 goto out_free;
2322 }
2323
2324 if (conv(&lval, tbl_data, 1, data)) {
2325 err = -EINVAL;
2326 goto out_free;
2327 }
2328
2329 if (!err && left)
2330 left -= proc_skip_spaces(&p);
2331
2332out_free:
2333 kfree(kbuf);
2334 if (err)
2335 return -EINVAL;
2336
2337 return 0;
2338
2339 /* This is in keeping with old __do_proc_dointvec() */
2340bail_early:
2341 *ppos += *lenp;
2342 return err;
2343}
2344
2345static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2346 size_t *lenp, loff_t *ppos,
2347 int (*conv)(unsigned long *lvalp,
2348 unsigned int *valp,
2349 int write, void *data),
2350 void *data)
2351{
2352 unsigned long lval;
2353 int err = 0;
2354 size_t left;
2355
2356 left = *lenp;
2357
2358 if (conv(&lval, tbl_data, 0, data)) {
2359 err = -EINVAL;
2360 goto out;
2361 }
2362
2363 err = proc_put_long(&buffer, &left, lval, false);
2364 if (err || !left)
2365 goto out;
2366
2367 err = proc_put_char(&buffer, &left, '\n');
2368
2369out:
2370 *lenp -= left;
2371 *ppos += *lenp;
2372
2373 return err;
2374}
2375
2376static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2377 int write, void __user *buffer,
2378 size_t *lenp, loff_t *ppos,
2379 int (*conv)(unsigned long *lvalp,
2380 unsigned int *valp,
2381 int write, void *data),
2382 void *data)
2383{
2384 unsigned int *i, vleft;
2385
2386 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2387 *lenp = 0;
2388 return 0;
2389 }
2390
2391 i = (unsigned int *) tbl_data;
2392 vleft = table->maxlen / sizeof(*i);
2393
2394 /*
2395 * Arrays are not supported, keep this simple. *Do not* add
2396 * support for them.
2397 */
2398 if (vleft != 1) {
2399 *lenp = 0;
2400 return -EINVAL;
2401 }
2402
2403 if (!conv)
2404 conv = do_proc_douintvec_conv;
2405
2406 if (write)
2407 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2408 conv, data);
2409 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2410}
2411
2412static int do_proc_douintvec(struct ctl_table *table, int write,
2413 void __user *buffer, size_t *lenp, loff_t *ppos,
2414 int (*conv)(unsigned long *lvalp,
2415 unsigned int *valp,
2416 int write, void *data),
2417 void *data)
2418{
2419 return __do_proc_douintvec(table->data, table, write,
2420 buffer, lenp, ppos, conv, data);
2421}
2422
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423/**
2424 * proc_dointvec - read a vector of integers
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 * @buffer: the user buffer
2428 * @lenp: the size of the user buffer
2429 * @ppos: file position
2430 *
2431 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2432 * values from/to the user buffer, treated as an ASCII string.
2433 *
2434 * Returns 0 on success.
2435 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002436int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002439 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2440}
2441
2442/**
2443 * proc_douintvec - read a vector of unsigned integers
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
2446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2449 *
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2451 * values from/to the user buffer, treated as an ASCII string.
2452 *
2453 * Returns 0 on success.
2454 */
2455int proc_douintvec(struct ctl_table *table, int write,
2456 void __user *buffer, size_t *lenp, loff_t *ppos)
2457{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002458 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2459 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002462/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002463 * Taint values can only be increased
2464 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002465 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002466static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002467 void __user *buffer, size_t *lenp, loff_t *ppos)
2468{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002469 struct ctl_table t;
2470 unsigned long tmptaint = get_taint();
2471 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002472
Bastian Blank91fcd412007-04-23 14:41:14 -07002473 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002474 return -EPERM;
2475
Andi Kleen25ddbb12008-10-15 22:01:41 -07002476 t = *table;
2477 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002478 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002479 if (err < 0)
2480 return err;
2481
2482 if (write) {
2483 /*
2484 * Poor man's atomic or. Not worth adding a primitive
2485 * to everyone's atomic.h for this
2486 */
2487 int i;
2488 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2489 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302490 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002491 }
2492 }
2493
2494 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002495}
2496
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002497#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002498static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002499 void __user *buffer, size_t *lenp, loff_t *ppos)
2500{
2501 if (write && !capable(CAP_SYS_ADMIN))
2502 return -EPERM;
2503
2504 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2505}
2506#endif
2507
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508struct do_proc_dointvec_minmax_conv_param {
2509 int *min;
2510 int *max;
2511};
2512
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2514 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 int write, void *data)
2516{
2517 struct do_proc_dointvec_minmax_conv_param *param = data;
2518 if (write) {
2519 int val = *negp ? -*lvalp : *lvalp;
2520 if ((param->min && *param->min > val) ||
2521 (param->max && *param->max < val))
2522 return -EINVAL;
2523 *valp = val;
2524 } else {
2525 int val = *valp;
2526 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002527 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002528 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002530 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 *lvalp = (unsigned long)val;
2532 }
2533 }
2534 return 0;
2535}
2536
2537/**
2538 * proc_dointvec_minmax - read a vector of integers with min/max values
2539 * @table: the sysctl table
2540 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 * @buffer: the user buffer
2542 * @lenp: the size of the user buffer
2543 * @ppos: file position
2544 *
2545 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2546 * values from/to the user buffer, treated as an ASCII string.
2547 *
2548 * This routine will ensure the values are within the range specified by
2549 * table->extra1 (min) and table->extra2 (max).
2550 *
2551 * Returns 0 on success.
2552 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002553int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 void __user *buffer, size_t *lenp, loff_t *ppos)
2555{
2556 struct do_proc_dointvec_minmax_conv_param param = {
2557 .min = (int *) table->extra1,
2558 .max = (int *) table->extra2,
2559 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002560 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 do_proc_dointvec_minmax_conv, &param);
2562}
2563
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002564struct do_proc_douintvec_minmax_conv_param {
2565 unsigned int *min;
2566 unsigned int *max;
2567};
2568
2569static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2570 unsigned int *valp,
2571 int write, void *data)
2572{
2573 struct do_proc_douintvec_minmax_conv_param *param = data;
2574
2575 if (write) {
2576 unsigned int val = *lvalp;
2577
2578 if ((param->min && *param->min > val) ||
2579 (param->max && *param->max < val))
2580 return -ERANGE;
2581
2582 if (*lvalp > UINT_MAX)
2583 return -EINVAL;
2584 *valp = val;
2585 } else {
2586 unsigned int val = *valp;
2587 *lvalp = (unsigned long) val;
2588 }
2589
2590 return 0;
2591}
2592
2593/**
2594 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2595 * @table: the sysctl table
2596 * @write: %TRUE if this is a write to the sysctl file
2597 * @buffer: the user buffer
2598 * @lenp: the size of the user buffer
2599 * @ppos: file position
2600 *
2601 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2602 * values from/to the user buffer, treated as an ASCII string. Negative
2603 * strings are not allowed.
2604 *
2605 * This routine will ensure the values are within the range specified by
2606 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2607 * check for UINT_MAX to avoid having to support wrap around uses from
2608 * userspace.
2609 *
2610 * Returns 0 on success.
2611 */
2612int proc_douintvec_minmax(struct ctl_table *table, int write,
2613 void __user *buffer, size_t *lenp, loff_t *ppos)
2614{
2615 struct do_proc_douintvec_minmax_conv_param param = {
2616 .min = (unsigned int *) table->extra1,
2617 .max = (unsigned int *) table->extra2,
2618 };
2619 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2620 do_proc_douintvec_minmax_conv, &param);
2621}
2622
Kees Cook54b50192012-07-30 14:39:18 -07002623static void validate_coredump_safety(void)
2624{
Alex Kelly046d6622012-10-04 17:15:23 -07002625#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002626 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002627 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002628 printk(KERN_WARNING
2629"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2630"Pipe handler or fully qualified core dump path required.\n"
2631"Set kernel.core_pattern before fs.suid_dumpable.\n"
2632 );
Kees Cook54b50192012-07-30 14:39:18 -07002633 }
Alex Kelly046d6622012-10-04 17:15:23 -07002634#endif
Kees Cook54b50192012-07-30 14:39:18 -07002635}
2636
2637static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2638 void __user *buffer, size_t *lenp, loff_t *ppos)
2639{
2640 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2641 if (!error)
2642 validate_coredump_safety();
2643 return error;
2644}
2645
Alex Kelly046d6622012-10-04 17:15:23 -07002646#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002647static int proc_dostring_coredump(struct ctl_table *table, int write,
2648 void __user *buffer, size_t *lenp, loff_t *ppos)
2649{
2650 int error = proc_dostring(table, write, buffer, lenp, ppos);
2651 if (!error)
2652 validate_coredump_safety();
2653 return error;
2654}
Alex Kelly046d6622012-10-04 17:15:23 -07002655#endif
Kees Cook54b50192012-07-30 14:39:18 -07002656
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002657static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 void __user *buffer,
2659 size_t *lenp, loff_t *ppos,
2660 unsigned long convmul,
2661 unsigned long convdiv)
2662{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002663 unsigned long *i, *min, *max;
2664 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002665 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002666 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002667
2668 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 *lenp = 0;
2670 return 0;
2671 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002672
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002673 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 min = (unsigned long *) table->extra1;
2675 max = (unsigned long *) table->extra2;
2676 vleft = table->maxlen / sizeof(unsigned long);
2677 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002678
2679 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002680 if (proc_first_pos_non_zero_ignore(ppos, table))
2681 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002682
Amerigo Wang00b7c332010-05-05 00:26:45 +00002683 if (left > PAGE_SIZE - 1)
2684 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002685 p = kbuf = memdup_user_nul(buffer, left);
2686 if (IS_ERR(kbuf))
2687 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002688 }
2689
Eric Dumazet27b3d802010-10-07 12:59:29 -07002690 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002691 unsigned long val;
2692
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002694 bool neg;
2695
Al Viro70f6cbb2015-12-24 00:13:10 -05002696 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002697
Al Viro70f6cbb2015-12-24 00:13:10 -05002698 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002699 proc_wspace_sep,
2700 sizeof(proc_wspace_sep), NULL);
2701 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 break;
2703 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002705 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 if ((min && val < *min) || (max && val > *max))
2707 continue;
2708 *i = val;
2709 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002710 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002711 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002712 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002713 if (err)
2714 break;
2715 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002716 err = proc_put_long(&buffer, &left, val, false);
2717 if (err)
2718 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 }
2720 }
2721
Amerigo Wang00b7c332010-05-05 00:26:45 +00002722 if (!write && !first && left && !err)
2723 err = proc_put_char(&buffer, &left, '\n');
2724 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002725 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002727 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002728 if (first)
2729 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002732out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002734 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735}
2736
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002737static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002738 void __user *buffer,
2739 size_t *lenp, loff_t *ppos,
2740 unsigned long convmul,
2741 unsigned long convdiv)
2742{
2743 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002744 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002745}
2746
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747/**
2748 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2749 * @table: the sysctl table
2750 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 * @buffer: the user buffer
2752 * @lenp: the size of the user buffer
2753 * @ppos: file position
2754 *
2755 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2756 * values from/to the user buffer, treated as an ASCII string.
2757 *
2758 * This routine will ensure the values are within the range specified by
2759 * table->extra1 (min) and table->extra2 (max).
2760 *
2761 * Returns 0 on success.
2762 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002763int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 void __user *buffer, size_t *lenp, loff_t *ppos)
2765{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002766 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767}
2768
2769/**
2770 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2771 * @table: the sysctl table
2772 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 * @buffer: the user buffer
2774 * @lenp: the size of the user buffer
2775 * @ppos: file position
2776 *
2777 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2778 * values from/to the user buffer, treated as an ASCII string. The values
2779 * are treated as milliseconds, and converted to jiffies when they are stored.
2780 *
2781 * This routine will ensure the values are within the range specified by
2782 * table->extra1 (min) and table->extra2 (max).
2783 *
2784 * Returns 0 on success.
2785 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002786int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 void __user *buffer,
2788 size_t *lenp, loff_t *ppos)
2789{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002790 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 lenp, ppos, HZ, 1000l);
2792}
2793
2794
Amerigo Wang00b7c332010-05-05 00:26:45 +00002795static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 int *valp,
2797 int write, void *data)
2798{
2799 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002800 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002801 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2803 } else {
2804 int val = *valp;
2805 unsigned long lval;
2806 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002807 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002808 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002810 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 lval = (unsigned long)val;
2812 }
2813 *lvalp = lval / HZ;
2814 }
2815 return 0;
2816}
2817
Amerigo Wang00b7c332010-05-05 00:26:45 +00002818static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 int *valp,
2820 int write, void *data)
2821{
2822 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002823 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2824 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2826 } else {
2827 int val = *valp;
2828 unsigned long lval;
2829 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002830 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002831 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002833 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 lval = (unsigned long)val;
2835 }
2836 *lvalp = jiffies_to_clock_t(lval);
2837 }
2838 return 0;
2839}
2840
Amerigo Wang00b7c332010-05-05 00:26:45 +00002841static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 int *valp,
2843 int write, void *data)
2844{
2845 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002846 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2847
2848 if (jif > INT_MAX)
2849 return 1;
2850 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 } else {
2852 int val = *valp;
2853 unsigned long lval;
2854 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002855 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002856 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002858 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 lval = (unsigned long)val;
2860 }
2861 *lvalp = jiffies_to_msecs(lval);
2862 }
2863 return 0;
2864}
2865
2866/**
2867 * proc_dointvec_jiffies - read a vector of integers as seconds
2868 * @table: the sysctl table
2869 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 * @buffer: the user buffer
2871 * @lenp: the size of the user buffer
2872 * @ppos: file position
2873 *
2874 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2875 * values from/to the user buffer, treated as an ASCII string.
2876 * The values read are assumed to be in seconds, and are converted into
2877 * jiffies.
2878 *
2879 * Returns 0 on success.
2880 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002881int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 void __user *buffer, size_t *lenp, loff_t *ppos)
2883{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002884 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 do_proc_dointvec_jiffies_conv,NULL);
2886}
2887
2888/**
2889 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2890 * @table: the sysctl table
2891 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 * @buffer: the user buffer
2893 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002894 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 *
2896 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2897 * values from/to the user buffer, treated as an ASCII string.
2898 * The values read are assumed to be in 1/USER_HZ seconds, and
2899 * are converted into jiffies.
2900 *
2901 * Returns 0 on success.
2902 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002903int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 void __user *buffer, size_t *lenp, loff_t *ppos)
2905{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002906 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 do_proc_dointvec_userhz_jiffies_conv,NULL);
2908}
2909
2910/**
2911 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2912 * @table: the sysctl table
2913 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 * @buffer: the user buffer
2915 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002916 * @ppos: file position
2917 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 *
2919 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2920 * values from/to the user buffer, treated as an ASCII string.
2921 * The values read are assumed to be in 1/1000 seconds, and
2922 * are converted into jiffies.
2923 *
2924 * Returns 0 on success.
2925 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002926int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 void __user *buffer, size_t *lenp, loff_t *ppos)
2928{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002929 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 do_proc_dointvec_ms_jiffies_conv, NULL);
2931}
2932
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002933static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002934 void __user *buffer, size_t *lenp, loff_t *ppos)
2935{
2936 struct pid *new_pid;
2937 pid_t tmp;
2938 int r;
2939
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002940 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002941
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002942 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002943 lenp, ppos, NULL, NULL);
2944 if (r || !write)
2945 return r;
2946
2947 new_pid = find_get_pid(tmp);
2948 if (!new_pid)
2949 return -ESRCH;
2950
2951 put_pid(xchg(&cad_pid, new_pid));
2952 return 0;
2953}
2954
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002955/**
2956 * proc_do_large_bitmap - read/write from/to a large bitmap
2957 * @table: the sysctl table
2958 * @write: %TRUE if this is a write to the sysctl file
2959 * @buffer: the user buffer
2960 * @lenp: the size of the user buffer
2961 * @ppos: file position
2962 *
2963 * The bitmap is stored at table->data and the bitmap length (in bits)
2964 * in table->maxlen.
2965 *
2966 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2967 * large bitmaps may be represented in a compact manner. Writing into
2968 * the file will clear the bitmap then update it with the given input.
2969 *
2970 * Returns 0 on success.
2971 */
2972int proc_do_large_bitmap(struct ctl_table *table, int write,
2973 void __user *buffer, size_t *lenp, loff_t *ppos)
2974{
2975 int err = 0;
2976 bool first = 1;
2977 size_t left = *lenp;
2978 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002979 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002980 unsigned long *tmp_bitmap = NULL;
2981 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2982
WANG Cong122ff242014-05-12 16:04:53 -07002983 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002984 *lenp = 0;
2985 return 0;
2986 }
2987
2988 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002989 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002990
2991 if (left > PAGE_SIZE - 1)
2992 left = PAGE_SIZE - 1;
2993
Al Viro70f6cbb2015-12-24 00:13:10 -05002994 p = kbuf = memdup_user_nul(buffer, left);
2995 if (IS_ERR(kbuf))
2996 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002997
2998 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2999 GFP_KERNEL);
3000 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003001 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003002 return -ENOMEM;
3003 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003004 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003005 while (!err && left) {
3006 unsigned long val_a, val_b;
3007 bool neg;
3008
Al Viro70f6cbb2015-12-24 00:13:10 -05003009 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003010 sizeof(tr_a), &c);
3011 if (err)
3012 break;
3013 if (val_a >= bitmap_len || neg) {
3014 err = -EINVAL;
3015 break;
3016 }
3017
3018 val_b = val_a;
3019 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003020 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003021 left--;
3022 }
3023
3024 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003025 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003026 &neg, tr_b, sizeof(tr_b),
3027 &c);
3028 if (err)
3029 break;
3030 if (val_b >= bitmap_len || neg ||
3031 val_a > val_b) {
3032 err = -EINVAL;
3033 break;
3034 }
3035 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003036 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003037 left--;
3038 }
3039 }
3040
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003041 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003042 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003043 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003044 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003045 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003046 } else {
3047 unsigned long bit_a, bit_b = 0;
3048
3049 while (left) {
3050 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3051 if (bit_a >= bitmap_len)
3052 break;
3053 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3054 bit_a + 1) - 1;
3055
3056 if (!first) {
3057 err = proc_put_char(&buffer, &left, ',');
3058 if (err)
3059 break;
3060 }
3061 err = proc_put_long(&buffer, &left, bit_a, false);
3062 if (err)
3063 break;
3064 if (bit_a != bit_b) {
3065 err = proc_put_char(&buffer, &left, '-');
3066 if (err)
3067 break;
3068 err = proc_put_long(&buffer, &left, bit_b, false);
3069 if (err)
3070 break;
3071 }
3072
3073 first = 0; bit_b++;
3074 }
3075 if (!err)
3076 err = proc_put_char(&buffer, &left, '\n');
3077 }
3078
3079 if (!err) {
3080 if (write) {
3081 if (*ppos)
3082 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3083 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003084 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003085 }
3086 kfree(tmp_bitmap);
3087 *lenp -= left;
3088 *ppos += *lenp;
3089 return 0;
3090 } else {
3091 kfree(tmp_bitmap);
3092 return err;
3093 }
3094}
3095
Jovi Zhang55610502011-01-12 17:00:45 -08003096#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003098int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 void __user *buffer, size_t *lenp, loff_t *ppos)
3100{
3101 return -ENOSYS;
3102}
3103
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003104int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 void __user *buffer, size_t *lenp, loff_t *ppos)
3106{
3107 return -ENOSYS;
3108}
3109
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003110int proc_douintvec(struct ctl_table *table, int write,
3111 void __user *buffer, size_t *lenp, loff_t *ppos)
3112{
3113 return -ENOSYS;
3114}
3115
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003116int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 void __user *buffer, size_t *lenp, loff_t *ppos)
3118{
3119 return -ENOSYS;
3120}
3121
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003122int proc_douintvec_minmax(struct ctl_table *table, int write,
3123 void __user *buffer, size_t *lenp, loff_t *ppos)
3124{
3125 return -ENOSYS;
3126}
3127
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003128int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 void __user *buffer, size_t *lenp, loff_t *ppos)
3130{
3131 return -ENOSYS;
3132}
3133
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003134int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 void __user *buffer, size_t *lenp, loff_t *ppos)
3136{
3137 return -ENOSYS;
3138}
3139
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003140int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 void __user *buffer, size_t *lenp, loff_t *ppos)
3142{
3143 return -ENOSYS;
3144}
3145
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003146int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 void __user *buffer, size_t *lenp, loff_t *ppos)
3148{
3149 return -ENOSYS;
3150}
3151
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003152int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 void __user *buffer,
3154 size_t *lenp, loff_t *ppos)
3155{
3156 return -ENOSYS;
3157}
3158
3159
Jovi Zhang55610502011-01-12 17:00:45 -08003160#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162/*
3163 * No sense putting this after each symbol definition, twice,
3164 * exception granted :-)
3165 */
3166EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003167EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168EXPORT_SYMBOL(proc_dointvec_jiffies);
3169EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003170EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3172EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3173EXPORT_SYMBOL(proc_dostring);
3174EXPORT_SYMBOL(proc_doulongvec_minmax);
3175EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);