blob: 59f09ea3ca3ef980a7b7bc3519eda2a3bd44aa7d [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>
Joe Lawrence7a8d1812017-11-17 15:29:24 -080069#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080071#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <asm/processor.h>
73
Andi Kleen29cbc782006-09-30 01:47:55 +020074#ifdef CONFIG_X86
75#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010076#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010077#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020078#endif
David Howellsd550bbd2012-03-28 18:30:03 +010079#ifdef CONFIG_SPARC
80#include <asm/setup.h>
81#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080082#ifdef CONFIG_BSD_PROCESS_ACCT
83#include <linux/acct.h>
84#endif
Dave Young4f0e0562010-03-10 15:24:09 -080085#ifdef CONFIG_RT_MUTEXES
86#include <linux/rtmutex.h>
87#endif
Dave Young2edf5e42010-03-10 15:24:10 -080088#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89#include <linux/lockdep.h>
90#endif
Dave Young15485a42010-03-10 15:24:07 -080091#ifdef CONFIG_CHR_DEV_SG
92#include <scsi/sg.h>
93#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020094
Don Zickus58687ac2010-05-07 17:11:44 -040095#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050096#include <linux/nmi.h>
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#if defined(CONFIG_SYSCTL)
100
101/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700102extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700103#ifdef CONFIG_COREDUMP
104extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700106extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300112extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700130static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700131#ifdef CONFIG_PRINTK
132static int ten_thousand = 10000;
133#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300134#ifdef CONFIG_PERF_EVENTS
135static int six_hundred_forty_kb = 640 * 1024;
136#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700137
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700138/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142static int maxolduid = 65535;
143static int minolduid;
144
145static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700146static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Liu Hua80df2842014-04-07 15:38:57 -0700148/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149#ifdef CONFIG_DETECT_HUNG_TASK
150static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
151#endif
152
Dave Youngd14f1722010-02-25 20:28:57 -0500153#ifdef CONFIG_INOTIFY_USER
154#include <linux/inotify.h>
155#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700156#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
159#ifdef __hppa__
160extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530161#endif
162
163#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164extern int unaligned_enabled;
165#endif
166
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800168extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800169#endif
170
Vineet Guptab6fca722013-01-09 20:06:28 +0530171#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172extern int no_unaligned_warning;
173#endif
174
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700175#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700176
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700177/**
178 * enum sysctl_writes_mode - supported sysctl write modes
179 *
180 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
181 * to be written, and multiple writes on the same sysctl file descriptor
182 * will rewrite the sysctl value, regardless of file position. No warning
183 * is issued when the initial position is not 0.
184 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
185 * not 0.
186 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
187 * file position 0 and the value must be fully contained in the buffer
188 * sent to the write syscall. If dealing with strings respect the file
189 * position, but restrict this to the max length of the buffer, anything
190 * passed the max lenght will be ignored. Multiple writes will append
191 * to the buffer.
192 *
193 * These write modes control how current file position affects the behavior of
194 * updating sysctl values through the proc interface on each write.
195 */
196enum sysctl_writes_mode {
197 SYSCTL_WRITES_LEGACY = -1,
198 SYSCTL_WRITES_WARN = 0,
199 SYSCTL_WRITES_STRICT = 1,
200};
Kees Cookf4aacea2014-06-06 14:37:19 -0700201
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700202static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700203
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700204static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700205 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700206static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800207 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700208#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700209
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700210#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700211static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700212 void __user *buffer, size_t *lenp, loff_t *ppos);
213#endif
214
Kees Cook54b50192012-07-30 14:39:18 -0700215static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
216 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700217#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700218static int proc_dostring_coredump(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700220#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800221static int proc_dopipe_max_size(struct ctl_table *table, int write,
222 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700223
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700224#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800225/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100226static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700227
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700228static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700229 void __user *buffer, size_t *lenp,
230 loff_t *ppos)
231{
232 int error;
233
234 error = proc_dointvec(table, write, buffer, lenp, ppos);
235 if (error)
236 return error;
237
238 if (write)
239 sysrq_toggle_support(__sysrq_enabled);
240
241 return 0;
242}
243
244#endif
245
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700246static struct ctl_table kern_table[];
247static struct ctl_table vm_table[];
248static struct ctl_table fs_table[];
249static struct ctl_table debug_table[];
250static struct ctl_table dev_table[];
251extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800252#ifdef CONFIG_EPOLL
253extern struct ctl_table epoll_table[];
254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
257int sysctl_legacy_va_layout;
258#endif
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/* The default sysctl tables: */
261
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800262static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 .procname = "kernel",
265 .mode = 0555,
266 .child = kern_table,
267 },
268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 .procname = "vm",
270 .mode = 0555,
271 .child = vm_table,
272 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .procname = "fs",
275 .mode = 0555,
276 .child = fs_table,
277 },
278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 .procname = "debug",
280 .mode = 0555,
281 .child = debug_table,
282 },
283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 .procname = "dev",
285 .mode = 0555,
286 .child = dev_table,
287 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700288 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289};
290
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100292static int min_sched_granularity_ns = 100000; /* 100 usecs */
293static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
294static int min_wakeup_granularity_ns; /* 0 usecs */
295static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200296#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100297static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
298static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200299#endif /* CONFIG_SMP */
300#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301
Mel Gorman5e771902010-05-24 14:32:31 -0700302#ifdef CONFIG_COMPACTION
303static int min_extfrag_threshold;
304static int max_extfrag_threshold = 1000;
305#endif
306
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700307static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200308 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200309 .procname = "sched_child_runs_first",
310 .data = &sysctl_sched_child_runs_first,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800313 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200314 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200315#ifdef CONFIG_SCHED_DEBUG
316 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100317 .procname = "sched_min_granularity_ns",
318 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800321 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100322 .extra1 = &min_sched_granularity_ns,
323 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200324 },
325 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200326 .procname = "sched_latency_ns",
327 .data = &sysctl_sched_latency,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800330 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200331 .extra1 = &min_sched_granularity_ns,
332 .extra2 = &max_sched_granularity_ns,
333 },
334 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200335 .procname = "sched_wakeup_granularity_ns",
336 .data = &sysctl_sched_wakeup_granularity,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800339 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200340 .extra1 = &min_wakeup_granularity_ns,
341 .extra2 = &max_wakeup_granularity_ns,
342 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200343#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200344 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100345 .procname = "sched_tunable_scaling",
346 .data = &sysctl_sched_tunable_scaling,
347 .maxlen = sizeof(enum sched_tunable_scaling),
348 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800349 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100350 .extra1 = &min_sched_tunable_scaling,
351 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200352 },
353 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900354 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200355 .data = &sysctl_sched_migration_cost,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800358 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200359 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100360 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100361 .procname = "sched_nr_migrate",
362 .data = &sysctl_sched_nr_migrate,
363 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800365 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100366 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530367 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900368 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200369 .data = &sysctl_sched_time_avg,
370 .maxlen = sizeof(unsigned int),
371 .mode = 0644,
Ethan Zhao5ccba442017-09-04 13:59:34 +0800372 .proc_handler = proc_dointvec_minmax,
373 .extra1 = &one,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200374 },
Mel Gormancb251762016-02-05 09:08:36 +0000375#ifdef CONFIG_SCHEDSTATS
376 {
377 .procname = "sched_schedstats",
378 .data = NULL,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
381 .proc_handler = sysctl_schedstats,
382 .extra1 = &zero,
383 .extra2 = &one,
384 },
385#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200386#endif /* CONFIG_SMP */
387#ifdef CONFIG_NUMA_BALANCING
388 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200389 .procname = "numa_balancing_scan_delay_ms",
390 .data = &sysctl_numa_balancing_scan_delay,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = proc_dointvec,
394 },
395 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200396 .procname = "numa_balancing_scan_period_min_ms",
397 .data = &sysctl_numa_balancing_scan_period_min,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = proc_dointvec,
401 },
402 {
403 .procname = "numa_balancing_scan_period_max_ms",
404 .data = &sysctl_numa_balancing_scan_period_max,
405 .maxlen = sizeof(unsigned int),
406 .mode = 0644,
407 .proc_handler = proc_dointvec,
408 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200409 {
410 .procname = "numa_balancing_scan_size_mb",
411 .data = &sysctl_numa_balancing_scan_size,
412 .maxlen = sizeof(unsigned int),
413 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400414 .proc_handler = proc_dointvec_minmax,
415 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200416 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100417 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800418 .procname = "numa_balancing",
419 .data = NULL, /* filled in by handler */
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
422 .proc_handler = sysctl_numa_balancing,
423 .extra1 = &zero,
424 .extra2 = &one,
425 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200426#endif /* CONFIG_NUMA_BALANCING */
427#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200428 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100429 .procname = "sched_rt_period_us",
430 .data = &sysctl_sched_rt_period,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100434 },
435 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100436 .procname = "sched_rt_runtime_us",
437 .data = &sysctl_sched_rt_runtime,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100441 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600442 {
443 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800444 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = sched_rr_handler,
448 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100449#ifdef CONFIG_SCHED_AUTOGROUP
450 {
451 .procname = "sched_autogroup_enabled",
452 .data = &sysctl_sched_autogroup_enabled,
453 .maxlen = sizeof(unsigned int),
454 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800455 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100456 .extra1 = &zero,
457 .extra2 = &one,
458 },
459#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700460#ifdef CONFIG_CFS_BANDWIDTH
461 {
462 .procname = "sched_cfs_bandwidth_slice_us",
463 .data = &sysctl_sched_cfs_bandwidth_slice,
464 .maxlen = sizeof(unsigned int),
465 .mode = 0644,
466 .proc_handler = proc_dointvec_minmax,
467 .extra1 = &one,
468 },
469#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700470#ifdef CONFIG_PROVE_LOCKING
471 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700472 .procname = "prove_locking",
473 .data = &prove_locking,
474 .maxlen = sizeof(int),
475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800476 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700477 },
478#endif
479#ifdef CONFIG_LOCK_STAT
480 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700481 .procname = "lock_stat",
482 .data = &lock_stat,
483 .maxlen = sizeof(int),
484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800485 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700486 },
487#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200488 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 .procname = "panic",
490 .data = &panic_timeout,
491 .maxlen = sizeof(int),
492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 },
Alex Kelly046d6622012-10-04 17:15:23 -0700495#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .procname = "core_uses_pid",
498 .data = &core_uses_pid,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800501 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 },
503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .procname = "core_pattern",
505 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700506 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700508 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 },
Neil Hormana2939802009-09-23 15:56:56 -0700510 {
Neil Hormana2939802009-09-23 15:56:56 -0700511 .procname = "core_pipe_limit",
512 .data = &core_pipe_limit,
513 .maxlen = sizeof(unsigned int),
514 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800515 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700516 },
Alex Kelly046d6622012-10-04 17:15:23 -0700517#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800518#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700521 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800523 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700525 {
526 .procname = "sysctl_writes_strict",
527 .data = &sysctl_writes_strict,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = proc_dointvec_minmax,
531 .extra1 = &neg_one,
532 .extra2 = &one,
533 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800534#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100535#ifdef CONFIG_LATENCYTOP
536 {
537 .procname = "latencytop",
538 .data = &latencytop_enabled,
539 .maxlen = sizeof(int),
540 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000541 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100542 },
543#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544#ifdef CONFIG_BLK_DEV_INITRD
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "real-root-dev",
547 .data = &real_root_dev,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700553 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700554 .procname = "print-fatal-signals",
555 .data = &print_fatal_signals,
556 .maxlen = sizeof(int),
557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800558 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700559 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700560#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "reboot-cmd",
563 .data = reboot_command,
564 .maxlen = 256,
565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 },
568 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 .procname = "stop-a",
570 .data = &stop_a_enabled,
571 .maxlen = sizeof (int),
572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800573 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 },
575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 .procname = "scons-poweroff",
577 .data = &scons_pwroff,
578 .maxlen = sizeof (int),
579 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800580 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 },
582#endif
David S. Miller08714202008-11-16 23:49:24 -0800583#ifdef CONFIG_SPARC64
584 {
David S. Miller08714202008-11-16 23:49:24 -0800585 .procname = "tsb-ratio",
586 .data = &sysctl_tsb_ratio,
587 .maxlen = sizeof (int),
588 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800589 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800590 },
591#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#ifdef __hppa__
593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "soft-power",
595 .data = &pwrsw_enabled,
596 .maxlen = sizeof (int),
597 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800598 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530600#endif
601#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .procname = "unaligned-trap",
604 .data = &unaligned_enabled,
605 .maxlen = sizeof (int),
606 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800607 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 },
609#endif
610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "ctrl-alt-del",
612 .data = &C_A_D,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800615 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400617#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200618 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200619 .procname = "ftrace_enabled",
620 .data = &ftrace_enabled,
621 .maxlen = sizeof(int),
622 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800623 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200624 },
625#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500626#ifdef CONFIG_STACK_TRACER
627 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500628 .procname = "stack_tracer_enabled",
629 .data = &stack_tracer_enabled,
630 .maxlen = sizeof(int),
631 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800632 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500633 },
634#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400635#ifdef CONFIG_TRACING
636 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100637 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400638 .data = &ftrace_dump_on_oops,
639 .maxlen = sizeof(int),
640 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800641 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400642 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400643 {
644 .procname = "traceoff_on_warning",
645 .data = &__disable_trace_on_warning,
646 .maxlen = sizeof(__disable_trace_on_warning),
647 .mode = 0644,
648 .proc_handler = proc_dointvec,
649 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500650 {
651 .procname = "tracepoint_printk",
652 .data = &tracepoint_printk,
653 .maxlen = sizeof(tracepoint_printk),
654 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500655 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500656 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400657#endif
Dave Young2965faa2015-09-09 15:38:55 -0700658#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800659 {
660 .procname = "kexec_load_disabled",
661 .data = &kexec_load_disabled,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 /* only handle a transition from default "0" to "1" */
665 .proc_handler = proc_dointvec_minmax,
666 .extra1 = &one,
667 .extra2 = &one,
668 },
669#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200670#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 .procname = "modprobe",
673 .data = &modprobe_path,
674 .maxlen = KMOD_PATH_LEN,
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 },
Kees Cook3d433212009-04-02 15:49:29 -0700678 {
Kees Cook3d433212009-04-02 15:49:29 -0700679 .procname = "modules_disabled",
680 .data = &modules_disabled,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800684 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700685 .extra1 = &one,
686 .extra2 = &one,
687 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700689#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100692 .data = &uevent_helper,
693 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800695 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
Michael Marineau86d56132014-04-10 14:09:31 -0700697#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#ifdef CONFIG_CHR_DEV_SG
699 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 .procname = "sg-big-buff",
701 .data = &sg_big_buff,
702 .maxlen = sizeof (int),
703 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800704 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 },
706#endif
707#ifdef CONFIG_BSD_PROCESS_ACCT
708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 .procname = "acct",
710 .data = &acct_parm,
711 .maxlen = 3*sizeof(int),
712 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800713 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
715#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#ifdef CONFIG_MAGIC_SYSRQ
717 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800719 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .maxlen = sizeof (int),
721 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700722 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 },
724#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700725#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700728 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .maxlen = sizeof (int),
730 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800731 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700733#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700736 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .maxlen = sizeof(int),
738 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700739 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 },
741 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .procname = "random",
743 .mode = 0555,
744 .child = random_table,
745 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 {
Eric Paris17f60a72011-04-01 17:07:50 -0400747 .procname = "usermodehelper",
748 .mode = 0555,
749 .child = usermodehelper_table,
750 },
751 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 .procname = "overflowuid",
753 .data = &overflowuid,
754 .maxlen = sizeof(int),
755 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800756 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 .extra1 = &minolduid,
758 .extra2 = &maxolduid,
759 },
760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .procname = "overflowgid",
762 .data = &overflowgid,
763 .maxlen = sizeof(int),
764 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800765 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 .extra1 = &minolduid,
767 .extra2 = &maxolduid,
768 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800769#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770#ifdef CONFIG_MATHEMU
771 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 .procname = "ieee_emulation_warnings",
773 .data = &sysctl_ieee_emulation_warnings,
774 .maxlen = sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 },
778#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200781 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .maxlen = sizeof(int),
783 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 },
786#endif
787 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .procname = "pid_max",
789 .data = &pid_max,
790 .maxlen = sizeof (int),
791 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 .extra1 = &pid_max_min,
794 .extra2 = &pid_max_max,
795 },
796 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .procname = "panic_on_oops",
798 .data = &panic_on_oops,
799 .maxlen = sizeof(int),
800 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800803#if defined CONFIG_PRINTK
804 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800805 .procname = "printk",
806 .data = &console_loglevel,
807 .maxlen = 4*sizeof(int),
808 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800809 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800810 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700813 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 .maxlen = sizeof(int),
815 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800816 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 },
818 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700820 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 .maxlen = sizeof(int),
822 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800823 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 },
Dave Youngaf913222009-09-22 16:43:33 -0700825 {
Dave Youngaf913222009-09-22 16:43:33 -0700826 .procname = "printk_delay",
827 .data = &printk_delay_msec,
828 .maxlen = sizeof(int),
829 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800830 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700831 .extra1 = &zero,
832 .extra2 = &ten_thousand,
833 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700835 .procname = "printk_devkmsg",
836 .data = devkmsg_log_str,
837 .maxlen = DEVKMSG_STR_MAX_SIZE,
838 .mode = 0644,
839 .proc_handler = devkmsg_sysctl_set_loglvl,
840 },
841 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800842 .procname = "dmesg_restrict",
843 .data = &dmesg_restrict,
844 .maxlen = sizeof(int),
845 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700846 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800847 .extra1 = &zero,
848 .extra2 = &one,
849 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800850 {
851 .procname = "kptr_restrict",
852 .data = &kptr_restrict,
853 .maxlen = sizeof(int),
854 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700855 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800856 .extra1 = &zero,
857 .extra2 = &two,
858 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800859#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800860 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 .procname = "ngroups_max",
862 .data = &ngroups_max,
863 .maxlen = sizeof (int),
864 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800865 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 },
Dan Ballard73efc032011-10-31 17:11:20 -0700867 {
868 .procname = "cap_last_cap",
869 .data = (void *)&cap_last_cap,
870 .maxlen = sizeof(int),
871 .mode = 0444,
872 .proc_handler = proc_dointvec,
873 },
Don Zickus58687ac2010-05-07 17:11:44 -0400874#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500875 {
Don Zickus58687ac2010-05-07 17:11:44 -0400876 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200877 .data = &watchdog_user_enabled,
878 .maxlen = sizeof(int),
879 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700880 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700881 .extra1 = &zero,
882 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400883 },
884 {
885 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700886 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400887 .maxlen = sizeof(int),
888 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700889 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800890 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400891 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500892 },
Don Zickus2508ce12010-05-07 17:11:46 -0400893 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700894 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200895 .data = &nmi_watchdog_user_enabled,
896 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200897 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700898 .proc_handler = proc_nmi_watchdog,
899 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700900 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700901 },
902 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700903 .procname = "watchdog_cpumask",
904 .data = &watchdog_cpumask_bits,
905 .maxlen = NR_CPUS,
906 .mode = 0644,
907 .proc_handler = proc_watchdog_cpumask,
908 },
909#ifdef CONFIG_SOFTLOCKUP_DETECTOR
910 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700911 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200912 .data = &soft_watchdog_user_enabled,
913 .maxlen = sizeof(int),
914 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700915 .proc_handler = proc_soft_watchdog,
916 .extra1 = &zero,
917 .extra2 = &one,
918 },
919 {
Don Zickus2508ce12010-05-07 17:11:46 -0400920 .procname = "softlockup_panic",
921 .data = &softlockup_panic,
922 .maxlen = sizeof(int),
923 .mode = 0644,
924 .proc_handler = proc_dointvec_minmax,
925 .extra1 = &zero,
926 .extra2 = &one,
927 },
Aaron Tomlined235872014-06-23 13:22:05 -0700928#ifdef CONFIG_SMP
929 {
930 .procname = "softlockup_all_cpu_backtrace",
931 .data = &sysctl_softlockup_all_cpu_backtrace,
932 .maxlen = sizeof(int),
933 .mode = 0644,
934 .proc_handler = proc_dointvec_minmax,
935 .extra1 = &zero,
936 .extra2 = &one,
937 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700938#endif /* CONFIG_SMP */
939#endif
940#ifdef CONFIG_HARDLOCKUP_DETECTOR
941 {
942 .procname = "hardlockup_panic",
943 .data = &hardlockup_panic,
944 .maxlen = sizeof(int),
945 .mode = 0644,
946 .proc_handler = proc_dointvec_minmax,
947 .extra1 = &zero,
948 .extra2 = &one,
949 },
950#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800951 {
952 .procname = "hardlockup_all_cpu_backtrace",
953 .data = &sysctl_hardlockup_all_cpu_backtrace,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = proc_dointvec_minmax,
957 .extra1 = &zero,
958 .extra2 = &one,
959 },
Aaron Tomlined235872014-06-23 13:22:05 -0700960#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500961#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700962#endif
963
Don Zickus5dc30552010-11-29 17:07:17 -0500964#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
965 {
966 .procname = "unknown_nmi_panic",
967 .data = &unknown_nmi_panic,
968 .maxlen = sizeof (int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec,
971 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500972#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973#if defined(CONFIG_X86)
974 {
Don Zickus8da5add2006-09-26 10:52:27 +0200975 .procname = "panic_on_unrecovered_nmi",
976 .data = &panic_on_unrecovered_nmi,
977 .maxlen = sizeof(int),
978 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800979 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200980 },
981 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700982 .procname = "panic_on_io_nmi",
983 .data = &panic_on_io_nmi,
984 .maxlen = sizeof(int),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700987 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900988#ifdef CONFIG_DEBUG_STACKOVERFLOW
989 {
990 .procname = "panic_on_stackoverflow",
991 .data = &sysctl_panic_on_stackoverflow,
992 .maxlen = sizeof(int),
993 .mode = 0644,
994 .proc_handler = proc_dointvec,
995 },
996#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700997 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 .procname = "bootloader_type",
999 .data = &bootloader_type,
1000 .maxlen = sizeof (int),
1001 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001004 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001005 .procname = "bootloader_version",
1006 .data = &bootloader_version,
1007 .maxlen = sizeof (int),
1008 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001010 },
1011 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001012 .procname = "io_delay_type",
1013 .data = &io_delay_type,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001017 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001019#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 .procname = "randomize_va_space",
1022 .data = &randomize_va_space,
1023 .maxlen = sizeof(int),
1024 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001025 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001027#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001028#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001029 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001030 .procname = "spin_retry",
1031 .data = &spin_retry,
1032 .maxlen = sizeof (int),
1033 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001034 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001035 },
1036#endif
Len Brown673d5b42007-07-28 03:33:16 -04001037#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001038 {
Pavel Machekc255d842006-02-20 18:27:58 -08001039 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001040 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001041 .maxlen = sizeof (unsigned long),
1042 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001043 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001044 },
1045#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301046#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001047 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001048 .procname = "ignore-unaligned-usertrap",
1049 .data = &no_unaligned_warning,
1050 .maxlen = sizeof (int),
1051 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001052 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001053 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301054#endif
1055#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001056 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001057 .procname = "unaligned-dump-stack",
1058 .data = &unaligned_dump_stack,
1059 .maxlen = sizeof (int),
1060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001062 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001063#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001064#ifdef CONFIG_DETECT_HUNG_TASK
1065 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001066 .procname = "hung_task_panic",
1067 .data = &sysctl_hung_task_panic,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001071 .extra1 = &zero,
1072 .extra2 = &one,
1073 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001074 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001075 .procname = "hung_task_check_count",
1076 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001077 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001078 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001079 .proc_handler = proc_dointvec_minmax,
1080 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001081 },
1082 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001083 .procname = "hung_task_timeout_secs",
1084 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001085 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001088 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001089 },
1090 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001091 .procname = "hung_task_warnings",
1092 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001093 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001094 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001095 .proc_handler = proc_dointvec_minmax,
1096 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001097 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001098#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001099#ifdef CONFIG_RT_MUTEXES
1100 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001101 .procname = "max_lock_depth",
1102 .data = &max_lock_depth,
1103 .maxlen = sizeof(int),
1104 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001105 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001106 },
1107#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001108 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001109 .procname = "poweroff_cmd",
1110 .data = &poweroff_cmd,
1111 .maxlen = POWEROFF_CMD_PATH_LEN,
1112 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001113 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001114 },
David Howells0b77f5b2008-04-29 01:01:32 -07001115#ifdef CONFIG_KEYS
1116 {
David Howells0b77f5b2008-04-29 01:01:32 -07001117 .procname = "keys",
1118 .mode = 0555,
1119 .child = key_sysctls,
1120 },
1121#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001122#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001123 /*
1124 * User-space scripts rely on the existence of this file
1125 * as a feature check for perf_events being enabled.
1126 *
1127 * So it's an ABI, do not remove!
1128 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001129 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001130 .procname = "perf_event_paranoid",
1131 .data = &sysctl_perf_event_paranoid,
1132 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001133 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001134 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001135 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001136 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001137 .procname = "perf_event_mlock_kb",
1138 .data = &sysctl_perf_event_mlock,
1139 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001140 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001141 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001142 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001143 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001144 .procname = "perf_event_max_sample_rate",
1145 .data = &sysctl_perf_event_sample_rate,
1146 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001147 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001148 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001149 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001150 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001151 {
1152 .procname = "perf_cpu_time_max_percent",
1153 .data = &sysctl_perf_cpu_time_max_percent,
1154 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1155 .mode = 0644,
1156 .proc_handler = perf_cpu_time_max_percent_handler,
1157 .extra1 = &zero,
1158 .extra2 = &one_hundred,
1159 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001160 {
1161 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001162 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001163 .maxlen = sizeof(sysctl_perf_event_max_stack),
1164 .mode = 0644,
1165 .proc_handler = perf_event_max_stack_handler,
1166 .extra1 = &zero,
1167 .extra2 = &six_hundred_forty_kb,
1168 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001169 {
1170 .procname = "perf_event_max_contexts_per_stack",
1171 .data = &sysctl_perf_event_max_contexts_per_stack,
1172 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1173 .mode = 0644,
1174 .proc_handler = perf_event_max_stack_handler,
1175 .extra1 = &zero,
1176 .extra2 = &one_thousand,
1177 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001178#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001179 {
1180 .procname = "panic_on_warn",
1181 .data = &panic_on_warn,
1182 .maxlen = sizeof(int),
1183 .mode = 0644,
1184 .proc_handler = proc_dointvec_minmax,
1185 .extra1 = &zero,
1186 .extra2 = &one,
1187 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001188#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1189 {
1190 .procname = "timer_migration",
1191 .data = &sysctl_timer_migration,
1192 .maxlen = sizeof(unsigned int),
1193 .mode = 0644,
1194 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001195 .extra1 = &zero,
1196 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001197 },
1198#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001199#ifdef CONFIG_BPF_SYSCALL
1200 {
1201 .procname = "unprivileged_bpf_disabled",
1202 .data = &sysctl_unprivileged_bpf_disabled,
1203 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1204 .mode = 0644,
1205 /* only handle a transition from default "0" to "1" */
1206 .proc_handler = proc_dointvec_minmax,
1207 .extra1 = &one,
1208 .extra2 = &one,
1209 },
1210#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001211#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1212 {
1213 .procname = "panic_on_rcu_stall",
1214 .data = &sysctl_panic_on_rcu_stall,
1215 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1216 .mode = 0644,
1217 .proc_handler = proc_dointvec_minmax,
1218 .extra1 = &zero,
1219 .extra2 = &one,
1220 },
1221#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001222 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223};
1224
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001225static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .procname = "overcommit_memory",
1228 .data = &sysctl_overcommit_memory,
1229 .maxlen = sizeof(sysctl_overcommit_memory),
1230 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001231 .proc_handler = proc_dointvec_minmax,
1232 .extra1 = &zero,
1233 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 },
1235 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001236 .procname = "panic_on_oom",
1237 .data = &sysctl_panic_on_oom,
1238 .maxlen = sizeof(sysctl_panic_on_oom),
1239 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001240 .proc_handler = proc_dointvec_minmax,
1241 .extra1 = &zero,
1242 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001243 },
1244 {
David Rientjesfe071d72007-10-16 23:25:56 -07001245 .procname = "oom_kill_allocating_task",
1246 .data = &sysctl_oom_kill_allocating_task,
1247 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1248 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001249 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001250 },
1251 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001252 .procname = "oom_dump_tasks",
1253 .data = &sysctl_oom_dump_tasks,
1254 .maxlen = sizeof(sysctl_oom_dump_tasks),
1255 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001256 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001257 },
1258 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 .procname = "overcommit_ratio",
1260 .data = &sysctl_overcommit_ratio,
1261 .maxlen = sizeof(sysctl_overcommit_ratio),
1262 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001263 .proc_handler = overcommit_ratio_handler,
1264 },
1265 {
1266 .procname = "overcommit_kbytes",
1267 .data = &sysctl_overcommit_kbytes,
1268 .maxlen = sizeof(sysctl_overcommit_kbytes),
1269 .mode = 0644,
1270 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 },
1272 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 .procname = "page-cluster",
1274 .data = &page_cluster,
1275 .maxlen = sizeof(int),
1276 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001277 .proc_handler = proc_dointvec_minmax,
1278 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 },
1280 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 .procname = "dirty_background_ratio",
1282 .data = &dirty_background_ratio,
1283 .maxlen = sizeof(dirty_background_ratio),
1284 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001285 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 .extra1 = &zero,
1287 .extra2 = &one_hundred,
1288 },
1289 {
David Rientjes2da02992009-01-06 14:39:31 -08001290 .procname = "dirty_background_bytes",
1291 .data = &dirty_background_bytes,
1292 .maxlen = sizeof(dirty_background_bytes),
1293 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001294 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001295 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001296 },
1297 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 .procname = "dirty_ratio",
1299 .data = &vm_dirty_ratio,
1300 .maxlen = sizeof(vm_dirty_ratio),
1301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 .extra1 = &zero,
1304 .extra2 = &one_hundred,
1305 },
1306 {
David Rientjes2da02992009-01-06 14:39:31 -08001307 .procname = "dirty_bytes",
1308 .data = &vm_dirty_bytes,
1309 .maxlen = sizeof(vm_dirty_bytes),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001312 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001313 },
1314 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001316 .data = &dirty_writeback_interval,
1317 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001319 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 },
1321 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001323 .data = &dirty_expire_interval,
1324 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001326 .proc_handler = proc_dointvec_minmax,
1327 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 },
1329 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001330 .procname = "dirtytime_expire_seconds",
1331 .data = &dirtytime_expire_interval,
1332 .maxlen = sizeof(dirty_expire_interval),
1333 .mode = 0644,
1334 .proc_handler = dirtytime_interval_handler,
1335 .extra1 = &zero,
1336 },
1337 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 .procname = "swappiness",
1339 .data = &vm_swappiness,
1340 .maxlen = sizeof(vm_swappiness),
1341 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001342 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 .extra1 = &zero,
1344 .extra2 = &one_hundred,
1345 },
1346#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001349 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .maxlen = sizeof(unsigned long),
1351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001353 },
1354#ifdef CONFIG_NUMA
1355 {
1356 .procname = "nr_hugepages_mempolicy",
1357 .data = NULL,
1358 .maxlen = sizeof(unsigned long),
1359 .mode = 0644,
1360 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001361 },
Kemi Wang45180852017-11-15 17:38:22 -08001362 {
1363 .procname = "numa_stat",
1364 .data = &sysctl_vm_numa_stat,
1365 .maxlen = sizeof(int),
1366 .mode = 0644,
1367 .proc_handler = sysctl_vm_numa_stat_handler,
1368 .extra1 = &zero,
1369 .extra2 = &one,
1370 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001371#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 .procname = "hugetlb_shm_group",
1374 .data = &sysctl_hugetlb_shm_group,
1375 .maxlen = sizeof(gid_t),
1376 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001377 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 },
Adam Litke54f9f802007-10-16 01:26:20 -07001379 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001380 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001381 .data = NULL,
1382 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001383 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001384 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001385 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386#endif
1387 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .procname = "lowmem_reserve_ratio",
1389 .data = &sysctl_lowmem_reserve_ratio,
1390 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001392 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 },
1394 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001395 .procname = "drop_caches",
1396 .data = &sysctl_drop_caches,
1397 .maxlen = sizeof(int),
1398 .mode = 0644,
1399 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001400 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001401 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001402 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001403#ifdef CONFIG_COMPACTION
1404 {
1405 .procname = "compact_memory",
1406 .data = &sysctl_compact_memory,
1407 .maxlen = sizeof(int),
1408 .mode = 0200,
1409 .proc_handler = sysctl_compaction_handler,
1410 },
Mel Gorman5e771902010-05-24 14:32:31 -07001411 {
1412 .procname = "extfrag_threshold",
1413 .data = &sysctl_extfrag_threshold,
1414 .maxlen = sizeof(int),
1415 .mode = 0644,
1416 .proc_handler = sysctl_extfrag_handler,
1417 .extra1 = &min_extfrag_threshold,
1418 .extra2 = &max_extfrag_threshold,
1419 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001420 {
1421 .procname = "compact_unevictable_allowed",
1422 .data = &sysctl_compact_unevictable_allowed,
1423 .maxlen = sizeof(int),
1424 .mode = 0644,
1425 .proc_handler = proc_dointvec,
1426 .extra1 = &zero,
1427 .extra2 = &one,
1428 },
Mel Gorman5e771902010-05-24 14:32:31 -07001429
Mel Gorman76ab0f52010-05-24 14:32:28 -07001430#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .procname = "min_free_kbytes",
1433 .data = &min_free_kbytes,
1434 .maxlen = sizeof(min_free_kbytes),
1435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 .extra1 = &zero,
1438 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001439 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001440 .procname = "watermark_scale_factor",
1441 .data = &watermark_scale_factor,
1442 .maxlen = sizeof(watermark_scale_factor),
1443 .mode = 0644,
1444 .proc_handler = watermark_scale_factor_sysctl_handler,
1445 .extra1 = &one,
1446 .extra2 = &one_thousand,
1447 },
1448 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001449 .procname = "percpu_pagelist_fraction",
1450 .data = &percpu_pagelist_fraction,
1451 .maxlen = sizeof(percpu_pagelist_fraction),
1452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001453 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001454 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001455 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456#ifdef CONFIG_MMU
1457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 .procname = "max_map_count",
1459 .data = &sysctl_max_map_count,
1460 .maxlen = sizeof(sysctl_max_map_count),
1461 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001462 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001463 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001465#else
1466 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001467 .procname = "nr_trim_pages",
1468 .data = &sysctl_nr_trim_pages,
1469 .maxlen = sizeof(sysctl_nr_trim_pages),
1470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001471 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001472 .extra1 = &zero,
1473 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474#endif
1475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 .procname = "laptop_mode",
1477 .data = &laptop_mode,
1478 .maxlen = sizeof(laptop_mode),
1479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001480 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 },
1482 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 .procname = "block_dump",
1484 .data = &block_dump,
1485 .maxlen = sizeof(block_dump),
1486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001487 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 .extra1 = &zero,
1489 },
1490 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 .procname = "vfs_cache_pressure",
1492 .data = &sysctl_vfs_cache_pressure,
1493 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1494 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001495 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 .extra1 = &zero,
1497 },
1498#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 .procname = "legacy_va_layout",
1501 .data = &sysctl_legacy_va_layout,
1502 .maxlen = sizeof(sysctl_legacy_va_layout),
1503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001504 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 .extra1 = &zero,
1506 },
1507#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001508#ifdef CONFIG_NUMA
1509 {
Christoph Lameter17436602006-01-18 17:42:32 -08001510 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001511 .data = &node_reclaim_mode,
1512 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001514 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001515 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001516 },
Christoph Lameter96146342006-07-03 00:24:13 -07001517 {
Christoph Lameter96146342006-07-03 00:24:13 -07001518 .procname = "min_unmapped_ratio",
1519 .data = &sysctl_min_unmapped_ratio,
1520 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1521 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001522 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001523 .extra1 = &zero,
1524 .extra2 = &one_hundred,
1525 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001526 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001527 .procname = "min_slab_ratio",
1528 .data = &sysctl_min_slab_ratio,
1529 .maxlen = sizeof(sysctl_min_slab_ratio),
1530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001531 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001532 .extra1 = &zero,
1533 .extra2 = &one_hundred,
1534 },
Christoph Lameter17436602006-01-18 17:42:32 -08001535#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001536#ifdef CONFIG_SMP
1537 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001538 .procname = "stat_interval",
1539 .data = &sysctl_stat_interval,
1540 .maxlen = sizeof(sysctl_stat_interval),
1541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001542 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001543 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001544 {
1545 .procname = "stat_refresh",
1546 .data = NULL,
1547 .maxlen = 0,
1548 .mode = 0600,
1549 .proc_handler = vmstat_refresh,
1550 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001551#endif
David Howells6e141542009-12-15 19:27:45 +00001552#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001553 {
Eric Parised032182007-06-28 15:55:21 -04001554 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001555 .data = &dac_mmap_min_addr,
1556 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001558 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001559 },
David Howells6e141542009-12-15 19:27:45 +00001560#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001561#ifdef CONFIG_NUMA
1562 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001563 .procname = "numa_zonelist_order",
1564 .data = &numa_zonelist_order,
1565 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001567 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001568 },
1569#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001570#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001571 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001572 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001573 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001574#ifdef CONFIG_X86_32
1575 .data = &vdso32_enabled,
1576 .maxlen = sizeof(vdso32_enabled),
1577#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001578 .data = &vdso_enabled,
1579 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001580#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001582 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001583 .extra1 = &zero,
1584 },
1585#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001586#ifdef CONFIG_HIGHMEM
1587 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001588 .procname = "highmem_is_dirtyable",
1589 .data = &vm_highmem_is_dirtyable,
1590 .maxlen = sizeof(vm_highmem_is_dirtyable),
1591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001592 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001593 .extra1 = &zero,
1594 .extra2 = &one,
1595 },
1596#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001597#ifdef CONFIG_MEMORY_FAILURE
1598 {
Andi Kleen6a460792009-09-16 11:50:15 +02001599 .procname = "memory_failure_early_kill",
1600 .data = &sysctl_memory_failure_early_kill,
1601 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001603 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001604 .extra1 = &zero,
1605 .extra2 = &one,
1606 },
1607 {
Andi Kleen6a460792009-09-16 11:50:15 +02001608 .procname = "memory_failure_recovery",
1609 .data = &sysctl_memory_failure_recovery,
1610 .maxlen = sizeof(sysctl_memory_failure_recovery),
1611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001612 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001613 .extra1 = &zero,
1614 .extra2 = &one,
1615 },
1616#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001617 {
1618 .procname = "user_reserve_kbytes",
1619 .data = &sysctl_user_reserve_kbytes,
1620 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1621 .mode = 0644,
1622 .proc_handler = proc_doulongvec_minmax,
1623 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001624 {
1625 .procname = "admin_reserve_kbytes",
1626 .data = &sysctl_admin_reserve_kbytes,
1627 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1628 .mode = 0644,
1629 .proc_handler = proc_doulongvec_minmax,
1630 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001631#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1632 {
1633 .procname = "mmap_rnd_bits",
1634 .data = &mmap_rnd_bits,
1635 .maxlen = sizeof(mmap_rnd_bits),
1636 .mode = 0600,
1637 .proc_handler = proc_dointvec_minmax,
1638 .extra1 = (void *)&mmap_rnd_bits_min,
1639 .extra2 = (void *)&mmap_rnd_bits_max,
1640 },
1641#endif
1642#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1643 {
1644 .procname = "mmap_rnd_compat_bits",
1645 .data = &mmap_rnd_compat_bits,
1646 .maxlen = sizeof(mmap_rnd_compat_bits),
1647 .mode = 0600,
1648 .proc_handler = proc_dointvec_minmax,
1649 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1650 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1651 },
1652#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001653 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654};
1655
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001656static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 .procname = "inode-nr",
1659 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001660 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001662 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 },
1664 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 .procname = "inode-state",
1666 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001667 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001669 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 },
1671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .procname = "file-nr",
1673 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001674 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001676 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 },
1678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .procname = "file-max",
1680 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001681 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001683 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 },
1685 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001686 .procname = "nr_open",
1687 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001688 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001690 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001691 .extra1 = &sysctl_nr_open_min,
1692 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001693 },
1694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 .procname = "dentry-state",
1696 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001697 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001699 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 },
1701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 .procname = "overflowuid",
1703 .data = &fs_overflowuid,
1704 .maxlen = sizeof(int),
1705 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001706 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 .extra1 = &minolduid,
1708 .extra2 = &maxolduid,
1709 },
1710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 .procname = "overflowgid",
1712 .data = &fs_overflowgid,
1713 .maxlen = sizeof(int),
1714 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001715 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 .extra1 = &minolduid,
1717 .extra2 = &maxolduid,
1718 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001719#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 .procname = "leases-enable",
1722 .data = &leases_enable,
1723 .maxlen = sizeof(int),
1724 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001725 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001727#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728#ifdef CONFIG_DNOTIFY
1729 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 .procname = "dir-notify-enable",
1731 .data = &dir_notify_enable,
1732 .maxlen = sizeof(int),
1733 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001734 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 },
1736#endif
1737#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001738#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 .procname = "lease-break-time",
1741 .data = &lease_break_time,
1742 .maxlen = sizeof(int),
1743 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001744 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001746#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001747#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 .procname = "aio-nr",
1750 .data = &aio_nr,
1751 .maxlen = sizeof(aio_nr),
1752 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001753 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 },
1755 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 .procname = "aio-max-nr",
1757 .data = &aio_max_nr,
1758 .maxlen = sizeof(aio_max_nr),
1759 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001760 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001762#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001763#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001764 {
Robert Love0399cb02005-07-13 12:38:18 -04001765 .procname = "inotify",
1766 .mode = 0555,
1767 .child = inotify_table,
1768 },
1769#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001770#ifdef CONFIG_EPOLL
1771 {
1772 .procname = "epoll",
1773 .mode = 0555,
1774 .child = epoll_table,
1775 },
1776#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001778 {
Kees Cook800179c2012-07-25 17:29:07 -07001779 .procname = "protected_symlinks",
1780 .data = &sysctl_protected_symlinks,
1781 .maxlen = sizeof(int),
1782 .mode = 0600,
1783 .proc_handler = proc_dointvec_minmax,
1784 .extra1 = &zero,
1785 .extra2 = &one,
1786 },
1787 {
1788 .procname = "protected_hardlinks",
1789 .data = &sysctl_protected_hardlinks,
1790 .maxlen = sizeof(int),
1791 .mode = 0600,
1792 .proc_handler = proc_dointvec_minmax,
1793 .extra1 = &zero,
1794 .extra2 = &one,
1795 },
1796 {
Alan Coxd6e71142005-06-23 00:09:43 -07001797 .procname = "suid_dumpable",
1798 .data = &suid_dumpable,
1799 .maxlen = sizeof(int),
1800 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001801 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001802 .extra1 = &zero,
1803 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001804 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001805#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1806 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001807 .procname = "binfmt_misc",
1808 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001809 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001810 },
1811#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001812 {
Jens Axboeff9da692010-06-03 14:54:39 +02001813 .procname = "pipe-max-size",
1814 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001815 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001816 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001817 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001818 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001819 {
1820 .procname = "pipe-user-pages-hard",
1821 .data = &pipe_user_pages_hard,
1822 .maxlen = sizeof(pipe_user_pages_hard),
1823 .mode = 0644,
1824 .proc_handler = proc_doulongvec_minmax,
1825 },
1826 {
1827 .procname = "pipe-user-pages-soft",
1828 .data = &pipe_user_pages_soft,
1829 .maxlen = sizeof(pipe_user_pages_soft),
1830 .mode = 0644,
1831 .proc_handler = proc_doulongvec_minmax,
1832 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001833 {
1834 .procname = "mount-max",
1835 .data = &sysctl_mount_max,
1836 .maxlen = sizeof(unsigned int),
1837 .mode = 0644,
1838 .proc_handler = proc_dointvec_minmax,
1839 .extra1 = &one,
1840 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001841 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842};
1843
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001844static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001845#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001846 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001847 .procname = "exception-trace",
1848 .data = &show_unhandled_signals,
1849 .maxlen = sizeof(int),
1850 .mode = 0644,
1851 .proc_handler = proc_dointvec
1852 },
1853#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001854#if defined(CONFIG_OPTPROBES)
1855 {
1856 .procname = "kprobes-optimization",
1857 .data = &sysctl_kprobes_optimization,
1858 .maxlen = sizeof(int),
1859 .mode = 0644,
1860 .proc_handler = proc_kprobes_optimization_handler,
1861 .extra1 = &zero,
1862 .extra2 = &one,
1863 },
1864#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001865 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866};
1867
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001868static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001869 { }
Robert Love0eeca282005-07-12 17:06:03 -04001870};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001872int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001873{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001874 struct ctl_table_header *hdr;
1875
1876 hdr = register_sysctl_table(sysctl_base_table);
1877 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001878 return 0;
1879}
1880
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001881#endif /* CONFIG_SYSCTL */
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883/*
1884 * /proc/sys support
1885 */
1886
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001887#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Kees Cookf8808302014-06-06 14:37:17 -07001889static int _proc_do_string(char *data, int maxlen, int write,
1890 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001891 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001892{
1893 size_t len;
1894 char __user *p;
1895 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001896
1897 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001898 *lenp = 0;
1899 return 0;
1900 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001901
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001902 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001903 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1904 /* Only continue writes not past the end of buffer. */
1905 len = strlen(data);
1906 if (len > maxlen - 1)
1907 len = maxlen - 1;
1908
1909 if (*ppos > len)
1910 return 0;
1911 len = *ppos;
1912 } else {
1913 /* Start writing from beginning of buffer. */
1914 len = 0;
1915 }
1916
Kees Cook2ca9bb42014-06-06 14:37:18 -07001917 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001918 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001919 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001920 if (get_user(c, p++))
1921 return -EFAULT;
1922 if (c == 0 || c == '\n')
1923 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001924 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001925 }
Kees Cookf8808302014-06-06 14:37:17 -07001926 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001927 } else {
1928 len = strlen(data);
1929 if (len > maxlen)
1930 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001931
1932 if (*ppos > len) {
1933 *lenp = 0;
1934 return 0;
1935 }
1936
1937 data += *ppos;
1938 len -= *ppos;
1939
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001940 if (len > *lenp)
1941 len = *lenp;
1942 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001943 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001944 return -EFAULT;
1945 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001946 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001947 return -EFAULT;
1948 len++;
1949 }
1950 *lenp = len;
1951 *ppos += len;
1952 }
1953 return 0;
1954}
1955
Kees Cookf4aacea2014-06-06 14:37:19 -07001956static void warn_sysctl_write(struct ctl_table *table)
1957{
1958 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1959 "This will not be supported in the future. To silence this\n"
1960 "warning, set kernel.sysctl_writes_strict = -1\n",
1961 current->comm, table->procname);
1962}
1963
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964/**
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001965 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1966 * @ppos: file position
1967 * @table: the sysctl table
1968 *
1969 * Returns true if the first position is non-zero and the sysctl_writes_strict
1970 * mode indicates this is not allowed for numeric input types. String proc
1971 * hadlers can ignore the return value.
1972 */
1973static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
1974 struct ctl_table *table)
1975{
1976 if (!*ppos)
1977 return false;
1978
1979 switch (sysctl_writes_strict) {
1980 case SYSCTL_WRITES_STRICT:
1981 return true;
1982 case SYSCTL_WRITES_WARN:
1983 warn_sysctl_write(table);
1984 return false;
1985 default:
1986 return false;
1987 }
1988}
1989
1990/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 * proc_dostring - read a string sysctl
1992 * @table: the sysctl table
1993 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 * @buffer: the user buffer
1995 * @lenp: the size of the user buffer
1996 * @ppos: file position
1997 *
1998 * Reads/writes a string from/to the user buffer. If the kernel
1999 * buffer provided is not large enough to hold the string, the
2000 * string is truncated. The copied string is %NULL-terminated.
2001 * If the string is being read by the user process, it is copied
2002 * and a newline '\n' is added. It is truncated if the buffer is
2003 * not large enough.
2004 *
2005 * Returns 0 on success.
2006 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002007int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 void __user *buffer, size_t *lenp, loff_t *ppos)
2009{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002010 if (write)
2011 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002012
Kees Cookf8808302014-06-06 14:37:17 -07002013 return _proc_do_string((char *)(table->data), table->maxlen, write,
2014 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015}
2016
Amerigo Wang00b7c332010-05-05 00:26:45 +00002017static size_t proc_skip_spaces(char **buf)
2018{
2019 size_t ret;
2020 char *tmp = skip_spaces(*buf);
2021 ret = tmp - *buf;
2022 *buf = tmp;
2023 return ret;
2024}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002026static void proc_skip_char(char **buf, size_t *size, const char v)
2027{
2028 while (*size) {
2029 if (**buf != v)
2030 break;
2031 (*size)--;
2032 (*buf)++;
2033 }
2034}
2035
Amerigo Wang00b7c332010-05-05 00:26:45 +00002036#define TMPBUFLEN 22
2037/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002038 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002039 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002040 * @buf: a kernel buffer
2041 * @size: size of the kernel buffer
2042 * @val: this is where the number will be stored
2043 * @neg: set to %TRUE if number is negative
2044 * @perm_tr: a vector which contains the allowed trailers
2045 * @perm_tr_len: size of the perm_tr vector
2046 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002047 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002048 * In case of success %0 is returned and @buf and @size are updated with
2049 * the amount of bytes read. If @tr is non-NULL and a trailing
2050 * character exists (size is non-zero after returning from this
2051 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002052 */
2053static int proc_get_long(char **buf, size_t *size,
2054 unsigned long *val, bool *neg,
2055 const char *perm_tr, unsigned perm_tr_len, char *tr)
2056{
2057 int len;
2058 char *p, tmp[TMPBUFLEN];
2059
2060 if (!*size)
2061 return -EINVAL;
2062
2063 len = *size;
2064 if (len > TMPBUFLEN - 1)
2065 len = TMPBUFLEN - 1;
2066
2067 memcpy(tmp, *buf, len);
2068
2069 tmp[len] = 0;
2070 p = tmp;
2071 if (*p == '-' && *size > 1) {
2072 *neg = true;
2073 p++;
2074 } else
2075 *neg = false;
2076 if (!isdigit(*p))
2077 return -EINVAL;
2078
2079 *val = simple_strtoul(p, &p, 0);
2080
2081 len = p - tmp;
2082
2083 /* We don't know if the next char is whitespace thus we may accept
2084 * invalid integers (e.g. 1234...a) or two integers instead of one
2085 * (e.g. 123...1). So lets not allow such large numbers. */
2086 if (len == TMPBUFLEN - 1)
2087 return -EINVAL;
2088
2089 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2090 return -EINVAL;
2091
2092 if (tr && (len < *size))
2093 *tr = *p;
2094
2095 *buf += len;
2096 *size -= len;
2097
2098 return 0;
2099}
2100
2101/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002102 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002103 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002104 * @buf: the user buffer
2105 * @size: the size of the user buffer
2106 * @val: the integer to be converted
2107 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002108 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002109 * In case of success %0 is returned and @buf and @size are updated with
2110 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002111 */
2112static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2113 bool neg)
2114{
2115 int len;
2116 char tmp[TMPBUFLEN], *p = tmp;
2117
2118 sprintf(p, "%s%lu", neg ? "-" : "", val);
2119 len = strlen(tmp);
2120 if (len > *size)
2121 len = *size;
2122 if (copy_to_user(*buf, tmp, len))
2123 return -EFAULT;
2124 *size -= len;
2125 *buf += len;
2126 return 0;
2127}
2128#undef TMPBUFLEN
2129
2130static int proc_put_char(void __user **buf, size_t *size, char c)
2131{
2132 if (*size) {
2133 char __user **buffer = (char __user **)buf;
2134 if (put_user(c, *buffer))
2135 return -EFAULT;
2136 (*size)--, (*buffer)++;
2137 *buf = *buffer;
2138 }
2139 return 0;
2140}
2141
2142static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 int *valp,
2144 int write, void *data)
2145{
2146 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002147 if (*negp) {
2148 if (*lvalp > (unsigned long) INT_MAX + 1)
2149 return -EINVAL;
2150 *valp = -*lvalp;
2151 } else {
2152 if (*lvalp > (unsigned long) INT_MAX)
2153 return -EINVAL;
2154 *valp = *lvalp;
2155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 } else {
2157 int val = *valp;
2158 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002159 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002160 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002162 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 *lvalp = (unsigned long)val;
2164 }
2165 }
2166 return 0;
2167}
2168
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002169static int do_proc_douintvec_conv(unsigned long *lvalp,
2170 unsigned int *valp,
2171 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002172{
2173 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002174 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002175 return -EINVAL;
2176 *valp = *lvalp;
2177 } else {
2178 unsigned int val = *valp;
2179 *lvalp = (unsigned long)val;
2180 }
2181 return 0;
2182}
2183
Amerigo Wang00b7c332010-05-05 00:26:45 +00002184static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2185
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002186static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002187 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002188 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002189 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 int write, void *data),
2191 void *data)
2192{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002193 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002194 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002195 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Amerigo Wang00b7c332010-05-05 00:26:45 +00002197 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 *lenp = 0;
2199 return 0;
2200 }
2201
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002202 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 vleft = table->maxlen / sizeof(*i);
2204 left = *lenp;
2205
2206 if (!conv)
2207 conv = do_proc_dointvec_conv;
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002210 if (proc_first_pos_non_zero_ignore(ppos, table))
2211 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002212
Amerigo Wang00b7c332010-05-05 00:26:45 +00002213 if (left > PAGE_SIZE - 1)
2214 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002215 p = kbuf = memdup_user_nul(buffer, left);
2216 if (IS_ERR(kbuf))
2217 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002218 }
2219
2220 for (; left && vleft--; i++, first=0) {
2221 unsigned long lval;
2222 bool neg;
2223
2224 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002225 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002226
J. R. Okajima563b0462010-05-25 16:10:14 -07002227 if (!left)
2228 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002229 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230 proc_wspace_sep,
2231 sizeof(proc_wspace_sep), NULL);
2232 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002234 if (conv(&neg, &lval, i, 1, data)) {
2235 err = -EINVAL;
2236 break;
2237 }
2238 } else {
2239 if (conv(&neg, &lval, i, 0, data)) {
2240 err = -EINVAL;
2241 break;
2242 }
2243 if (!first)
2244 err = proc_put_char(&buffer, &left, '\t');
2245 if (err)
2246 break;
2247 err = proc_put_long(&buffer, &left, lval, neg);
2248 if (err)
2249 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 }
2251 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002252
2253 if (!write && !first && left && !err)
2254 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002255 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002256 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002257 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002258 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002259 if (first)
2260 return err ? : -EINVAL;
2261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002263out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002265 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266}
2267
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002268static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002269 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002271 int write, void *data),
2272 void *data)
2273{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002274 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002275 buffer, lenp, ppos, conv, data);
2276}
2277
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002278static int do_proc_douintvec_w(unsigned int *tbl_data,
2279 struct ctl_table *table,
2280 void __user *buffer,
2281 size_t *lenp, loff_t *ppos,
2282 int (*conv)(unsigned long *lvalp,
2283 unsigned int *valp,
2284 int write, void *data),
2285 void *data)
2286{
2287 unsigned long lval;
2288 int err = 0;
2289 size_t left;
2290 bool neg;
2291 char *kbuf = NULL, *p;
2292
2293 left = *lenp;
2294
2295 if (proc_first_pos_non_zero_ignore(ppos, table))
2296 goto bail_early;
2297
2298 if (left > PAGE_SIZE - 1)
2299 left = PAGE_SIZE - 1;
2300
2301 p = kbuf = memdup_user_nul(buffer, left);
2302 if (IS_ERR(kbuf))
2303 return -EINVAL;
2304
2305 left -= proc_skip_spaces(&p);
2306 if (!left) {
2307 err = -EINVAL;
2308 goto out_free;
2309 }
2310
2311 err = proc_get_long(&p, &left, &lval, &neg,
2312 proc_wspace_sep,
2313 sizeof(proc_wspace_sep), NULL);
2314 if (err || neg) {
2315 err = -EINVAL;
2316 goto out_free;
2317 }
2318
2319 if (conv(&lval, tbl_data, 1, data)) {
2320 err = -EINVAL;
2321 goto out_free;
2322 }
2323
2324 if (!err && left)
2325 left -= proc_skip_spaces(&p);
2326
2327out_free:
2328 kfree(kbuf);
2329 if (err)
2330 return -EINVAL;
2331
2332 return 0;
2333
2334 /* This is in keeping with old __do_proc_dointvec() */
2335bail_early:
2336 *ppos += *lenp;
2337 return err;
2338}
2339
2340static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2341 size_t *lenp, loff_t *ppos,
2342 int (*conv)(unsigned long *lvalp,
2343 unsigned int *valp,
2344 int write, void *data),
2345 void *data)
2346{
2347 unsigned long lval;
2348 int err = 0;
2349 size_t left;
2350
2351 left = *lenp;
2352
2353 if (conv(&lval, tbl_data, 0, data)) {
2354 err = -EINVAL;
2355 goto out;
2356 }
2357
2358 err = proc_put_long(&buffer, &left, lval, false);
2359 if (err || !left)
2360 goto out;
2361
2362 err = proc_put_char(&buffer, &left, '\n');
2363
2364out:
2365 *lenp -= left;
2366 *ppos += *lenp;
2367
2368 return err;
2369}
2370
2371static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2372 int write, void __user *buffer,
2373 size_t *lenp, loff_t *ppos,
2374 int (*conv)(unsigned long *lvalp,
2375 unsigned int *valp,
2376 int write, void *data),
2377 void *data)
2378{
2379 unsigned int *i, vleft;
2380
2381 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2382 *lenp = 0;
2383 return 0;
2384 }
2385
2386 i = (unsigned int *) tbl_data;
2387 vleft = table->maxlen / sizeof(*i);
2388
2389 /*
2390 * Arrays are not supported, keep this simple. *Do not* add
2391 * support for them.
2392 */
2393 if (vleft != 1) {
2394 *lenp = 0;
2395 return -EINVAL;
2396 }
2397
2398 if (!conv)
2399 conv = do_proc_douintvec_conv;
2400
2401 if (write)
2402 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2403 conv, data);
2404 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2405}
2406
2407static int do_proc_douintvec(struct ctl_table *table, int write,
2408 void __user *buffer, size_t *lenp, loff_t *ppos,
2409 int (*conv)(unsigned long *lvalp,
2410 unsigned int *valp,
2411 int write, void *data),
2412 void *data)
2413{
2414 return __do_proc_douintvec(table->data, table, write,
2415 buffer, lenp, ppos, conv, data);
2416}
2417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418/**
2419 * proc_dointvec - read a vector of integers
2420 * @table: the sysctl table
2421 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 * @buffer: the user buffer
2423 * @lenp: the size of the user buffer
2424 * @ppos: file position
2425 *
2426 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2427 * values from/to the user buffer, treated as an ASCII string.
2428 *
2429 * Returns 0 on success.
2430 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002431int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 void __user *buffer, size_t *lenp, loff_t *ppos)
2433{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002434 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2435}
2436
2437/**
2438 * proc_douintvec - read a vector of unsigned integers
2439 * @table: the sysctl table
2440 * @write: %TRUE if this is a write to the sysctl file
2441 * @buffer: the user buffer
2442 * @lenp: the size of the user buffer
2443 * @ppos: file position
2444 *
2445 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2446 * values from/to the user buffer, treated as an ASCII string.
2447 *
2448 * Returns 0 on success.
2449 */
2450int proc_douintvec(struct ctl_table *table, int write,
2451 void __user *buffer, size_t *lenp, loff_t *ppos)
2452{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002453 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2454 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455}
2456
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002457/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002458 * Taint values can only be increased
2459 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002460 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002461static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002462 void __user *buffer, size_t *lenp, loff_t *ppos)
2463{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002464 struct ctl_table t;
2465 unsigned long tmptaint = get_taint();
2466 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002467
Bastian Blank91fcd412007-04-23 14:41:14 -07002468 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002469 return -EPERM;
2470
Andi Kleen25ddbb12008-10-15 22:01:41 -07002471 t = *table;
2472 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002473 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002474 if (err < 0)
2475 return err;
2476
2477 if (write) {
2478 /*
2479 * Poor man's atomic or. Not worth adding a primitive
2480 * to everyone's atomic.h for this
2481 */
2482 int i;
2483 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2484 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302485 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002486 }
2487 }
2488
2489 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002490}
2491
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002492#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002493static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002494 void __user *buffer, size_t *lenp, loff_t *ppos)
2495{
2496 if (write && !capable(CAP_SYS_ADMIN))
2497 return -EPERM;
2498
2499 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2500}
2501#endif
2502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503struct do_proc_dointvec_minmax_conv_param {
2504 int *min;
2505 int *max;
2506};
2507
Amerigo Wang00b7c332010-05-05 00:26:45 +00002508static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2509 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 int write, void *data)
2511{
2512 struct do_proc_dointvec_minmax_conv_param *param = data;
2513 if (write) {
2514 int val = *negp ? -*lvalp : *lvalp;
2515 if ((param->min && *param->min > val) ||
2516 (param->max && *param->max < val))
2517 return -EINVAL;
2518 *valp = val;
2519 } else {
2520 int val = *valp;
2521 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002522 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002523 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002525 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 *lvalp = (unsigned long)val;
2527 }
2528 }
2529 return 0;
2530}
2531
2532/**
2533 * proc_dointvec_minmax - read a vector of integers with min/max values
2534 * @table: the sysctl table
2535 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 * @buffer: the user buffer
2537 * @lenp: the size of the user buffer
2538 * @ppos: file position
2539 *
2540 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2541 * values from/to the user buffer, treated as an ASCII string.
2542 *
2543 * This routine will ensure the values are within the range specified by
2544 * table->extra1 (min) and table->extra2 (max).
2545 *
2546 * Returns 0 on success.
2547 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002548int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 void __user *buffer, size_t *lenp, loff_t *ppos)
2550{
2551 struct do_proc_dointvec_minmax_conv_param param = {
2552 .min = (int *) table->extra1,
2553 .max = (int *) table->extra2,
2554 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002555 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 do_proc_dointvec_minmax_conv, &param);
2557}
2558
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002559struct do_proc_douintvec_minmax_conv_param {
2560 unsigned int *min;
2561 unsigned int *max;
2562};
2563
2564static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2565 unsigned int *valp,
2566 int write, void *data)
2567{
2568 struct do_proc_douintvec_minmax_conv_param *param = data;
2569
2570 if (write) {
2571 unsigned int val = *lvalp;
2572
Joe Lawrencefb910c42017-11-17 15:29:28 -08002573 if (*lvalp > UINT_MAX)
2574 return -EINVAL;
2575
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002576 if ((param->min && *param->min > val) ||
2577 (param->max && *param->max < val))
2578 return -ERANGE;
2579
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002580 *valp = val;
2581 } else {
2582 unsigned int val = *valp;
2583 *lvalp = (unsigned long) val;
2584 }
2585
2586 return 0;
2587}
2588
2589/**
2590 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2591 * @table: the sysctl table
2592 * @write: %TRUE if this is a write to the sysctl file
2593 * @buffer: the user buffer
2594 * @lenp: the size of the user buffer
2595 * @ppos: file position
2596 *
2597 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2598 * values from/to the user buffer, treated as an ASCII string. Negative
2599 * strings are not allowed.
2600 *
2601 * This routine will ensure the values are within the range specified by
2602 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2603 * check for UINT_MAX to avoid having to support wrap around uses from
2604 * userspace.
2605 *
2606 * Returns 0 on success.
2607 */
2608int proc_douintvec_minmax(struct ctl_table *table, int write,
2609 void __user *buffer, size_t *lenp, loff_t *ppos)
2610{
2611 struct do_proc_douintvec_minmax_conv_param param = {
2612 .min = (unsigned int *) table->extra1,
2613 .max = (unsigned int *) table->extra2,
2614 };
2615 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2616 do_proc_douintvec_minmax_conv, &param);
2617}
2618
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002619static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2620 unsigned int *valp,
2621 int write, void *data)
2622{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002623 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002624 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002625
Joe Lawrencefb910c42017-11-17 15:29:28 -08002626 if (*lvalp > UINT_MAX)
2627 return -EINVAL;
2628
2629 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002630 if (val == 0)
2631 return -EINVAL;
2632
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002633 *valp = val;
2634 } else {
2635 unsigned int val = *valp;
2636 *lvalp = (unsigned long) val;
2637 }
2638
2639 return 0;
2640}
2641
Eric Biggers319e0a22018-02-06 15:41:49 -08002642static int proc_dopipe_max_size(struct ctl_table *table, int write,
2643 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002644{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002645 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002646 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002647}
2648
Kees Cook54b50192012-07-30 14:39:18 -07002649static void validate_coredump_safety(void)
2650{
Alex Kelly046d6622012-10-04 17:15:23 -07002651#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002652 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002653 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002654 printk(KERN_WARNING
2655"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2656"Pipe handler or fully qualified core dump path required.\n"
2657"Set kernel.core_pattern before fs.suid_dumpable.\n"
2658 );
Kees Cook54b50192012-07-30 14:39:18 -07002659 }
Alex Kelly046d6622012-10-04 17:15:23 -07002660#endif
Kees Cook54b50192012-07-30 14:39:18 -07002661}
2662
2663static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2664 void __user *buffer, size_t *lenp, loff_t *ppos)
2665{
2666 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2667 if (!error)
2668 validate_coredump_safety();
2669 return error;
2670}
2671
Alex Kelly046d6622012-10-04 17:15:23 -07002672#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002673static int proc_dostring_coredump(struct ctl_table *table, int write,
2674 void __user *buffer, size_t *lenp, loff_t *ppos)
2675{
2676 int error = proc_dostring(table, write, buffer, lenp, ppos);
2677 if (!error)
2678 validate_coredump_safety();
2679 return error;
2680}
Alex Kelly046d6622012-10-04 17:15:23 -07002681#endif
Kees Cook54b50192012-07-30 14:39:18 -07002682
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002683static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 void __user *buffer,
2685 size_t *lenp, loff_t *ppos,
2686 unsigned long convmul,
2687 unsigned long convdiv)
2688{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002689 unsigned long *i, *min, *max;
2690 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002691 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002692 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002693
2694 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 *lenp = 0;
2696 return 0;
2697 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002698
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002699 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 min = (unsigned long *) table->extra1;
2701 max = (unsigned long *) table->extra2;
2702 vleft = table->maxlen / sizeof(unsigned long);
2703 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002704
2705 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002706 if (proc_first_pos_non_zero_ignore(ppos, table))
2707 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002708
Amerigo Wang00b7c332010-05-05 00:26:45 +00002709 if (left > PAGE_SIZE - 1)
2710 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002711 p = kbuf = memdup_user_nul(buffer, left);
2712 if (IS_ERR(kbuf))
2713 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002714 }
2715
Eric Dumazet27b3d802010-10-07 12:59:29 -07002716 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002717 unsigned long val;
2718
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002720 bool neg;
2721
Al Viro70f6cbb2015-12-24 00:13:10 -05002722 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002723
Al Viro70f6cbb2015-12-24 00:13:10 -05002724 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002725 proc_wspace_sep,
2726 sizeof(proc_wspace_sep), NULL);
2727 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 break;
2729 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002731 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 if ((min && val < *min) || (max && val > *max))
2733 continue;
2734 *i = val;
2735 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002736 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002737 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002738 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002739 if (err)
2740 break;
2741 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002742 err = proc_put_long(&buffer, &left, val, false);
2743 if (err)
2744 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 }
2746 }
2747
Amerigo Wang00b7c332010-05-05 00:26:45 +00002748 if (!write && !first && left && !err)
2749 err = proc_put_char(&buffer, &left, '\n');
2750 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002751 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002753 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002754 if (first)
2755 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002758out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002760 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761}
2762
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002763static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002764 void __user *buffer,
2765 size_t *lenp, loff_t *ppos,
2766 unsigned long convmul,
2767 unsigned long convdiv)
2768{
2769 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002770 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002771}
2772
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773/**
2774 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2775 * @table: the sysctl table
2776 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 * @buffer: the user buffer
2778 * @lenp: the size of the user buffer
2779 * @ppos: file position
2780 *
2781 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2782 * values from/to the user buffer, treated as an ASCII string.
2783 *
2784 * This routine will ensure the values are within the range specified by
2785 * table->extra1 (min) and table->extra2 (max).
2786 *
2787 * Returns 0 on success.
2788 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002789int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 void __user *buffer, size_t *lenp, loff_t *ppos)
2791{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002792 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793}
2794
2795/**
2796 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2797 * @table: the sysctl table
2798 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 * @buffer: the user buffer
2800 * @lenp: the size of the user buffer
2801 * @ppos: file position
2802 *
2803 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2804 * values from/to the user buffer, treated as an ASCII string. The values
2805 * are treated as milliseconds, and converted to jiffies when they are stored.
2806 *
2807 * This routine will ensure the values are within the range specified by
2808 * table->extra1 (min) and table->extra2 (max).
2809 *
2810 * Returns 0 on success.
2811 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002812int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 void __user *buffer,
2814 size_t *lenp, loff_t *ppos)
2815{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002816 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 lenp, ppos, HZ, 1000l);
2818}
2819
2820
Amerigo Wang00b7c332010-05-05 00:26:45 +00002821static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 int *valp,
2823 int write, void *data)
2824{
2825 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002826 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002827 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2829 } else {
2830 int val = *valp;
2831 unsigned long lval;
2832 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002833 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002834 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002836 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 lval = (unsigned long)val;
2838 }
2839 *lvalp = lval / HZ;
2840 }
2841 return 0;
2842}
2843
Amerigo Wang00b7c332010-05-05 00:26:45 +00002844static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 int *valp,
2846 int write, void *data)
2847{
2848 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002849 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2850 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2852 } else {
2853 int val = *valp;
2854 unsigned long lval;
2855 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002856 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002857 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002859 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 lval = (unsigned long)val;
2861 }
2862 *lvalp = jiffies_to_clock_t(lval);
2863 }
2864 return 0;
2865}
2866
Amerigo Wang00b7c332010-05-05 00:26:45 +00002867static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 int *valp,
2869 int write, void *data)
2870{
2871 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002872 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2873
2874 if (jif > INT_MAX)
2875 return 1;
2876 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 } else {
2878 int val = *valp;
2879 unsigned long lval;
2880 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002881 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002882 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002884 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 lval = (unsigned long)val;
2886 }
2887 *lvalp = jiffies_to_msecs(lval);
2888 }
2889 return 0;
2890}
2891
2892/**
2893 * proc_dointvec_jiffies - read a vector of integers as seconds
2894 * @table: the sysctl table
2895 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 * @buffer: the user buffer
2897 * @lenp: the size of the user buffer
2898 * @ppos: file position
2899 *
2900 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2901 * values from/to the user buffer, treated as an ASCII string.
2902 * The values read are assumed to be in seconds, and are converted into
2903 * jiffies.
2904 *
2905 * Returns 0 on success.
2906 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002907int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 void __user *buffer, size_t *lenp, loff_t *ppos)
2909{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002910 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 do_proc_dointvec_jiffies_conv,NULL);
2912}
2913
2914/**
2915 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2916 * @table: the sysctl table
2917 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 * @buffer: the user buffer
2919 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002920 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 *
2922 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2923 * values from/to the user buffer, treated as an ASCII string.
2924 * The values read are assumed to be in 1/USER_HZ seconds, and
2925 * are converted into jiffies.
2926 *
2927 * Returns 0 on success.
2928 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002929int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 void __user *buffer, size_t *lenp, loff_t *ppos)
2931{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002932 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 do_proc_dointvec_userhz_jiffies_conv,NULL);
2934}
2935
2936/**
2937 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2938 * @table: the sysctl table
2939 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 * @buffer: the user buffer
2941 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002942 * @ppos: file position
2943 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 *
2945 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2946 * values from/to the user buffer, treated as an ASCII string.
2947 * The values read are assumed to be in 1/1000 seconds, and
2948 * are converted into jiffies.
2949 *
2950 * Returns 0 on success.
2951 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002952int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 void __user *buffer, size_t *lenp, loff_t *ppos)
2954{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002955 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 do_proc_dointvec_ms_jiffies_conv, NULL);
2957}
2958
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002959static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002960 void __user *buffer, size_t *lenp, loff_t *ppos)
2961{
2962 struct pid *new_pid;
2963 pid_t tmp;
2964 int r;
2965
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002966 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002967
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002968 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002969 lenp, ppos, NULL, NULL);
2970 if (r || !write)
2971 return r;
2972
2973 new_pid = find_get_pid(tmp);
2974 if (!new_pid)
2975 return -ESRCH;
2976
2977 put_pid(xchg(&cad_pid, new_pid));
2978 return 0;
2979}
2980
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002981/**
2982 * proc_do_large_bitmap - read/write from/to a large bitmap
2983 * @table: the sysctl table
2984 * @write: %TRUE if this is a write to the sysctl file
2985 * @buffer: the user buffer
2986 * @lenp: the size of the user buffer
2987 * @ppos: file position
2988 *
2989 * The bitmap is stored at table->data and the bitmap length (in bits)
2990 * in table->maxlen.
2991 *
2992 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2993 * large bitmaps may be represented in a compact manner. Writing into
2994 * the file will clear the bitmap then update it with the given input.
2995 *
2996 * Returns 0 on success.
2997 */
2998int proc_do_large_bitmap(struct ctl_table *table, int write,
2999 void __user *buffer, size_t *lenp, loff_t *ppos)
3000{
3001 int err = 0;
3002 bool first = 1;
3003 size_t left = *lenp;
3004 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003005 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003006 unsigned long *tmp_bitmap = NULL;
3007 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3008
WANG Cong122ff242014-05-12 16:04:53 -07003009 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003010 *lenp = 0;
3011 return 0;
3012 }
3013
3014 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003015 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003016
3017 if (left > PAGE_SIZE - 1)
3018 left = PAGE_SIZE - 1;
3019
Al Viro70f6cbb2015-12-24 00:13:10 -05003020 p = kbuf = memdup_user_nul(buffer, left);
3021 if (IS_ERR(kbuf))
3022 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003023
3024 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
3025 GFP_KERNEL);
3026 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003027 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003028 return -ENOMEM;
3029 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003030 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003031 while (!err && left) {
3032 unsigned long val_a, val_b;
3033 bool neg;
3034
Al Viro70f6cbb2015-12-24 00:13:10 -05003035 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003036 sizeof(tr_a), &c);
3037 if (err)
3038 break;
3039 if (val_a >= bitmap_len || neg) {
3040 err = -EINVAL;
3041 break;
3042 }
3043
3044 val_b = val_a;
3045 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003046 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003047 left--;
3048 }
3049
3050 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003051 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003052 &neg, tr_b, sizeof(tr_b),
3053 &c);
3054 if (err)
3055 break;
3056 if (val_b >= bitmap_len || neg ||
3057 val_a > val_b) {
3058 err = -EINVAL;
3059 break;
3060 }
3061 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003062 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003063 left--;
3064 }
3065 }
3066
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003067 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003068 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003069 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003070 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003071 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003072 } else {
3073 unsigned long bit_a, bit_b = 0;
3074
3075 while (left) {
3076 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3077 if (bit_a >= bitmap_len)
3078 break;
3079 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3080 bit_a + 1) - 1;
3081
3082 if (!first) {
3083 err = proc_put_char(&buffer, &left, ',');
3084 if (err)
3085 break;
3086 }
3087 err = proc_put_long(&buffer, &left, bit_a, false);
3088 if (err)
3089 break;
3090 if (bit_a != bit_b) {
3091 err = proc_put_char(&buffer, &left, '-');
3092 if (err)
3093 break;
3094 err = proc_put_long(&buffer, &left, bit_b, false);
3095 if (err)
3096 break;
3097 }
3098
3099 first = 0; bit_b++;
3100 }
3101 if (!err)
3102 err = proc_put_char(&buffer, &left, '\n');
3103 }
3104
3105 if (!err) {
3106 if (write) {
3107 if (*ppos)
3108 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3109 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003110 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003111 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003112 *lenp -= left;
3113 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003114 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003115
3116 kfree(tmp_bitmap);
3117 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003118}
3119
Jovi Zhang55610502011-01-12 17:00:45 -08003120#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003122int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 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(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
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003134int proc_douintvec(struct ctl_table *table, int write,
3135 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_minmax(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
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003146int proc_douintvec_minmax(struct ctl_table *table, int write,
3147 void __user *buffer, size_t *lenp, loff_t *ppos)
3148{
3149 return -ENOSYS;
3150}
3151
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003152int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 void __user *buffer, size_t *lenp, loff_t *ppos)
3154{
3155 return -ENOSYS;
3156}
3157
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003158int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 void __user *buffer, size_t *lenp, loff_t *ppos)
3160{
3161 return -ENOSYS;
3162}
3163
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003164int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 void __user *buffer, size_t *lenp, loff_t *ppos)
3166{
3167 return -ENOSYS;
3168}
3169
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003170int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 void __user *buffer, size_t *lenp, loff_t *ppos)
3172{
3173 return -ENOSYS;
3174}
3175
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003176int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 void __user *buffer,
3178 size_t *lenp, loff_t *ppos)
3179{
3180 return -ENOSYS;
3181}
3182
3183
Jovi Zhang55610502011-01-12 17:00:45 -08003184#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186/*
3187 * No sense putting this after each symbol definition, twice,
3188 * exception granted :-)
3189 */
3190EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003191EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192EXPORT_SYMBOL(proc_dointvec_jiffies);
3193EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003194EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3196EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3197EXPORT_SYMBOL(proc_dostring);
3198EXPORT_SYMBOL(proc_doulongvec_minmax);
3199EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);