blob: cc02050fd0c493378228eb6960e15449754f1387 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010065#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050068#include <linux/mount.h>
Joe Lawrence7a8d1812017-11-17 15:29:24 -080069#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080071#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <asm/processor.h>
73
Andi Kleen29cbc782006-09-30 01:47:55 +020074#ifdef CONFIG_X86
75#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010076#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010077#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020078#endif
David Howellsd550bbd2012-03-28 18:30:03 +010079#ifdef CONFIG_SPARC
80#include <asm/setup.h>
81#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080082#ifdef CONFIG_BSD_PROCESS_ACCT
83#include <linux/acct.h>
84#endif
Dave Young4f0e0562010-03-10 15:24:09 -080085#ifdef CONFIG_RT_MUTEXES
86#include <linux/rtmutex.h>
87#endif
Dave Young2edf5e42010-03-10 15:24:10 -080088#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89#include <linux/lockdep.h>
90#endif
Dave Young15485a42010-03-10 15:24:07 -080091#ifdef CONFIG_CHR_DEV_SG
92#include <scsi/sg.h>
93#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020094
Don Zickus58687ac2010-05-07 17:11:44 -040095#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050096#include <linux/nmi.h>
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#if defined(CONFIG_SYSCTL)
100
101/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700102extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700103#ifdef CONFIG_COREDUMP
104extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700106extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300112extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700130static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700131#ifdef CONFIG_PRINTK
132static int ten_thousand = 10000;
133#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300134#ifdef CONFIG_PERF_EVENTS
135static int six_hundred_forty_kb = 640 * 1024;
136#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700137
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700138/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142static int maxolduid = 65535;
143static int minolduid;
144
145static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700146static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700148/*
149 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
150 * and hung_task_check_interval_secs
151 */
Liu Hua80df2842014-04-07 15:38:57 -0700152#ifdef CONFIG_DETECT_HUNG_TASK
153static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
154#endif
155
Dave Youngd14f1722010-02-25 20:28:57 -0500156#ifdef CONFIG_INOTIFY_USER
157#include <linux/inotify.h>
158#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700159#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#endif
161
162#ifdef __hppa__
163extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530164#endif
165
166#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167extern int unaligned_enabled;
168#endif
169
Jes Sorensend2b176e2006-02-28 09:42:23 -0800170#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800171extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800172#endif
173
Vineet Guptab6fca722013-01-09 20:06:28 +0530174#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
175extern int no_unaligned_warning;
176#endif
177
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700178#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700179
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700180/**
181 * enum sysctl_writes_mode - supported sysctl write modes
182 *
183 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
184 * to be written, and multiple writes on the same sysctl file descriptor
185 * will rewrite the sysctl value, regardless of file position. No warning
186 * is issued when the initial position is not 0.
187 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
188 * not 0.
189 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
190 * file position 0 and the value must be fully contained in the buffer
191 * sent to the write syscall. If dealing with strings respect the file
192 * position, but restrict this to the max length of the buffer, anything
193 * passed the max lenght will be ignored. Multiple writes will append
194 * to the buffer.
195 *
196 * These write modes control how current file position affects the behavior of
197 * updating sysctl values through the proc interface on each write.
198 */
199enum sysctl_writes_mode {
200 SYSCTL_WRITES_LEGACY = -1,
201 SYSCTL_WRITES_WARN = 0,
202 SYSCTL_WRITES_STRICT = 1,
203};
Kees Cookf4aacea2014-06-06 14:37:19 -0700204
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700205static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700206
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700207static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700208 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700209static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800210 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700211#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700212
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700213#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700214static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700215 void __user *buffer, size_t *lenp, loff_t *ppos);
216#endif
217
Kees Cook54b50192012-07-30 14:39:18 -0700218static int proc_dointvec_minmax_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#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700221static int proc_dostring_coredump(struct ctl_table *table, int write,
222 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700223#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800224static int proc_dopipe_max_size(struct ctl_table *table, int write,
225 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700226
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700227#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700228/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100229static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700230
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700231static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700232 void __user *buffer, size_t *lenp,
233 loff_t *ppos)
234{
235 int error;
236
237 error = proc_dointvec(table, write, buffer, lenp, ppos);
238 if (error)
239 return error;
240
241 if (write)
242 sysrq_toggle_support(__sysrq_enabled);
243
244 return 0;
245}
246
247#endif
248
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700249static struct ctl_table kern_table[];
250static struct ctl_table vm_table[];
251static struct ctl_table fs_table[];
252static struct ctl_table debug_table[];
253static struct ctl_table dev_table[];
254extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800255#ifdef CONFIG_EPOLL
256extern struct ctl_table epoll_table[];
257#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800259#ifdef CONFIG_FW_LOADER_USER_HELPER
260extern struct ctl_table firmware_config_table[];
261#endif
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
264int sysctl_legacy_va_layout;
265#endif
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267/* The default sysctl tables: */
268
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800269static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 .procname = "kernel",
272 .mode = 0555,
273 .child = kern_table,
274 },
275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 .procname = "vm",
277 .mode = 0555,
278 .child = vm_table,
279 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 .procname = "fs",
282 .mode = 0555,
283 .child = fs_table,
284 },
285 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .procname = "debug",
287 .mode = 0555,
288 .child = debug_table,
289 },
290 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 .procname = "dev",
292 .mode = 0555,
293 .child = dev_table,
294 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700295 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296};
297
Ingo Molnar77e54a12007-07-09 18:52:00 +0200298#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100299static int min_sched_granularity_ns = 100000; /* 100 usecs */
300static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
301static int min_wakeup_granularity_ns; /* 0 usecs */
302static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200303#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100304static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
305static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200306#endif /* CONFIG_SMP */
307#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200308
Mel Gorman5e771902010-05-24 14:32:31 -0700309#ifdef CONFIG_COMPACTION
310static int min_extfrag_threshold;
311static int max_extfrag_threshold = 1000;
312#endif
313
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700314static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200315 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200316 .procname = "sched_child_runs_first",
317 .data = &sysctl_sched_child_runs_first,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800320 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200321 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200322#ifdef CONFIG_SCHED_DEBUG
323 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100324 .procname = "sched_min_granularity_ns",
325 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800328 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100329 .extra1 = &min_sched_granularity_ns,
330 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200331 },
332 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200333 .procname = "sched_latency_ns",
334 .data = &sysctl_sched_latency,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800337 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200338 .extra1 = &min_sched_granularity_ns,
339 .extra2 = &max_sched_granularity_ns,
340 },
341 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200342 .procname = "sched_wakeup_granularity_ns",
343 .data = &sysctl_sched_wakeup_granularity,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800346 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200347 .extra1 = &min_wakeup_granularity_ns,
348 .extra2 = &max_wakeup_granularity_ns,
349 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200350#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200351 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100352 .procname = "sched_tunable_scaling",
353 .data = &sysctl_sched_tunable_scaling,
354 .maxlen = sizeof(enum sched_tunable_scaling),
355 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800356 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100357 .extra1 = &min_sched_tunable_scaling,
358 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200359 },
360 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900361 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200362 .data = &sysctl_sched_migration_cost,
363 .maxlen = sizeof(unsigned int),
364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800365 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200366 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100367 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100368 .procname = "sched_nr_migrate",
369 .data = &sysctl_sched_nr_migrate,
370 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800372 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100373 },
Mel Gormancb251762016-02-05 09:08:36 +0000374#ifdef CONFIG_SCHEDSTATS
375 {
376 .procname = "sched_schedstats",
377 .data = NULL,
378 .maxlen = sizeof(unsigned int),
379 .mode = 0644,
380 .proc_handler = sysctl_schedstats,
381 .extra1 = &zero,
382 .extra2 = &one,
383 },
384#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200385#endif /* CONFIG_SMP */
386#ifdef CONFIG_NUMA_BALANCING
387 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200388 .procname = "numa_balancing_scan_delay_ms",
389 .data = &sysctl_numa_balancing_scan_delay,
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
392 .proc_handler = proc_dointvec,
393 },
394 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200395 .procname = "numa_balancing_scan_period_min_ms",
396 .data = &sysctl_numa_balancing_scan_period_min,
397 .maxlen = sizeof(unsigned int),
398 .mode = 0644,
399 .proc_handler = proc_dointvec,
400 },
401 {
402 .procname = "numa_balancing_scan_period_max_ms",
403 .data = &sysctl_numa_balancing_scan_period_max,
404 .maxlen = sizeof(unsigned int),
405 .mode = 0644,
406 .proc_handler = proc_dointvec,
407 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200408 {
409 .procname = "numa_balancing_scan_size_mb",
410 .data = &sysctl_numa_balancing_scan_size,
411 .maxlen = sizeof(unsigned int),
412 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400413 .proc_handler = proc_dointvec_minmax,
414 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200415 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100416 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800417 .procname = "numa_balancing",
418 .data = NULL, /* filled in by handler */
419 .maxlen = sizeof(unsigned int),
420 .mode = 0644,
421 .proc_handler = sysctl_numa_balancing,
422 .extra1 = &zero,
423 .extra2 = &one,
424 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200425#endif /* CONFIG_NUMA_BALANCING */
426#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200427 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100428 .procname = "sched_rt_period_us",
429 .data = &sysctl_sched_rt_period,
430 .maxlen = sizeof(unsigned int),
431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800432 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100433 },
434 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100435 .procname = "sched_rt_runtime_us",
436 .data = &sysctl_sched_rt_runtime,
437 .maxlen = sizeof(int),
438 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800439 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100440 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600441 {
442 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800443 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600444 .maxlen = sizeof(int),
445 .mode = 0644,
446 .proc_handler = sched_rr_handler,
447 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100448#ifdef CONFIG_SCHED_AUTOGROUP
449 {
450 .procname = "sched_autogroup_enabled",
451 .data = &sysctl_sched_autogroup_enabled,
452 .maxlen = sizeof(unsigned int),
453 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800454 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100455 .extra1 = &zero,
456 .extra2 = &one,
457 },
458#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700459#ifdef CONFIG_CFS_BANDWIDTH
460 {
461 .procname = "sched_cfs_bandwidth_slice_us",
462 .data = &sysctl_sched_cfs_bandwidth_slice,
463 .maxlen = sizeof(unsigned int),
464 .mode = 0644,
465 .proc_handler = proc_dointvec_minmax,
466 .extra1 = &one,
467 },
468#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700469#ifdef CONFIG_PROVE_LOCKING
470 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700471 .procname = "prove_locking",
472 .data = &prove_locking,
473 .maxlen = sizeof(int),
474 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800475 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700476 },
477#endif
478#ifdef CONFIG_LOCK_STAT
479 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700480 .procname = "lock_stat",
481 .data = &lock_stat,
482 .maxlen = sizeof(int),
483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800484 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700485 },
486#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200487 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .procname = "panic",
489 .data = &panic_timeout,
490 .maxlen = sizeof(int),
491 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800492 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 },
Alex Kelly046d6622012-10-04 17:15:23 -0700494#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "core_uses_pid",
497 .data = &core_uses_pid,
498 .maxlen = sizeof(int),
499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800500 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 },
502 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 .procname = "core_pattern",
504 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700505 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700507 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 },
Neil Hormana2939802009-09-23 15:56:56 -0700509 {
Neil Hormana2939802009-09-23 15:56:56 -0700510 .procname = "core_pipe_limit",
511 .data = &core_pipe_limit,
512 .maxlen = sizeof(unsigned int),
513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800514 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700515 },
Alex Kelly046d6622012-10-04 17:15:23 -0700516#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800517#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700520 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800521 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800522 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700524 {
525 .procname = "sysctl_writes_strict",
526 .data = &sysctl_writes_strict,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = proc_dointvec_minmax,
530 .extra1 = &neg_one,
531 .extra2 = &one,
532 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800533#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100534#ifdef CONFIG_LATENCYTOP
535 {
536 .procname = "latencytop",
537 .data = &latencytop_enabled,
538 .maxlen = sizeof(int),
539 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000540 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100541 },
542#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#ifdef CONFIG_BLK_DEV_INITRD
544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "real-root-dev",
546 .data = &real_root_dev,
547 .maxlen = sizeof(int),
548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
551#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700552 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700553 .procname = "print-fatal-signals",
554 .data = &print_fatal_signals,
555 .maxlen = sizeof(int),
556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800557 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700558 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700559#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .procname = "reboot-cmd",
562 .data = reboot_command,
563 .maxlen = 256,
564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 },
567 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 .procname = "stop-a",
569 .data = &stop_a_enabled,
570 .maxlen = sizeof (int),
571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800572 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 },
574 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .procname = "scons-poweroff",
576 .data = &scons_pwroff,
577 .maxlen = sizeof (int),
578 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800579 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 },
581#endif
David S. Miller08714202008-11-16 23:49:24 -0800582#ifdef CONFIG_SPARC64
583 {
David S. Miller08714202008-11-16 23:49:24 -0800584 .procname = "tsb-ratio",
585 .data = &sysctl_tsb_ratio,
586 .maxlen = sizeof (int),
587 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800588 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800589 },
590#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#ifdef __hppa__
592 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .procname = "soft-power",
594 .data = &pwrsw_enabled,
595 .maxlen = sizeof (int),
596 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800597 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530599#endif
600#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .procname = "unaligned-trap",
603 .data = &unaligned_enabled,
604 .maxlen = sizeof (int),
605 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800606 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 },
608#endif
609 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 .procname = "ctrl-alt-del",
611 .data = &C_A_D,
612 .maxlen = sizeof(int),
613 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800614 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400616#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200617 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200618 .procname = "ftrace_enabled",
619 .data = &ftrace_enabled,
620 .maxlen = sizeof(int),
621 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800622 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200623 },
624#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500625#ifdef CONFIG_STACK_TRACER
626 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500627 .procname = "stack_tracer_enabled",
628 .data = &stack_tracer_enabled,
629 .maxlen = sizeof(int),
630 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800631 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500632 },
633#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400634#ifdef CONFIG_TRACING
635 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100636 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400637 .data = &ftrace_dump_on_oops,
638 .maxlen = sizeof(int),
639 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800640 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400641 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400642 {
643 .procname = "traceoff_on_warning",
644 .data = &__disable_trace_on_warning,
645 .maxlen = sizeof(__disable_trace_on_warning),
646 .mode = 0644,
647 .proc_handler = proc_dointvec,
648 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500649 {
650 .procname = "tracepoint_printk",
651 .data = &tracepoint_printk,
652 .maxlen = sizeof(tracepoint_printk),
653 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500654 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500655 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400656#endif
Dave Young2965faa2015-09-09 15:38:55 -0700657#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800658 {
659 .procname = "kexec_load_disabled",
660 .data = &kexec_load_disabled,
661 .maxlen = sizeof(int),
662 .mode = 0644,
663 /* only handle a transition from default "0" to "1" */
664 .proc_handler = proc_dointvec_minmax,
665 .extra1 = &one,
666 .extra2 = &one,
667 },
668#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200669#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .procname = "modprobe",
672 .data = &modprobe_path,
673 .maxlen = KMOD_PATH_LEN,
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 },
Kees Cook3d433212009-04-02 15:49:29 -0700677 {
Kees Cook3d433212009-04-02 15:49:29 -0700678 .procname = "modules_disabled",
679 .data = &modules_disabled,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700684 .extra1 = &one,
685 .extra2 = &one,
686 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700688#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100691 .data = &uevent_helper,
692 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800694 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 },
Michael Marineau86d56132014-04-10 14:09:31 -0700696#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#ifdef CONFIG_CHR_DEV_SG
698 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .procname = "sg-big-buff",
700 .data = &sg_big_buff,
701 .maxlen = sizeof (int),
702 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800703 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 },
705#endif
706#ifdef CONFIG_BSD_PROCESS_ACCT
707 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 .procname = "acct",
709 .data = &acct_parm,
710 .maxlen = 3*sizeof(int),
711 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800712 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 },
714#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#ifdef CONFIG_MAGIC_SYSRQ
716 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800718 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .maxlen = sizeof (int),
720 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700721 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 },
723#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700724#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700727 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .maxlen = sizeof (int),
729 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800730 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700732#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700735 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .maxlen = sizeof(int),
737 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700738 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 },
740 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 .procname = "random",
742 .mode = 0555,
743 .child = random_table,
744 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 {
Eric Paris17f60a72011-04-01 17:07:50 -0400746 .procname = "usermodehelper",
747 .mode = 0555,
748 .child = usermodehelper_table,
749 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800750#ifdef CONFIG_FW_LOADER_USER_HELPER
751 {
752 .procname = "firmware_config",
753 .mode = 0555,
754 .child = firmware_config_table,
755 },
756#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .procname = "overflowuid",
759 .data = &overflowuid,
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 },
766 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .procname = "overflowgid",
768 .data = &overflowgid,
769 .maxlen = sizeof(int),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 .extra1 = &minolduid,
773 .extra2 = &maxolduid,
774 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800775#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776#ifdef CONFIG_MATHEMU
777 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 .procname = "ieee_emulation_warnings",
779 .data = &sysctl_ieee_emulation_warnings,
780 .maxlen = sizeof(int),
781 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800782 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 },
784#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200787 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .maxlen = sizeof(int),
789 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800790 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 },
792#endif
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .procname = "pid_max",
795 .data = &pid_max,
796 .maxlen = sizeof (int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .extra1 = &pid_max_min,
800 .extra2 = &pid_max_max,
801 },
802 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 .procname = "panic_on_oops",
804 .data = &panic_on_oops,
805 .maxlen = sizeof(int),
806 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800807 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800809#if defined CONFIG_PRINTK
810 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800811 .procname = "printk",
812 .data = &console_loglevel,
813 .maxlen = 4*sizeof(int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800816 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700819 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 .maxlen = sizeof(int),
821 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800822 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 },
824 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700826 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 .maxlen = sizeof(int),
828 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800829 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 },
Dave Youngaf913222009-09-22 16:43:33 -0700831 {
Dave Youngaf913222009-09-22 16:43:33 -0700832 .procname = "printk_delay",
833 .data = &printk_delay_msec,
834 .maxlen = sizeof(int),
835 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800836 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700837 .extra1 = &zero,
838 .extra2 = &ten_thousand,
839 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700841 .procname = "printk_devkmsg",
842 .data = devkmsg_log_str,
843 .maxlen = DEVKMSG_STR_MAX_SIZE,
844 .mode = 0644,
845 .proc_handler = devkmsg_sysctl_set_loglvl,
846 },
847 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800848 .procname = "dmesg_restrict",
849 .data = &dmesg_restrict,
850 .maxlen = sizeof(int),
851 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700852 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800853 .extra1 = &zero,
854 .extra2 = &one,
855 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800856 {
857 .procname = "kptr_restrict",
858 .data = &kptr_restrict,
859 .maxlen = sizeof(int),
860 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700861 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800862 .extra1 = &zero,
863 .extra2 = &two,
864 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800865#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800866 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 .procname = "ngroups_max",
868 .data = &ngroups_max,
869 .maxlen = sizeof (int),
870 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800871 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 },
Dan Ballard73efc032011-10-31 17:11:20 -0700873 {
874 .procname = "cap_last_cap",
875 .data = (void *)&cap_last_cap,
876 .maxlen = sizeof(int),
877 .mode = 0444,
878 .proc_handler = proc_dointvec,
879 },
Don Zickus58687ac2010-05-07 17:11:44 -0400880#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500881 {
Don Zickus58687ac2010-05-07 17:11:44 -0400882 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200883 .data = &watchdog_user_enabled,
884 .maxlen = sizeof(int),
885 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700886 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700887 .extra1 = &zero,
888 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400889 },
890 {
891 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700892 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400893 .maxlen = sizeof(int),
894 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700895 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800896 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400897 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500898 },
Don Zickus2508ce12010-05-07 17:11:46 -0400899 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700900 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200901 .data = &nmi_watchdog_user_enabled,
902 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200903 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700904 .proc_handler = proc_nmi_watchdog,
905 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700906 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700907 },
908 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700909 .procname = "watchdog_cpumask",
910 .data = &watchdog_cpumask_bits,
911 .maxlen = NR_CPUS,
912 .mode = 0644,
913 .proc_handler = proc_watchdog_cpumask,
914 },
915#ifdef CONFIG_SOFTLOCKUP_DETECTOR
916 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700917 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200918 .data = &soft_watchdog_user_enabled,
919 .maxlen = sizeof(int),
920 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700921 .proc_handler = proc_soft_watchdog,
922 .extra1 = &zero,
923 .extra2 = &one,
924 },
925 {
Don Zickus2508ce12010-05-07 17:11:46 -0400926 .procname = "softlockup_panic",
927 .data = &softlockup_panic,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec_minmax,
931 .extra1 = &zero,
932 .extra2 = &one,
933 },
Aaron Tomlined235872014-06-23 13:22:05 -0700934#ifdef CONFIG_SMP
935 {
936 .procname = "softlockup_all_cpu_backtrace",
937 .data = &sysctl_softlockup_all_cpu_backtrace,
938 .maxlen = sizeof(int),
939 .mode = 0644,
940 .proc_handler = proc_dointvec_minmax,
941 .extra1 = &zero,
942 .extra2 = &one,
943 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700944#endif /* CONFIG_SMP */
945#endif
946#ifdef CONFIG_HARDLOCKUP_DETECTOR
947 {
948 .procname = "hardlockup_panic",
949 .data = &hardlockup_panic,
950 .maxlen = sizeof(int),
951 .mode = 0644,
952 .proc_handler = proc_dointvec_minmax,
953 .extra1 = &zero,
954 .extra2 = &one,
955 },
956#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800957 {
958 .procname = "hardlockup_all_cpu_backtrace",
959 .data = &sysctl_hardlockup_all_cpu_backtrace,
960 .maxlen = sizeof(int),
961 .mode = 0644,
962 .proc_handler = proc_dointvec_minmax,
963 .extra1 = &zero,
964 .extra2 = &one,
965 },
Aaron Tomlined235872014-06-23 13:22:05 -0700966#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500967#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700968#endif
969
Don Zickus5dc30552010-11-29 17:07:17 -0500970#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
971 {
972 .procname = "unknown_nmi_panic",
973 .data = &unknown_nmi_panic,
974 .maxlen = sizeof (int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec,
977 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500978#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979#if defined(CONFIG_X86)
980 {
Don Zickus8da5add2006-09-26 10:52:27 +0200981 .procname = "panic_on_unrecovered_nmi",
982 .data = &panic_on_unrecovered_nmi,
983 .maxlen = sizeof(int),
984 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800985 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200986 },
987 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700988 .procname = "panic_on_io_nmi",
989 .data = &panic_on_io_nmi,
990 .maxlen = sizeof(int),
991 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800992 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700993 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900994#ifdef CONFIG_DEBUG_STACKOVERFLOW
995 {
996 .procname = "panic_on_stackoverflow",
997 .data = &sysctl_panic_on_stackoverflow,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec,
1001 },
1002#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001003 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 .procname = "bootloader_type",
1005 .data = &bootloader_type,
1006 .maxlen = sizeof (int),
1007 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001008 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001010 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001011 .procname = "bootloader_version",
1012 .data = &bootloader_version,
1013 .maxlen = sizeof (int),
1014 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001016 },
1017 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001018 .procname = "io_delay_type",
1019 .data = &io_delay_type,
1020 .maxlen = sizeof(int),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001023 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001025#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 .procname = "randomize_va_space",
1028 .data = &randomize_va_space,
1029 .maxlen = sizeof(int),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001033#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001034#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001035 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001036 .procname = "spin_retry",
1037 .data = &spin_retry,
1038 .maxlen = sizeof (int),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001041 },
1042#endif
Len Brown673d5b42007-07-28 03:33:16 -04001043#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001044 {
Pavel Machekc255d842006-02-20 18:27:58 -08001045 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001046 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001047 .maxlen = sizeof (unsigned long),
1048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001050 },
1051#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301052#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001053 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001054 .procname = "ignore-unaligned-usertrap",
1055 .data = &no_unaligned_warning,
1056 .maxlen = sizeof (int),
1057 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001058 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001059 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301060#endif
1061#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001062 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001063 .procname = "unaligned-dump-stack",
1064 .data = &unaligned_dump_stack,
1065 .maxlen = sizeof (int),
1066 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001067 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001068 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001069#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001070#ifdef CONFIG_DETECT_HUNG_TASK
1071 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001072 .procname = "hung_task_panic",
1073 .data = &sysctl_hung_task_panic,
1074 .maxlen = sizeof(int),
1075 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001076 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001077 .extra1 = &zero,
1078 .extra2 = &one,
1079 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001080 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001081 .procname = "hung_task_check_count",
1082 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001083 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001084 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001085 .proc_handler = proc_dointvec_minmax,
1086 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001087 },
1088 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001089 .procname = "hung_task_timeout_secs",
1090 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001091 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001092 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001093 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001094 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001095 },
1096 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001097 .procname = "hung_task_check_interval_secs",
1098 .data = &sysctl_hung_task_check_interval_secs,
1099 .maxlen = sizeof(unsigned long),
1100 .mode = 0644,
1101 .proc_handler = proc_dohung_task_timeout_secs,
1102 .extra2 = &hung_task_timeout_max,
1103 },
1104 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001105 .procname = "hung_task_warnings",
1106 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001107 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001108 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001109 .proc_handler = proc_dointvec_minmax,
1110 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001111 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001112#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001113#ifdef CONFIG_RT_MUTEXES
1114 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001115 .procname = "max_lock_depth",
1116 .data = &max_lock_depth,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001119 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001120 },
1121#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001122 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001123 .procname = "poweroff_cmd",
1124 .data = &poweroff_cmd,
1125 .maxlen = POWEROFF_CMD_PATH_LEN,
1126 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001127 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001128 },
David Howells0b77f5b2008-04-29 01:01:32 -07001129#ifdef CONFIG_KEYS
1130 {
David Howells0b77f5b2008-04-29 01:01:32 -07001131 .procname = "keys",
1132 .mode = 0555,
1133 .child = key_sysctls,
1134 },
1135#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001136#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001137 /*
1138 * User-space scripts rely on the existence of this file
1139 * as a feature check for perf_events being enabled.
1140 *
1141 * So it's an ABI, do not remove!
1142 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001143 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001144 .procname = "perf_event_paranoid",
1145 .data = &sysctl_perf_event_paranoid,
1146 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001147 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001148 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001149 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001150 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001151 .procname = "perf_event_mlock_kb",
1152 .data = &sysctl_perf_event_mlock,
1153 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001154 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001155 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001156 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001157 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001158 .procname = "perf_event_max_sample_rate",
1159 .data = &sysctl_perf_event_sample_rate,
1160 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001161 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001162 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001163 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001164 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001165 {
1166 .procname = "perf_cpu_time_max_percent",
1167 .data = &sysctl_perf_cpu_time_max_percent,
1168 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1169 .mode = 0644,
1170 .proc_handler = perf_cpu_time_max_percent_handler,
1171 .extra1 = &zero,
1172 .extra2 = &one_hundred,
1173 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001174 {
1175 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001176 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001177 .maxlen = sizeof(sysctl_perf_event_max_stack),
1178 .mode = 0644,
1179 .proc_handler = perf_event_max_stack_handler,
1180 .extra1 = &zero,
1181 .extra2 = &six_hundred_forty_kb,
1182 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001183 {
1184 .procname = "perf_event_max_contexts_per_stack",
1185 .data = &sysctl_perf_event_max_contexts_per_stack,
1186 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1187 .mode = 0644,
1188 .proc_handler = perf_event_max_stack_handler,
1189 .extra1 = &zero,
1190 .extra2 = &one_thousand,
1191 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001192#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001193 {
1194 .procname = "panic_on_warn",
1195 .data = &panic_on_warn,
1196 .maxlen = sizeof(int),
1197 .mode = 0644,
1198 .proc_handler = proc_dointvec_minmax,
1199 .extra1 = &zero,
1200 .extra2 = &one,
1201 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001202#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1203 {
1204 .procname = "timer_migration",
1205 .data = &sysctl_timer_migration,
1206 .maxlen = sizeof(unsigned int),
1207 .mode = 0644,
1208 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001209 .extra1 = &zero,
1210 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001211 },
1212#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001213#ifdef CONFIG_BPF_SYSCALL
1214 {
1215 .procname = "unprivileged_bpf_disabled",
1216 .data = &sysctl_unprivileged_bpf_disabled,
1217 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1218 .mode = 0644,
1219 /* only handle a transition from default "0" to "1" */
1220 .proc_handler = proc_dointvec_minmax,
1221 .extra1 = &one,
1222 .extra2 = &one,
1223 },
1224#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001225#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1226 {
1227 .procname = "panic_on_rcu_stall",
1228 .data = &sysctl_panic_on_rcu_stall,
1229 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1230 .mode = 0644,
1231 .proc_handler = proc_dointvec_minmax,
1232 .extra1 = &zero,
1233 .extra2 = &one,
1234 },
1235#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001236 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237};
1238
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001239static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 .procname = "overcommit_memory",
1242 .data = &sysctl_overcommit_memory,
1243 .maxlen = sizeof(sysctl_overcommit_memory),
1244 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001245 .proc_handler = proc_dointvec_minmax,
1246 .extra1 = &zero,
1247 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 },
1249 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001250 .procname = "panic_on_oom",
1251 .data = &sysctl_panic_on_oom,
1252 .maxlen = sizeof(sysctl_panic_on_oom),
1253 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001254 .proc_handler = proc_dointvec_minmax,
1255 .extra1 = &zero,
1256 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001257 },
1258 {
David Rientjesfe071d72007-10-16 23:25:56 -07001259 .procname = "oom_kill_allocating_task",
1260 .data = &sysctl_oom_kill_allocating_task,
1261 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1262 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001263 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001264 },
1265 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001266 .procname = "oom_dump_tasks",
1267 .data = &sysctl_oom_dump_tasks,
1268 .maxlen = sizeof(sysctl_oom_dump_tasks),
1269 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001270 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001271 },
1272 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 .procname = "overcommit_ratio",
1274 .data = &sysctl_overcommit_ratio,
1275 .maxlen = sizeof(sysctl_overcommit_ratio),
1276 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001277 .proc_handler = overcommit_ratio_handler,
1278 },
1279 {
1280 .procname = "overcommit_kbytes",
1281 .data = &sysctl_overcommit_kbytes,
1282 .maxlen = sizeof(sysctl_overcommit_kbytes),
1283 .mode = 0644,
1284 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 },
1286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 .procname = "page-cluster",
1288 .data = &page_cluster,
1289 .maxlen = sizeof(int),
1290 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001291 .proc_handler = proc_dointvec_minmax,
1292 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 },
1294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 .procname = "dirty_background_ratio",
1296 .data = &dirty_background_ratio,
1297 .maxlen = sizeof(dirty_background_ratio),
1298 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001299 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 .extra1 = &zero,
1301 .extra2 = &one_hundred,
1302 },
1303 {
David Rientjes2da02992009-01-06 14:39:31 -08001304 .procname = "dirty_background_bytes",
1305 .data = &dirty_background_bytes,
1306 .maxlen = sizeof(dirty_background_bytes),
1307 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001308 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001309 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001310 },
1311 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 .procname = "dirty_ratio",
1313 .data = &vm_dirty_ratio,
1314 .maxlen = sizeof(vm_dirty_ratio),
1315 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001316 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 .extra1 = &zero,
1318 .extra2 = &one_hundred,
1319 },
1320 {
David Rientjes2da02992009-01-06 14:39:31 -08001321 .procname = "dirty_bytes",
1322 .data = &vm_dirty_bytes,
1323 .maxlen = sizeof(vm_dirty_bytes),
1324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001325 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001326 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001327 },
1328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001330 .data = &dirty_writeback_interval,
1331 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001333 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 },
1335 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001337 .data = &dirty_expire_interval,
1338 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001340 .proc_handler = proc_dointvec_minmax,
1341 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 },
1343 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001344 .procname = "dirtytime_expire_seconds",
1345 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001346 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001347 .mode = 0644,
1348 .proc_handler = dirtytime_interval_handler,
1349 .extra1 = &zero,
1350 },
1351 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 .procname = "swappiness",
1353 .data = &vm_swappiness,
1354 .maxlen = sizeof(vm_swappiness),
1355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001356 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .extra1 = &zero,
1358 .extra2 = &one_hundred,
1359 },
1360#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001363 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .maxlen = sizeof(unsigned long),
1365 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001366 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001367 },
1368#ifdef CONFIG_NUMA
1369 {
1370 .procname = "nr_hugepages_mempolicy",
1371 .data = NULL,
1372 .maxlen = sizeof(unsigned long),
1373 .mode = 0644,
1374 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001375 },
Kemi Wang45180852017-11-15 17:38:22 -08001376 {
1377 .procname = "numa_stat",
1378 .data = &sysctl_vm_numa_stat,
1379 .maxlen = sizeof(int),
1380 .mode = 0644,
1381 .proc_handler = sysctl_vm_numa_stat_handler,
1382 .extra1 = &zero,
1383 .extra2 = &one,
1384 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001385#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 .procname = "hugetlb_shm_group",
1388 .data = &sysctl_hugetlb_shm_group,
1389 .maxlen = sizeof(gid_t),
1390 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001391 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 },
Adam Litke54f9f802007-10-16 01:26:20 -07001393 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001394 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001395 .data = NULL,
1396 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001397 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001398 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001399 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400#endif
1401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 .procname = "lowmem_reserve_ratio",
1403 .data = &sysctl_lowmem_reserve_ratio,
1404 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1405 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001406 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 },
1408 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001409 .procname = "drop_caches",
1410 .data = &sysctl_drop_caches,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
1413 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001414 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001415 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001416 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001417#ifdef CONFIG_COMPACTION
1418 {
1419 .procname = "compact_memory",
1420 .data = &sysctl_compact_memory,
1421 .maxlen = sizeof(int),
1422 .mode = 0200,
1423 .proc_handler = sysctl_compaction_handler,
1424 },
Mel Gorman5e771902010-05-24 14:32:31 -07001425 {
1426 .procname = "extfrag_threshold",
1427 .data = &sysctl_extfrag_threshold,
1428 .maxlen = sizeof(int),
1429 .mode = 0644,
1430 .proc_handler = sysctl_extfrag_handler,
1431 .extra1 = &min_extfrag_threshold,
1432 .extra2 = &max_extfrag_threshold,
1433 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001434 {
1435 .procname = "compact_unevictable_allowed",
1436 .data = &sysctl_compact_unevictable_allowed,
1437 .maxlen = sizeof(int),
1438 .mode = 0644,
1439 .proc_handler = proc_dointvec,
1440 .extra1 = &zero,
1441 .extra2 = &one,
1442 },
Mel Gorman5e771902010-05-24 14:32:31 -07001443
Mel Gorman76ab0f52010-05-24 14:32:28 -07001444#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .procname = "min_free_kbytes",
1447 .data = &min_free_kbytes,
1448 .maxlen = sizeof(min_free_kbytes),
1449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001450 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 .extra1 = &zero,
1452 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001453 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001454 .procname = "watermark_scale_factor",
1455 .data = &watermark_scale_factor,
1456 .maxlen = sizeof(watermark_scale_factor),
1457 .mode = 0644,
1458 .proc_handler = watermark_scale_factor_sysctl_handler,
1459 .extra1 = &one,
1460 .extra2 = &one_thousand,
1461 },
1462 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001463 .procname = "percpu_pagelist_fraction",
1464 .data = &percpu_pagelist_fraction,
1465 .maxlen = sizeof(percpu_pagelist_fraction),
1466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001467 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001468 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001469 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470#ifdef CONFIG_MMU
1471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 .procname = "max_map_count",
1473 .data = &sysctl_max_map_count,
1474 .maxlen = sizeof(sysctl_max_map_count),
1475 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001476 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001477 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001479#else
1480 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001481 .procname = "nr_trim_pages",
1482 .data = &sysctl_nr_trim_pages,
1483 .maxlen = sizeof(sysctl_nr_trim_pages),
1484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001485 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001486 .extra1 = &zero,
1487 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488#endif
1489 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 .procname = "laptop_mode",
1491 .data = &laptop_mode,
1492 .maxlen = sizeof(laptop_mode),
1493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001494 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 },
1496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 .procname = "block_dump",
1498 .data = &block_dump,
1499 .maxlen = sizeof(block_dump),
1500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001501 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 .extra1 = &zero,
1503 },
1504 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 .procname = "vfs_cache_pressure",
1506 .data = &sysctl_vfs_cache_pressure,
1507 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001509 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 .extra1 = &zero,
1511 },
1512#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 .procname = "legacy_va_layout",
1515 .data = &sysctl_legacy_va_layout,
1516 .maxlen = sizeof(sysctl_legacy_va_layout),
1517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001518 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 .extra1 = &zero,
1520 },
1521#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001522#ifdef CONFIG_NUMA
1523 {
Christoph Lameter17436602006-01-18 17:42:32 -08001524 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001525 .data = &node_reclaim_mode,
1526 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001528 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001529 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001530 },
Christoph Lameter96146342006-07-03 00:24:13 -07001531 {
Christoph Lameter96146342006-07-03 00:24:13 -07001532 .procname = "min_unmapped_ratio",
1533 .data = &sysctl_min_unmapped_ratio,
1534 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1535 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001536 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001537 .extra1 = &zero,
1538 .extra2 = &one_hundred,
1539 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001540 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001541 .procname = "min_slab_ratio",
1542 .data = &sysctl_min_slab_ratio,
1543 .maxlen = sizeof(sysctl_min_slab_ratio),
1544 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001545 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001546 .extra1 = &zero,
1547 .extra2 = &one_hundred,
1548 },
Christoph Lameter17436602006-01-18 17:42:32 -08001549#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001550#ifdef CONFIG_SMP
1551 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001552 .procname = "stat_interval",
1553 .data = &sysctl_stat_interval,
1554 .maxlen = sizeof(sysctl_stat_interval),
1555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001557 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001558 {
1559 .procname = "stat_refresh",
1560 .data = NULL,
1561 .maxlen = 0,
1562 .mode = 0600,
1563 .proc_handler = vmstat_refresh,
1564 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001565#endif
David Howells6e141542009-12-15 19:27:45 +00001566#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001567 {
Eric Parised032182007-06-28 15:55:21 -04001568 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001569 .data = &dac_mmap_min_addr,
1570 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001572 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001573 },
David Howells6e141542009-12-15 19:27:45 +00001574#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001575#ifdef CONFIG_NUMA
1576 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001577 .procname = "numa_zonelist_order",
1578 .data = &numa_zonelist_order,
1579 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1580 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001581 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001582 },
1583#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001584#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001585 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001586 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001587 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001588#ifdef CONFIG_X86_32
1589 .data = &vdso32_enabled,
1590 .maxlen = sizeof(vdso32_enabled),
1591#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001592 .data = &vdso_enabled,
1593 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001594#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001596 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001597 .extra1 = &zero,
1598 },
1599#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001600#ifdef CONFIG_HIGHMEM
1601 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001602 .procname = "highmem_is_dirtyable",
1603 .data = &vm_highmem_is_dirtyable,
1604 .maxlen = sizeof(vm_highmem_is_dirtyable),
1605 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001606 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001607 .extra1 = &zero,
1608 .extra2 = &one,
1609 },
1610#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001611#ifdef CONFIG_MEMORY_FAILURE
1612 {
Andi Kleen6a460792009-09-16 11:50:15 +02001613 .procname = "memory_failure_early_kill",
1614 .data = &sysctl_memory_failure_early_kill,
1615 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001617 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001618 .extra1 = &zero,
1619 .extra2 = &one,
1620 },
1621 {
Andi Kleen6a460792009-09-16 11:50:15 +02001622 .procname = "memory_failure_recovery",
1623 .data = &sysctl_memory_failure_recovery,
1624 .maxlen = sizeof(sysctl_memory_failure_recovery),
1625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001626 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001627 .extra1 = &zero,
1628 .extra2 = &one,
1629 },
1630#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001631 {
1632 .procname = "user_reserve_kbytes",
1633 .data = &sysctl_user_reserve_kbytes,
1634 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1635 .mode = 0644,
1636 .proc_handler = proc_doulongvec_minmax,
1637 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001638 {
1639 .procname = "admin_reserve_kbytes",
1640 .data = &sysctl_admin_reserve_kbytes,
1641 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1642 .mode = 0644,
1643 .proc_handler = proc_doulongvec_minmax,
1644 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001645#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1646 {
1647 .procname = "mmap_rnd_bits",
1648 .data = &mmap_rnd_bits,
1649 .maxlen = sizeof(mmap_rnd_bits),
1650 .mode = 0600,
1651 .proc_handler = proc_dointvec_minmax,
1652 .extra1 = (void *)&mmap_rnd_bits_min,
1653 .extra2 = (void *)&mmap_rnd_bits_max,
1654 },
1655#endif
1656#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1657 {
1658 .procname = "mmap_rnd_compat_bits",
1659 .data = &mmap_rnd_compat_bits,
1660 .maxlen = sizeof(mmap_rnd_compat_bits),
1661 .mode = 0600,
1662 .proc_handler = proc_dointvec_minmax,
1663 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1664 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1665 },
1666#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001667 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668};
1669
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001670static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .procname = "inode-nr",
1673 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001674 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001676 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 },
1678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .procname = "inode-state",
1680 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001681 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001683 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 },
1685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 .procname = "file-nr",
1687 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001688 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001690 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 },
1692 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 .procname = "file-max",
1694 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001695 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001697 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 },
1699 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001700 .procname = "nr_open",
1701 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001702 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001703 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001704 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001705 .extra1 = &sysctl_nr_open_min,
1706 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001707 },
1708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 .procname = "dentry-state",
1710 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001711 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001713 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 },
1715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 .procname = "overflowuid",
1717 .data = &fs_overflowuid,
1718 .maxlen = sizeof(int),
1719 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001720 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 .extra1 = &minolduid,
1722 .extra2 = &maxolduid,
1723 },
1724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 .procname = "overflowgid",
1726 .data = &fs_overflowgid,
1727 .maxlen = sizeof(int),
1728 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001729 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 .extra1 = &minolduid,
1731 .extra2 = &maxolduid,
1732 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001733#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 .procname = "leases-enable",
1736 .data = &leases_enable,
1737 .maxlen = sizeof(int),
1738 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001739 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001741#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742#ifdef CONFIG_DNOTIFY
1743 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 .procname = "dir-notify-enable",
1745 .data = &dir_notify_enable,
1746 .maxlen = sizeof(int),
1747 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001748 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 },
1750#endif
1751#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001752#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .procname = "lease-break-time",
1755 .data = &lease_break_time,
1756 .maxlen = sizeof(int),
1757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001758 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001760#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001761#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 .procname = "aio-nr",
1764 .data = &aio_nr,
1765 .maxlen = sizeof(aio_nr),
1766 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001767 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 },
1769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 .procname = "aio-max-nr",
1771 .data = &aio_max_nr,
1772 .maxlen = sizeof(aio_max_nr),
1773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001774 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001776#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001777#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001778 {
Robert Love0399cb02005-07-13 12:38:18 -04001779 .procname = "inotify",
1780 .mode = 0555,
1781 .child = inotify_table,
1782 },
1783#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001784#ifdef CONFIG_EPOLL
1785 {
1786 .procname = "epoll",
1787 .mode = 0555,
1788 .child = epoll_table,
1789 },
1790#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001792 {
Kees Cook800179c2012-07-25 17:29:07 -07001793 .procname = "protected_symlinks",
1794 .data = &sysctl_protected_symlinks,
1795 .maxlen = sizeof(int),
1796 .mode = 0600,
1797 .proc_handler = proc_dointvec_minmax,
1798 .extra1 = &zero,
1799 .extra2 = &one,
1800 },
1801 {
1802 .procname = "protected_hardlinks",
1803 .data = &sysctl_protected_hardlinks,
1804 .maxlen = sizeof(int),
1805 .mode = 0600,
1806 .proc_handler = proc_dointvec_minmax,
1807 .extra1 = &zero,
1808 .extra2 = &one,
1809 },
1810 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001811 .procname = "protected_fifos",
1812 .data = &sysctl_protected_fifos,
1813 .maxlen = sizeof(int),
1814 .mode = 0600,
1815 .proc_handler = proc_dointvec_minmax,
1816 .extra1 = &zero,
1817 .extra2 = &two,
1818 },
1819 {
1820 .procname = "protected_regular",
1821 .data = &sysctl_protected_regular,
1822 .maxlen = sizeof(int),
1823 .mode = 0600,
1824 .proc_handler = proc_dointvec_minmax,
1825 .extra1 = &zero,
1826 .extra2 = &two,
1827 },
1828 {
Alan Coxd6e71142005-06-23 00:09:43 -07001829 .procname = "suid_dumpable",
1830 .data = &suid_dumpable,
1831 .maxlen = sizeof(int),
1832 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001833 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001834 .extra1 = &zero,
1835 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001836 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001837#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1838 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001839 .procname = "binfmt_misc",
1840 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001841 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001842 },
1843#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001844 {
Jens Axboeff9da692010-06-03 14:54:39 +02001845 .procname = "pipe-max-size",
1846 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001847 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001848 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001849 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001850 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001851 {
1852 .procname = "pipe-user-pages-hard",
1853 .data = &pipe_user_pages_hard,
1854 .maxlen = sizeof(pipe_user_pages_hard),
1855 .mode = 0644,
1856 .proc_handler = proc_doulongvec_minmax,
1857 },
1858 {
1859 .procname = "pipe-user-pages-soft",
1860 .data = &pipe_user_pages_soft,
1861 .maxlen = sizeof(pipe_user_pages_soft),
1862 .mode = 0644,
1863 .proc_handler = proc_doulongvec_minmax,
1864 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001865 {
1866 .procname = "mount-max",
1867 .data = &sysctl_mount_max,
1868 .maxlen = sizeof(unsigned int),
1869 .mode = 0644,
1870 .proc_handler = proc_dointvec_minmax,
1871 .extra1 = &one,
1872 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001873 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874};
1875
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001876static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001877#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001878 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001879 .procname = "exception-trace",
1880 .data = &show_unhandled_signals,
1881 .maxlen = sizeof(int),
1882 .mode = 0644,
1883 .proc_handler = proc_dointvec
1884 },
1885#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001886#if defined(CONFIG_OPTPROBES)
1887 {
1888 .procname = "kprobes-optimization",
1889 .data = &sysctl_kprobes_optimization,
1890 .maxlen = sizeof(int),
1891 .mode = 0644,
1892 .proc_handler = proc_kprobes_optimization_handler,
1893 .extra1 = &zero,
1894 .extra2 = &one,
1895 },
1896#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001897 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898};
1899
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001900static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001901 { }
Robert Love0eeca282005-07-12 17:06:03 -04001902};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001904int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001905{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001906 struct ctl_table_header *hdr;
1907
1908 hdr = register_sysctl_table(sysctl_base_table);
1909 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001910 return 0;
1911}
1912
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001913#endif /* CONFIG_SYSCTL */
1914
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915/*
1916 * /proc/sys support
1917 */
1918
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001919#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Kees Cookf8808302014-06-06 14:37:17 -07001921static int _proc_do_string(char *data, int maxlen, int write,
1922 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001923 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001924{
1925 size_t len;
1926 char __user *p;
1927 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001928
1929 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001930 *lenp = 0;
1931 return 0;
1932 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001933
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001934 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001935 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1936 /* Only continue writes not past the end of buffer. */
1937 len = strlen(data);
1938 if (len > maxlen - 1)
1939 len = maxlen - 1;
1940
1941 if (*ppos > len)
1942 return 0;
1943 len = *ppos;
1944 } else {
1945 /* Start writing from beginning of buffer. */
1946 len = 0;
1947 }
1948
Kees Cook2ca9bb42014-06-06 14:37:18 -07001949 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001950 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001951 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001952 if (get_user(c, p++))
1953 return -EFAULT;
1954 if (c == 0 || c == '\n')
1955 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001956 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001957 }
Kees Cookf8808302014-06-06 14:37:17 -07001958 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001959 } else {
1960 len = strlen(data);
1961 if (len > maxlen)
1962 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001963
1964 if (*ppos > len) {
1965 *lenp = 0;
1966 return 0;
1967 }
1968
1969 data += *ppos;
1970 len -= *ppos;
1971
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001972 if (len > *lenp)
1973 len = *lenp;
1974 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001975 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001976 return -EFAULT;
1977 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001978 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001979 return -EFAULT;
1980 len++;
1981 }
1982 *lenp = len;
1983 *ppos += len;
1984 }
1985 return 0;
1986}
1987
Kees Cookf4aacea2014-06-06 14:37:19 -07001988static void warn_sysctl_write(struct ctl_table *table)
1989{
1990 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1991 "This will not be supported in the future. To silence this\n"
1992 "warning, set kernel.sysctl_writes_strict = -1\n",
1993 current->comm, table->procname);
1994}
1995
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07001997 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001998 * @ppos: file position
1999 * @table: the sysctl table
2000 *
2001 * Returns true if the first position is non-zero and the sysctl_writes_strict
2002 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002003 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002004 */
2005static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2006 struct ctl_table *table)
2007{
2008 if (!*ppos)
2009 return false;
2010
2011 switch (sysctl_writes_strict) {
2012 case SYSCTL_WRITES_STRICT:
2013 return true;
2014 case SYSCTL_WRITES_WARN:
2015 warn_sysctl_write(table);
2016 return false;
2017 default:
2018 return false;
2019 }
2020}
2021
2022/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 * proc_dostring - read a string sysctl
2024 * @table: the sysctl table
2025 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 * @buffer: the user buffer
2027 * @lenp: the size of the user buffer
2028 * @ppos: file position
2029 *
2030 * Reads/writes a string from/to the user buffer. If the kernel
2031 * buffer provided is not large enough to hold the string, the
2032 * string is truncated. The copied string is %NULL-terminated.
2033 * If the string is being read by the user process, it is copied
2034 * and a newline '\n' is added. It is truncated if the buffer is
2035 * not large enough.
2036 *
2037 * Returns 0 on success.
2038 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002039int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 void __user *buffer, size_t *lenp, loff_t *ppos)
2041{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002042 if (write)
2043 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002044
Kees Cookf8808302014-06-06 14:37:17 -07002045 return _proc_do_string((char *)(table->data), table->maxlen, write,
2046 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047}
2048
Amerigo Wang00b7c332010-05-05 00:26:45 +00002049static size_t proc_skip_spaces(char **buf)
2050{
2051 size_t ret;
2052 char *tmp = skip_spaces(*buf);
2053 ret = tmp - *buf;
2054 *buf = tmp;
2055 return ret;
2056}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002058static void proc_skip_char(char **buf, size_t *size, const char v)
2059{
2060 while (*size) {
2061 if (**buf != v)
2062 break;
2063 (*size)--;
2064 (*buf)++;
2065 }
2066}
2067
Amerigo Wang00b7c332010-05-05 00:26:45 +00002068#define TMPBUFLEN 22
2069/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002070 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002071 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002072 * @buf: a kernel buffer
2073 * @size: size of the kernel buffer
2074 * @val: this is where the number will be stored
2075 * @neg: set to %TRUE if number is negative
2076 * @perm_tr: a vector which contains the allowed trailers
2077 * @perm_tr_len: size of the perm_tr vector
2078 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002079 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002080 * In case of success %0 is returned and @buf and @size are updated with
2081 * the amount of bytes read. If @tr is non-NULL and a trailing
2082 * character exists (size is non-zero after returning from this
2083 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002084 */
2085static int proc_get_long(char **buf, size_t *size,
2086 unsigned long *val, bool *neg,
2087 const char *perm_tr, unsigned perm_tr_len, char *tr)
2088{
2089 int len;
2090 char *p, tmp[TMPBUFLEN];
2091
2092 if (!*size)
2093 return -EINVAL;
2094
2095 len = *size;
2096 if (len > TMPBUFLEN - 1)
2097 len = TMPBUFLEN - 1;
2098
2099 memcpy(tmp, *buf, len);
2100
2101 tmp[len] = 0;
2102 p = tmp;
2103 if (*p == '-' && *size > 1) {
2104 *neg = true;
2105 p++;
2106 } else
2107 *neg = false;
2108 if (!isdigit(*p))
2109 return -EINVAL;
2110
2111 *val = simple_strtoul(p, &p, 0);
2112
2113 len = p - tmp;
2114
2115 /* We don't know if the next char is whitespace thus we may accept
2116 * invalid integers (e.g. 1234...a) or two integers instead of one
2117 * (e.g. 123...1). So lets not allow such large numbers. */
2118 if (len == TMPBUFLEN - 1)
2119 return -EINVAL;
2120
2121 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2122 return -EINVAL;
2123
2124 if (tr && (len < *size))
2125 *tr = *p;
2126
2127 *buf += len;
2128 *size -= len;
2129
2130 return 0;
2131}
2132
2133/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002134 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002136 * @buf: the user buffer
2137 * @size: the size of the user buffer
2138 * @val: the integer to be converted
2139 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002140 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002141 * In case of success %0 is returned and @buf and @size are updated with
2142 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002143 */
2144static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2145 bool neg)
2146{
2147 int len;
2148 char tmp[TMPBUFLEN], *p = tmp;
2149
2150 sprintf(p, "%s%lu", neg ? "-" : "", val);
2151 len = strlen(tmp);
2152 if (len > *size)
2153 len = *size;
2154 if (copy_to_user(*buf, tmp, len))
2155 return -EFAULT;
2156 *size -= len;
2157 *buf += len;
2158 return 0;
2159}
2160#undef TMPBUFLEN
2161
2162static int proc_put_char(void __user **buf, size_t *size, char c)
2163{
2164 if (*size) {
2165 char __user **buffer = (char __user **)buf;
2166 if (put_user(c, *buffer))
2167 return -EFAULT;
2168 (*size)--, (*buffer)++;
2169 *buf = *buffer;
2170 }
2171 return 0;
2172}
2173
2174static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 int *valp,
2176 int write, void *data)
2177{
2178 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002179 if (*negp) {
2180 if (*lvalp > (unsigned long) INT_MAX + 1)
2181 return -EINVAL;
2182 *valp = -*lvalp;
2183 } else {
2184 if (*lvalp > (unsigned long) INT_MAX)
2185 return -EINVAL;
2186 *valp = *lvalp;
2187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 } else {
2189 int val = *valp;
2190 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002192 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002194 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 *lvalp = (unsigned long)val;
2196 }
2197 }
2198 return 0;
2199}
2200
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002201static int do_proc_douintvec_conv(unsigned long *lvalp,
2202 unsigned int *valp,
2203 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002204{
2205 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002206 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002207 return -EINVAL;
2208 *valp = *lvalp;
2209 } else {
2210 unsigned int val = *valp;
2211 *lvalp = (unsigned long)val;
2212 }
2213 return 0;
2214}
2215
Amerigo Wang00b7c332010-05-05 00:26:45 +00002216static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2217
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002218static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002219 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002220 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002221 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 int write, void *data),
2223 void *data)
2224{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002225 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002226 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002227 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
Amerigo Wang00b7c332010-05-05 00:26:45 +00002229 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 *lenp = 0;
2231 return 0;
2232 }
2233
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002234 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 vleft = table->maxlen / sizeof(*i);
2236 left = *lenp;
2237
2238 if (!conv)
2239 conv = do_proc_dointvec_conv;
2240
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002242 if (proc_first_pos_non_zero_ignore(ppos, table))
2243 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002244
Amerigo Wang00b7c332010-05-05 00:26:45 +00002245 if (left > PAGE_SIZE - 1)
2246 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002247 p = kbuf = memdup_user_nul(buffer, left);
2248 if (IS_ERR(kbuf))
2249 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002250 }
2251
2252 for (; left && vleft--; i++, first=0) {
2253 unsigned long lval;
2254 bool neg;
2255
2256 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002257 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258
J. R. Okajima563b0462010-05-25 16:10:14 -07002259 if (!left)
2260 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002261 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 proc_wspace_sep,
2263 sizeof(proc_wspace_sep), NULL);
2264 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002266 if (conv(&neg, &lval, i, 1, data)) {
2267 err = -EINVAL;
2268 break;
2269 }
2270 } else {
2271 if (conv(&neg, &lval, i, 0, data)) {
2272 err = -EINVAL;
2273 break;
2274 }
2275 if (!first)
2276 err = proc_put_char(&buffer, &left, '\t');
2277 if (err)
2278 break;
2279 err = proc_put_long(&buffer, &left, lval, neg);
2280 if (err)
2281 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 }
2283 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284
2285 if (!write && !first && left && !err)
2286 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002287 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002288 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002289 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002290 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002291 if (first)
2292 return err ? : -EINVAL;
2293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002295out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002297 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002300static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002301 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002302 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002303 int write, void *data),
2304 void *data)
2305{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002306 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002307 buffer, lenp, ppos, conv, data);
2308}
2309
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002310static int do_proc_douintvec_w(unsigned int *tbl_data,
2311 struct ctl_table *table,
2312 void __user *buffer,
2313 size_t *lenp, loff_t *ppos,
2314 int (*conv)(unsigned long *lvalp,
2315 unsigned int *valp,
2316 int write, void *data),
2317 void *data)
2318{
2319 unsigned long lval;
2320 int err = 0;
2321 size_t left;
2322 bool neg;
2323 char *kbuf = NULL, *p;
2324
2325 left = *lenp;
2326
2327 if (proc_first_pos_non_zero_ignore(ppos, table))
2328 goto bail_early;
2329
2330 if (left > PAGE_SIZE - 1)
2331 left = PAGE_SIZE - 1;
2332
2333 p = kbuf = memdup_user_nul(buffer, left);
2334 if (IS_ERR(kbuf))
2335 return -EINVAL;
2336
2337 left -= proc_skip_spaces(&p);
2338 if (!left) {
2339 err = -EINVAL;
2340 goto out_free;
2341 }
2342
2343 err = proc_get_long(&p, &left, &lval, &neg,
2344 proc_wspace_sep,
2345 sizeof(proc_wspace_sep), NULL);
2346 if (err || neg) {
2347 err = -EINVAL;
2348 goto out_free;
2349 }
2350
2351 if (conv(&lval, tbl_data, 1, data)) {
2352 err = -EINVAL;
2353 goto out_free;
2354 }
2355
2356 if (!err && left)
2357 left -= proc_skip_spaces(&p);
2358
2359out_free:
2360 kfree(kbuf);
2361 if (err)
2362 return -EINVAL;
2363
2364 return 0;
2365
2366 /* This is in keeping with old __do_proc_dointvec() */
2367bail_early:
2368 *ppos += *lenp;
2369 return err;
2370}
2371
2372static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2373 size_t *lenp, loff_t *ppos,
2374 int (*conv)(unsigned long *lvalp,
2375 unsigned int *valp,
2376 int write, void *data),
2377 void *data)
2378{
2379 unsigned long lval;
2380 int err = 0;
2381 size_t left;
2382
2383 left = *lenp;
2384
2385 if (conv(&lval, tbl_data, 0, data)) {
2386 err = -EINVAL;
2387 goto out;
2388 }
2389
2390 err = proc_put_long(&buffer, &left, lval, false);
2391 if (err || !left)
2392 goto out;
2393
2394 err = proc_put_char(&buffer, &left, '\n');
2395
2396out:
2397 *lenp -= left;
2398 *ppos += *lenp;
2399
2400 return err;
2401}
2402
2403static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2404 int write, void __user *buffer,
2405 size_t *lenp, loff_t *ppos,
2406 int (*conv)(unsigned long *lvalp,
2407 unsigned int *valp,
2408 int write, void *data),
2409 void *data)
2410{
2411 unsigned int *i, vleft;
2412
2413 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2414 *lenp = 0;
2415 return 0;
2416 }
2417
2418 i = (unsigned int *) tbl_data;
2419 vleft = table->maxlen / sizeof(*i);
2420
2421 /*
2422 * Arrays are not supported, keep this simple. *Do not* add
2423 * support for them.
2424 */
2425 if (vleft != 1) {
2426 *lenp = 0;
2427 return -EINVAL;
2428 }
2429
2430 if (!conv)
2431 conv = do_proc_douintvec_conv;
2432
2433 if (write)
2434 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2435 conv, data);
2436 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2437}
2438
2439static int do_proc_douintvec(struct ctl_table *table, int write,
2440 void __user *buffer, size_t *lenp, loff_t *ppos,
2441 int (*conv)(unsigned long *lvalp,
2442 unsigned int *valp,
2443 int write, void *data),
2444 void *data)
2445{
2446 return __do_proc_douintvec(table->data, table, write,
2447 buffer, lenp, ppos, conv, data);
2448}
2449
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450/**
2451 * proc_dointvec - read a vector of integers
2452 * @table: the sysctl table
2453 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 * @buffer: the user buffer
2455 * @lenp: the size of the user buffer
2456 * @ppos: file position
2457 *
2458 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2459 * values from/to the user buffer, treated as an ASCII string.
2460 *
2461 * Returns 0 on success.
2462 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002463int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 void __user *buffer, size_t *lenp, loff_t *ppos)
2465{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002466 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2467}
2468
2469/**
2470 * proc_douintvec - read a vector of unsigned integers
2471 * @table: the sysctl table
2472 * @write: %TRUE if this is a write to the sysctl file
2473 * @buffer: the user buffer
2474 * @lenp: the size of the user buffer
2475 * @ppos: file position
2476 *
2477 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2478 * values from/to the user buffer, treated as an ASCII string.
2479 *
2480 * Returns 0 on success.
2481 */
2482int proc_douintvec(struct ctl_table *table, int write,
2483 void __user *buffer, size_t *lenp, loff_t *ppos)
2484{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002485 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2486 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487}
2488
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002489/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002490 * Taint values can only be increased
2491 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002492 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002493static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002494 void __user *buffer, size_t *lenp, loff_t *ppos)
2495{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002496 struct ctl_table t;
2497 unsigned long tmptaint = get_taint();
2498 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002499
Bastian Blank91fcd412007-04-23 14:41:14 -07002500 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002501 return -EPERM;
2502
Andi Kleen25ddbb12008-10-15 22:01:41 -07002503 t = *table;
2504 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002505 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002506 if (err < 0)
2507 return err;
2508
2509 if (write) {
2510 /*
2511 * Poor man's atomic or. Not worth adding a primitive
2512 * to everyone's atomic.h for this
2513 */
2514 int i;
2515 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2516 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302517 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002518 }
2519 }
2520
2521 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002522}
2523
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002524#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002525static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002526 void __user *buffer, size_t *lenp, loff_t *ppos)
2527{
2528 if (write && !capable(CAP_SYS_ADMIN))
2529 return -EPERM;
2530
2531 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2532}
2533#endif
2534
Waiman Long24704f32018-04-10 16:35:38 -07002535/**
2536 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2537 * @min: pointer to minimum allowable value
2538 * @max: pointer to maximum allowable value
2539 *
2540 * The do_proc_dointvec_minmax_conv_param structure provides the
2541 * minimum and maximum values for doing range checking for those sysctl
2542 * parameters that use the proc_dointvec_minmax() handler.
2543 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544struct do_proc_dointvec_minmax_conv_param {
2545 int *min;
2546 int *max;
2547};
2548
Amerigo Wang00b7c332010-05-05 00:26:45 +00002549static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2550 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 int write, void *data)
2552{
2553 struct do_proc_dointvec_minmax_conv_param *param = data;
2554 if (write) {
2555 int val = *negp ? -*lvalp : *lvalp;
2556 if ((param->min && *param->min > val) ||
2557 (param->max && *param->max < val))
2558 return -EINVAL;
2559 *valp = val;
2560 } else {
2561 int val = *valp;
2562 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002563 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002564 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002566 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 *lvalp = (unsigned long)val;
2568 }
2569 }
2570 return 0;
2571}
2572
2573/**
2574 * proc_dointvec_minmax - read a vector of integers with min/max values
2575 * @table: the sysctl table
2576 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 * @buffer: the user buffer
2578 * @lenp: the size of the user buffer
2579 * @ppos: file position
2580 *
2581 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2582 * values from/to the user buffer, treated as an ASCII string.
2583 *
2584 * This routine will ensure the values are within the range specified by
2585 * table->extra1 (min) and table->extra2 (max).
2586 *
Waiman Long24704f32018-04-10 16:35:38 -07002587 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002589int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 void __user *buffer, size_t *lenp, loff_t *ppos)
2591{
2592 struct do_proc_dointvec_minmax_conv_param param = {
2593 .min = (int *) table->extra1,
2594 .max = (int *) table->extra2,
2595 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002596 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 do_proc_dointvec_minmax_conv, &param);
2598}
2599
Waiman Long24704f32018-04-10 16:35:38 -07002600/**
2601 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2602 * @min: pointer to minimum allowable value
2603 * @max: pointer to maximum allowable value
2604 *
2605 * The do_proc_douintvec_minmax_conv_param structure provides the
2606 * minimum and maximum values for doing range checking for those sysctl
2607 * parameters that use the proc_douintvec_minmax() handler.
2608 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002609struct do_proc_douintvec_minmax_conv_param {
2610 unsigned int *min;
2611 unsigned int *max;
2612};
2613
2614static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2615 unsigned int *valp,
2616 int write, void *data)
2617{
2618 struct do_proc_douintvec_minmax_conv_param *param = data;
2619
2620 if (write) {
2621 unsigned int val = *lvalp;
2622
Joe Lawrencefb910c42017-11-17 15:29:28 -08002623 if (*lvalp > UINT_MAX)
2624 return -EINVAL;
2625
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002626 if ((param->min && *param->min > val) ||
2627 (param->max && *param->max < val))
2628 return -ERANGE;
2629
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002630 *valp = val;
2631 } else {
2632 unsigned int val = *valp;
2633 *lvalp = (unsigned long) val;
2634 }
2635
2636 return 0;
2637}
2638
2639/**
2640 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2641 * @table: the sysctl table
2642 * @write: %TRUE if this is a write to the sysctl file
2643 * @buffer: the user buffer
2644 * @lenp: the size of the user buffer
2645 * @ppos: file position
2646 *
2647 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2648 * values from/to the user buffer, treated as an ASCII string. Negative
2649 * strings are not allowed.
2650 *
2651 * This routine will ensure the values are within the range specified by
2652 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2653 * check for UINT_MAX to avoid having to support wrap around uses from
2654 * userspace.
2655 *
Waiman Long24704f32018-04-10 16:35:38 -07002656 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002657 */
2658int proc_douintvec_minmax(struct ctl_table *table, int write,
2659 void __user *buffer, size_t *lenp, loff_t *ppos)
2660{
2661 struct do_proc_douintvec_minmax_conv_param param = {
2662 .min = (unsigned int *) table->extra1,
2663 .max = (unsigned int *) table->extra2,
2664 };
2665 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2666 do_proc_douintvec_minmax_conv, &param);
2667}
2668
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002669static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2670 unsigned int *valp,
2671 int write, void *data)
2672{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002673 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002674 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002675
Joe Lawrencefb910c42017-11-17 15:29:28 -08002676 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002677 if (val == 0)
2678 return -EINVAL;
2679
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002680 *valp = val;
2681 } else {
2682 unsigned int val = *valp;
2683 *lvalp = (unsigned long) val;
2684 }
2685
2686 return 0;
2687}
2688
Eric Biggers319e0a22018-02-06 15:41:49 -08002689static int proc_dopipe_max_size(struct ctl_table *table, int write,
2690 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002691{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002692 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002693 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002694}
2695
Kees Cook54b50192012-07-30 14:39:18 -07002696static void validate_coredump_safety(void)
2697{
Alex Kelly046d6622012-10-04 17:15:23 -07002698#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002699 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002700 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002701 printk(KERN_WARNING
2702"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2703"Pipe handler or fully qualified core dump path required.\n"
2704"Set kernel.core_pattern before fs.suid_dumpable.\n"
2705 );
Kees Cook54b50192012-07-30 14:39:18 -07002706 }
Alex Kelly046d6622012-10-04 17:15:23 -07002707#endif
Kees Cook54b50192012-07-30 14:39:18 -07002708}
2709
2710static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2712{
2713 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2714 if (!error)
2715 validate_coredump_safety();
2716 return error;
2717}
2718
Alex Kelly046d6622012-10-04 17:15:23 -07002719#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002720static int proc_dostring_coredump(struct ctl_table *table, int write,
2721 void __user *buffer, size_t *lenp, loff_t *ppos)
2722{
2723 int error = proc_dostring(table, write, buffer, lenp, ppos);
2724 if (!error)
2725 validate_coredump_safety();
2726 return error;
2727}
Alex Kelly046d6622012-10-04 17:15:23 -07002728#endif
Kees Cook54b50192012-07-30 14:39:18 -07002729
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002730static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 void __user *buffer,
2732 size_t *lenp, loff_t *ppos,
2733 unsigned long convmul,
2734 unsigned long convdiv)
2735{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002736 unsigned long *i, *min, *max;
2737 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002738 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002739 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002740
2741 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 *lenp = 0;
2743 return 0;
2744 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002745
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002746 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 min = (unsigned long *) table->extra1;
2748 max = (unsigned long *) table->extra2;
2749 vleft = table->maxlen / sizeof(unsigned long);
2750 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002751
2752 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002753 if (proc_first_pos_non_zero_ignore(ppos, table))
2754 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002755
Amerigo Wang00b7c332010-05-05 00:26:45 +00002756 if (left > PAGE_SIZE - 1)
2757 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002758 p = kbuf = memdup_user_nul(buffer, left);
2759 if (IS_ERR(kbuf))
2760 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002761 }
2762
Eric Dumazet27b3d802010-10-07 12:59:29 -07002763 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002764 unsigned long val;
2765
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002767 bool neg;
2768
Al Viro70f6cbb2015-12-24 00:13:10 -05002769 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002770
Al Viro70f6cbb2015-12-24 00:13:10 -05002771 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002772 proc_wspace_sep,
2773 sizeof(proc_wspace_sep), NULL);
2774 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 break;
2776 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002778 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 if ((min && val < *min) || (max && val > *max))
2780 continue;
2781 *i = val;
2782 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002783 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002784 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002785 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002786 if (err)
2787 break;
2788 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002789 err = proc_put_long(&buffer, &left, val, false);
2790 if (err)
2791 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
2793 }
2794
Amerigo Wang00b7c332010-05-05 00:26:45 +00002795 if (!write && !first && left && !err)
2796 err = proc_put_char(&buffer, &left, '\n');
2797 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002798 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002800 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002801 if (first)
2802 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002805out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002807 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808}
2809
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002810static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002811 void __user *buffer,
2812 size_t *lenp, loff_t *ppos,
2813 unsigned long convmul,
2814 unsigned long convdiv)
2815{
2816 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002817 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002818}
2819
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820/**
2821 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2822 * @table: the sysctl table
2823 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 * @buffer: the user buffer
2825 * @lenp: the size of the user buffer
2826 * @ppos: file position
2827 *
2828 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2829 * values from/to the user buffer, treated as an ASCII string.
2830 *
2831 * This routine will ensure the values are within the range specified by
2832 * table->extra1 (min) and table->extra2 (max).
2833 *
2834 * Returns 0 on success.
2835 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002836int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 void __user *buffer, size_t *lenp, loff_t *ppos)
2838{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002839 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840}
2841
2842/**
2843 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2844 * @table: the sysctl table
2845 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 * @buffer: the user buffer
2847 * @lenp: the size of the user buffer
2848 * @ppos: file position
2849 *
2850 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2851 * values from/to the user buffer, treated as an ASCII string. The values
2852 * are treated as milliseconds, and converted to jiffies when they are stored.
2853 *
2854 * This routine will ensure the values are within the range specified by
2855 * table->extra1 (min) and table->extra2 (max).
2856 *
2857 * Returns 0 on success.
2858 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002859int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 void __user *buffer,
2861 size_t *lenp, loff_t *ppos)
2862{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002863 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 lenp, ppos, HZ, 1000l);
2865}
2866
2867
Amerigo Wang00b7c332010-05-05 00:26:45 +00002868static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 int *valp,
2870 int write, void *data)
2871{
2872 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002873 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002874 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2876 } else {
2877 int val = *valp;
2878 unsigned long lval;
2879 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002880 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002881 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002883 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 lval = (unsigned long)val;
2885 }
2886 *lvalp = lval / HZ;
2887 }
2888 return 0;
2889}
2890
Amerigo Wang00b7c332010-05-05 00:26:45 +00002891static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 int *valp,
2893 int write, void *data)
2894{
2895 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002896 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2897 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2899 } else {
2900 int val = *valp;
2901 unsigned long lval;
2902 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002903 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002904 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002906 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 lval = (unsigned long)val;
2908 }
2909 *lvalp = jiffies_to_clock_t(lval);
2910 }
2911 return 0;
2912}
2913
Amerigo Wang00b7c332010-05-05 00:26:45 +00002914static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 int *valp,
2916 int write, void *data)
2917{
2918 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002919 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2920
2921 if (jif > INT_MAX)
2922 return 1;
2923 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 } else {
2925 int val = *valp;
2926 unsigned long lval;
2927 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002928 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002929 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002931 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 lval = (unsigned long)val;
2933 }
2934 *lvalp = jiffies_to_msecs(lval);
2935 }
2936 return 0;
2937}
2938
2939/**
2940 * proc_dointvec_jiffies - read a vector of integers as seconds
2941 * @table: the sysctl table
2942 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 * @buffer: the user buffer
2944 * @lenp: the size of the user buffer
2945 * @ppos: file position
2946 *
2947 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2948 * values from/to the user buffer, treated as an ASCII string.
2949 * The values read are assumed to be in seconds, and are converted into
2950 * jiffies.
2951 *
2952 * Returns 0 on success.
2953 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002954int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 void __user *buffer, size_t *lenp, loff_t *ppos)
2956{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002957 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 do_proc_dointvec_jiffies_conv,NULL);
2959}
2960
2961/**
2962 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2963 * @table: the sysctl table
2964 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 * @buffer: the user buffer
2966 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002967 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 *
2969 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2970 * values from/to the user buffer, treated as an ASCII string.
2971 * The values read are assumed to be in 1/USER_HZ seconds, and
2972 * are converted into jiffies.
2973 *
2974 * Returns 0 on success.
2975 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002976int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 void __user *buffer, size_t *lenp, loff_t *ppos)
2978{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002979 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 do_proc_dointvec_userhz_jiffies_conv,NULL);
2981}
2982
2983/**
2984 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2985 * @table: the sysctl table
2986 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 * @buffer: the user buffer
2988 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002989 * @ppos: file position
2990 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 *
2992 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2993 * values from/to the user buffer, treated as an ASCII string.
2994 * The values read are assumed to be in 1/1000 seconds, and
2995 * are converted into jiffies.
2996 *
2997 * Returns 0 on success.
2998 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002999int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 void __user *buffer, size_t *lenp, loff_t *ppos)
3001{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003002 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 do_proc_dointvec_ms_jiffies_conv, NULL);
3004}
3005
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003006static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003007 void __user *buffer, size_t *lenp, loff_t *ppos)
3008{
3009 struct pid *new_pid;
3010 pid_t tmp;
3011 int r;
3012
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003013 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003014
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003015 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003016 lenp, ppos, NULL, NULL);
3017 if (r || !write)
3018 return r;
3019
3020 new_pid = find_get_pid(tmp);
3021 if (!new_pid)
3022 return -ESRCH;
3023
3024 put_pid(xchg(&cad_pid, new_pid));
3025 return 0;
3026}
3027
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003028/**
3029 * proc_do_large_bitmap - read/write from/to a large bitmap
3030 * @table: the sysctl table
3031 * @write: %TRUE if this is a write to the sysctl file
3032 * @buffer: the user buffer
3033 * @lenp: the size of the user buffer
3034 * @ppos: file position
3035 *
3036 * The bitmap is stored at table->data and the bitmap length (in bits)
3037 * in table->maxlen.
3038 *
3039 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3040 * large bitmaps may be represented in a compact manner. Writing into
3041 * the file will clear the bitmap then update it with the given input.
3042 *
3043 * Returns 0 on success.
3044 */
3045int proc_do_large_bitmap(struct ctl_table *table, int write,
3046 void __user *buffer, size_t *lenp, loff_t *ppos)
3047{
3048 int err = 0;
3049 bool first = 1;
3050 size_t left = *lenp;
3051 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003052 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003053 unsigned long *tmp_bitmap = NULL;
3054 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3055
WANG Cong122ff242014-05-12 16:04:53 -07003056 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003057 *lenp = 0;
3058 return 0;
3059 }
3060
3061 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003062 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003063
3064 if (left > PAGE_SIZE - 1)
3065 left = PAGE_SIZE - 1;
3066
Al Viro70f6cbb2015-12-24 00:13:10 -05003067 p = kbuf = memdup_user_nul(buffer, left);
3068 if (IS_ERR(kbuf))
3069 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003070
Kees Cook6396bb22018-06-12 14:03:40 -07003071 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3072 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003073 GFP_KERNEL);
3074 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003075 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003076 return -ENOMEM;
3077 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003078 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003079 while (!err && left) {
3080 unsigned long val_a, val_b;
3081 bool neg;
3082
Al Viro70f6cbb2015-12-24 00:13:10 -05003083 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003084 sizeof(tr_a), &c);
3085 if (err)
3086 break;
3087 if (val_a >= bitmap_len || neg) {
3088 err = -EINVAL;
3089 break;
3090 }
3091
3092 val_b = val_a;
3093 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003094 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003095 left--;
3096 }
3097
3098 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003099 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003100 &neg, tr_b, sizeof(tr_b),
3101 &c);
3102 if (err)
3103 break;
3104 if (val_b >= bitmap_len || neg ||
3105 val_a > val_b) {
3106 err = -EINVAL;
3107 break;
3108 }
3109 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003110 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003111 left--;
3112 }
3113 }
3114
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003115 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003116 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003117 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003118 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003119 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003120 } else {
3121 unsigned long bit_a, bit_b = 0;
3122
3123 while (left) {
3124 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3125 if (bit_a >= bitmap_len)
3126 break;
3127 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3128 bit_a + 1) - 1;
3129
3130 if (!first) {
3131 err = proc_put_char(&buffer, &left, ',');
3132 if (err)
3133 break;
3134 }
3135 err = proc_put_long(&buffer, &left, bit_a, false);
3136 if (err)
3137 break;
3138 if (bit_a != bit_b) {
3139 err = proc_put_char(&buffer, &left, '-');
3140 if (err)
3141 break;
3142 err = proc_put_long(&buffer, &left, bit_b, false);
3143 if (err)
3144 break;
3145 }
3146
3147 first = 0; bit_b++;
3148 }
3149 if (!err)
3150 err = proc_put_char(&buffer, &left, '\n');
3151 }
3152
3153 if (!err) {
3154 if (write) {
3155 if (*ppos)
3156 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3157 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003158 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003159 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003160 *lenp -= left;
3161 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003162 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003163
3164 kfree(tmp_bitmap);
3165 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003166}
3167
Jovi Zhang55610502011-01-12 17:00:45 -08003168#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003170int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 void __user *buffer, size_t *lenp, loff_t *ppos)
3172{
3173 return -ENOSYS;
3174}
3175
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003176int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 void __user *buffer, size_t *lenp, loff_t *ppos)
3178{
3179 return -ENOSYS;
3180}
3181
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003182int proc_douintvec(struct ctl_table *table, int write,
3183 void __user *buffer, size_t *lenp, loff_t *ppos)
3184{
3185 return -ENOSYS;
3186}
3187
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003188int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 void __user *buffer, size_t *lenp, loff_t *ppos)
3190{
3191 return -ENOSYS;
3192}
3193
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003194int proc_douintvec_minmax(struct ctl_table *table, int write,
3195 void __user *buffer, size_t *lenp, loff_t *ppos)
3196{
3197 return -ENOSYS;
3198}
3199
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003200int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 void __user *buffer, size_t *lenp, loff_t *ppos)
3202{
3203 return -ENOSYS;
3204}
3205
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003206int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 void __user *buffer, size_t *lenp, loff_t *ppos)
3208{
3209 return -ENOSYS;
3210}
3211
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003212int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 void __user *buffer, size_t *lenp, loff_t *ppos)
3214{
3215 return -ENOSYS;
3216}
3217
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003218int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 void __user *buffer, size_t *lenp, loff_t *ppos)
3220{
3221 return -ENOSYS;
3222}
3223
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003224int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 void __user *buffer,
3226 size_t *lenp, loff_t *ppos)
3227{
3228 return -ENOSYS;
3229}
3230
3231
Jovi Zhang55610502011-01-12 17:00:45 -08003232#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234/*
3235 * No sense putting this after each symbol definition, twice,
3236 * exception granted :-)
3237 */
3238EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003239EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240EXPORT_SYMBOL(proc_dointvec_jiffies);
3241EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003242EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3244EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3245EXPORT_SYMBOL(proc_dostring);
3246EXPORT_SYMBOL(proc_doulongvec_minmax);
3247EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);