blob: 987ae08147bf6f195ddcd4f8b578e2dd284cd396 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010065#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050068#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080070#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <asm/processor.h>
72
Andi Kleen29cbc782006-09-30 01:47:55 +020073#ifdef CONFIG_X86
74#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010075#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010076#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020077#endif
David Howellsd550bbd2012-03-28 18:30:03 +010078#ifdef CONFIG_SPARC
79#include <asm/setup.h>
80#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080081#ifdef CONFIG_BSD_PROCESS_ACCT
82#include <linux/acct.h>
83#endif
Dave Young4f0e0562010-03-10 15:24:09 -080084#ifdef CONFIG_RT_MUTEXES
85#include <linux/rtmutex.h>
86#endif
Dave Young2edf5e42010-03-10 15:24:10 -080087#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88#include <linux/lockdep.h>
89#endif
Dave Young15485a42010-03-10 15:24:07 -080090#ifdef CONFIG_CHR_DEV_SG
91#include <scsi/sg.h>
92#endif
Alexander Popov964c9df2018-08-17 01:17:03 +030093#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
94#include <linux/stackleak.h>
95#endif
Don Zickus58687ac2010-05-07 17:11:44 -040096#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050097#include <linux/nmi.h>
98#endif
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#if defined(CONFIG_SYSCTL)
101
102/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700103extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700104#ifdef CONFIG_COREDUMP
105extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700107extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800111extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100112extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300113extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000114#ifndef CONFIG_MMU
115extern int sysctl_nr_trim_pages;
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400119#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int sixty = 60;
121#endif
122
Aaron Tomlin270750db2014-01-20 17:34:13 +0000123static int __maybe_unused neg_one = -1;
124
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700125static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700126static int __maybe_unused one = 1;
127static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700128static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800129static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700130static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700131static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700132#ifdef CONFIG_PRINTK
133static int ten_thousand = 10000;
134#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300135#ifdef CONFIG_PERF_EVENTS
136static int six_hundred_forty_kb = 640 * 1024;
137#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700138
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700139/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
140static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
143static int maxolduid = 65535;
144static int minolduid;
145
146static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700147static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700149/*
150 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
151 * and hung_task_check_interval_secs
152 */
Liu Hua80df2842014-04-07 15:38:57 -0700153#ifdef CONFIG_DETECT_HUNG_TASK
154static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
155#endif
156
Dave Youngd14f1722010-02-25 20:28:57 -0500157#ifdef CONFIG_INOTIFY_USER
158#include <linux/inotify.h>
159#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700160#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#endif
162
163#ifdef __hppa__
164extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530165#endif
166
167#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168extern int unaligned_enabled;
169#endif
170
Jes Sorensend2b176e2006-02-28 09:42:23 -0800171#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800172extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800173#endif
174
Vineet Guptab6fca722013-01-09 20:06:28 +0530175#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
176extern int no_unaligned_warning;
177#endif
178
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700179#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700180
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700181/**
182 * enum sysctl_writes_mode - supported sysctl write modes
183 *
184 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
185 * to be written, and multiple writes on the same sysctl file descriptor
186 * will rewrite the sysctl value, regardless of file position. No warning
187 * is issued when the initial position is not 0.
188 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
189 * not 0.
190 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
191 * file position 0 and the value must be fully contained in the buffer
192 * sent to the write syscall. If dealing with strings respect the file
193 * position, but restrict this to the max length of the buffer, anything
194 * passed the max lenght will be ignored. Multiple writes will append
195 * to the buffer.
196 *
197 * These write modes control how current file position affects the behavior of
198 * updating sysctl values through the proc interface on each write.
199 */
200enum sysctl_writes_mode {
201 SYSCTL_WRITES_LEGACY = -1,
202 SYSCTL_WRITES_WARN = 0,
203 SYSCTL_WRITES_STRICT = 1,
204};
Kees Cookf4aacea2014-06-06 14:37:19 -0700205
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700206static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700207
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700208static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700209 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700210static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800211 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700212#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700213
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700214#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700215static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700216 void __user *buffer, size_t *lenp, loff_t *ppos);
217#endif
218
Kees Cook54b50192012-07-30 14:39:18 -0700219static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
220 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700221#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700222static int proc_dostring_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700224#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800225static int proc_dopipe_max_size(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700227
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700228#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700229/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100230static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700231
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700232static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700233 void __user *buffer, size_t *lenp,
234 loff_t *ppos)
235{
236 int error;
237
238 error = proc_dointvec(table, write, buffer, lenp, ppos);
239 if (error)
240 return error;
241
242 if (write)
243 sysrq_toggle_support(__sysrq_enabled);
244
245 return 0;
246}
247
248#endif
249
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700250static struct ctl_table kern_table[];
251static struct ctl_table vm_table[];
252static struct ctl_table fs_table[];
253static struct ctl_table debug_table[];
254static struct ctl_table dev_table[];
255extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800256#ifdef CONFIG_EPOLL
257extern struct ctl_table epoll_table[];
258#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800260#ifdef CONFIG_FW_LOADER_USER_HELPER
261extern struct ctl_table firmware_config_table[];
262#endif
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
265int sysctl_legacy_va_layout;
266#endif
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/* The default sysctl tables: */
269
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800270static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .procname = "kernel",
273 .mode = 0555,
274 .child = kern_table,
275 },
276 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .procname = "vm",
278 .mode = 0555,
279 .child = vm_table,
280 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "fs",
283 .mode = 0555,
284 .child = fs_table,
285 },
286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 .procname = "debug",
288 .mode = 0555,
289 .child = debug_table,
290 },
291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .procname = "dev",
293 .mode = 0555,
294 .child = dev_table,
295 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700296 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297};
298
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100300static int min_sched_granularity_ns = 100000; /* 100 usecs */
301static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
302static int min_wakeup_granularity_ns; /* 0 usecs */
303static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200304#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100305static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
306static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200307#endif /* CONFIG_SMP */
308#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200309
Mel Gorman5e771902010-05-24 14:32:31 -0700310#ifdef CONFIG_COMPACTION
311static int min_extfrag_threshold;
312static int max_extfrag_threshold = 1000;
313#endif
314
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700315static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200316 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200317 .procname = "sched_child_runs_first",
318 .data = &sysctl_sched_child_runs_first,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800321 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200322 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200323#ifdef CONFIG_SCHED_DEBUG
324 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100325 .procname = "sched_min_granularity_ns",
326 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800329 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100330 .extra1 = &min_sched_granularity_ns,
331 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200332 },
333 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200334 .procname = "sched_latency_ns",
335 .data = &sysctl_sched_latency,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800338 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200339 .extra1 = &min_sched_granularity_ns,
340 .extra2 = &max_sched_granularity_ns,
341 },
342 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200343 .procname = "sched_wakeup_granularity_ns",
344 .data = &sysctl_sched_wakeup_granularity,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800347 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200348 .extra1 = &min_wakeup_granularity_ns,
349 .extra2 = &max_wakeup_granularity_ns,
350 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200351#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200352 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100353 .procname = "sched_tunable_scaling",
354 .data = &sysctl_sched_tunable_scaling,
355 .maxlen = sizeof(enum sched_tunable_scaling),
356 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800357 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100358 .extra1 = &min_sched_tunable_scaling,
359 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200360 },
361 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900362 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200363 .data = &sysctl_sched_migration_cost,
364 .maxlen = sizeof(unsigned int),
365 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800366 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200367 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100368 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100369 .procname = "sched_nr_migrate",
370 .data = &sysctl_sched_nr_migrate,
371 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100372 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800373 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100374 },
Mel Gormancb251762016-02-05 09:08:36 +0000375#ifdef CONFIG_SCHEDSTATS
376 {
377 .procname = "sched_schedstats",
378 .data = NULL,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
381 .proc_handler = sysctl_schedstats,
382 .extra1 = &zero,
383 .extra2 = &one,
384 },
385#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200386#endif /* CONFIG_SMP */
387#ifdef CONFIG_NUMA_BALANCING
388 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200389 .procname = "numa_balancing_scan_delay_ms",
390 .data = &sysctl_numa_balancing_scan_delay,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = proc_dointvec,
394 },
395 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200396 .procname = "numa_balancing_scan_period_min_ms",
397 .data = &sysctl_numa_balancing_scan_period_min,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = proc_dointvec,
401 },
402 {
403 .procname = "numa_balancing_scan_period_max_ms",
404 .data = &sysctl_numa_balancing_scan_period_max,
405 .maxlen = sizeof(unsigned int),
406 .mode = 0644,
407 .proc_handler = proc_dointvec,
408 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200409 {
410 .procname = "numa_balancing_scan_size_mb",
411 .data = &sysctl_numa_balancing_scan_size,
412 .maxlen = sizeof(unsigned int),
413 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400414 .proc_handler = proc_dointvec_minmax,
415 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200416 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100417 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800418 .procname = "numa_balancing",
419 .data = NULL, /* filled in by handler */
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
422 .proc_handler = sysctl_numa_balancing,
423 .extra1 = &zero,
424 .extra2 = &one,
425 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200426#endif /* CONFIG_NUMA_BALANCING */
427#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200428 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100429 .procname = "sched_rt_period_us",
430 .data = &sysctl_sched_rt_period,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100434 },
435 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100436 .procname = "sched_rt_runtime_us",
437 .data = &sysctl_sched_rt_runtime,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100441 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600442 {
443 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800444 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = sched_rr_handler,
448 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100449#ifdef CONFIG_SCHED_AUTOGROUP
450 {
451 .procname = "sched_autogroup_enabled",
452 .data = &sysctl_sched_autogroup_enabled,
453 .maxlen = sizeof(unsigned int),
454 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800455 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100456 .extra1 = &zero,
457 .extra2 = &one,
458 },
459#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700460#ifdef CONFIG_CFS_BANDWIDTH
461 {
462 .procname = "sched_cfs_bandwidth_slice_us",
463 .data = &sysctl_sched_cfs_bandwidth_slice,
464 .maxlen = sizeof(unsigned int),
465 .mode = 0644,
466 .proc_handler = proc_dointvec_minmax,
467 .extra1 = &one,
468 },
469#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000470#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
471 {
472 .procname = "sched_energy_aware",
473 .data = &sysctl_sched_energy_aware,
474 .maxlen = sizeof(unsigned int),
475 .mode = 0644,
476 .proc_handler = sched_energy_aware_handler,
477 .extra1 = &zero,
478 .extra2 = &one,
479 },
480#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700481#ifdef CONFIG_PROVE_LOCKING
482 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700483 .procname = "prove_locking",
484 .data = &prove_locking,
485 .maxlen = sizeof(int),
486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800487 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700488 },
489#endif
490#ifdef CONFIG_LOCK_STAT
491 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700492 .procname = "lock_stat",
493 .data = &lock_stat,
494 .maxlen = sizeof(int),
495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800496 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700497 },
498#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .procname = "panic",
501 .data = &panic_timeout,
502 .maxlen = sizeof(int),
503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800504 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 },
Alex Kelly046d6622012-10-04 17:15:23 -0700506#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .procname = "core_uses_pid",
509 .data = &core_uses_pid,
510 .maxlen = sizeof(int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
514 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 .procname = "core_pattern",
516 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700517 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700519 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 },
Neil Hormana2939802009-09-23 15:56:56 -0700521 {
Neil Hormana2939802009-09-23 15:56:56 -0700522 .procname = "core_pipe_limit",
523 .data = &core_pipe_limit,
524 .maxlen = sizeof(unsigned int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700527 },
Alex Kelly046d6622012-10-04 17:15:23 -0700528#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800529#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700532 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700536 {
537 .procname = "sysctl_writes_strict",
538 .data = &sysctl_writes_strict,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = proc_dointvec_minmax,
542 .extra1 = &neg_one,
543 .extra2 = &one,
544 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800545#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100546#ifdef CONFIG_LATENCYTOP
547 {
548 .procname = "latencytop",
549 .data = &latencytop_enabled,
550 .maxlen = sizeof(int),
551 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000552 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100553 },
554#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#ifdef CONFIG_BLK_DEV_INITRD
556 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .procname = "real-root-dev",
558 .data = &real_root_dev,
559 .maxlen = sizeof(int),
560 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800561 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 },
563#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700564 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700565 .procname = "print-fatal-signals",
566 .data = &print_fatal_signals,
567 .maxlen = sizeof(int),
568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700570 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700571#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "reboot-cmd",
574 .data = reboot_command,
575 .maxlen = 256,
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "stop-a",
581 .data = &stop_a_enabled,
582 .maxlen = sizeof (int),
583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800584 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .procname = "scons-poweroff",
588 .data = &scons_pwroff,
589 .maxlen = sizeof (int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
593#endif
David S. Miller08714202008-11-16 23:49:24 -0800594#ifdef CONFIG_SPARC64
595 {
David S. Miller08714202008-11-16 23:49:24 -0800596 .procname = "tsb-ratio",
597 .data = &sysctl_tsb_ratio,
598 .maxlen = sizeof (int),
599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800600 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800601 },
602#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#ifdef __hppa__
604 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 .procname = "soft-power",
606 .data = &pwrsw_enabled,
607 .maxlen = sizeof (int),
608 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800609 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530611#endif
612#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "unaligned-trap",
615 .data = &unaligned_enabled,
616 .maxlen = sizeof (int),
617 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800618 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 },
620#endif
621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "ctrl-alt-del",
623 .data = &C_A_D,
624 .maxlen = sizeof(int),
625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800626 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400628#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200629 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200630 .procname = "ftrace_enabled",
631 .data = &ftrace_enabled,
632 .maxlen = sizeof(int),
633 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800634 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200635 },
636#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500637#ifdef CONFIG_STACK_TRACER
638 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500639 .procname = "stack_tracer_enabled",
640 .data = &stack_tracer_enabled,
641 .maxlen = sizeof(int),
642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800643 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500644 },
645#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400646#ifdef CONFIG_TRACING
647 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100648 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400649 .data = &ftrace_dump_on_oops,
650 .maxlen = sizeof(int),
651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400653 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400654 {
655 .procname = "traceoff_on_warning",
656 .data = &__disable_trace_on_warning,
657 .maxlen = sizeof(__disable_trace_on_warning),
658 .mode = 0644,
659 .proc_handler = proc_dointvec,
660 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500661 {
662 .procname = "tracepoint_printk",
663 .data = &tracepoint_printk,
664 .maxlen = sizeof(tracepoint_printk),
665 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500666 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500667 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400668#endif
Dave Young2965faa2015-09-09 15:38:55 -0700669#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800670 {
671 .procname = "kexec_load_disabled",
672 .data = &kexec_load_disabled,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 /* only handle a transition from default "0" to "1" */
676 .proc_handler = proc_dointvec_minmax,
677 .extra1 = &one,
678 .extra2 = &one,
679 },
680#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200681#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .procname = "modprobe",
684 .data = &modprobe_path,
685 .maxlen = KMOD_PATH_LEN,
686 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800687 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 },
Kees Cook3d433212009-04-02 15:49:29 -0700689 {
Kees Cook3d433212009-04-02 15:49:29 -0700690 .procname = "modules_disabled",
691 .data = &modules_disabled,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800695 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700696 .extra1 = &one,
697 .extra2 = &one,
698 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700700#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100703 .data = &uevent_helper,
704 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800706 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Michael Marineau86d56132014-04-10 14:09:31 -0700708#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709#ifdef CONFIG_CHR_DEV_SG
710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 .procname = "sg-big-buff",
712 .data = &sg_big_buff,
713 .maxlen = sizeof (int),
714 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800715 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 },
717#endif
718#ifdef CONFIG_BSD_PROCESS_ACCT
719 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .procname = "acct",
721 .data = &acct_parm,
722 .maxlen = 3*sizeof(int),
723 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800724 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 },
726#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#ifdef CONFIG_MAGIC_SYSRQ
728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800730 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .maxlen = sizeof (int),
732 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700733 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 },
735#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700736#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700739 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .maxlen = sizeof (int),
741 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800742 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700744#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700747 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .maxlen = sizeof(int),
749 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700750 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 },
752 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .procname = "random",
754 .mode = 0555,
755 .child = random_table,
756 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 {
Eric Paris17f60a72011-04-01 17:07:50 -0400758 .procname = "usermodehelper",
759 .mode = 0555,
760 .child = usermodehelper_table,
761 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800762#ifdef CONFIG_FW_LOADER_USER_HELPER
763 {
764 .procname = "firmware_config",
765 .mode = 0555,
766 .child = firmware_config_table,
767 },
768#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .procname = "overflowuid",
771 .data = &overflowuid,
772 .maxlen = sizeof(int),
773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800774 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .extra1 = &minolduid,
776 .extra2 = &maxolduid,
777 },
778 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .procname = "overflowgid",
780 .data = &overflowgid,
781 .maxlen = sizeof(int),
782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .extra1 = &minolduid,
785 .extra2 = &maxolduid,
786 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800787#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788#ifdef CONFIG_MATHEMU
789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .procname = "ieee_emulation_warnings",
791 .data = &sysctl_ieee_emulation_warnings,
792 .maxlen = sizeof(int),
793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 },
796#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200799 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .maxlen = sizeof(int),
801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800802 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 },
804#endif
805 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 .procname = "pid_max",
807 .data = &pid_max,
808 .maxlen = sizeof (int),
809 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800810 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .extra1 = &pid_max_min,
812 .extra2 = &pid_max_max,
813 },
814 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 .procname = "panic_on_oops",
816 .data = &panic_on_oops,
817 .maxlen = sizeof(int),
818 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800819 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 },
Feng Tang81c9d432019-01-03 15:28:20 -0800821 {
822 .procname = "panic_print",
823 .data = &panic_print,
824 .maxlen = sizeof(unsigned long),
825 .mode = 0644,
826 .proc_handler = proc_doulongvec_minmax,
827 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800828#if defined CONFIG_PRINTK
829 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800830 .procname = "printk",
831 .data = &console_loglevel,
832 .maxlen = 4*sizeof(int),
833 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800834 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800835 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700838 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 .maxlen = sizeof(int),
840 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800841 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 },
843 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700845 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 .maxlen = sizeof(int),
847 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800848 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 },
Dave Youngaf913222009-09-22 16:43:33 -0700850 {
Dave Youngaf913222009-09-22 16:43:33 -0700851 .procname = "printk_delay",
852 .data = &printk_delay_msec,
853 .maxlen = sizeof(int),
854 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800855 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700856 .extra1 = &zero,
857 .extra2 = &ten_thousand,
858 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700860 .procname = "printk_devkmsg",
861 .data = devkmsg_log_str,
862 .maxlen = DEVKMSG_STR_MAX_SIZE,
863 .mode = 0644,
864 .proc_handler = devkmsg_sysctl_set_loglvl,
865 },
866 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800867 .procname = "dmesg_restrict",
868 .data = &dmesg_restrict,
869 .maxlen = sizeof(int),
870 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700871 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800872 .extra1 = &zero,
873 .extra2 = &one,
874 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800875 {
876 .procname = "kptr_restrict",
877 .data = &kptr_restrict,
878 .maxlen = sizeof(int),
879 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700880 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800881 .extra1 = &zero,
882 .extra2 = &two,
883 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800884#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800885 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 .procname = "ngroups_max",
887 .data = &ngroups_max,
888 .maxlen = sizeof (int),
889 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800890 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 },
Dan Ballard73efc032011-10-31 17:11:20 -0700892 {
893 .procname = "cap_last_cap",
894 .data = (void *)&cap_last_cap,
895 .maxlen = sizeof(int),
896 .mode = 0444,
897 .proc_handler = proc_dointvec,
898 },
Don Zickus58687ac2010-05-07 17:11:44 -0400899#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500900 {
Don Zickus58687ac2010-05-07 17:11:44 -0400901 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200902 .data = &watchdog_user_enabled,
903 .maxlen = sizeof(int),
904 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700905 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700906 .extra1 = &zero,
907 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400908 },
909 {
910 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700911 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400912 .maxlen = sizeof(int),
913 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700914 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800915 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400916 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500917 },
Don Zickus2508ce12010-05-07 17:11:46 -0400918 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700919 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200920 .data = &nmi_watchdog_user_enabled,
921 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200922 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700923 .proc_handler = proc_nmi_watchdog,
924 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700925 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700926 },
927 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700928 .procname = "watchdog_cpumask",
929 .data = &watchdog_cpumask_bits,
930 .maxlen = NR_CPUS,
931 .mode = 0644,
932 .proc_handler = proc_watchdog_cpumask,
933 },
934#ifdef CONFIG_SOFTLOCKUP_DETECTOR
935 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700936 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200937 .data = &soft_watchdog_user_enabled,
938 .maxlen = sizeof(int),
939 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700940 .proc_handler = proc_soft_watchdog,
941 .extra1 = &zero,
942 .extra2 = &one,
943 },
944 {
Don Zickus2508ce12010-05-07 17:11:46 -0400945 .procname = "softlockup_panic",
946 .data = &softlockup_panic,
947 .maxlen = sizeof(int),
948 .mode = 0644,
949 .proc_handler = proc_dointvec_minmax,
950 .extra1 = &zero,
951 .extra2 = &one,
952 },
Aaron Tomlined235872014-06-23 13:22:05 -0700953#ifdef CONFIG_SMP
954 {
955 .procname = "softlockup_all_cpu_backtrace",
956 .data = &sysctl_softlockup_all_cpu_backtrace,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = proc_dointvec_minmax,
960 .extra1 = &zero,
961 .extra2 = &one,
962 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700963#endif /* CONFIG_SMP */
964#endif
965#ifdef CONFIG_HARDLOCKUP_DETECTOR
966 {
967 .procname = "hardlockup_panic",
968 .data = &hardlockup_panic,
969 .maxlen = sizeof(int),
970 .mode = 0644,
971 .proc_handler = proc_dointvec_minmax,
972 .extra1 = &zero,
973 .extra2 = &one,
974 },
975#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800976 {
977 .procname = "hardlockup_all_cpu_backtrace",
978 .data = &sysctl_hardlockup_all_cpu_backtrace,
979 .maxlen = sizeof(int),
980 .mode = 0644,
981 .proc_handler = proc_dointvec_minmax,
982 .extra1 = &zero,
983 .extra2 = &one,
984 },
Aaron Tomlined235872014-06-23 13:22:05 -0700985#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500986#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700987#endif
988
Don Zickus5dc30552010-11-29 17:07:17 -0500989#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
990 {
991 .procname = "unknown_nmi_panic",
992 .data = &unknown_nmi_panic,
993 .maxlen = sizeof (int),
994 .mode = 0644,
995 .proc_handler = proc_dointvec,
996 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500997#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998#if defined(CONFIG_X86)
999 {
Don Zickus8da5add2006-09-26 10:52:27 +02001000 .procname = "panic_on_unrecovered_nmi",
1001 .data = &panic_on_unrecovered_nmi,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001004 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001005 },
1006 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001007 .procname = "panic_on_io_nmi",
1008 .data = &panic_on_io_nmi,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001011 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001012 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001013#ifdef CONFIG_DEBUG_STACKOVERFLOW
1014 {
1015 .procname = "panic_on_stackoverflow",
1016 .data = &sysctl_panic_on_stackoverflow,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
1019 .proc_handler = proc_dointvec,
1020 },
1021#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001022 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .procname = "bootloader_type",
1024 .data = &bootloader_type,
1025 .maxlen = sizeof (int),
1026 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001027 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001029 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001030 .procname = "bootloader_version",
1031 .data = &bootloader_version,
1032 .maxlen = sizeof (int),
1033 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001034 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001035 },
1036 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001037 .procname = "io_delay_type",
1038 .data = &io_delay_type,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001042 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001044#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 .procname = "randomize_va_space",
1047 .data = &randomize_va_space,
1048 .maxlen = sizeof(int),
1049 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001050 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001052#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001053#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001054 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001055 .procname = "spin_retry",
1056 .data = &spin_retry,
1057 .maxlen = sizeof (int),
1058 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001059 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001060 },
1061#endif
Len Brown673d5b42007-07-28 03:33:16 -04001062#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001063 {
Pavel Machekc255d842006-02-20 18:27:58 -08001064 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001065 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001066 .maxlen = sizeof (unsigned long),
1067 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001068 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001069 },
1070#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301071#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001072 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001073 .procname = "ignore-unaligned-usertrap",
1074 .data = &no_unaligned_warning,
1075 .maxlen = sizeof (int),
1076 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001077 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001078 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301079#endif
1080#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001081 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001082 .procname = "unaligned-dump-stack",
1083 .data = &unaligned_dump_stack,
1084 .maxlen = sizeof (int),
1085 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001086 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001087 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001088#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001089#ifdef CONFIG_DETECT_HUNG_TASK
1090 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001091 .procname = "hung_task_panic",
1092 .data = &sysctl_hung_task_panic,
1093 .maxlen = sizeof(int),
1094 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001095 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001096 .extra1 = &zero,
1097 .extra2 = &one,
1098 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001099 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001100 .procname = "hung_task_check_count",
1101 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001102 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001103 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001104 .proc_handler = proc_dointvec_minmax,
1105 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001106 },
1107 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001108 .procname = "hung_task_timeout_secs",
1109 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001110 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001111 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001112 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001113 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001114 },
1115 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001116 .procname = "hung_task_check_interval_secs",
1117 .data = &sysctl_hung_task_check_interval_secs,
1118 .maxlen = sizeof(unsigned long),
1119 .mode = 0644,
1120 .proc_handler = proc_dohung_task_timeout_secs,
1121 .extra2 = &hung_task_timeout_max,
1122 },
1123 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001124 .procname = "hung_task_warnings",
1125 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001126 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001127 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001128 .proc_handler = proc_dointvec_minmax,
1129 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001130 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001131#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001132#ifdef CONFIG_RT_MUTEXES
1133 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001134 .procname = "max_lock_depth",
1135 .data = &max_lock_depth,
1136 .maxlen = sizeof(int),
1137 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001138 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001139 },
1140#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001141 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001142 .procname = "poweroff_cmd",
1143 .data = &poweroff_cmd,
1144 .maxlen = POWEROFF_CMD_PATH_LEN,
1145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001146 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001147 },
David Howells0b77f5b2008-04-29 01:01:32 -07001148#ifdef CONFIG_KEYS
1149 {
David Howells0b77f5b2008-04-29 01:01:32 -07001150 .procname = "keys",
1151 .mode = 0555,
1152 .child = key_sysctls,
1153 },
1154#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001155#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001156 /*
1157 * User-space scripts rely on the existence of this file
1158 * as a feature check for perf_events being enabled.
1159 *
1160 * So it's an ABI, do not remove!
1161 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001162 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001163 .procname = "perf_event_paranoid",
1164 .data = &sysctl_perf_event_paranoid,
1165 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001166 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001167 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001168 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001169 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001170 .procname = "perf_event_mlock_kb",
1171 .data = &sysctl_perf_event_mlock,
1172 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001173 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001174 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001175 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001176 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001177 .procname = "perf_event_max_sample_rate",
1178 .data = &sysctl_perf_event_sample_rate,
1179 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001180 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001181 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001182 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001183 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001184 {
1185 .procname = "perf_cpu_time_max_percent",
1186 .data = &sysctl_perf_cpu_time_max_percent,
1187 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1188 .mode = 0644,
1189 .proc_handler = perf_cpu_time_max_percent_handler,
1190 .extra1 = &zero,
1191 .extra2 = &one_hundred,
1192 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001193 {
1194 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001195 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001196 .maxlen = sizeof(sysctl_perf_event_max_stack),
1197 .mode = 0644,
1198 .proc_handler = perf_event_max_stack_handler,
1199 .extra1 = &zero,
1200 .extra2 = &six_hundred_forty_kb,
1201 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001202 {
1203 .procname = "perf_event_max_contexts_per_stack",
1204 .data = &sysctl_perf_event_max_contexts_per_stack,
1205 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1206 .mode = 0644,
1207 .proc_handler = perf_event_max_stack_handler,
1208 .extra1 = &zero,
1209 .extra2 = &one_thousand,
1210 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001211#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001212 {
1213 .procname = "panic_on_warn",
1214 .data = &panic_on_warn,
1215 .maxlen = sizeof(int),
1216 .mode = 0644,
1217 .proc_handler = proc_dointvec_minmax,
1218 .extra1 = &zero,
1219 .extra2 = &one,
1220 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001221#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1222 {
1223 .procname = "timer_migration",
1224 .data = &sysctl_timer_migration,
1225 .maxlen = sizeof(unsigned int),
1226 .mode = 0644,
1227 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001228 .extra1 = &zero,
1229 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001230 },
1231#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001232#ifdef CONFIG_BPF_SYSCALL
1233 {
1234 .procname = "unprivileged_bpf_disabled",
1235 .data = &sysctl_unprivileged_bpf_disabled,
1236 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1237 .mode = 0644,
1238 /* only handle a transition from default "0" to "1" */
1239 .proc_handler = proc_dointvec_minmax,
1240 .extra1 = &one,
1241 .extra2 = &one,
1242 },
1243#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001244#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1245 {
1246 .procname = "panic_on_rcu_stall",
1247 .data = &sysctl_panic_on_rcu_stall,
1248 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1249 .mode = 0644,
1250 .proc_handler = proc_dointvec_minmax,
1251 .extra1 = &zero,
1252 .extra2 = &one,
1253 },
1254#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001255#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1256 {
1257 .procname = "stack_erasing",
1258 .data = NULL,
1259 .maxlen = sizeof(int),
1260 .mode = 0600,
1261 .proc_handler = stack_erasing_sysctl,
1262 .extra1 = &zero,
1263 .extra2 = &one,
1264 },
1265#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001266 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267};
1268
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001269static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 .procname = "overcommit_memory",
1272 .data = &sysctl_overcommit_memory,
1273 .maxlen = sizeof(sysctl_overcommit_memory),
1274 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001275 .proc_handler = proc_dointvec_minmax,
1276 .extra1 = &zero,
1277 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 },
1279 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001280 .procname = "panic_on_oom",
1281 .data = &sysctl_panic_on_oom,
1282 .maxlen = sizeof(sysctl_panic_on_oom),
1283 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001284 .proc_handler = proc_dointvec_minmax,
1285 .extra1 = &zero,
1286 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001287 },
1288 {
David Rientjesfe071d72007-10-16 23:25:56 -07001289 .procname = "oom_kill_allocating_task",
1290 .data = &sysctl_oom_kill_allocating_task,
1291 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1292 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001293 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001294 },
1295 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001296 .procname = "oom_dump_tasks",
1297 .data = &sysctl_oom_dump_tasks,
1298 .maxlen = sizeof(sysctl_oom_dump_tasks),
1299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001301 },
1302 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 .procname = "overcommit_ratio",
1304 .data = &sysctl_overcommit_ratio,
1305 .maxlen = sizeof(sysctl_overcommit_ratio),
1306 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001307 .proc_handler = overcommit_ratio_handler,
1308 },
1309 {
1310 .procname = "overcommit_kbytes",
1311 .data = &sysctl_overcommit_kbytes,
1312 .maxlen = sizeof(sysctl_overcommit_kbytes),
1313 .mode = 0644,
1314 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 },
1316 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 .procname = "page-cluster",
1318 .data = &page_cluster,
1319 .maxlen = sizeof(int),
1320 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001321 .proc_handler = proc_dointvec_minmax,
1322 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 },
1324 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 .procname = "dirty_background_ratio",
1326 .data = &dirty_background_ratio,
1327 .maxlen = sizeof(dirty_background_ratio),
1328 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001329 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 .extra1 = &zero,
1331 .extra2 = &one_hundred,
1332 },
1333 {
David Rientjes2da02992009-01-06 14:39:31 -08001334 .procname = "dirty_background_bytes",
1335 .data = &dirty_background_bytes,
1336 .maxlen = sizeof(dirty_background_bytes),
1337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001338 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001339 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001340 },
1341 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 .procname = "dirty_ratio",
1343 .data = &vm_dirty_ratio,
1344 .maxlen = sizeof(vm_dirty_ratio),
1345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001346 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 .extra1 = &zero,
1348 .extra2 = &one_hundred,
1349 },
1350 {
David Rientjes2da02992009-01-06 14:39:31 -08001351 .procname = "dirty_bytes",
1352 .data = &vm_dirty_bytes,
1353 .maxlen = sizeof(vm_dirty_bytes),
1354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001355 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001356 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001357 },
1358 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001360 .data = &dirty_writeback_interval,
1361 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 },
1365 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001367 .data = &dirty_expire_interval,
1368 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001370 .proc_handler = proc_dointvec_minmax,
1371 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 },
1373 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001374 .procname = "dirtytime_expire_seconds",
1375 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001376 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001377 .mode = 0644,
1378 .proc_handler = dirtytime_interval_handler,
1379 .extra1 = &zero,
1380 },
1381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .procname = "swappiness",
1383 .data = &vm_swappiness,
1384 .maxlen = sizeof(vm_swappiness),
1385 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001386 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 .extra1 = &zero,
1388 .extra2 = &one_hundred,
1389 },
1390#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001393 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .maxlen = sizeof(unsigned long),
1395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001396 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001397 },
1398#ifdef CONFIG_NUMA
1399 {
1400 .procname = "nr_hugepages_mempolicy",
1401 .data = NULL,
1402 .maxlen = sizeof(unsigned long),
1403 .mode = 0644,
1404 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001405 },
Kemi Wang45180852017-11-15 17:38:22 -08001406 {
1407 .procname = "numa_stat",
1408 .data = &sysctl_vm_numa_stat,
1409 .maxlen = sizeof(int),
1410 .mode = 0644,
1411 .proc_handler = sysctl_vm_numa_stat_handler,
1412 .extra1 = &zero,
1413 .extra2 = &one,
1414 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001415#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 .procname = "hugetlb_shm_group",
1418 .data = &sysctl_hugetlb_shm_group,
1419 .maxlen = sizeof(gid_t),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
Adam Litke54f9f802007-10-16 01:26:20 -07001423 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001424 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001425 .data = NULL,
1426 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001427 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001428 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001429 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430#endif
1431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .procname = "lowmem_reserve_ratio",
1433 .data = &sysctl_lowmem_reserve_ratio,
1434 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 },
1438 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001439 .procname = "drop_caches",
1440 .data = &sysctl_drop_caches,
1441 .maxlen = sizeof(int),
1442 .mode = 0644,
1443 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001444 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001445 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001446 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001447#ifdef CONFIG_COMPACTION
1448 {
1449 .procname = "compact_memory",
1450 .data = &sysctl_compact_memory,
1451 .maxlen = sizeof(int),
1452 .mode = 0200,
1453 .proc_handler = sysctl_compaction_handler,
1454 },
Mel Gorman5e771902010-05-24 14:32:31 -07001455 {
1456 .procname = "extfrag_threshold",
1457 .data = &sysctl_extfrag_threshold,
1458 .maxlen = sizeof(int),
1459 .mode = 0644,
1460 .proc_handler = sysctl_extfrag_handler,
1461 .extra1 = &min_extfrag_threshold,
1462 .extra2 = &max_extfrag_threshold,
1463 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001464 {
1465 .procname = "compact_unevictable_allowed",
1466 .data = &sysctl_compact_unevictable_allowed,
1467 .maxlen = sizeof(int),
1468 .mode = 0644,
1469 .proc_handler = proc_dointvec,
1470 .extra1 = &zero,
1471 .extra2 = &one,
1472 },
Mel Gorman5e771902010-05-24 14:32:31 -07001473
Mel Gorman76ab0f52010-05-24 14:32:28 -07001474#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 .procname = "min_free_kbytes",
1477 .data = &min_free_kbytes,
1478 .maxlen = sizeof(min_free_kbytes),
1479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001480 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 .extra1 = &zero,
1482 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001483 {
Mel Gorman1c308442018-12-28 00:35:52 -08001484 .procname = "watermark_boost_factor",
1485 .data = &watermark_boost_factor,
1486 .maxlen = sizeof(watermark_boost_factor),
1487 .mode = 0644,
1488 .proc_handler = watermark_boost_factor_sysctl_handler,
1489 .extra1 = &zero,
1490 },
1491 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001492 .procname = "watermark_scale_factor",
1493 .data = &watermark_scale_factor,
1494 .maxlen = sizeof(watermark_scale_factor),
1495 .mode = 0644,
1496 .proc_handler = watermark_scale_factor_sysctl_handler,
1497 .extra1 = &one,
1498 .extra2 = &one_thousand,
1499 },
1500 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001501 .procname = "percpu_pagelist_fraction",
1502 .data = &percpu_pagelist_fraction,
1503 .maxlen = sizeof(percpu_pagelist_fraction),
1504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001505 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001506 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001507 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508#ifdef CONFIG_MMU
1509 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 .procname = "max_map_count",
1511 .data = &sysctl_max_map_count,
1512 .maxlen = sizeof(sysctl_max_map_count),
1513 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001514 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001515 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001517#else
1518 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001519 .procname = "nr_trim_pages",
1520 .data = &sysctl_nr_trim_pages,
1521 .maxlen = sizeof(sysctl_nr_trim_pages),
1522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001523 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001524 .extra1 = &zero,
1525 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526#endif
1527 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 .procname = "laptop_mode",
1529 .data = &laptop_mode,
1530 .maxlen = sizeof(laptop_mode),
1531 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001532 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 },
1534 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 .procname = "block_dump",
1536 .data = &block_dump,
1537 .maxlen = sizeof(block_dump),
1538 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001539 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 .extra1 = &zero,
1541 },
1542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 .procname = "vfs_cache_pressure",
1544 .data = &sysctl_vfs_cache_pressure,
1545 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001547 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 .extra1 = &zero,
1549 },
1550#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 .procname = "legacy_va_layout",
1553 .data = &sysctl_legacy_va_layout,
1554 .maxlen = sizeof(sysctl_legacy_va_layout),
1555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 .extra1 = &zero,
1558 },
1559#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001560#ifdef CONFIG_NUMA
1561 {
Christoph Lameter17436602006-01-18 17:42:32 -08001562 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001563 .data = &node_reclaim_mode,
1564 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001566 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001567 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001568 },
Christoph Lameter96146342006-07-03 00:24:13 -07001569 {
Christoph Lameter96146342006-07-03 00:24:13 -07001570 .procname = "min_unmapped_ratio",
1571 .data = &sysctl_min_unmapped_ratio,
1572 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1573 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001574 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001575 .extra1 = &zero,
1576 .extra2 = &one_hundred,
1577 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001578 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001579 .procname = "min_slab_ratio",
1580 .data = &sysctl_min_slab_ratio,
1581 .maxlen = sizeof(sysctl_min_slab_ratio),
1582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001583 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001584 .extra1 = &zero,
1585 .extra2 = &one_hundred,
1586 },
Christoph Lameter17436602006-01-18 17:42:32 -08001587#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001588#ifdef CONFIG_SMP
1589 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001590 .procname = "stat_interval",
1591 .data = &sysctl_stat_interval,
1592 .maxlen = sizeof(sysctl_stat_interval),
1593 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001594 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001595 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001596 {
1597 .procname = "stat_refresh",
1598 .data = NULL,
1599 .maxlen = 0,
1600 .mode = 0600,
1601 .proc_handler = vmstat_refresh,
1602 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001603#endif
David Howells6e141542009-12-15 19:27:45 +00001604#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001605 {
Eric Parised032182007-06-28 15:55:21 -04001606 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001607 .data = &dac_mmap_min_addr,
1608 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001610 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001611 },
David Howells6e141542009-12-15 19:27:45 +00001612#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001613#ifdef CONFIG_NUMA
1614 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001615 .procname = "numa_zonelist_order",
1616 .data = &numa_zonelist_order,
1617 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001619 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001620 },
1621#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001622#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001623 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001624 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001625 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001626#ifdef CONFIG_X86_32
1627 .data = &vdso32_enabled,
1628 .maxlen = sizeof(vdso32_enabled),
1629#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001630 .data = &vdso_enabled,
1631 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001632#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001633 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001634 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001635 .extra1 = &zero,
1636 },
1637#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001638#ifdef CONFIG_HIGHMEM
1639 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001640 .procname = "highmem_is_dirtyable",
1641 .data = &vm_highmem_is_dirtyable,
1642 .maxlen = sizeof(vm_highmem_is_dirtyable),
1643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001644 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001645 .extra1 = &zero,
1646 .extra2 = &one,
1647 },
1648#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001649#ifdef CONFIG_MEMORY_FAILURE
1650 {
Andi Kleen6a460792009-09-16 11:50:15 +02001651 .procname = "memory_failure_early_kill",
1652 .data = &sysctl_memory_failure_early_kill,
1653 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1654 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001655 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001656 .extra1 = &zero,
1657 .extra2 = &one,
1658 },
1659 {
Andi Kleen6a460792009-09-16 11:50:15 +02001660 .procname = "memory_failure_recovery",
1661 .data = &sysctl_memory_failure_recovery,
1662 .maxlen = sizeof(sysctl_memory_failure_recovery),
1663 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001664 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001665 .extra1 = &zero,
1666 .extra2 = &one,
1667 },
1668#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001669 {
1670 .procname = "user_reserve_kbytes",
1671 .data = &sysctl_user_reserve_kbytes,
1672 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1673 .mode = 0644,
1674 .proc_handler = proc_doulongvec_minmax,
1675 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001676 {
1677 .procname = "admin_reserve_kbytes",
1678 .data = &sysctl_admin_reserve_kbytes,
1679 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1680 .mode = 0644,
1681 .proc_handler = proc_doulongvec_minmax,
1682 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001683#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1684 {
1685 .procname = "mmap_rnd_bits",
1686 .data = &mmap_rnd_bits,
1687 .maxlen = sizeof(mmap_rnd_bits),
1688 .mode = 0600,
1689 .proc_handler = proc_dointvec_minmax,
1690 .extra1 = (void *)&mmap_rnd_bits_min,
1691 .extra2 = (void *)&mmap_rnd_bits_max,
1692 },
1693#endif
1694#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1695 {
1696 .procname = "mmap_rnd_compat_bits",
1697 .data = &mmap_rnd_compat_bits,
1698 .maxlen = sizeof(mmap_rnd_compat_bits),
1699 .mode = 0600,
1700 .proc_handler = proc_dointvec_minmax,
1701 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1702 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1703 },
1704#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001705 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706};
1707
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001708static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 .procname = "inode-nr",
1711 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001712 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001714 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 },
1716 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 .procname = "inode-state",
1718 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001719 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001721 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 },
1723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 .procname = "file-nr",
1725 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001726 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001728 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 },
1730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 .procname = "file-max",
1732 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001733 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001735 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 },
1737 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001738 .procname = "nr_open",
1739 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001740 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001741 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001742 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001743 .extra1 = &sysctl_nr_open_min,
1744 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001745 },
1746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 .procname = "dentry-state",
1748 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001749 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001751 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 },
1753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .procname = "overflowuid",
1755 .data = &fs_overflowuid,
1756 .maxlen = sizeof(int),
1757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001758 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 .extra1 = &minolduid,
1760 .extra2 = &maxolduid,
1761 },
1762 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 .procname = "overflowgid",
1764 .data = &fs_overflowgid,
1765 .maxlen = sizeof(int),
1766 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001767 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 .extra1 = &minolduid,
1769 .extra2 = &maxolduid,
1770 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001771#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 .procname = "leases-enable",
1774 .data = &leases_enable,
1775 .maxlen = sizeof(int),
1776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001777 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001779#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780#ifdef CONFIG_DNOTIFY
1781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 .procname = "dir-notify-enable",
1783 .data = &dir_notify_enable,
1784 .maxlen = sizeof(int),
1785 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001786 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 },
1788#endif
1789#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001790#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 .procname = "lease-break-time",
1793 .data = &lease_break_time,
1794 .maxlen = sizeof(int),
1795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001796 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001798#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001799#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 .procname = "aio-nr",
1802 .data = &aio_nr,
1803 .maxlen = sizeof(aio_nr),
1804 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001805 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 },
1807 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 .procname = "aio-max-nr",
1809 .data = &aio_max_nr,
1810 .maxlen = sizeof(aio_max_nr),
1811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001812 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001814#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001815#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001816 {
Robert Love0399cb02005-07-13 12:38:18 -04001817 .procname = "inotify",
1818 .mode = 0555,
1819 .child = inotify_table,
1820 },
1821#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001822#ifdef CONFIG_EPOLL
1823 {
1824 .procname = "epoll",
1825 .mode = 0555,
1826 .child = epoll_table,
1827 },
1828#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001830 {
Kees Cook800179c2012-07-25 17:29:07 -07001831 .procname = "protected_symlinks",
1832 .data = &sysctl_protected_symlinks,
1833 .maxlen = sizeof(int),
1834 .mode = 0600,
1835 .proc_handler = proc_dointvec_minmax,
1836 .extra1 = &zero,
1837 .extra2 = &one,
1838 },
1839 {
1840 .procname = "protected_hardlinks",
1841 .data = &sysctl_protected_hardlinks,
1842 .maxlen = sizeof(int),
1843 .mode = 0600,
1844 .proc_handler = proc_dointvec_minmax,
1845 .extra1 = &zero,
1846 .extra2 = &one,
1847 },
1848 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001849 .procname = "protected_fifos",
1850 .data = &sysctl_protected_fifos,
1851 .maxlen = sizeof(int),
1852 .mode = 0600,
1853 .proc_handler = proc_dointvec_minmax,
1854 .extra1 = &zero,
1855 .extra2 = &two,
1856 },
1857 {
1858 .procname = "protected_regular",
1859 .data = &sysctl_protected_regular,
1860 .maxlen = sizeof(int),
1861 .mode = 0600,
1862 .proc_handler = proc_dointvec_minmax,
1863 .extra1 = &zero,
1864 .extra2 = &two,
1865 },
1866 {
Alan Coxd6e71142005-06-23 00:09:43 -07001867 .procname = "suid_dumpable",
1868 .data = &suid_dumpable,
1869 .maxlen = sizeof(int),
1870 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001871 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001872 .extra1 = &zero,
1873 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001874 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001875#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1876 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001877 .procname = "binfmt_misc",
1878 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001879 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001880 },
1881#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001882 {
Jens Axboeff9da692010-06-03 14:54:39 +02001883 .procname = "pipe-max-size",
1884 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001885 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001886 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001887 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001888 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001889 {
1890 .procname = "pipe-user-pages-hard",
1891 .data = &pipe_user_pages_hard,
1892 .maxlen = sizeof(pipe_user_pages_hard),
1893 .mode = 0644,
1894 .proc_handler = proc_doulongvec_minmax,
1895 },
1896 {
1897 .procname = "pipe-user-pages-soft",
1898 .data = &pipe_user_pages_soft,
1899 .maxlen = sizeof(pipe_user_pages_soft),
1900 .mode = 0644,
1901 .proc_handler = proc_doulongvec_minmax,
1902 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001903 {
1904 .procname = "mount-max",
1905 .data = &sysctl_mount_max,
1906 .maxlen = sizeof(unsigned int),
1907 .mode = 0644,
1908 .proc_handler = proc_dointvec_minmax,
1909 .extra1 = &one,
1910 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001911 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912};
1913
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001914static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001915#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001916 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001917 .procname = "exception-trace",
1918 .data = &show_unhandled_signals,
1919 .maxlen = sizeof(int),
1920 .mode = 0644,
1921 .proc_handler = proc_dointvec
1922 },
1923#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001924#if defined(CONFIG_OPTPROBES)
1925 {
1926 .procname = "kprobes-optimization",
1927 .data = &sysctl_kprobes_optimization,
1928 .maxlen = sizeof(int),
1929 .mode = 0644,
1930 .proc_handler = proc_kprobes_optimization_handler,
1931 .extra1 = &zero,
1932 .extra2 = &one,
1933 },
1934#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001935 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936};
1937
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001938static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001939 { }
Robert Love0eeca282005-07-12 17:06:03 -04001940};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001942int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001943{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001944 struct ctl_table_header *hdr;
1945
1946 hdr = register_sysctl_table(sysctl_base_table);
1947 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001948 return 0;
1949}
1950
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001951#endif /* CONFIG_SYSCTL */
1952
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953/*
1954 * /proc/sys support
1955 */
1956
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001957#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Kees Cookf8808302014-06-06 14:37:17 -07001959static int _proc_do_string(char *data, int maxlen, int write,
1960 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001961 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001962{
1963 size_t len;
1964 char __user *p;
1965 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001966
1967 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001968 *lenp = 0;
1969 return 0;
1970 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001971
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001972 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001973 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1974 /* Only continue writes not past the end of buffer. */
1975 len = strlen(data);
1976 if (len > maxlen - 1)
1977 len = maxlen - 1;
1978
1979 if (*ppos > len)
1980 return 0;
1981 len = *ppos;
1982 } else {
1983 /* Start writing from beginning of buffer. */
1984 len = 0;
1985 }
1986
Kees Cook2ca9bb42014-06-06 14:37:18 -07001987 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001988 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001989 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001990 if (get_user(c, p++))
1991 return -EFAULT;
1992 if (c == 0 || c == '\n')
1993 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001994 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001995 }
Kees Cookf8808302014-06-06 14:37:17 -07001996 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001997 } else {
1998 len = strlen(data);
1999 if (len > maxlen)
2000 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002001
2002 if (*ppos > len) {
2003 *lenp = 0;
2004 return 0;
2005 }
2006
2007 data += *ppos;
2008 len -= *ppos;
2009
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002010 if (len > *lenp)
2011 len = *lenp;
2012 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002013 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002014 return -EFAULT;
2015 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002016 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002017 return -EFAULT;
2018 len++;
2019 }
2020 *lenp = len;
2021 *ppos += len;
2022 }
2023 return 0;
2024}
2025
Kees Cookf4aacea2014-06-06 14:37:19 -07002026static void warn_sysctl_write(struct ctl_table *table)
2027{
2028 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2029 "This will not be supported in the future. To silence this\n"
2030 "warning, set kernel.sysctl_writes_strict = -1\n",
2031 current->comm, table->procname);
2032}
2033
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002035 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002036 * @ppos: file position
2037 * @table: the sysctl table
2038 *
2039 * Returns true if the first position is non-zero and the sysctl_writes_strict
2040 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002041 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002042 */
2043static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2044 struct ctl_table *table)
2045{
2046 if (!*ppos)
2047 return false;
2048
2049 switch (sysctl_writes_strict) {
2050 case SYSCTL_WRITES_STRICT:
2051 return true;
2052 case SYSCTL_WRITES_WARN:
2053 warn_sysctl_write(table);
2054 return false;
2055 default:
2056 return false;
2057 }
2058}
2059
2060/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 * proc_dostring - read a string sysctl
2062 * @table: the sysctl table
2063 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2067 *
2068 * Reads/writes a string from/to the user buffer. If the kernel
2069 * buffer provided is not large enough to hold the string, the
2070 * string is truncated. The copied string is %NULL-terminated.
2071 * If the string is being read by the user process, it is copied
2072 * and a newline '\n' is added. It is truncated if the buffer is
2073 * not large enough.
2074 *
2075 * Returns 0 on success.
2076 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002077int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 void __user *buffer, size_t *lenp, loff_t *ppos)
2079{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002080 if (write)
2081 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002082
Kees Cookf8808302014-06-06 14:37:17 -07002083 return _proc_do_string((char *)(table->data), table->maxlen, write,
2084 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085}
2086
Amerigo Wang00b7c332010-05-05 00:26:45 +00002087static size_t proc_skip_spaces(char **buf)
2088{
2089 size_t ret;
2090 char *tmp = skip_spaces(*buf);
2091 ret = tmp - *buf;
2092 *buf = tmp;
2093 return ret;
2094}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002096static void proc_skip_char(char **buf, size_t *size, const char v)
2097{
2098 while (*size) {
2099 if (**buf != v)
2100 break;
2101 (*size)--;
2102 (*buf)++;
2103 }
2104}
2105
Amerigo Wang00b7c332010-05-05 00:26:45 +00002106#define TMPBUFLEN 22
2107/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002108 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002110 * @buf: a kernel buffer
2111 * @size: size of the kernel buffer
2112 * @val: this is where the number will be stored
2113 * @neg: set to %TRUE if number is negative
2114 * @perm_tr: a vector which contains the allowed trailers
2115 * @perm_tr_len: size of the perm_tr vector
2116 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002117 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002118 * In case of success %0 is returned and @buf and @size are updated with
2119 * the amount of bytes read. If @tr is non-NULL and a trailing
2120 * character exists (size is non-zero after returning from this
2121 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002122 */
2123static int proc_get_long(char **buf, size_t *size,
2124 unsigned long *val, bool *neg,
2125 const char *perm_tr, unsigned perm_tr_len, char *tr)
2126{
2127 int len;
2128 char *p, tmp[TMPBUFLEN];
2129
2130 if (!*size)
2131 return -EINVAL;
2132
2133 len = *size;
2134 if (len > TMPBUFLEN - 1)
2135 len = TMPBUFLEN - 1;
2136
2137 memcpy(tmp, *buf, len);
2138
2139 tmp[len] = 0;
2140 p = tmp;
2141 if (*p == '-' && *size > 1) {
2142 *neg = true;
2143 p++;
2144 } else
2145 *neg = false;
2146 if (!isdigit(*p))
2147 return -EINVAL;
2148
2149 *val = simple_strtoul(p, &p, 0);
2150
2151 len = p - tmp;
2152
2153 /* We don't know if the next char is whitespace thus we may accept
2154 * invalid integers (e.g. 1234...a) or two integers instead of one
2155 * (e.g. 123...1). So lets not allow such large numbers. */
2156 if (len == TMPBUFLEN - 1)
2157 return -EINVAL;
2158
2159 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2160 return -EINVAL;
2161
2162 if (tr && (len < *size))
2163 *tr = *p;
2164
2165 *buf += len;
2166 *size -= len;
2167
2168 return 0;
2169}
2170
2171/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002172 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002173 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002174 * @buf: the user buffer
2175 * @size: the size of the user buffer
2176 * @val: the integer to be converted
2177 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002178 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002179 * In case of success %0 is returned and @buf and @size are updated with
2180 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002181 */
2182static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2183 bool neg)
2184{
2185 int len;
2186 char tmp[TMPBUFLEN], *p = tmp;
2187
2188 sprintf(p, "%s%lu", neg ? "-" : "", val);
2189 len = strlen(tmp);
2190 if (len > *size)
2191 len = *size;
2192 if (copy_to_user(*buf, tmp, len))
2193 return -EFAULT;
2194 *size -= len;
2195 *buf += len;
2196 return 0;
2197}
2198#undef TMPBUFLEN
2199
2200static int proc_put_char(void __user **buf, size_t *size, char c)
2201{
2202 if (*size) {
2203 char __user **buffer = (char __user **)buf;
2204 if (put_user(c, *buffer))
2205 return -EFAULT;
2206 (*size)--, (*buffer)++;
2207 *buf = *buffer;
2208 }
2209 return 0;
2210}
2211
2212static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 int *valp,
2214 int write, void *data)
2215{
2216 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002217 if (*negp) {
2218 if (*lvalp > (unsigned long) INT_MAX + 1)
2219 return -EINVAL;
2220 *valp = -*lvalp;
2221 } else {
2222 if (*lvalp > (unsigned long) INT_MAX)
2223 return -EINVAL;
2224 *valp = *lvalp;
2225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 } else {
2227 int val = *valp;
2228 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002229 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002230 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002232 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 *lvalp = (unsigned long)val;
2234 }
2235 }
2236 return 0;
2237}
2238
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002239static int do_proc_douintvec_conv(unsigned long *lvalp,
2240 unsigned int *valp,
2241 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002242{
2243 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002244 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002245 return -EINVAL;
2246 *valp = *lvalp;
2247 } else {
2248 unsigned int val = *valp;
2249 *lvalp = (unsigned long)val;
2250 }
2251 return 0;
2252}
2253
Amerigo Wang00b7c332010-05-05 00:26:45 +00002254static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2255
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002256static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002257 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002258 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002259 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 int write, void *data),
2261 void *data)
2262{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002264 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002265 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Amerigo Wang00b7c332010-05-05 00:26:45 +00002267 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 *lenp = 0;
2269 return 0;
2270 }
2271
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002272 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 vleft = table->maxlen / sizeof(*i);
2274 left = *lenp;
2275
2276 if (!conv)
2277 conv = do_proc_dointvec_conv;
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002280 if (proc_first_pos_non_zero_ignore(ppos, table))
2281 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002282
Amerigo Wang00b7c332010-05-05 00:26:45 +00002283 if (left > PAGE_SIZE - 1)
2284 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002285 p = kbuf = memdup_user_nul(buffer, left);
2286 if (IS_ERR(kbuf))
2287 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002288 }
2289
2290 for (; left && vleft--; i++, first=0) {
2291 unsigned long lval;
2292 bool neg;
2293
2294 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002295 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002296
J. R. Okajima563b0462010-05-25 16:10:14 -07002297 if (!left)
2298 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002299 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002300 proc_wspace_sep,
2301 sizeof(proc_wspace_sep), NULL);
2302 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002304 if (conv(&neg, &lval, i, 1, data)) {
2305 err = -EINVAL;
2306 break;
2307 }
2308 } else {
2309 if (conv(&neg, &lval, i, 0, data)) {
2310 err = -EINVAL;
2311 break;
2312 }
2313 if (!first)
2314 err = proc_put_char(&buffer, &left, '\t');
2315 if (err)
2316 break;
2317 err = proc_put_long(&buffer, &left, lval, neg);
2318 if (err)
2319 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 }
2321 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322
2323 if (!write && !first && left && !err)
2324 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002325 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002326 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002327 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002328 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002329 if (first)
2330 return err ? : -EINVAL;
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002333out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002335 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336}
2337
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002338static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002339 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002340 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002341 int write, void *data),
2342 void *data)
2343{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002344 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002345 buffer, lenp, ppos, conv, data);
2346}
2347
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002348static int do_proc_douintvec_w(unsigned int *tbl_data,
2349 struct ctl_table *table,
2350 void __user *buffer,
2351 size_t *lenp, loff_t *ppos,
2352 int (*conv)(unsigned long *lvalp,
2353 unsigned int *valp,
2354 int write, void *data),
2355 void *data)
2356{
2357 unsigned long lval;
2358 int err = 0;
2359 size_t left;
2360 bool neg;
2361 char *kbuf = NULL, *p;
2362
2363 left = *lenp;
2364
2365 if (proc_first_pos_non_zero_ignore(ppos, table))
2366 goto bail_early;
2367
2368 if (left > PAGE_SIZE - 1)
2369 left = PAGE_SIZE - 1;
2370
2371 p = kbuf = memdup_user_nul(buffer, left);
2372 if (IS_ERR(kbuf))
2373 return -EINVAL;
2374
2375 left -= proc_skip_spaces(&p);
2376 if (!left) {
2377 err = -EINVAL;
2378 goto out_free;
2379 }
2380
2381 err = proc_get_long(&p, &left, &lval, &neg,
2382 proc_wspace_sep,
2383 sizeof(proc_wspace_sep), NULL);
2384 if (err || neg) {
2385 err = -EINVAL;
2386 goto out_free;
2387 }
2388
2389 if (conv(&lval, tbl_data, 1, data)) {
2390 err = -EINVAL;
2391 goto out_free;
2392 }
2393
2394 if (!err && left)
2395 left -= proc_skip_spaces(&p);
2396
2397out_free:
2398 kfree(kbuf);
2399 if (err)
2400 return -EINVAL;
2401
2402 return 0;
2403
2404 /* This is in keeping with old __do_proc_dointvec() */
2405bail_early:
2406 *ppos += *lenp;
2407 return err;
2408}
2409
2410static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2411 size_t *lenp, loff_t *ppos,
2412 int (*conv)(unsigned long *lvalp,
2413 unsigned int *valp,
2414 int write, void *data),
2415 void *data)
2416{
2417 unsigned long lval;
2418 int err = 0;
2419 size_t left;
2420
2421 left = *lenp;
2422
2423 if (conv(&lval, tbl_data, 0, data)) {
2424 err = -EINVAL;
2425 goto out;
2426 }
2427
2428 err = proc_put_long(&buffer, &left, lval, false);
2429 if (err || !left)
2430 goto out;
2431
2432 err = proc_put_char(&buffer, &left, '\n');
2433
2434out:
2435 *lenp -= left;
2436 *ppos += *lenp;
2437
2438 return err;
2439}
2440
2441static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2442 int write, void __user *buffer,
2443 size_t *lenp, loff_t *ppos,
2444 int (*conv)(unsigned long *lvalp,
2445 unsigned int *valp,
2446 int write, void *data),
2447 void *data)
2448{
2449 unsigned int *i, vleft;
2450
2451 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2452 *lenp = 0;
2453 return 0;
2454 }
2455
2456 i = (unsigned int *) tbl_data;
2457 vleft = table->maxlen / sizeof(*i);
2458
2459 /*
2460 * Arrays are not supported, keep this simple. *Do not* add
2461 * support for them.
2462 */
2463 if (vleft != 1) {
2464 *lenp = 0;
2465 return -EINVAL;
2466 }
2467
2468 if (!conv)
2469 conv = do_proc_douintvec_conv;
2470
2471 if (write)
2472 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2473 conv, data);
2474 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2475}
2476
2477static int do_proc_douintvec(struct ctl_table *table, int write,
2478 void __user *buffer, size_t *lenp, loff_t *ppos,
2479 int (*conv)(unsigned long *lvalp,
2480 unsigned int *valp,
2481 int write, void *data),
2482 void *data)
2483{
2484 return __do_proc_douintvec(table->data, table, write,
2485 buffer, lenp, ppos, conv, data);
2486}
2487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488/**
2489 * proc_dointvec - read a vector of integers
2490 * @table: the sysctl table
2491 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 * @buffer: the user buffer
2493 * @lenp: the size of the user buffer
2494 * @ppos: file position
2495 *
2496 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2497 * values from/to the user buffer, treated as an ASCII string.
2498 *
2499 * Returns 0 on success.
2500 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002501int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 void __user *buffer, size_t *lenp, loff_t *ppos)
2503{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002504 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2505}
2506
2507/**
2508 * proc_douintvec - read a vector of unsigned integers
2509 * @table: the sysctl table
2510 * @write: %TRUE if this is a write to the sysctl file
2511 * @buffer: the user buffer
2512 * @lenp: the size of the user buffer
2513 * @ppos: file position
2514 *
2515 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2516 * values from/to the user buffer, treated as an ASCII string.
2517 *
2518 * Returns 0 on success.
2519 */
2520int proc_douintvec(struct ctl_table *table, int write,
2521 void __user *buffer, size_t *lenp, loff_t *ppos)
2522{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002523 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2524 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525}
2526
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002527/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002528 * Taint values can only be increased
2529 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002530 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002531static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002532 void __user *buffer, size_t *lenp, loff_t *ppos)
2533{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002534 struct ctl_table t;
2535 unsigned long tmptaint = get_taint();
2536 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002537
Bastian Blank91fcd412007-04-23 14:41:14 -07002538 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002539 return -EPERM;
2540
Andi Kleen25ddbb12008-10-15 22:01:41 -07002541 t = *table;
2542 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002543 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002544 if (err < 0)
2545 return err;
2546
2547 if (write) {
2548 /*
2549 * Poor man's atomic or. Not worth adding a primitive
2550 * to everyone's atomic.h for this
2551 */
2552 int i;
2553 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2554 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302555 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002556 }
2557 }
2558
2559 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002560}
2561
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002562#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002563static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002564 void __user *buffer, size_t *lenp, loff_t *ppos)
2565{
2566 if (write && !capable(CAP_SYS_ADMIN))
2567 return -EPERM;
2568
2569 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2570}
2571#endif
2572
Waiman Long24704f32018-04-10 16:35:38 -07002573/**
2574 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2575 * @min: pointer to minimum allowable value
2576 * @max: pointer to maximum allowable value
2577 *
2578 * The do_proc_dointvec_minmax_conv_param structure provides the
2579 * minimum and maximum values for doing range checking for those sysctl
2580 * parameters that use the proc_dointvec_minmax() handler.
2581 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582struct do_proc_dointvec_minmax_conv_param {
2583 int *min;
2584 int *max;
2585};
2586
Amerigo Wang00b7c332010-05-05 00:26:45 +00002587static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2588 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 int write, void *data)
2590{
2591 struct do_proc_dointvec_minmax_conv_param *param = data;
2592 if (write) {
2593 int val = *negp ? -*lvalp : *lvalp;
2594 if ((param->min && *param->min > val) ||
2595 (param->max && *param->max < val))
2596 return -EINVAL;
2597 *valp = val;
2598 } else {
2599 int val = *valp;
2600 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002601 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002602 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002604 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 *lvalp = (unsigned long)val;
2606 }
2607 }
2608 return 0;
2609}
2610
2611/**
2612 * proc_dointvec_minmax - read a vector of integers with min/max values
2613 * @table: the sysctl table
2614 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 * @buffer: the user buffer
2616 * @lenp: the size of the user buffer
2617 * @ppos: file position
2618 *
2619 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2620 * values from/to the user buffer, treated as an ASCII string.
2621 *
2622 * This routine will ensure the values are within the range specified by
2623 * table->extra1 (min) and table->extra2 (max).
2624 *
Waiman Long24704f32018-04-10 16:35:38 -07002625 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002627int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 void __user *buffer, size_t *lenp, loff_t *ppos)
2629{
2630 struct do_proc_dointvec_minmax_conv_param param = {
2631 .min = (int *) table->extra1,
2632 .max = (int *) table->extra2,
2633 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002634 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 do_proc_dointvec_minmax_conv, &param);
2636}
2637
Waiman Long24704f32018-04-10 16:35:38 -07002638/**
2639 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2640 * @min: pointer to minimum allowable value
2641 * @max: pointer to maximum allowable value
2642 *
2643 * The do_proc_douintvec_minmax_conv_param structure provides the
2644 * minimum and maximum values for doing range checking for those sysctl
2645 * parameters that use the proc_douintvec_minmax() handler.
2646 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002647struct do_proc_douintvec_minmax_conv_param {
2648 unsigned int *min;
2649 unsigned int *max;
2650};
2651
2652static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2653 unsigned int *valp,
2654 int write, void *data)
2655{
2656 struct do_proc_douintvec_minmax_conv_param *param = data;
2657
2658 if (write) {
2659 unsigned int val = *lvalp;
2660
Joe Lawrencefb910c42017-11-17 15:29:28 -08002661 if (*lvalp > UINT_MAX)
2662 return -EINVAL;
2663
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002664 if ((param->min && *param->min > val) ||
2665 (param->max && *param->max < val))
2666 return -ERANGE;
2667
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002668 *valp = val;
2669 } else {
2670 unsigned int val = *valp;
2671 *lvalp = (unsigned long) val;
2672 }
2673
2674 return 0;
2675}
2676
2677/**
2678 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2679 * @table: the sysctl table
2680 * @write: %TRUE if this is a write to the sysctl file
2681 * @buffer: the user buffer
2682 * @lenp: the size of the user buffer
2683 * @ppos: file position
2684 *
2685 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2686 * values from/to the user buffer, treated as an ASCII string. Negative
2687 * strings are not allowed.
2688 *
2689 * This routine will ensure the values are within the range specified by
2690 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2691 * check for UINT_MAX to avoid having to support wrap around uses from
2692 * userspace.
2693 *
Waiman Long24704f32018-04-10 16:35:38 -07002694 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002695 */
2696int proc_douintvec_minmax(struct ctl_table *table, int write,
2697 void __user *buffer, size_t *lenp, loff_t *ppos)
2698{
2699 struct do_proc_douintvec_minmax_conv_param param = {
2700 .min = (unsigned int *) table->extra1,
2701 .max = (unsigned int *) table->extra2,
2702 };
2703 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2704 do_proc_douintvec_minmax_conv, &param);
2705}
2706
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002707static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2708 unsigned int *valp,
2709 int write, void *data)
2710{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002711 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002712 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002713
Joe Lawrencefb910c42017-11-17 15:29:28 -08002714 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002715 if (val == 0)
2716 return -EINVAL;
2717
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002718 *valp = val;
2719 } else {
2720 unsigned int val = *valp;
2721 *lvalp = (unsigned long) val;
2722 }
2723
2724 return 0;
2725}
2726
Eric Biggers319e0a22018-02-06 15:41:49 -08002727static int proc_dopipe_max_size(struct ctl_table *table, int write,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002729{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002730 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002731 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002732}
2733
Kees Cook54b50192012-07-30 14:39:18 -07002734static void validate_coredump_safety(void)
2735{
Alex Kelly046d6622012-10-04 17:15:23 -07002736#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002737 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002738 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002739 printk(KERN_WARNING
2740"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2741"Pipe handler or fully qualified core dump path required.\n"
2742"Set kernel.core_pattern before fs.suid_dumpable.\n"
2743 );
Kees Cook54b50192012-07-30 14:39:18 -07002744 }
Alex Kelly046d6622012-10-04 17:15:23 -07002745#endif
Kees Cook54b50192012-07-30 14:39:18 -07002746}
2747
2748static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2749 void __user *buffer, size_t *lenp, loff_t *ppos)
2750{
2751 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2752 if (!error)
2753 validate_coredump_safety();
2754 return error;
2755}
2756
Alex Kelly046d6622012-10-04 17:15:23 -07002757#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002758static int proc_dostring_coredump(struct ctl_table *table, int write,
2759 void __user *buffer, size_t *lenp, loff_t *ppos)
2760{
2761 int error = proc_dostring(table, write, buffer, lenp, ppos);
2762 if (!error)
2763 validate_coredump_safety();
2764 return error;
2765}
Alex Kelly046d6622012-10-04 17:15:23 -07002766#endif
Kees Cook54b50192012-07-30 14:39:18 -07002767
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002768static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 void __user *buffer,
2770 size_t *lenp, loff_t *ppos,
2771 unsigned long convmul,
2772 unsigned long convdiv)
2773{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002774 unsigned long *i, *min, *max;
2775 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002776 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002777 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002778
2779 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 *lenp = 0;
2781 return 0;
2782 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002783
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002784 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 min = (unsigned long *) table->extra1;
2786 max = (unsigned long *) table->extra2;
2787 vleft = table->maxlen / sizeof(unsigned long);
2788 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002789
2790 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002791 if (proc_first_pos_non_zero_ignore(ppos, table))
2792 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002793
Amerigo Wang00b7c332010-05-05 00:26:45 +00002794 if (left > PAGE_SIZE - 1)
2795 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002796 p = kbuf = memdup_user_nul(buffer, left);
2797 if (IS_ERR(kbuf))
2798 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002799 }
2800
Eric Dumazet27b3d802010-10-07 12:59:29 -07002801 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002802 unsigned long val;
2803
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002805 bool neg;
2806
Al Viro70f6cbb2015-12-24 00:13:10 -05002807 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002808 if (!left)
2809 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002810
Al Viro70f6cbb2015-12-24 00:13:10 -05002811 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002812 proc_wspace_sep,
2813 sizeof(proc_wspace_sep), NULL);
2814 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 break;
2816 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002818 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 if ((min && val < *min) || (max && val > *max))
2820 continue;
2821 *i = val;
2822 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002823 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002824 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002825 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002826 if (err)
2827 break;
2828 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002829 err = proc_put_long(&buffer, &left, val, false);
2830 if (err)
2831 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 }
2833 }
2834
Amerigo Wang00b7c332010-05-05 00:26:45 +00002835 if (!write && !first && left && !err)
2836 err = proc_put_char(&buffer, &left, '\n');
2837 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002838 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002840 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002841 if (first)
2842 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002845out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002847 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848}
2849
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002850static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002851 void __user *buffer,
2852 size_t *lenp, loff_t *ppos,
2853 unsigned long convmul,
2854 unsigned long convdiv)
2855{
2856 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002857 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002858}
2859
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860/**
2861 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2862 * @table: the sysctl table
2863 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 * @buffer: the user buffer
2865 * @lenp: the size of the user buffer
2866 * @ppos: file position
2867 *
2868 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2869 * values from/to the user buffer, treated as an ASCII string.
2870 *
2871 * This routine will ensure the values are within the range specified by
2872 * table->extra1 (min) and table->extra2 (max).
2873 *
2874 * Returns 0 on success.
2875 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002876int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 void __user *buffer, size_t *lenp, loff_t *ppos)
2878{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002879 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880}
2881
2882/**
2883 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2884 * @table: the sysctl table
2885 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 * @buffer: the user buffer
2887 * @lenp: the size of the user buffer
2888 * @ppos: file position
2889 *
2890 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2891 * values from/to the user buffer, treated as an ASCII string. The values
2892 * are treated as milliseconds, and converted to jiffies when they are stored.
2893 *
2894 * This routine will ensure the values are within the range specified by
2895 * table->extra1 (min) and table->extra2 (max).
2896 *
2897 * Returns 0 on success.
2898 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002899int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 void __user *buffer,
2901 size_t *lenp, loff_t *ppos)
2902{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002903 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 lenp, ppos, HZ, 1000l);
2905}
2906
2907
Amerigo Wang00b7c332010-05-05 00:26:45 +00002908static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 int *valp,
2910 int write, void *data)
2911{
2912 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002913 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002914 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2916 } else {
2917 int val = *valp;
2918 unsigned long lval;
2919 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002920 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002921 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002923 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 lval = (unsigned long)val;
2925 }
2926 *lvalp = lval / HZ;
2927 }
2928 return 0;
2929}
2930
Amerigo Wang00b7c332010-05-05 00:26:45 +00002931static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 int *valp,
2933 int write, void *data)
2934{
2935 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002936 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2937 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2939 } else {
2940 int val = *valp;
2941 unsigned long lval;
2942 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002943 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002944 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002946 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 lval = (unsigned long)val;
2948 }
2949 *lvalp = jiffies_to_clock_t(lval);
2950 }
2951 return 0;
2952}
2953
Amerigo Wang00b7c332010-05-05 00:26:45 +00002954static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 int *valp,
2956 int write, void *data)
2957{
2958 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002959 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2960
2961 if (jif > INT_MAX)
2962 return 1;
2963 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 } else {
2965 int val = *valp;
2966 unsigned long lval;
2967 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002968 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002969 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002971 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 lval = (unsigned long)val;
2973 }
2974 *lvalp = jiffies_to_msecs(lval);
2975 }
2976 return 0;
2977}
2978
2979/**
2980 * proc_dointvec_jiffies - read a vector of integers as seconds
2981 * @table: the sysctl table
2982 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 * @buffer: the user buffer
2984 * @lenp: the size of the user buffer
2985 * @ppos: file position
2986 *
2987 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2988 * values from/to the user buffer, treated as an ASCII string.
2989 * The values read are assumed to be in seconds, and are converted into
2990 * jiffies.
2991 *
2992 * Returns 0 on success.
2993 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002994int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 void __user *buffer, size_t *lenp, loff_t *ppos)
2996{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002997 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 do_proc_dointvec_jiffies_conv,NULL);
2999}
3000
3001/**
3002 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3003 * @table: the sysctl table
3004 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 * @buffer: the user buffer
3006 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003007 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 *
3009 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3010 * values from/to the user buffer, treated as an ASCII string.
3011 * The values read are assumed to be in 1/USER_HZ seconds, and
3012 * are converted into jiffies.
3013 *
3014 * Returns 0 on success.
3015 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003016int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 void __user *buffer, size_t *lenp, loff_t *ppos)
3018{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003019 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 do_proc_dointvec_userhz_jiffies_conv,NULL);
3021}
3022
3023/**
3024 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3025 * @table: the sysctl table
3026 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 * @buffer: the user buffer
3028 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003029 * @ppos: file position
3030 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 *
3032 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3033 * values from/to the user buffer, treated as an ASCII string.
3034 * The values read are assumed to be in 1/1000 seconds, and
3035 * are converted into jiffies.
3036 *
3037 * Returns 0 on success.
3038 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003039int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 void __user *buffer, size_t *lenp, loff_t *ppos)
3041{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003042 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 do_proc_dointvec_ms_jiffies_conv, NULL);
3044}
3045
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003046static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003047 void __user *buffer, size_t *lenp, loff_t *ppos)
3048{
3049 struct pid *new_pid;
3050 pid_t tmp;
3051 int r;
3052
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003053 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003054
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003055 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003056 lenp, ppos, NULL, NULL);
3057 if (r || !write)
3058 return r;
3059
3060 new_pid = find_get_pid(tmp);
3061 if (!new_pid)
3062 return -ESRCH;
3063
3064 put_pid(xchg(&cad_pid, new_pid));
3065 return 0;
3066}
3067
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003068/**
3069 * proc_do_large_bitmap - read/write from/to a large bitmap
3070 * @table: the sysctl table
3071 * @write: %TRUE if this is a write to the sysctl file
3072 * @buffer: the user buffer
3073 * @lenp: the size of the user buffer
3074 * @ppos: file position
3075 *
3076 * The bitmap is stored at table->data and the bitmap length (in bits)
3077 * in table->maxlen.
3078 *
3079 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3080 * large bitmaps may be represented in a compact manner. Writing into
3081 * the file will clear the bitmap then update it with the given input.
3082 *
3083 * Returns 0 on success.
3084 */
3085int proc_do_large_bitmap(struct ctl_table *table, int write,
3086 void __user *buffer, size_t *lenp, loff_t *ppos)
3087{
3088 int err = 0;
3089 bool first = 1;
3090 size_t left = *lenp;
3091 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003092 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003093 unsigned long *tmp_bitmap = NULL;
3094 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3095
WANG Cong122ff242014-05-12 16:04:53 -07003096 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003097 *lenp = 0;
3098 return 0;
3099 }
3100
3101 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003102 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003103
3104 if (left > PAGE_SIZE - 1)
3105 left = PAGE_SIZE - 1;
3106
Al Viro70f6cbb2015-12-24 00:13:10 -05003107 p = kbuf = memdup_user_nul(buffer, left);
3108 if (IS_ERR(kbuf))
3109 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003110
Kees Cook6396bb22018-06-12 14:03:40 -07003111 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3112 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003113 GFP_KERNEL);
3114 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003115 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003116 return -ENOMEM;
3117 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003118 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003119 while (!err && left) {
3120 unsigned long val_a, val_b;
3121 bool neg;
3122
Al Viro70f6cbb2015-12-24 00:13:10 -05003123 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003124 sizeof(tr_a), &c);
3125 if (err)
3126 break;
3127 if (val_a >= bitmap_len || neg) {
3128 err = -EINVAL;
3129 break;
3130 }
3131
3132 val_b = val_a;
3133 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003134 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003135 left--;
3136 }
3137
3138 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003139 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003140 &neg, tr_b, sizeof(tr_b),
3141 &c);
3142 if (err)
3143 break;
3144 if (val_b >= bitmap_len || neg ||
3145 val_a > val_b) {
3146 err = -EINVAL;
3147 break;
3148 }
3149 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003150 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003151 left--;
3152 }
3153 }
3154
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003155 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003156 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003157 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003158 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003159 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003160 } else {
3161 unsigned long bit_a, bit_b = 0;
3162
3163 while (left) {
3164 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3165 if (bit_a >= bitmap_len)
3166 break;
3167 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3168 bit_a + 1) - 1;
3169
3170 if (!first) {
3171 err = proc_put_char(&buffer, &left, ',');
3172 if (err)
3173 break;
3174 }
3175 err = proc_put_long(&buffer, &left, bit_a, false);
3176 if (err)
3177 break;
3178 if (bit_a != bit_b) {
3179 err = proc_put_char(&buffer, &left, '-');
3180 if (err)
3181 break;
3182 err = proc_put_long(&buffer, &left, bit_b, false);
3183 if (err)
3184 break;
3185 }
3186
3187 first = 0; bit_b++;
3188 }
3189 if (!err)
3190 err = proc_put_char(&buffer, &left, '\n');
3191 }
3192
3193 if (!err) {
3194 if (write) {
3195 if (*ppos)
3196 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3197 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003198 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003199 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003200 *lenp -= left;
3201 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003202 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003203
3204 kfree(tmp_bitmap);
3205 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003206}
3207
Jovi Zhang55610502011-01-12 17:00:45 -08003208#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003210int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 void __user *buffer, size_t *lenp, loff_t *ppos)
3212{
3213 return -ENOSYS;
3214}
3215
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003216int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 void __user *buffer, size_t *lenp, loff_t *ppos)
3218{
3219 return -ENOSYS;
3220}
3221
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003222int proc_douintvec(struct ctl_table *table, int write,
3223 void __user *buffer, size_t *lenp, loff_t *ppos)
3224{
3225 return -ENOSYS;
3226}
3227
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003228int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 void __user *buffer, size_t *lenp, loff_t *ppos)
3230{
3231 return -ENOSYS;
3232}
3233
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003234int proc_douintvec_minmax(struct ctl_table *table, int write,
3235 void __user *buffer, size_t *lenp, loff_t *ppos)
3236{
3237 return -ENOSYS;
3238}
3239
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003240int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 void __user *buffer, size_t *lenp, loff_t *ppos)
3242{
3243 return -ENOSYS;
3244}
3245
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003246int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 void __user *buffer, size_t *lenp, loff_t *ppos)
3248{
3249 return -ENOSYS;
3250}
3251
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003252int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 void __user *buffer, size_t *lenp, loff_t *ppos)
3254{
3255 return -ENOSYS;
3256}
3257
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003258int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 void __user *buffer, size_t *lenp, loff_t *ppos)
3260{
3261 return -ENOSYS;
3262}
3263
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003264int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 void __user *buffer,
3266 size_t *lenp, loff_t *ppos)
3267{
3268 return -ENOSYS;
3269}
3270
3271
Jovi Zhang55610502011-01-12 17:00:45 -08003272#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274/*
3275 * No sense putting this after each symbol definition, twice,
3276 * exception granted :-)
3277 */
3278EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003279EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280EXPORT_SYMBOL(proc_dointvec_jiffies);
3281EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003282EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3284EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3285EXPORT_SYMBOL(proc_dostring);
3286EXPORT_SYMBOL(proc_doulongvec_minmax);
3287EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);