blob: 6648fbbb8157fc12703d02fa0fdc9ff85c527ac4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010066#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080067#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070068#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050069#include <linux/mount.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
Kees Cook54b50192012-07-30 14:39:18 -0700221
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700222#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800223/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100224static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700225
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700226static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700227 void __user *buffer, size_t *lenp,
228 loff_t *ppos)
229{
230 int error;
231
232 error = proc_dointvec(table, write, buffer, lenp, ppos);
233 if (error)
234 return error;
235
236 if (write)
237 sysrq_toggle_support(__sysrq_enabled);
238
239 return 0;
240}
241
242#endif
243
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700244static struct ctl_table kern_table[];
245static struct ctl_table vm_table[];
246static struct ctl_table fs_table[];
247static struct ctl_table debug_table[];
248static struct ctl_table dev_table[];
249extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800250#ifdef CONFIG_EPOLL
251extern struct ctl_table epoll_table[];
252#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
255int sysctl_legacy_va_layout;
256#endif
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* The default sysctl tables: */
259
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800260static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 .procname = "kernel",
263 .mode = 0555,
264 .child = kern_table,
265 },
266 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 .procname = "vm",
268 .mode = 0555,
269 .child = vm_table,
270 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .procname = "fs",
273 .mode = 0555,
274 .child = fs_table,
275 },
276 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .procname = "debug",
278 .mode = 0555,
279 .child = debug_table,
280 },
281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "dev",
283 .mode = 0555,
284 .child = dev_table,
285 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700286 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287};
288
Ingo Molnar77e54a12007-07-09 18:52:00 +0200289#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100290static int min_sched_granularity_ns = 100000; /* 100 usecs */
291static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
292static int min_wakeup_granularity_ns; /* 0 usecs */
293static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200294#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100295static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
296static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200297#endif /* CONFIG_SMP */
298#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299
Mel Gorman5e771902010-05-24 14:32:31 -0700300#ifdef CONFIG_COMPACTION
301static int min_extfrag_threshold;
302static int max_extfrag_threshold = 1000;
303#endif
304
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700305static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200306 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200307 .procname = "sched_child_runs_first",
308 .data = &sysctl_sched_child_runs_first,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800311 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200312 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200313#ifdef CONFIG_SCHED_DEBUG
314 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100315 .procname = "sched_min_granularity_ns",
316 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800319 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100320 .extra1 = &min_sched_granularity_ns,
321 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200322 },
323 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200324 .procname = "sched_latency_ns",
325 .data = &sysctl_sched_latency,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800328 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200329 .extra1 = &min_sched_granularity_ns,
330 .extra2 = &max_sched_granularity_ns,
331 },
332 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200333 .procname = "sched_wakeup_granularity_ns",
334 .data = &sysctl_sched_wakeup_granularity,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800337 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200338 .extra1 = &min_wakeup_granularity_ns,
339 .extra2 = &max_wakeup_granularity_ns,
340 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200341#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200342 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100343 .procname = "sched_tunable_scaling",
344 .data = &sysctl_sched_tunable_scaling,
345 .maxlen = sizeof(enum sched_tunable_scaling),
346 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800347 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100348 .extra1 = &min_sched_tunable_scaling,
349 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200350 },
351 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900352 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200353 .data = &sysctl_sched_migration_cost,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800356 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200357 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100358 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100359 .procname = "sched_nr_migrate",
360 .data = &sysctl_sched_nr_migrate,
361 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100364 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530365 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900366 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200367 .data = &sysctl_sched_time_avg,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800370 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200371 },
Mel Gormancb251762016-02-05 09:08:36 +0000372#ifdef CONFIG_SCHEDSTATS
373 {
374 .procname = "sched_schedstats",
375 .data = NULL,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = sysctl_schedstats,
379 .extra1 = &zero,
380 .extra2 = &one,
381 },
382#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200383#endif /* CONFIG_SMP */
384#ifdef CONFIG_NUMA_BALANCING
385 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200386 .procname = "numa_balancing_scan_delay_ms",
387 .data = &sysctl_numa_balancing_scan_delay,
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = proc_dointvec,
391 },
392 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200393 .procname = "numa_balancing_scan_period_min_ms",
394 .data = &sysctl_numa_balancing_scan_period_min,
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
398 },
399 {
400 .procname = "numa_balancing_scan_period_max_ms",
401 .data = &sysctl_numa_balancing_scan_period_max,
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = proc_dointvec,
405 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200406 {
407 .procname = "numa_balancing_scan_size_mb",
408 .data = &sysctl_numa_balancing_scan_size,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400411 .proc_handler = proc_dointvec_minmax,
412 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200413 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100414 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800415 .procname = "numa_balancing",
416 .data = NULL, /* filled in by handler */
417 .maxlen = sizeof(unsigned int),
418 .mode = 0644,
419 .proc_handler = sysctl_numa_balancing,
420 .extra1 = &zero,
421 .extra2 = &one,
422 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200423#endif /* CONFIG_NUMA_BALANCING */
424#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200425 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100426 .procname = "sched_rt_period_us",
427 .data = &sysctl_sched_rt_period,
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800430 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100431 },
432 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100433 .procname = "sched_rt_runtime_us",
434 .data = &sysctl_sched_rt_runtime,
435 .maxlen = sizeof(int),
436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800437 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100438 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600439 {
440 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800441 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = sched_rr_handler,
445 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100446#ifdef CONFIG_SCHED_AUTOGROUP
447 {
448 .procname = "sched_autogroup_enabled",
449 .data = &sysctl_sched_autogroup_enabled,
450 .maxlen = sizeof(unsigned int),
451 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800452 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100453 .extra1 = &zero,
454 .extra2 = &one,
455 },
456#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700457#ifdef CONFIG_CFS_BANDWIDTH
458 {
459 .procname = "sched_cfs_bandwidth_slice_us",
460 .data = &sysctl_sched_cfs_bandwidth_slice,
461 .maxlen = sizeof(unsigned int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec_minmax,
464 .extra1 = &one,
465 },
466#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700467#ifdef CONFIG_PROVE_LOCKING
468 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700469 .procname = "prove_locking",
470 .data = &prove_locking,
471 .maxlen = sizeof(int),
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700474 },
475#endif
476#ifdef CONFIG_LOCK_STAT
477 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700478 .procname = "lock_stat",
479 .data = &lock_stat,
480 .maxlen = sizeof(int),
481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800482 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700483 },
484#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200485 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .procname = "panic",
487 .data = &panic_timeout,
488 .maxlen = sizeof(int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 },
Alex Kelly046d6622012-10-04 17:15:23 -0700492#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "core_uses_pid",
495 .data = &core_uses_pid,
496 .maxlen = sizeof(int),
497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "core_pattern",
502 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700503 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700505 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
Neil Hormana2939802009-09-23 15:56:56 -0700507 {
Neil Hormana2939802009-09-23 15:56:56 -0700508 .procname = "core_pipe_limit",
509 .data = &core_pipe_limit,
510 .maxlen = sizeof(unsigned int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700513 },
Alex Kelly046d6622012-10-04 17:15:23 -0700514#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800515#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700518 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700522 {
523 .procname = "sysctl_writes_strict",
524 .data = &sysctl_writes_strict,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = proc_dointvec_minmax,
528 .extra1 = &neg_one,
529 .extra2 = &one,
530 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800531#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100532#ifdef CONFIG_LATENCYTOP
533 {
534 .procname = "latencytop",
535 .data = &latencytop_enabled,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000538 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100539 },
540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#ifdef CONFIG_BLK_DEV_INITRD
542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 .procname = "real-root-dev",
544 .data = &real_root_dev,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800547 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 },
549#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700550 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700551 .procname = "print-fatal-signals",
552 .data = &print_fatal_signals,
553 .maxlen = sizeof(int),
554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800555 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700556 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700557#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .procname = "reboot-cmd",
560 .data = reboot_command,
561 .maxlen = 256,
562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800563 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 },
565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .procname = "stop-a",
567 .data = &stop_a_enabled,
568 .maxlen = sizeof (int),
569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800570 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 },
572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "scons-poweroff",
574 .data = &scons_pwroff,
575 .maxlen = sizeof (int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
579#endif
David S. Miller08714202008-11-16 23:49:24 -0800580#ifdef CONFIG_SPARC64
581 {
David S. Miller08714202008-11-16 23:49:24 -0800582 .procname = "tsb-ratio",
583 .data = &sysctl_tsb_ratio,
584 .maxlen = sizeof (int),
585 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800586 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800587 },
588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#ifdef __hppa__
590 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .procname = "soft-power",
592 .data = &pwrsw_enabled,
593 .maxlen = sizeof (int),
594 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800595 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530597#endif
598#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .procname = "unaligned-trap",
601 .data = &unaligned_enabled,
602 .maxlen = sizeof (int),
603 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800604 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 },
606#endif
607 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .procname = "ctrl-alt-del",
609 .data = &C_A_D,
610 .maxlen = sizeof(int),
611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800612 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400614#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200615 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200616 .procname = "ftrace_enabled",
617 .data = &ftrace_enabled,
618 .maxlen = sizeof(int),
619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800620 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200621 },
622#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500623#ifdef CONFIG_STACK_TRACER
624 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500625 .procname = "stack_tracer_enabled",
626 .data = &stack_tracer_enabled,
627 .maxlen = sizeof(int),
628 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800629 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500630 },
631#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400632#ifdef CONFIG_TRACING
633 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100634 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400635 .data = &ftrace_dump_on_oops,
636 .maxlen = sizeof(int),
637 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800638 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400639 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400640 {
641 .procname = "traceoff_on_warning",
642 .data = &__disable_trace_on_warning,
643 .maxlen = sizeof(__disable_trace_on_warning),
644 .mode = 0644,
645 .proc_handler = proc_dointvec,
646 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500647 {
648 .procname = "tracepoint_printk",
649 .data = &tracepoint_printk,
650 .maxlen = sizeof(tracepoint_printk),
651 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500652 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500653 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400654#endif
Dave Young2965faa2015-09-09 15:38:55 -0700655#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800656 {
657 .procname = "kexec_load_disabled",
658 .data = &kexec_load_disabled,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 /* only handle a transition from default "0" to "1" */
662 .proc_handler = proc_dointvec_minmax,
663 .extra1 = &one,
664 .extra2 = &one,
665 },
666#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200667#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 .procname = "modprobe",
670 .data = &modprobe_path,
671 .maxlen = KMOD_PATH_LEN,
672 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800673 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 },
Kees Cook3d433212009-04-02 15:49:29 -0700675 {
Kees Cook3d433212009-04-02 15:49:29 -0700676 .procname = "modules_disabled",
677 .data = &modules_disabled,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700682 .extra1 = &one,
683 .extra2 = &one,
684 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700686#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100689 .data = &uevent_helper,
690 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800692 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 },
Michael Marineau86d56132014-04-10 14:09:31 -0700694#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#ifdef CONFIG_CHR_DEV_SG
696 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .procname = "sg-big-buff",
698 .data = &sg_big_buff,
699 .maxlen = sizeof (int),
700 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800701 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 },
703#endif
704#ifdef CONFIG_BSD_PROCESS_ACCT
705 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 .procname = "acct",
707 .data = &acct_parm,
708 .maxlen = 3*sizeof(int),
709 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800710 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 },
712#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713#ifdef CONFIG_MAGIC_SYSRQ
714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800716 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .maxlen = sizeof (int),
718 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700719 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 },
721#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700722#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700725 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .maxlen = sizeof (int),
727 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800728 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700730#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700733 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .maxlen = sizeof(int),
735 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700736 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 },
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "random",
740 .mode = 0555,
741 .child = random_table,
742 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 {
Eric Paris17f60a72011-04-01 17:07:50 -0400744 .procname = "usermodehelper",
745 .mode = 0555,
746 .child = usermodehelper_table,
747 },
748 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .procname = "overflowuid",
750 .data = &overflowuid,
751 .maxlen = sizeof(int),
752 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800753 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 .extra1 = &minolduid,
755 .extra2 = &maxolduid,
756 },
757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .procname = "overflowgid",
759 .data = &overflowgid,
760 .maxlen = sizeof(int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 .extra1 = &minolduid,
764 .extra2 = &maxolduid,
765 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800766#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767#ifdef CONFIG_MATHEMU
768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .procname = "ieee_emulation_warnings",
770 .data = &sysctl_ieee_emulation_warnings,
771 .maxlen = sizeof(int),
772 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 },
775#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200778 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .maxlen = sizeof(int),
780 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800781 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 },
783#endif
784 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 .procname = "pid_max",
786 .data = &pid_max,
787 .maxlen = sizeof (int),
788 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800789 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .extra1 = &pid_max_min,
791 .extra2 = &pid_max_max,
792 },
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .procname = "panic_on_oops",
795 .data = &panic_on_oops,
796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800800#if defined CONFIG_PRINTK
801 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800802 .procname = "printk",
803 .data = &console_loglevel,
804 .maxlen = 4*sizeof(int),
805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800806 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800807 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700810 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .maxlen = sizeof(int),
812 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800813 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 },
815 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700817 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 .maxlen = sizeof(int),
819 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800820 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 },
Dave Youngaf913222009-09-22 16:43:33 -0700822 {
Dave Youngaf913222009-09-22 16:43:33 -0700823 .procname = "printk_delay",
824 .data = &printk_delay_msec,
825 .maxlen = sizeof(int),
826 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700828 .extra1 = &zero,
829 .extra2 = &ten_thousand,
830 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700832 .procname = "printk_devkmsg",
833 .data = devkmsg_log_str,
834 .maxlen = DEVKMSG_STR_MAX_SIZE,
835 .mode = 0644,
836 .proc_handler = devkmsg_sysctl_set_loglvl,
837 },
838 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800839 .procname = "dmesg_restrict",
840 .data = &dmesg_restrict,
841 .maxlen = sizeof(int),
842 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700843 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800844 .extra1 = &zero,
845 .extra2 = &one,
846 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800847 {
848 .procname = "kptr_restrict",
849 .data = &kptr_restrict,
850 .maxlen = sizeof(int),
851 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700852 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800853 .extra1 = &zero,
854 .extra2 = &two,
855 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800856#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800857 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 .procname = "ngroups_max",
859 .data = &ngroups_max,
860 .maxlen = sizeof (int),
861 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 },
Dan Ballard73efc032011-10-31 17:11:20 -0700864 {
865 .procname = "cap_last_cap",
866 .data = (void *)&cap_last_cap,
867 .maxlen = sizeof(int),
868 .mode = 0444,
869 .proc_handler = proc_dointvec,
870 },
Don Zickus58687ac2010-05-07 17:11:44 -0400871#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500872 {
Don Zickus58687ac2010-05-07 17:11:44 -0400873 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200874 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500875 .maxlen = sizeof (int),
876 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700877 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700878 .extra1 = &zero,
879 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400880 },
881 {
882 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700883 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400884 .maxlen = sizeof(int),
885 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700886 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800887 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400888 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500889 },
Don Zickus2508ce12010-05-07 17:11:46 -0400890 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700891 .procname = "nmi_watchdog",
892 .data = &nmi_watchdog_enabled,
893 .maxlen = sizeof (int),
894 .mode = 0644,
895 .proc_handler = proc_nmi_watchdog,
896 .extra1 = &zero,
897#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
898 .extra2 = &one,
899#else
900 .extra2 = &zero,
901#endif
902 },
903 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700904 .procname = "watchdog_cpumask",
905 .data = &watchdog_cpumask_bits,
906 .maxlen = NR_CPUS,
907 .mode = 0644,
908 .proc_handler = proc_watchdog_cpumask,
909 },
910#ifdef CONFIG_SOFTLOCKUP_DETECTOR
911 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700912 .procname = "soft_watchdog",
913 .data = &soft_watchdog_enabled,
914 .maxlen = sizeof (int),
915 .mode = 0644,
916 .proc_handler = proc_soft_watchdog,
917 .extra1 = &zero,
918 .extra2 = &one,
919 },
920 {
Don Zickus2508ce12010-05-07 17:11:46 -0400921 .procname = "softlockup_panic",
922 .data = &softlockup_panic,
923 .maxlen = sizeof(int),
924 .mode = 0644,
925 .proc_handler = proc_dointvec_minmax,
926 .extra1 = &zero,
927 .extra2 = &one,
928 },
Aaron Tomlined235872014-06-23 13:22:05 -0700929#ifdef CONFIG_SMP
930 {
931 .procname = "softlockup_all_cpu_backtrace",
932 .data = &sysctl_softlockup_all_cpu_backtrace,
933 .maxlen = sizeof(int),
934 .mode = 0644,
935 .proc_handler = proc_dointvec_minmax,
936 .extra1 = &zero,
937 .extra2 = &one,
938 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700939#endif /* CONFIG_SMP */
940#endif
941#ifdef CONFIG_HARDLOCKUP_DETECTOR
942 {
943 .procname = "hardlockup_panic",
944 .data = &hardlockup_panic,
945 .maxlen = sizeof(int),
946 .mode = 0644,
947 .proc_handler = proc_dointvec_minmax,
948 .extra1 = &zero,
949 .extra2 = &one,
950 },
951#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800952 {
953 .procname = "hardlockup_all_cpu_backtrace",
954 .data = &sysctl_hardlockup_all_cpu_backtrace,
955 .maxlen = sizeof(int),
956 .mode = 0644,
957 .proc_handler = proc_dointvec_minmax,
958 .extra1 = &zero,
959 .extra2 = &one,
960 },
Aaron Tomlined235872014-06-23 13:22:05 -0700961#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500962#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700963#endif
964
Don Zickus5dc30552010-11-29 17:07:17 -0500965#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
966 {
967 .procname = "unknown_nmi_panic",
968 .data = &unknown_nmi_panic,
969 .maxlen = sizeof (int),
970 .mode = 0644,
971 .proc_handler = proc_dointvec,
972 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500973#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974#if defined(CONFIG_X86)
975 {
Don Zickus8da5add2006-09-26 10:52:27 +0200976 .procname = "panic_on_unrecovered_nmi",
977 .data = &panic_on_unrecovered_nmi,
978 .maxlen = sizeof(int),
979 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800980 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200981 },
982 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700983 .procname = "panic_on_io_nmi",
984 .data = &panic_on_io_nmi,
985 .maxlen = sizeof(int),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700988 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900989#ifdef CONFIG_DEBUG_STACKOVERFLOW
990 {
991 .procname = "panic_on_stackoverflow",
992 .data = &sysctl_panic_on_stackoverflow,
993 .maxlen = sizeof(int),
994 .mode = 0644,
995 .proc_handler = proc_dointvec,
996 },
997#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700998 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .procname = "bootloader_type",
1000 .data = &bootloader_type,
1001 .maxlen = sizeof (int),
1002 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001003 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001005 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001006 .procname = "bootloader_version",
1007 .data = &bootloader_version,
1008 .maxlen = sizeof (int),
1009 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001010 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001011 },
1012 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001013 .procname = "io_delay_type",
1014 .data = &io_delay_type,
1015 .maxlen = sizeof(int),
1016 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001017 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001018 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001020#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .procname = "randomize_va_space",
1023 .data = &randomize_va_space,
1024 .maxlen = sizeof(int),
1025 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001026 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001028#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001029#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001030 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001031 .procname = "spin_retry",
1032 .data = &spin_retry,
1033 .maxlen = sizeof (int),
1034 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001036 },
1037#endif
Len Brown673d5b42007-07-28 03:33:16 -04001038#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001039 {
Pavel Machekc255d842006-02-20 18:27:58 -08001040 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001041 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001042 .maxlen = sizeof (unsigned long),
1043 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001044 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001045 },
1046#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301047#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001048 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001049 .procname = "ignore-unaligned-usertrap",
1050 .data = &no_unaligned_warning,
1051 .maxlen = sizeof (int),
1052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001054 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301055#endif
1056#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001057 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001058 .procname = "unaligned-dump-stack",
1059 .data = &unaligned_dump_stack,
1060 .maxlen = sizeof (int),
1061 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001062 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001063 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001064#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001065#ifdef CONFIG_DETECT_HUNG_TASK
1066 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001067 .procname = "hung_task_panic",
1068 .data = &sysctl_hung_task_panic,
1069 .maxlen = sizeof(int),
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001072 .extra1 = &zero,
1073 .extra2 = &one,
1074 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001075 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001076 .procname = "hung_task_check_count",
1077 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001078 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001079 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001080 .proc_handler = proc_dointvec_minmax,
1081 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001082 },
1083 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001084 .procname = "hung_task_timeout_secs",
1085 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001086 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001087 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001088 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001089 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001090 },
1091 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001092 .procname = "hung_task_warnings",
1093 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001094 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001095 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001096 .proc_handler = proc_dointvec_minmax,
1097 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001098 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001099#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001100#ifdef CONFIG_RT_MUTEXES
1101 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001102 .procname = "max_lock_depth",
1103 .data = &max_lock_depth,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001106 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001107 },
1108#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001109 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001110 .procname = "poweroff_cmd",
1111 .data = &poweroff_cmd,
1112 .maxlen = POWEROFF_CMD_PATH_LEN,
1113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001115 },
David Howells0b77f5b2008-04-29 01:01:32 -07001116#ifdef CONFIG_KEYS
1117 {
David Howells0b77f5b2008-04-29 01:01:32 -07001118 .procname = "keys",
1119 .mode = 0555,
1120 .child = key_sysctls,
1121 },
1122#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001123#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001124 /*
1125 * User-space scripts rely on the existence of this file
1126 * as a feature check for perf_events being enabled.
1127 *
1128 * So it's an ABI, do not remove!
1129 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001130 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001131 .procname = "perf_event_paranoid",
1132 .data = &sysctl_perf_event_paranoid,
1133 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001134 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001135 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001136 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001137 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001138 .procname = "perf_event_mlock_kb",
1139 .data = &sysctl_perf_event_mlock,
1140 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001141 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001142 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001143 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001144 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001145 .procname = "perf_event_max_sample_rate",
1146 .data = &sysctl_perf_event_sample_rate,
1147 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001148 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001149 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001150 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001151 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001152 {
1153 .procname = "perf_cpu_time_max_percent",
1154 .data = &sysctl_perf_cpu_time_max_percent,
1155 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1156 .mode = 0644,
1157 .proc_handler = perf_cpu_time_max_percent_handler,
1158 .extra1 = &zero,
1159 .extra2 = &one_hundred,
1160 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001161 {
1162 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001163 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001164 .maxlen = sizeof(sysctl_perf_event_max_stack),
1165 .mode = 0644,
1166 .proc_handler = perf_event_max_stack_handler,
1167 .extra1 = &zero,
1168 .extra2 = &six_hundred_forty_kb,
1169 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001170 {
1171 .procname = "perf_event_max_contexts_per_stack",
1172 .data = &sysctl_perf_event_max_contexts_per_stack,
1173 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1174 .mode = 0644,
1175 .proc_handler = perf_event_max_stack_handler,
1176 .extra1 = &zero,
1177 .extra2 = &one_thousand,
1178 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001179#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001180#ifdef CONFIG_KMEMCHECK
1181 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001182 .procname = "kmemcheck",
1183 .data = &kmemcheck_enabled,
1184 .maxlen = sizeof(int),
1185 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001186 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001187 },
1188#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001189 {
1190 .procname = "panic_on_warn",
1191 .data = &panic_on_warn,
1192 .maxlen = sizeof(int),
1193 .mode = 0644,
1194 .proc_handler = proc_dointvec_minmax,
1195 .extra1 = &zero,
1196 .extra2 = &one,
1197 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001198#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1199 {
1200 .procname = "timer_migration",
1201 .data = &sysctl_timer_migration,
1202 .maxlen = sizeof(unsigned int),
1203 .mode = 0644,
1204 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001205 .extra1 = &zero,
1206 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001207 },
1208#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001209#ifdef CONFIG_BPF_SYSCALL
1210 {
1211 .procname = "unprivileged_bpf_disabled",
1212 .data = &sysctl_unprivileged_bpf_disabled,
1213 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1214 .mode = 0644,
1215 /* only handle a transition from default "0" to "1" */
1216 .proc_handler = proc_dointvec_minmax,
1217 .extra1 = &one,
1218 .extra2 = &one,
1219 },
1220#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001221#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1222 {
1223 .procname = "panic_on_rcu_stall",
1224 .data = &sysctl_panic_on_rcu_stall,
1225 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1226 .mode = 0644,
1227 .proc_handler = proc_dointvec_minmax,
1228 .extra1 = &zero,
1229 .extra2 = &one,
1230 },
1231#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001232 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233};
1234
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001235static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 .procname = "overcommit_memory",
1238 .data = &sysctl_overcommit_memory,
1239 .maxlen = sizeof(sysctl_overcommit_memory),
1240 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001241 .proc_handler = proc_dointvec_minmax,
1242 .extra1 = &zero,
1243 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 },
1245 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001246 .procname = "panic_on_oom",
1247 .data = &sysctl_panic_on_oom,
1248 .maxlen = sizeof(sysctl_panic_on_oom),
1249 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001250 .proc_handler = proc_dointvec_minmax,
1251 .extra1 = &zero,
1252 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001253 },
1254 {
David Rientjesfe071d72007-10-16 23:25:56 -07001255 .procname = "oom_kill_allocating_task",
1256 .data = &sysctl_oom_kill_allocating_task,
1257 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1258 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001259 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001260 },
1261 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001262 .procname = "oom_dump_tasks",
1263 .data = &sysctl_oom_dump_tasks,
1264 .maxlen = sizeof(sysctl_oom_dump_tasks),
1265 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001266 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001267 },
1268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 .procname = "overcommit_ratio",
1270 .data = &sysctl_overcommit_ratio,
1271 .maxlen = sizeof(sysctl_overcommit_ratio),
1272 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001273 .proc_handler = overcommit_ratio_handler,
1274 },
1275 {
1276 .procname = "overcommit_kbytes",
1277 .data = &sysctl_overcommit_kbytes,
1278 .maxlen = sizeof(sysctl_overcommit_kbytes),
1279 .mode = 0644,
1280 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 },
1282 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 .procname = "page-cluster",
1284 .data = &page_cluster,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001287 .proc_handler = proc_dointvec_minmax,
1288 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 },
1290 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 .procname = "dirty_background_ratio",
1292 .data = &dirty_background_ratio,
1293 .maxlen = sizeof(dirty_background_ratio),
1294 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001295 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 .extra1 = &zero,
1297 .extra2 = &one_hundred,
1298 },
1299 {
David Rientjes2da02992009-01-06 14:39:31 -08001300 .procname = "dirty_background_bytes",
1301 .data = &dirty_background_bytes,
1302 .maxlen = sizeof(dirty_background_bytes),
1303 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001304 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001305 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001306 },
1307 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 .procname = "dirty_ratio",
1309 .data = &vm_dirty_ratio,
1310 .maxlen = sizeof(vm_dirty_ratio),
1311 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001312 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 .extra1 = &zero,
1314 .extra2 = &one_hundred,
1315 },
1316 {
David Rientjes2da02992009-01-06 14:39:31 -08001317 .procname = "dirty_bytes",
1318 .data = &vm_dirty_bytes,
1319 .maxlen = sizeof(vm_dirty_bytes),
1320 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001321 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001322 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001323 },
1324 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001326 .data = &dirty_writeback_interval,
1327 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001329 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 },
1331 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001333 .data = &dirty_expire_interval,
1334 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001336 .proc_handler = proc_dointvec_minmax,
1337 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 },
1339 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001340 .procname = "dirtytime_expire_seconds",
1341 .data = &dirtytime_expire_interval,
1342 .maxlen = sizeof(dirty_expire_interval),
1343 .mode = 0644,
1344 .proc_handler = dirtytime_interval_handler,
1345 .extra1 = &zero,
1346 },
1347 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001348 .procname = "nr_pdflush_threads",
1349 .mode = 0444 /* read-only */,
1350 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 },
1352 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 .procname = "swappiness",
1354 .data = &vm_swappiness,
1355 .maxlen = sizeof(vm_swappiness),
1356 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001357 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 .extra1 = &zero,
1359 .extra2 = &one_hundred,
1360 },
1361#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001362 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001364 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 .maxlen = sizeof(unsigned long),
1366 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001367 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001368 },
1369#ifdef CONFIG_NUMA
1370 {
1371 .procname = "nr_hugepages_mempolicy",
1372 .data = NULL,
1373 .maxlen = sizeof(unsigned long),
1374 .mode = 0644,
1375 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001376 },
1377#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .procname = "hugetlb_shm_group",
1380 .data = &sysctl_hugetlb_shm_group,
1381 .maxlen = sizeof(gid_t),
1382 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001383 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 },
Mel Gorman396faf02007-07-17 04:03:13 -07001385 {
Mel Gorman396faf02007-07-17 04:03:13 -07001386 .procname = "hugepages_treat_as_movable",
1387 .data = &hugepages_treat_as_movable,
1388 .maxlen = sizeof(int),
1389 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001390 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001391 },
Adam Litke54f9f802007-10-16 01:26:20 -07001392 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001393 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001394 .data = NULL,
1395 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001398 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399#endif
1400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 .procname = "lowmem_reserve_ratio",
1402 .data = &sysctl_lowmem_reserve_ratio,
1403 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1404 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001405 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 },
1407 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001408 .procname = "drop_caches",
1409 .data = &sysctl_drop_caches,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
1412 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001413 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001414 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001415 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001416#ifdef CONFIG_COMPACTION
1417 {
1418 .procname = "compact_memory",
1419 .data = &sysctl_compact_memory,
1420 .maxlen = sizeof(int),
1421 .mode = 0200,
1422 .proc_handler = sysctl_compaction_handler,
1423 },
Mel Gorman5e771902010-05-24 14:32:31 -07001424 {
1425 .procname = "extfrag_threshold",
1426 .data = &sysctl_extfrag_threshold,
1427 .maxlen = sizeof(int),
1428 .mode = 0644,
1429 .proc_handler = sysctl_extfrag_handler,
1430 .extra1 = &min_extfrag_threshold,
1431 .extra2 = &max_extfrag_threshold,
1432 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001433 {
1434 .procname = "compact_unevictable_allowed",
1435 .data = &sysctl_compact_unevictable_allowed,
1436 .maxlen = sizeof(int),
1437 .mode = 0644,
1438 .proc_handler = proc_dointvec,
1439 .extra1 = &zero,
1440 .extra2 = &one,
1441 },
Mel Gorman5e771902010-05-24 14:32:31 -07001442
Mel Gorman76ab0f52010-05-24 14:32:28 -07001443#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001444 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 .procname = "min_free_kbytes",
1446 .data = &min_free_kbytes,
1447 .maxlen = sizeof(min_free_kbytes),
1448 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001449 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 .extra1 = &zero,
1451 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001452 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001453 .procname = "watermark_scale_factor",
1454 .data = &watermark_scale_factor,
1455 .maxlen = sizeof(watermark_scale_factor),
1456 .mode = 0644,
1457 .proc_handler = watermark_scale_factor_sysctl_handler,
1458 .extra1 = &one,
1459 .extra2 = &one_thousand,
1460 },
1461 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001462 .procname = "percpu_pagelist_fraction",
1463 .data = &percpu_pagelist_fraction,
1464 .maxlen = sizeof(percpu_pagelist_fraction),
1465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001466 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001467 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001468 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469#ifdef CONFIG_MMU
1470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 .procname = "max_map_count",
1472 .data = &sysctl_max_map_count,
1473 .maxlen = sizeof(sysctl_max_map_count),
1474 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001475 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001476 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001478#else
1479 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001480 .procname = "nr_trim_pages",
1481 .data = &sysctl_nr_trim_pages,
1482 .maxlen = sizeof(sysctl_nr_trim_pages),
1483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001484 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001485 .extra1 = &zero,
1486 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487#endif
1488 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 .procname = "laptop_mode",
1490 .data = &laptop_mode,
1491 .maxlen = sizeof(laptop_mode),
1492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001493 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 },
1495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 .procname = "block_dump",
1497 .data = &block_dump,
1498 .maxlen = sizeof(block_dump),
1499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001500 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 .extra1 = &zero,
1502 },
1503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 .procname = "vfs_cache_pressure",
1505 .data = &sysctl_vfs_cache_pressure,
1506 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001508 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 .extra1 = &zero,
1510 },
1511#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 .procname = "legacy_va_layout",
1514 .data = &sysctl_legacy_va_layout,
1515 .maxlen = sizeof(sysctl_legacy_va_layout),
1516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001517 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 .extra1 = &zero,
1519 },
1520#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001521#ifdef CONFIG_NUMA
1522 {
Christoph Lameter17436602006-01-18 17:42:32 -08001523 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001524 .data = &node_reclaim_mode,
1525 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001526 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001527 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001528 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001529 },
Christoph Lameter96146342006-07-03 00:24:13 -07001530 {
Christoph Lameter96146342006-07-03 00:24:13 -07001531 .procname = "min_unmapped_ratio",
1532 .data = &sysctl_min_unmapped_ratio,
1533 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001535 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001536 .extra1 = &zero,
1537 .extra2 = &one_hundred,
1538 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001539 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001540 .procname = "min_slab_ratio",
1541 .data = &sysctl_min_slab_ratio,
1542 .maxlen = sizeof(sysctl_min_slab_ratio),
1543 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001544 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001545 .extra1 = &zero,
1546 .extra2 = &one_hundred,
1547 },
Christoph Lameter17436602006-01-18 17:42:32 -08001548#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001549#ifdef CONFIG_SMP
1550 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001551 .procname = "stat_interval",
1552 .data = &sysctl_stat_interval,
1553 .maxlen = sizeof(sysctl_stat_interval),
1554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001555 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001556 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001557 {
1558 .procname = "stat_refresh",
1559 .data = NULL,
1560 .maxlen = 0,
1561 .mode = 0600,
1562 .proc_handler = vmstat_refresh,
1563 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001564#endif
David Howells6e141542009-12-15 19:27:45 +00001565#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001566 {
Eric Parised032182007-06-28 15:55:21 -04001567 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001568 .data = &dac_mmap_min_addr,
1569 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001570 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001571 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001572 },
David Howells6e141542009-12-15 19:27:45 +00001573#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001574#ifdef CONFIG_NUMA
1575 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001576 .procname = "numa_zonelist_order",
1577 .data = &numa_zonelist_order,
1578 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1579 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001580 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001581 },
1582#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001583#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001584 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001585 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001586 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001587#ifdef CONFIG_X86_32
1588 .data = &vdso32_enabled,
1589 .maxlen = sizeof(vdso32_enabled),
1590#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001591 .data = &vdso_enabled,
1592 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001593#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001594 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001595 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001596 .extra1 = &zero,
1597 },
1598#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001599#ifdef CONFIG_HIGHMEM
1600 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001601 .procname = "highmem_is_dirtyable",
1602 .data = &vm_highmem_is_dirtyable,
1603 .maxlen = sizeof(vm_highmem_is_dirtyable),
1604 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001605 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001606 .extra1 = &zero,
1607 .extra2 = &one,
1608 },
1609#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001610#ifdef CONFIG_MEMORY_FAILURE
1611 {
Andi Kleen6a460792009-09-16 11:50:15 +02001612 .procname = "memory_failure_early_kill",
1613 .data = &sysctl_memory_failure_early_kill,
1614 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001616 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001617 .extra1 = &zero,
1618 .extra2 = &one,
1619 },
1620 {
Andi Kleen6a460792009-09-16 11:50:15 +02001621 .procname = "memory_failure_recovery",
1622 .data = &sysctl_memory_failure_recovery,
1623 .maxlen = sizeof(sysctl_memory_failure_recovery),
1624 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001625 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001626 .extra1 = &zero,
1627 .extra2 = &one,
1628 },
1629#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001630 {
1631 .procname = "user_reserve_kbytes",
1632 .data = &sysctl_user_reserve_kbytes,
1633 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1634 .mode = 0644,
1635 .proc_handler = proc_doulongvec_minmax,
1636 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001637 {
1638 .procname = "admin_reserve_kbytes",
1639 .data = &sysctl_admin_reserve_kbytes,
1640 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1641 .mode = 0644,
1642 .proc_handler = proc_doulongvec_minmax,
1643 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001644#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1645 {
1646 .procname = "mmap_rnd_bits",
1647 .data = &mmap_rnd_bits,
1648 .maxlen = sizeof(mmap_rnd_bits),
1649 .mode = 0600,
1650 .proc_handler = proc_dointvec_minmax,
1651 .extra1 = (void *)&mmap_rnd_bits_min,
1652 .extra2 = (void *)&mmap_rnd_bits_max,
1653 },
1654#endif
1655#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1656 {
1657 .procname = "mmap_rnd_compat_bits",
1658 .data = &mmap_rnd_compat_bits,
1659 .maxlen = sizeof(mmap_rnd_compat_bits),
1660 .mode = 0600,
1661 .proc_handler = proc_dointvec_minmax,
1662 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1663 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1664 },
1665#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001666 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667};
1668
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001669static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 .procname = "inode-nr",
1672 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001673 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001675 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 },
1677 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 .procname = "inode-state",
1679 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001680 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001682 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 },
1684 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 .procname = "file-nr",
1686 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001687 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001689 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 },
1691 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 .procname = "file-max",
1693 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001694 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001696 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 },
1698 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001699 .procname = "nr_open",
1700 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001701 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001702 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001703 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001704 .extra1 = &sysctl_nr_open_min,
1705 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001706 },
1707 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 .procname = "dentry-state",
1709 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001710 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001712 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 },
1714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 .procname = "overflowuid",
1716 .data = &fs_overflowuid,
1717 .maxlen = sizeof(int),
1718 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001719 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 .extra1 = &minolduid,
1721 .extra2 = &maxolduid,
1722 },
1723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 .procname = "overflowgid",
1725 .data = &fs_overflowgid,
1726 .maxlen = sizeof(int),
1727 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001728 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 .extra1 = &minolduid,
1730 .extra2 = &maxolduid,
1731 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001732#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .procname = "leases-enable",
1735 .data = &leases_enable,
1736 .maxlen = sizeof(int),
1737 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001738 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001740#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741#ifdef CONFIG_DNOTIFY
1742 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .procname = "dir-notify-enable",
1744 .data = &dir_notify_enable,
1745 .maxlen = sizeof(int),
1746 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001747 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 },
1749#endif
1750#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001751#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .procname = "lease-break-time",
1754 .data = &lease_break_time,
1755 .maxlen = sizeof(int),
1756 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001757 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001759#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001760#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 .procname = "aio-nr",
1763 .data = &aio_nr,
1764 .maxlen = sizeof(aio_nr),
1765 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001766 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 },
1768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 .procname = "aio-max-nr",
1770 .data = &aio_max_nr,
1771 .maxlen = sizeof(aio_max_nr),
1772 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001773 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001775#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001776#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001777 {
Robert Love0399cb02005-07-13 12:38:18 -04001778 .procname = "inotify",
1779 .mode = 0555,
1780 .child = inotify_table,
1781 },
1782#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001783#ifdef CONFIG_EPOLL
1784 {
1785 .procname = "epoll",
1786 .mode = 0555,
1787 .child = epoll_table,
1788 },
1789#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001791 {
Kees Cook800179c2012-07-25 17:29:07 -07001792 .procname = "protected_symlinks",
1793 .data = &sysctl_protected_symlinks,
1794 .maxlen = sizeof(int),
1795 .mode = 0600,
1796 .proc_handler = proc_dointvec_minmax,
1797 .extra1 = &zero,
1798 .extra2 = &one,
1799 },
1800 {
1801 .procname = "protected_hardlinks",
1802 .data = &sysctl_protected_hardlinks,
1803 .maxlen = sizeof(int),
1804 .mode = 0600,
1805 .proc_handler = proc_dointvec_minmax,
1806 .extra1 = &zero,
1807 .extra2 = &one,
1808 },
1809 {
Alan Coxd6e71142005-06-23 00:09:43 -07001810 .procname = "suid_dumpable",
1811 .data = &suid_dumpable,
1812 .maxlen = sizeof(int),
1813 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001814 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001815 .extra1 = &zero,
1816 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001817 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001818#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1819 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001820 .procname = "binfmt_misc",
1821 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001822 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001823 },
1824#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001825 {
Jens Axboeff9da692010-06-03 14:54:39 +02001826 .procname = "pipe-max-size",
1827 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001828 .maxlen = sizeof(int),
1829 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001830 .proc_handler = &pipe_proc_fn,
1831 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001832 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001833 {
1834 .procname = "pipe-user-pages-hard",
1835 .data = &pipe_user_pages_hard,
1836 .maxlen = sizeof(pipe_user_pages_hard),
1837 .mode = 0644,
1838 .proc_handler = proc_doulongvec_minmax,
1839 },
1840 {
1841 .procname = "pipe-user-pages-soft",
1842 .data = &pipe_user_pages_soft,
1843 .maxlen = sizeof(pipe_user_pages_soft),
1844 .mode = 0644,
1845 .proc_handler = proc_doulongvec_minmax,
1846 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001847 {
1848 .procname = "mount-max",
1849 .data = &sysctl_mount_max,
1850 .maxlen = sizeof(unsigned int),
1851 .mode = 0644,
1852 .proc_handler = proc_dointvec_minmax,
1853 .extra1 = &one,
1854 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001855 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856};
1857
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001858static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001859#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001860 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001861 .procname = "exception-trace",
1862 .data = &show_unhandled_signals,
1863 .maxlen = sizeof(int),
1864 .mode = 0644,
1865 .proc_handler = proc_dointvec
1866 },
1867#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001868#if defined(CONFIG_OPTPROBES)
1869 {
1870 .procname = "kprobes-optimization",
1871 .data = &sysctl_kprobes_optimization,
1872 .maxlen = sizeof(int),
1873 .mode = 0644,
1874 .proc_handler = proc_kprobes_optimization_handler,
1875 .extra1 = &zero,
1876 .extra2 = &one,
1877 },
1878#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001879 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880};
1881
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001882static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001883 { }
Robert Love0eeca282005-07-12 17:06:03 -04001884};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001886int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001887{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001888 struct ctl_table_header *hdr;
1889
1890 hdr = register_sysctl_table(sysctl_base_table);
1891 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001892 return 0;
1893}
1894
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001895#endif /* CONFIG_SYSCTL */
1896
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897/*
1898 * /proc/sys support
1899 */
1900
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001901#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Kees Cookf8808302014-06-06 14:37:17 -07001903static int _proc_do_string(char *data, int maxlen, int write,
1904 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001905 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001906{
1907 size_t len;
1908 char __user *p;
1909 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001910
1911 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001912 *lenp = 0;
1913 return 0;
1914 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001915
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001916 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001917 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1918 /* Only continue writes not past the end of buffer. */
1919 len = strlen(data);
1920 if (len > maxlen - 1)
1921 len = maxlen - 1;
1922
1923 if (*ppos > len)
1924 return 0;
1925 len = *ppos;
1926 } else {
1927 /* Start writing from beginning of buffer. */
1928 len = 0;
1929 }
1930
Kees Cook2ca9bb42014-06-06 14:37:18 -07001931 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001932 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001933 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001934 if (get_user(c, p++))
1935 return -EFAULT;
1936 if (c == 0 || c == '\n')
1937 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001938 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001939 }
Kees Cookf8808302014-06-06 14:37:17 -07001940 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001941 } else {
1942 len = strlen(data);
1943 if (len > maxlen)
1944 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001945
1946 if (*ppos > len) {
1947 *lenp = 0;
1948 return 0;
1949 }
1950
1951 data += *ppos;
1952 len -= *ppos;
1953
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001954 if (len > *lenp)
1955 len = *lenp;
1956 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001957 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001958 return -EFAULT;
1959 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001960 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001961 return -EFAULT;
1962 len++;
1963 }
1964 *lenp = len;
1965 *ppos += len;
1966 }
1967 return 0;
1968}
1969
Kees Cookf4aacea2014-06-06 14:37:19 -07001970static void warn_sysctl_write(struct ctl_table *table)
1971{
1972 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1973 "This will not be supported in the future. To silence this\n"
1974 "warning, set kernel.sysctl_writes_strict = -1\n",
1975 current->comm, table->procname);
1976}
1977
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978/**
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001979 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1980 * @ppos: file position
1981 * @table: the sysctl table
1982 *
1983 * Returns true if the first position is non-zero and the sysctl_writes_strict
1984 * mode indicates this is not allowed for numeric input types. String proc
1985 * hadlers can ignore the return value.
1986 */
1987static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
1988 struct ctl_table *table)
1989{
1990 if (!*ppos)
1991 return false;
1992
1993 switch (sysctl_writes_strict) {
1994 case SYSCTL_WRITES_STRICT:
1995 return true;
1996 case SYSCTL_WRITES_WARN:
1997 warn_sysctl_write(table);
1998 return false;
1999 default:
2000 return false;
2001 }
2002}
2003
2004/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 * proc_dostring - read a string sysctl
2006 * @table: the sysctl table
2007 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 * @buffer: the user buffer
2009 * @lenp: the size of the user buffer
2010 * @ppos: file position
2011 *
2012 * Reads/writes a string from/to the user buffer. If the kernel
2013 * buffer provided is not large enough to hold the string, the
2014 * string is truncated. The copied string is %NULL-terminated.
2015 * If the string is being read by the user process, it is copied
2016 * and a newline '\n' is added. It is truncated if the buffer is
2017 * not large enough.
2018 *
2019 * Returns 0 on success.
2020 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002021int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 void __user *buffer, size_t *lenp, loff_t *ppos)
2023{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002024 if (write)
2025 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002026
Kees Cookf8808302014-06-06 14:37:17 -07002027 return _proc_do_string((char *)(table->data), table->maxlen, write,
2028 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029}
2030
Amerigo Wang00b7c332010-05-05 00:26:45 +00002031static size_t proc_skip_spaces(char **buf)
2032{
2033 size_t ret;
2034 char *tmp = skip_spaces(*buf);
2035 ret = tmp - *buf;
2036 *buf = tmp;
2037 return ret;
2038}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002040static void proc_skip_char(char **buf, size_t *size, const char v)
2041{
2042 while (*size) {
2043 if (**buf != v)
2044 break;
2045 (*size)--;
2046 (*buf)++;
2047 }
2048}
2049
Amerigo Wang00b7c332010-05-05 00:26:45 +00002050#define TMPBUFLEN 22
2051/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002052 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002053 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002054 * @buf: a kernel buffer
2055 * @size: size of the kernel buffer
2056 * @val: this is where the number will be stored
2057 * @neg: set to %TRUE if number is negative
2058 * @perm_tr: a vector which contains the allowed trailers
2059 * @perm_tr_len: size of the perm_tr vector
2060 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002061 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002062 * In case of success %0 is returned and @buf and @size are updated with
2063 * the amount of bytes read. If @tr is non-NULL and a trailing
2064 * character exists (size is non-zero after returning from this
2065 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002066 */
2067static int proc_get_long(char **buf, size_t *size,
2068 unsigned long *val, bool *neg,
2069 const char *perm_tr, unsigned perm_tr_len, char *tr)
2070{
2071 int len;
2072 char *p, tmp[TMPBUFLEN];
2073
2074 if (!*size)
2075 return -EINVAL;
2076
2077 len = *size;
2078 if (len > TMPBUFLEN - 1)
2079 len = TMPBUFLEN - 1;
2080
2081 memcpy(tmp, *buf, len);
2082
2083 tmp[len] = 0;
2084 p = tmp;
2085 if (*p == '-' && *size > 1) {
2086 *neg = true;
2087 p++;
2088 } else
2089 *neg = false;
2090 if (!isdigit(*p))
2091 return -EINVAL;
2092
2093 *val = simple_strtoul(p, &p, 0);
2094
2095 len = p - tmp;
2096
2097 /* We don't know if the next char is whitespace thus we may accept
2098 * invalid integers (e.g. 1234...a) or two integers instead of one
2099 * (e.g. 123...1). So lets not allow such large numbers. */
2100 if (len == TMPBUFLEN - 1)
2101 return -EINVAL;
2102
2103 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2104 return -EINVAL;
2105
2106 if (tr && (len < *size))
2107 *tr = *p;
2108
2109 *buf += len;
2110 *size -= len;
2111
2112 return 0;
2113}
2114
2115/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002116 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002117 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002118 * @buf: the user buffer
2119 * @size: the size of the user buffer
2120 * @val: the integer to be converted
2121 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002122 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002123 * In case of success %0 is returned and @buf and @size are updated with
2124 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002125 */
2126static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2127 bool neg)
2128{
2129 int len;
2130 char tmp[TMPBUFLEN], *p = tmp;
2131
2132 sprintf(p, "%s%lu", neg ? "-" : "", val);
2133 len = strlen(tmp);
2134 if (len > *size)
2135 len = *size;
2136 if (copy_to_user(*buf, tmp, len))
2137 return -EFAULT;
2138 *size -= len;
2139 *buf += len;
2140 return 0;
2141}
2142#undef TMPBUFLEN
2143
2144static int proc_put_char(void __user **buf, size_t *size, char c)
2145{
2146 if (*size) {
2147 char __user **buffer = (char __user **)buf;
2148 if (put_user(c, *buffer))
2149 return -EFAULT;
2150 (*size)--, (*buffer)++;
2151 *buf = *buffer;
2152 }
2153 return 0;
2154}
2155
2156static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 int *valp,
2158 int write, void *data)
2159{
2160 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002161 if (*negp) {
2162 if (*lvalp > (unsigned long) INT_MAX + 1)
2163 return -EINVAL;
2164 *valp = -*lvalp;
2165 } else {
2166 if (*lvalp > (unsigned long) INT_MAX)
2167 return -EINVAL;
2168 *valp = *lvalp;
2169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 } else {
2171 int val = *valp;
2172 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002173 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002174 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002176 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 *lvalp = (unsigned long)val;
2178 }
2179 }
2180 return 0;
2181}
2182
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002183static int do_proc_douintvec_conv(unsigned long *lvalp,
2184 unsigned int *valp,
2185 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002186{
2187 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002188 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002189 return -EINVAL;
Liping Zhang425fffd2017-04-07 23:51:07 +08002190 if (*lvalp > UINT_MAX)
2191 return -EINVAL;
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002192 *valp = *lvalp;
2193 } else {
2194 unsigned int val = *valp;
2195 *lvalp = (unsigned long)val;
2196 }
2197 return 0;
2198}
2199
Amerigo Wang00b7c332010-05-05 00:26:45 +00002200static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2201
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002202static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002203 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002204 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002205 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 int write, void *data),
2207 void *data)
2208{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002209 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002210 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002211 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Amerigo Wang00b7c332010-05-05 00:26:45 +00002213 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 *lenp = 0;
2215 return 0;
2216 }
2217
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002218 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 vleft = table->maxlen / sizeof(*i);
2220 left = *lenp;
2221
2222 if (!conv)
2223 conv = do_proc_dointvec_conv;
2224
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002226 if (proc_first_pos_non_zero_ignore(ppos, table))
2227 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002228
Amerigo Wang00b7c332010-05-05 00:26:45 +00002229 if (left > PAGE_SIZE - 1)
2230 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002231 p = kbuf = memdup_user_nul(buffer, left);
2232 if (IS_ERR(kbuf))
2233 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002234 }
2235
2236 for (; left && vleft--; i++, first=0) {
2237 unsigned long lval;
2238 bool neg;
2239
2240 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002241 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242
J. R. Okajima563b0462010-05-25 16:10:14 -07002243 if (!left)
2244 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002245 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 proc_wspace_sep,
2247 sizeof(proc_wspace_sep), NULL);
2248 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002250 if (conv(&neg, &lval, i, 1, data)) {
2251 err = -EINVAL;
2252 break;
2253 }
2254 } else {
2255 if (conv(&neg, &lval, i, 0, data)) {
2256 err = -EINVAL;
2257 break;
2258 }
2259 if (!first)
2260 err = proc_put_char(&buffer, &left, '\t');
2261 if (err)
2262 break;
2263 err = proc_put_long(&buffer, &left, lval, neg);
2264 if (err)
2265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 }
2267 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268
2269 if (!write && !first && left && !err)
2270 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002271 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002272 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002274 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002275 if (first)
2276 return err ? : -EINVAL;
2277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002279out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282}
2283
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002284static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002285 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002286 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002287 int write, void *data),
2288 void *data)
2289{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002290 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002291 buffer, lenp, ppos, conv, data);
2292}
2293
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002294static int do_proc_douintvec_w(unsigned int *tbl_data,
2295 struct ctl_table *table,
2296 void __user *buffer,
2297 size_t *lenp, loff_t *ppos,
2298 int (*conv)(unsigned long *lvalp,
2299 unsigned int *valp,
2300 int write, void *data),
2301 void *data)
2302{
2303 unsigned long lval;
2304 int err = 0;
2305 size_t left;
2306 bool neg;
2307 char *kbuf = NULL, *p;
2308
2309 left = *lenp;
2310
2311 if (proc_first_pos_non_zero_ignore(ppos, table))
2312 goto bail_early;
2313
2314 if (left > PAGE_SIZE - 1)
2315 left = PAGE_SIZE - 1;
2316
2317 p = kbuf = memdup_user_nul(buffer, left);
2318 if (IS_ERR(kbuf))
2319 return -EINVAL;
2320
2321 left -= proc_skip_spaces(&p);
2322 if (!left) {
2323 err = -EINVAL;
2324 goto out_free;
2325 }
2326
2327 err = proc_get_long(&p, &left, &lval, &neg,
2328 proc_wspace_sep,
2329 sizeof(proc_wspace_sep), NULL);
2330 if (err || neg) {
2331 err = -EINVAL;
2332 goto out_free;
2333 }
2334
2335 if (conv(&lval, tbl_data, 1, data)) {
2336 err = -EINVAL;
2337 goto out_free;
2338 }
2339
2340 if (!err && left)
2341 left -= proc_skip_spaces(&p);
2342
2343out_free:
2344 kfree(kbuf);
2345 if (err)
2346 return -EINVAL;
2347
2348 return 0;
2349
2350 /* This is in keeping with old __do_proc_dointvec() */
2351bail_early:
2352 *ppos += *lenp;
2353 return err;
2354}
2355
2356static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2357 size_t *lenp, loff_t *ppos,
2358 int (*conv)(unsigned long *lvalp,
2359 unsigned int *valp,
2360 int write, void *data),
2361 void *data)
2362{
2363 unsigned long lval;
2364 int err = 0;
2365 size_t left;
2366
2367 left = *lenp;
2368
2369 if (conv(&lval, tbl_data, 0, data)) {
2370 err = -EINVAL;
2371 goto out;
2372 }
2373
2374 err = proc_put_long(&buffer, &left, lval, false);
2375 if (err || !left)
2376 goto out;
2377
2378 err = proc_put_char(&buffer, &left, '\n');
2379
2380out:
2381 *lenp -= left;
2382 *ppos += *lenp;
2383
2384 return err;
2385}
2386
2387static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2388 int write, void __user *buffer,
2389 size_t *lenp, loff_t *ppos,
2390 int (*conv)(unsigned long *lvalp,
2391 unsigned int *valp,
2392 int write, void *data),
2393 void *data)
2394{
2395 unsigned int *i, vleft;
2396
2397 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2398 *lenp = 0;
2399 return 0;
2400 }
2401
2402 i = (unsigned int *) tbl_data;
2403 vleft = table->maxlen / sizeof(*i);
2404
2405 /*
2406 * Arrays are not supported, keep this simple. *Do not* add
2407 * support for them.
2408 */
2409 if (vleft != 1) {
2410 *lenp = 0;
2411 return -EINVAL;
2412 }
2413
2414 if (!conv)
2415 conv = do_proc_douintvec_conv;
2416
2417 if (write)
2418 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2419 conv, data);
2420 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2421}
2422
2423static int do_proc_douintvec(struct ctl_table *table, int write,
2424 void __user *buffer, size_t *lenp, loff_t *ppos,
2425 int (*conv)(unsigned long *lvalp,
2426 unsigned int *valp,
2427 int write, void *data),
2428 void *data)
2429{
2430 return __do_proc_douintvec(table->data, table, write,
2431 buffer, lenp, ppos, conv, data);
2432}
2433
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434/**
2435 * proc_dointvec - read a vector of integers
2436 * @table: the sysctl table
2437 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 * @buffer: the user buffer
2439 * @lenp: the size of the user buffer
2440 * @ppos: file position
2441 *
2442 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2443 * values from/to the user buffer, treated as an ASCII string.
2444 *
2445 * Returns 0 on success.
2446 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002447int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 void __user *buffer, size_t *lenp, loff_t *ppos)
2449{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002450 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2451}
2452
2453/**
2454 * proc_douintvec - read a vector of unsigned integers
2455 * @table: the sysctl table
2456 * @write: %TRUE if this is a write to the sysctl file
2457 * @buffer: the user buffer
2458 * @lenp: the size of the user buffer
2459 * @ppos: file position
2460 *
2461 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2462 * values from/to the user buffer, treated as an ASCII string.
2463 *
2464 * Returns 0 on success.
2465 */
2466int proc_douintvec(struct ctl_table *table, int write,
2467 void __user *buffer, size_t *lenp, loff_t *ppos)
2468{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002469 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2470 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471}
2472
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002473/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002474 * Taint values can only be increased
2475 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002476 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002477static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002478 void __user *buffer, size_t *lenp, loff_t *ppos)
2479{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002480 struct ctl_table t;
2481 unsigned long tmptaint = get_taint();
2482 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002483
Bastian Blank91fcd412007-04-23 14:41:14 -07002484 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002485 return -EPERM;
2486
Andi Kleen25ddbb12008-10-15 22:01:41 -07002487 t = *table;
2488 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002489 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002490 if (err < 0)
2491 return err;
2492
2493 if (write) {
2494 /*
2495 * Poor man's atomic or. Not worth adding a primitive
2496 * to everyone's atomic.h for this
2497 */
2498 int i;
2499 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2500 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302501 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002502 }
2503 }
2504
2505 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002506}
2507
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002508#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002509static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002510 void __user *buffer, size_t *lenp, loff_t *ppos)
2511{
2512 if (write && !capable(CAP_SYS_ADMIN))
2513 return -EPERM;
2514
2515 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2516}
2517#endif
2518
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519struct do_proc_dointvec_minmax_conv_param {
2520 int *min;
2521 int *max;
2522};
2523
Amerigo Wang00b7c332010-05-05 00:26:45 +00002524static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2525 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 int write, void *data)
2527{
2528 struct do_proc_dointvec_minmax_conv_param *param = data;
2529 if (write) {
2530 int val = *negp ? -*lvalp : *lvalp;
2531 if ((param->min && *param->min > val) ||
2532 (param->max && *param->max < val))
2533 return -EINVAL;
2534 *valp = val;
2535 } else {
2536 int val = *valp;
2537 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002538 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002539 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002541 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 *lvalp = (unsigned long)val;
2543 }
2544 }
2545 return 0;
2546}
2547
2548/**
2549 * proc_dointvec_minmax - read a vector of integers with min/max values
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2555 *
2556 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2557 * values from/to the user buffer, treated as an ASCII string.
2558 *
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2561 *
2562 * Returns 0 on success.
2563 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002564int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 void __user *buffer, size_t *lenp, loff_t *ppos)
2566{
2567 struct do_proc_dointvec_minmax_conv_param param = {
2568 .min = (int *) table->extra1,
2569 .max = (int *) table->extra2,
2570 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002571 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 do_proc_dointvec_minmax_conv, &param);
2573}
2574
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002575struct do_proc_douintvec_minmax_conv_param {
2576 unsigned int *min;
2577 unsigned int *max;
2578};
2579
2580static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2581 unsigned int *valp,
2582 int write, void *data)
2583{
2584 struct do_proc_douintvec_minmax_conv_param *param = data;
2585
2586 if (write) {
2587 unsigned int val = *lvalp;
2588
2589 if ((param->min && *param->min > val) ||
2590 (param->max && *param->max < val))
2591 return -ERANGE;
2592
2593 if (*lvalp > UINT_MAX)
2594 return -EINVAL;
2595 *valp = val;
2596 } else {
2597 unsigned int val = *valp;
2598 *lvalp = (unsigned long) val;
2599 }
2600
2601 return 0;
2602}
2603
2604/**
2605 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2606 * @table: the sysctl table
2607 * @write: %TRUE if this is a write to the sysctl file
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: file position
2611 *
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2613 * values from/to the user buffer, treated as an ASCII string. Negative
2614 * strings are not allowed.
2615 *
2616 * This routine will ensure the values are within the range specified by
2617 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2618 * check for UINT_MAX to avoid having to support wrap around uses from
2619 * userspace.
2620 *
2621 * Returns 0 on success.
2622 */
2623int proc_douintvec_minmax(struct ctl_table *table, int write,
2624 void __user *buffer, size_t *lenp, loff_t *ppos)
2625{
2626 struct do_proc_douintvec_minmax_conv_param param = {
2627 .min = (unsigned int *) table->extra1,
2628 .max = (unsigned int *) table->extra2,
2629 };
2630 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2631 do_proc_douintvec_minmax_conv, &param);
2632}
2633
Kees Cook54b50192012-07-30 14:39:18 -07002634static void validate_coredump_safety(void)
2635{
Alex Kelly046d6622012-10-04 17:15:23 -07002636#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002637 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002638 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002639 printk(KERN_WARNING
2640"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2641"Pipe handler or fully qualified core dump path required.\n"
2642"Set kernel.core_pattern before fs.suid_dumpable.\n"
2643 );
Kees Cook54b50192012-07-30 14:39:18 -07002644 }
Alex Kelly046d6622012-10-04 17:15:23 -07002645#endif
Kees Cook54b50192012-07-30 14:39:18 -07002646}
2647
2648static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2649 void __user *buffer, size_t *lenp, loff_t *ppos)
2650{
2651 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2652 if (!error)
2653 validate_coredump_safety();
2654 return error;
2655}
2656
Alex Kelly046d6622012-10-04 17:15:23 -07002657#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002658static int proc_dostring_coredump(struct ctl_table *table, int write,
2659 void __user *buffer, size_t *lenp, loff_t *ppos)
2660{
2661 int error = proc_dostring(table, write, buffer, lenp, ppos);
2662 if (!error)
2663 validate_coredump_safety();
2664 return error;
2665}
Alex Kelly046d6622012-10-04 17:15:23 -07002666#endif
Kees Cook54b50192012-07-30 14:39:18 -07002667
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002668static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 void __user *buffer,
2670 size_t *lenp, loff_t *ppos,
2671 unsigned long convmul,
2672 unsigned long convdiv)
2673{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002674 unsigned long *i, *min, *max;
2675 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002676 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002677 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002678
2679 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 *lenp = 0;
2681 return 0;
2682 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002683
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002684 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 min = (unsigned long *) table->extra1;
2686 max = (unsigned long *) table->extra2;
2687 vleft = table->maxlen / sizeof(unsigned long);
2688 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002689
2690 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002691 if (proc_first_pos_non_zero_ignore(ppos, table))
2692 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002693
Amerigo Wang00b7c332010-05-05 00:26:45 +00002694 if (left > PAGE_SIZE - 1)
2695 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002696 p = kbuf = memdup_user_nul(buffer, left);
2697 if (IS_ERR(kbuf))
2698 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002699 }
2700
Eric Dumazet27b3d802010-10-07 12:59:29 -07002701 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002702 unsigned long val;
2703
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002705 bool neg;
2706
Al Viro70f6cbb2015-12-24 00:13:10 -05002707 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002708
Al Viro70f6cbb2015-12-24 00:13:10 -05002709 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002710 proc_wspace_sep,
2711 sizeof(proc_wspace_sep), NULL);
2712 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 break;
2714 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002716 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if ((min && val < *min) || (max && val > *max))
2718 continue;
2719 *i = val;
2720 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002721 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002722 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002723 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002724 if (err)
2725 break;
2726 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002727 err = proc_put_long(&buffer, &left, val, false);
2728 if (err)
2729 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 }
2731 }
2732
Amerigo Wang00b7c332010-05-05 00:26:45 +00002733 if (!write && !first && left && !err)
2734 err = proc_put_char(&buffer, &left, '\n');
2735 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002736 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002738 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002739 if (first)
2740 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002743out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002745 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746}
2747
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002748static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002749 void __user *buffer,
2750 size_t *lenp, loff_t *ppos,
2751 unsigned long convmul,
2752 unsigned long convdiv)
2753{
2754 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002755 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002756}
2757
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758/**
2759 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2760 * @table: the sysctl table
2761 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 * @buffer: the user buffer
2763 * @lenp: the size of the user buffer
2764 * @ppos: file position
2765 *
2766 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2767 * values from/to the user buffer, treated as an ASCII string.
2768 *
2769 * This routine will ensure the values are within the range specified by
2770 * table->extra1 (min) and table->extra2 (max).
2771 *
2772 * Returns 0 on success.
2773 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002774int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 void __user *buffer, size_t *lenp, loff_t *ppos)
2776{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002777 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778}
2779
2780/**
2781 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2782 * @table: the sysctl table
2783 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 * @buffer: the user buffer
2785 * @lenp: the size of the user buffer
2786 * @ppos: file position
2787 *
2788 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2789 * values from/to the user buffer, treated as an ASCII string. The values
2790 * are treated as milliseconds, and converted to jiffies when they are stored.
2791 *
2792 * This routine will ensure the values are within the range specified by
2793 * table->extra1 (min) and table->extra2 (max).
2794 *
2795 * Returns 0 on success.
2796 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002797int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 void __user *buffer,
2799 size_t *lenp, loff_t *ppos)
2800{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002801 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 lenp, ppos, HZ, 1000l);
2803}
2804
2805
Amerigo Wang00b7c332010-05-05 00:26:45 +00002806static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 int *valp,
2808 int write, void *data)
2809{
2810 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002811 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002812 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2814 } else {
2815 int val = *valp;
2816 unsigned long lval;
2817 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002818 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002819 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002821 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 lval = (unsigned long)val;
2823 }
2824 *lvalp = lval / HZ;
2825 }
2826 return 0;
2827}
2828
Amerigo Wang00b7c332010-05-05 00:26:45 +00002829static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 int *valp,
2831 int write, void *data)
2832{
2833 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002834 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2835 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2837 } else {
2838 int val = *valp;
2839 unsigned long lval;
2840 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002841 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002842 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002844 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 lval = (unsigned long)val;
2846 }
2847 *lvalp = jiffies_to_clock_t(lval);
2848 }
2849 return 0;
2850}
2851
Amerigo Wang00b7c332010-05-05 00:26:45 +00002852static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 int *valp,
2854 int write, void *data)
2855{
2856 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002857 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2858
2859 if (jif > INT_MAX)
2860 return 1;
2861 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 } else {
2863 int val = *valp;
2864 unsigned long lval;
2865 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002866 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002867 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002869 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 lval = (unsigned long)val;
2871 }
2872 *lvalp = jiffies_to_msecs(lval);
2873 }
2874 return 0;
2875}
2876
2877/**
2878 * proc_dointvec_jiffies - read a vector of integers as seconds
2879 * @table: the sysctl table
2880 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 * @buffer: the user buffer
2882 * @lenp: the size of the user buffer
2883 * @ppos: file position
2884 *
2885 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2886 * values from/to the user buffer, treated as an ASCII string.
2887 * The values read are assumed to be in seconds, and are converted into
2888 * jiffies.
2889 *
2890 * Returns 0 on success.
2891 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002892int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 void __user *buffer, size_t *lenp, loff_t *ppos)
2894{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002895 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 do_proc_dointvec_jiffies_conv,NULL);
2897}
2898
2899/**
2900 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2901 * @table: the sysctl table
2902 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 * @buffer: the user buffer
2904 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002905 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 *
2907 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2908 * values from/to the user buffer, treated as an ASCII string.
2909 * The values read are assumed to be in 1/USER_HZ seconds, and
2910 * are converted into jiffies.
2911 *
2912 * Returns 0 on success.
2913 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002914int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 void __user *buffer, size_t *lenp, loff_t *ppos)
2916{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002917 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 do_proc_dointvec_userhz_jiffies_conv,NULL);
2919}
2920
2921/**
2922 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2923 * @table: the sysctl table
2924 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 * @buffer: the user buffer
2926 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002927 * @ppos: file position
2928 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 *
2930 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2931 * values from/to the user buffer, treated as an ASCII string.
2932 * The values read are assumed to be in 1/1000 seconds, and
2933 * are converted into jiffies.
2934 *
2935 * Returns 0 on success.
2936 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002937int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 void __user *buffer, size_t *lenp, loff_t *ppos)
2939{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 do_proc_dointvec_ms_jiffies_conv, NULL);
2942}
2943
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002944static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002945 void __user *buffer, size_t *lenp, loff_t *ppos)
2946{
2947 struct pid *new_pid;
2948 pid_t tmp;
2949 int r;
2950
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002951 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002952
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002953 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002954 lenp, ppos, NULL, NULL);
2955 if (r || !write)
2956 return r;
2957
2958 new_pid = find_get_pid(tmp);
2959 if (!new_pid)
2960 return -ESRCH;
2961
2962 put_pid(xchg(&cad_pid, new_pid));
2963 return 0;
2964}
2965
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002966/**
2967 * proc_do_large_bitmap - read/write from/to a large bitmap
2968 * @table: the sysctl table
2969 * @write: %TRUE if this is a write to the sysctl file
2970 * @buffer: the user buffer
2971 * @lenp: the size of the user buffer
2972 * @ppos: file position
2973 *
2974 * The bitmap is stored at table->data and the bitmap length (in bits)
2975 * in table->maxlen.
2976 *
2977 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2978 * large bitmaps may be represented in a compact manner. Writing into
2979 * the file will clear the bitmap then update it with the given input.
2980 *
2981 * Returns 0 on success.
2982 */
2983int proc_do_large_bitmap(struct ctl_table *table, int write,
2984 void __user *buffer, size_t *lenp, loff_t *ppos)
2985{
2986 int err = 0;
2987 bool first = 1;
2988 size_t left = *lenp;
2989 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002990 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002991 unsigned long *tmp_bitmap = NULL;
2992 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2993
WANG Cong122ff242014-05-12 16:04:53 -07002994 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002995 *lenp = 0;
2996 return 0;
2997 }
2998
2999 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003000 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003001
3002 if (left > PAGE_SIZE - 1)
3003 left = PAGE_SIZE - 1;
3004
Al Viro70f6cbb2015-12-24 00:13:10 -05003005 p = kbuf = memdup_user_nul(buffer, left);
3006 if (IS_ERR(kbuf))
3007 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003008
3009 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
3010 GFP_KERNEL);
3011 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003012 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003013 return -ENOMEM;
3014 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003015 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003016 while (!err && left) {
3017 unsigned long val_a, val_b;
3018 bool neg;
3019
Al Viro70f6cbb2015-12-24 00:13:10 -05003020 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003021 sizeof(tr_a), &c);
3022 if (err)
3023 break;
3024 if (val_a >= bitmap_len || neg) {
3025 err = -EINVAL;
3026 break;
3027 }
3028
3029 val_b = val_a;
3030 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003031 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003032 left--;
3033 }
3034
3035 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003036 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003037 &neg, tr_b, sizeof(tr_b),
3038 &c);
3039 if (err)
3040 break;
3041 if (val_b >= bitmap_len || neg ||
3042 val_a > val_b) {
3043 err = -EINVAL;
3044 break;
3045 }
3046 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003047 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003048 left--;
3049 }
3050 }
3051
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003052 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003053 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003054 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003055 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003056 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003057 } else {
3058 unsigned long bit_a, bit_b = 0;
3059
3060 while (left) {
3061 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3062 if (bit_a >= bitmap_len)
3063 break;
3064 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3065 bit_a + 1) - 1;
3066
3067 if (!first) {
3068 err = proc_put_char(&buffer, &left, ',');
3069 if (err)
3070 break;
3071 }
3072 err = proc_put_long(&buffer, &left, bit_a, false);
3073 if (err)
3074 break;
3075 if (bit_a != bit_b) {
3076 err = proc_put_char(&buffer, &left, '-');
3077 if (err)
3078 break;
3079 err = proc_put_long(&buffer, &left, bit_b, false);
3080 if (err)
3081 break;
3082 }
3083
3084 first = 0; bit_b++;
3085 }
3086 if (!err)
3087 err = proc_put_char(&buffer, &left, '\n');
3088 }
3089
3090 if (!err) {
3091 if (write) {
3092 if (*ppos)
3093 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3094 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003095 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003096 }
3097 kfree(tmp_bitmap);
3098 *lenp -= left;
3099 *ppos += *lenp;
3100 return 0;
3101 } else {
3102 kfree(tmp_bitmap);
3103 return err;
3104 }
3105}
3106
Jovi Zhang55610502011-01-12 17:00:45 -08003107#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003109int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 void __user *buffer, size_t *lenp, loff_t *ppos)
3111{
3112 return -ENOSYS;
3113}
3114
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003115int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 void __user *buffer, size_t *lenp, loff_t *ppos)
3117{
3118 return -ENOSYS;
3119}
3120
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003121int proc_douintvec(struct ctl_table *table, int write,
3122 void __user *buffer, size_t *lenp, loff_t *ppos)
3123{
3124 return -ENOSYS;
3125}
3126
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003127int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 void __user *buffer, size_t *lenp, loff_t *ppos)
3129{
3130 return -ENOSYS;
3131}
3132
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003133int proc_douintvec_minmax(struct ctl_table *table, int write,
3134 void __user *buffer, size_t *lenp, loff_t *ppos)
3135{
3136 return -ENOSYS;
3137}
3138
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003139int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 void __user *buffer, size_t *lenp, loff_t *ppos)
3141{
3142 return -ENOSYS;
3143}
3144
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003145int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 void __user *buffer, size_t *lenp, loff_t *ppos)
3147{
3148 return -ENOSYS;
3149}
3150
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003151int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 void __user *buffer, size_t *lenp, loff_t *ppos)
3153{
3154 return -ENOSYS;
3155}
3156
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003157int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 void __user *buffer, size_t *lenp, loff_t *ppos)
3159{
3160 return -ENOSYS;
3161}
3162
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003163int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 void __user *buffer,
3165 size_t *lenp, loff_t *ppos)
3166{
3167 return -ENOSYS;
3168}
3169
3170
Jovi Zhang55610502011-01-12 17:00:45 -08003171#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173/*
3174 * No sense putting this after each symbol definition, twice,
3175 * exception granted :-)
3176 */
3177EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003178EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179EXPORT_SYMBOL(proc_dointvec_jiffies);
3180EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003181EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3183EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3184EXPORT_SYMBOL(proc_dostring);
3185EXPORT_SYMBOL(proc_doulongvec_minmax);
3186EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);