blob: a2854f6e07430b0c84e24582e233388925a7ba0b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010065#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050068#include <linux/mount.h>
Joe Lawrence7a8d1812017-11-17 15:29:24 -080069#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080071#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <asm/processor.h>
73
Andi Kleen29cbc782006-09-30 01:47:55 +020074#ifdef CONFIG_X86
75#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010076#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010077#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020078#endif
David Howellsd550bbd2012-03-28 18:30:03 +010079#ifdef CONFIG_SPARC
80#include <asm/setup.h>
81#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080082#ifdef CONFIG_BSD_PROCESS_ACCT
83#include <linux/acct.h>
84#endif
Dave Young4f0e0562010-03-10 15:24:09 -080085#ifdef CONFIG_RT_MUTEXES
86#include <linux/rtmutex.h>
87#endif
Dave Young2edf5e42010-03-10 15:24:10 -080088#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89#include <linux/lockdep.h>
90#endif
Dave Young15485a42010-03-10 15:24:07 -080091#ifdef CONFIG_CHR_DEV_SG
92#include <scsi/sg.h>
93#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020094
Don Zickus58687ac2010-05-07 17:11:44 -040095#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050096#include <linux/nmi.h>
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#if defined(CONFIG_SYSCTL)
100
101/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700102extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700103#ifdef CONFIG_COREDUMP
104extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700106extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300112extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700130static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700131#ifdef CONFIG_PRINTK
132static int ten_thousand = 10000;
133#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300134#ifdef CONFIG_PERF_EVENTS
135static int six_hundred_forty_kb = 640 * 1024;
136#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700137
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700138/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142static int maxolduid = 65535;
143static int minolduid;
144
145static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700146static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Liu Hua80df2842014-04-07 15:38:57 -0700148/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149#ifdef CONFIG_DETECT_HUNG_TASK
150static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
151#endif
152
Dave Youngd14f1722010-02-25 20:28:57 -0500153#ifdef CONFIG_INOTIFY_USER
154#include <linux/inotify.h>
155#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700156#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
159#ifdef __hppa__
160extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530161#endif
162
163#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164extern int unaligned_enabled;
165#endif
166
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800168extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800169#endif
170
Vineet Guptab6fca722013-01-09 20:06:28 +0530171#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172extern int no_unaligned_warning;
173#endif
174
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700175#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700176
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700177/**
178 * enum sysctl_writes_mode - supported sysctl write modes
179 *
180 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
181 * to be written, and multiple writes on the same sysctl file descriptor
182 * will rewrite the sysctl value, regardless of file position. No warning
183 * is issued when the initial position is not 0.
184 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
185 * not 0.
186 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
187 * file position 0 and the value must be fully contained in the buffer
188 * sent to the write syscall. If dealing with strings respect the file
189 * position, but restrict this to the max length of the buffer, anything
190 * passed the max lenght will be ignored. Multiple writes will append
191 * to the buffer.
192 *
193 * These write modes control how current file position affects the behavior of
194 * updating sysctl values through the proc interface on each write.
195 */
196enum sysctl_writes_mode {
197 SYSCTL_WRITES_LEGACY = -1,
198 SYSCTL_WRITES_WARN = 0,
199 SYSCTL_WRITES_STRICT = 1,
200};
Kees Cookf4aacea2014-06-06 14:37:19 -0700201
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700202static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700203
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700204static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700205 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700206static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800207 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700208#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700209
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700210#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700211static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700212 void __user *buffer, size_t *lenp, loff_t *ppos);
213#endif
214
Kees Cook54b50192012-07-30 14:39:18 -0700215static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
216 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700217#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700218static int proc_dostring_coredump(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700220#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800221static int proc_dopipe_max_size(struct ctl_table *table, int write,
222 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700223
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700224#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800225/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100226static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700227
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700228static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700229 void __user *buffer, size_t *lenp,
230 loff_t *ppos)
231{
232 int error;
233
234 error = proc_dointvec(table, write, buffer, lenp, ppos);
235 if (error)
236 return error;
237
238 if (write)
239 sysrq_toggle_support(__sysrq_enabled);
240
241 return 0;
242}
243
244#endif
245
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700246static struct ctl_table kern_table[];
247static struct ctl_table vm_table[];
248static struct ctl_table fs_table[];
249static struct ctl_table debug_table[];
250static struct ctl_table dev_table[];
251extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800252#ifdef CONFIG_EPOLL
253extern struct ctl_table epoll_table[];
254#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800256#ifdef CONFIG_FW_LOADER_USER_HELPER
257extern struct ctl_table firmware_config_table[];
258#endif
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
261int sysctl_legacy_va_layout;
262#endif
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264/* The default sysctl tables: */
265
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800266static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 .procname = "kernel",
269 .mode = 0555,
270 .child = kern_table,
271 },
272 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 .procname = "vm",
274 .mode = 0555,
275 .child = vm_table,
276 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 .procname = "fs",
279 .mode = 0555,
280 .child = fs_table,
281 },
282 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .procname = "debug",
284 .mode = 0555,
285 .child = debug_table,
286 },
287 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 .procname = "dev",
289 .mode = 0555,
290 .child = dev_table,
291 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700292 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293};
294
Ingo Molnar77e54a12007-07-09 18:52:00 +0200295#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100296static int min_sched_granularity_ns = 100000; /* 100 usecs */
297static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
298static int min_wakeup_granularity_ns; /* 0 usecs */
299static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200300#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100301static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
302static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200303#endif /* CONFIG_SMP */
304#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200305
Mel Gorman5e771902010-05-24 14:32:31 -0700306#ifdef CONFIG_COMPACTION
307static int min_extfrag_threshold;
308static int max_extfrag_threshold = 1000;
309#endif
310
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700311static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200312 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200313 .procname = "sched_child_runs_first",
314 .data = &sysctl_sched_child_runs_first,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800317 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200318 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200319#ifdef CONFIG_SCHED_DEBUG
320 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100321 .procname = "sched_min_granularity_ns",
322 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800325 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100326 .extra1 = &min_sched_granularity_ns,
327 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200328 },
329 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200330 .procname = "sched_latency_ns",
331 .data = &sysctl_sched_latency,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800334 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200335 .extra1 = &min_sched_granularity_ns,
336 .extra2 = &max_sched_granularity_ns,
337 },
338 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200339 .procname = "sched_wakeup_granularity_ns",
340 .data = &sysctl_sched_wakeup_granularity,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800343 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200344 .extra1 = &min_wakeup_granularity_ns,
345 .extra2 = &max_wakeup_granularity_ns,
346 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200347#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200348 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100349 .procname = "sched_tunable_scaling",
350 .data = &sysctl_sched_tunable_scaling,
351 .maxlen = sizeof(enum sched_tunable_scaling),
352 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800353 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100354 .extra1 = &min_sched_tunable_scaling,
355 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200356 },
357 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900358 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200359 .data = &sysctl_sched_migration_cost,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800362 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200363 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100364 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100365 .procname = "sched_nr_migrate",
366 .data = &sysctl_sched_nr_migrate,
367 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800369 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100370 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530371 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900372 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200373 .data = &sysctl_sched_time_avg,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
Ethan Zhao5ccba442017-09-04 13:59:34 +0800376 .proc_handler = proc_dointvec_minmax,
377 .extra1 = &one,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200378 },
Mel Gormancb251762016-02-05 09:08:36 +0000379#ifdef CONFIG_SCHEDSTATS
380 {
381 .procname = "sched_schedstats",
382 .data = NULL,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = sysctl_schedstats,
386 .extra1 = &zero,
387 .extra2 = &one,
388 },
389#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200390#endif /* CONFIG_SMP */
391#ifdef CONFIG_NUMA_BALANCING
392 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200393 .procname = "numa_balancing_scan_delay_ms",
394 .data = &sysctl_numa_balancing_scan_delay,
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
398 },
399 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200400 .procname = "numa_balancing_scan_period_min_ms",
401 .data = &sysctl_numa_balancing_scan_period_min,
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = proc_dointvec,
405 },
406 {
407 .procname = "numa_balancing_scan_period_max_ms",
408 .data = &sysctl_numa_balancing_scan_period_max,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
411 .proc_handler = proc_dointvec,
412 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200413 {
414 .procname = "numa_balancing_scan_size_mb",
415 .data = &sysctl_numa_balancing_scan_size,
416 .maxlen = sizeof(unsigned int),
417 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400418 .proc_handler = proc_dointvec_minmax,
419 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200420 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100421 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800422 .procname = "numa_balancing",
423 .data = NULL, /* filled in by handler */
424 .maxlen = sizeof(unsigned int),
425 .mode = 0644,
426 .proc_handler = sysctl_numa_balancing,
427 .extra1 = &zero,
428 .extra2 = &one,
429 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200430#endif /* CONFIG_NUMA_BALANCING */
431#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200432 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100433 .procname = "sched_rt_period_us",
434 .data = &sysctl_sched_rt_period,
435 .maxlen = sizeof(unsigned int),
436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800437 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100438 },
439 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100440 .procname = "sched_rt_runtime_us",
441 .data = &sysctl_sched_rt_runtime,
442 .maxlen = sizeof(int),
443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800444 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100445 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600446 {
447 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800448 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600449 .maxlen = sizeof(int),
450 .mode = 0644,
451 .proc_handler = sched_rr_handler,
452 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100453#ifdef CONFIG_SCHED_AUTOGROUP
454 {
455 .procname = "sched_autogroup_enabled",
456 .data = &sysctl_sched_autogroup_enabled,
457 .maxlen = sizeof(unsigned int),
458 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800459 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100460 .extra1 = &zero,
461 .extra2 = &one,
462 },
463#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700464#ifdef CONFIG_CFS_BANDWIDTH
465 {
466 .procname = "sched_cfs_bandwidth_slice_us",
467 .data = &sysctl_sched_cfs_bandwidth_slice,
468 .maxlen = sizeof(unsigned int),
469 .mode = 0644,
470 .proc_handler = proc_dointvec_minmax,
471 .extra1 = &one,
472 },
473#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700474#ifdef CONFIG_PROVE_LOCKING
475 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700476 .procname = "prove_locking",
477 .data = &prove_locking,
478 .maxlen = sizeof(int),
479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800480 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700481 },
482#endif
483#ifdef CONFIG_LOCK_STAT
484 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700485 .procname = "lock_stat",
486 .data = &lock_stat,
487 .maxlen = sizeof(int),
488 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800489 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700490 },
491#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .procname = "panic",
494 .data = &panic_timeout,
495 .maxlen = sizeof(int),
496 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800497 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 },
Alex Kelly046d6622012-10-04 17:15:23 -0700499#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "core_uses_pid",
502 .data = &core_uses_pid,
503 .maxlen = sizeof(int),
504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800505 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .procname = "core_pattern",
509 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700510 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700512 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
Neil Hormana2939802009-09-23 15:56:56 -0700514 {
Neil Hormana2939802009-09-23 15:56:56 -0700515 .procname = "core_pipe_limit",
516 .data = &core_pipe_limit,
517 .maxlen = sizeof(unsigned int),
518 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800519 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700520 },
Alex Kelly046d6622012-10-04 17:15:23 -0700521#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800522#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700525 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800526 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800527 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700529 {
530 .procname = "sysctl_writes_strict",
531 .data = &sysctl_writes_strict,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = proc_dointvec_minmax,
535 .extra1 = &neg_one,
536 .extra2 = &one,
537 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800538#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100539#ifdef CONFIG_LATENCYTOP
540 {
541 .procname = "latencytop",
542 .data = &latencytop_enabled,
543 .maxlen = sizeof(int),
544 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000545 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100546 },
547#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#ifdef CONFIG_BLK_DEV_INITRD
549 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 .procname = "real-root-dev",
551 .data = &real_root_dev,
552 .maxlen = sizeof(int),
553 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800554 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 },
556#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700557 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700558 .procname = "print-fatal-signals",
559 .data = &print_fatal_signals,
560 .maxlen = sizeof(int),
561 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800562 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700563 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700564#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .procname = "reboot-cmd",
567 .data = reboot_command,
568 .maxlen = 256,
569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800570 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 },
572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "stop-a",
574 .data = &stop_a_enabled,
575 .maxlen = sizeof (int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "scons-poweroff",
581 .data = &scons_pwroff,
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#endif
David S. Miller08714202008-11-16 23:49:24 -0800587#ifdef CONFIG_SPARC64
588 {
David S. Miller08714202008-11-16 23:49:24 -0800589 .procname = "tsb-ratio",
590 .data = &sysctl_tsb_ratio,
591 .maxlen = sizeof (int),
592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800593 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800594 },
595#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#ifdef __hppa__
597 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .procname = "soft-power",
599 .data = &pwrsw_enabled,
600 .maxlen = sizeof (int),
601 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800602 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530604#endif
605#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "unaligned-trap",
608 .data = &unaligned_enabled,
609 .maxlen = sizeof (int),
610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 },
613#endif
614 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 .procname = "ctrl-alt-del",
616 .data = &C_A_D,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800619 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400621#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200622 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200623 .procname = "ftrace_enabled",
624 .data = &ftrace_enabled,
625 .maxlen = sizeof(int),
626 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800627 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200628 },
629#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500630#ifdef CONFIG_STACK_TRACER
631 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500632 .procname = "stack_tracer_enabled",
633 .data = &stack_tracer_enabled,
634 .maxlen = sizeof(int),
635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800636 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500637 },
638#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400639#ifdef CONFIG_TRACING
640 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100641 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400642 .data = &ftrace_dump_on_oops,
643 .maxlen = sizeof(int),
644 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800645 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400646 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400647 {
648 .procname = "traceoff_on_warning",
649 .data = &__disable_trace_on_warning,
650 .maxlen = sizeof(__disable_trace_on_warning),
651 .mode = 0644,
652 .proc_handler = proc_dointvec,
653 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500654 {
655 .procname = "tracepoint_printk",
656 .data = &tracepoint_printk,
657 .maxlen = sizeof(tracepoint_printk),
658 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500659 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500660 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400661#endif
Dave Young2965faa2015-09-09 15:38:55 -0700662#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800663 {
664 .procname = "kexec_load_disabled",
665 .data = &kexec_load_disabled,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 /* only handle a transition from default "0" to "1" */
669 .proc_handler = proc_dointvec_minmax,
670 .extra1 = &one,
671 .extra2 = &one,
672 },
673#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200674#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .procname = "modprobe",
677 .data = &modprobe_path,
678 .maxlen = KMOD_PATH_LEN,
679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 },
Kees Cook3d433212009-04-02 15:49:29 -0700682 {
Kees Cook3d433212009-04-02 15:49:29 -0700683 .procname = "modules_disabled",
684 .data = &modules_disabled,
685 .maxlen = sizeof(int),
686 .mode = 0644,
687 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800688 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700689 .extra1 = &one,
690 .extra2 = &one,
691 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700693#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100696 .data = &uevent_helper,
697 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800699 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 },
Michael Marineau86d56132014-04-10 14:09:31 -0700701#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702#ifdef CONFIG_CHR_DEV_SG
703 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .procname = "sg-big-buff",
705 .data = &sg_big_buff,
706 .maxlen = sizeof (int),
707 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800708 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 },
710#endif
711#ifdef CONFIG_BSD_PROCESS_ACCT
712 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .procname = "acct",
714 .data = &acct_parm,
715 .maxlen = 3*sizeof(int),
716 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800717 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 },
719#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720#ifdef CONFIG_MAGIC_SYSRQ
721 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800723 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .maxlen = sizeof (int),
725 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700726 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 },
728#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700729#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700732 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 .maxlen = sizeof (int),
734 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800735 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700737#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700740 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 .maxlen = sizeof(int),
742 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700743 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 },
745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .procname = "random",
747 .mode = 0555,
748 .child = random_table,
749 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 {
Eric Paris17f60a72011-04-01 17:07:50 -0400751 .procname = "usermodehelper",
752 .mode = 0555,
753 .child = usermodehelper_table,
754 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800755#ifdef CONFIG_FW_LOADER_USER_HELPER
756 {
757 .procname = "firmware_config",
758 .mode = 0555,
759 .child = firmware_config_table,
760 },
761#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400762 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 .procname = "overflowuid",
764 .data = &overflowuid,
765 .maxlen = sizeof(int),
766 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800767 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 .extra1 = &minolduid,
769 .extra2 = &maxolduid,
770 },
771 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 .procname = "overflowgid",
773 .data = &overflowgid,
774 .maxlen = sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 .extra1 = &minolduid,
778 .extra2 = &maxolduid,
779 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800780#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781#ifdef CONFIG_MATHEMU
782 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .procname = "ieee_emulation_warnings",
784 .data = &sysctl_ieee_emulation_warnings,
785 .maxlen = sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 },
789#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200792 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 .maxlen = sizeof(int),
794 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800795 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 },
797#endif
798 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .procname = "pid_max",
800 .data = &pid_max,
801 .maxlen = sizeof (int),
802 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800803 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 .extra1 = &pid_max_min,
805 .extra2 = &pid_max_max,
806 },
807 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .procname = "panic_on_oops",
809 .data = &panic_on_oops,
810 .maxlen = sizeof(int),
811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800812 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800814#if defined CONFIG_PRINTK
815 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800816 .procname = "printk",
817 .data = &console_loglevel,
818 .maxlen = 4*sizeof(int),
819 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800820 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800821 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700824 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 .maxlen = sizeof(int),
826 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 },
829 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700831 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 .maxlen = sizeof(int),
833 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800834 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 },
Dave Youngaf913222009-09-22 16:43:33 -0700836 {
Dave Youngaf913222009-09-22 16:43:33 -0700837 .procname = "printk_delay",
838 .data = &printk_delay_msec,
839 .maxlen = sizeof(int),
840 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800841 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700842 .extra1 = &zero,
843 .extra2 = &ten_thousand,
844 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700846 .procname = "printk_devkmsg",
847 .data = devkmsg_log_str,
848 .maxlen = DEVKMSG_STR_MAX_SIZE,
849 .mode = 0644,
850 .proc_handler = devkmsg_sysctl_set_loglvl,
851 },
852 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800853 .procname = "dmesg_restrict",
854 .data = &dmesg_restrict,
855 .maxlen = sizeof(int),
856 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700857 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800858 .extra1 = &zero,
859 .extra2 = &one,
860 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800861 {
862 .procname = "kptr_restrict",
863 .data = &kptr_restrict,
864 .maxlen = sizeof(int),
865 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700866 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800867 .extra1 = &zero,
868 .extra2 = &two,
869 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800870#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800871 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 .procname = "ngroups_max",
873 .data = &ngroups_max,
874 .maxlen = sizeof (int),
875 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800876 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 },
Dan Ballard73efc032011-10-31 17:11:20 -0700878 {
879 .procname = "cap_last_cap",
880 .data = (void *)&cap_last_cap,
881 .maxlen = sizeof(int),
882 .mode = 0444,
883 .proc_handler = proc_dointvec,
884 },
Don Zickus58687ac2010-05-07 17:11:44 -0400885#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500886 {
Don Zickus58687ac2010-05-07 17:11:44 -0400887 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200888 .data = &watchdog_user_enabled,
889 .maxlen = sizeof(int),
890 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700891 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700892 .extra1 = &zero,
893 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400894 },
895 {
896 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700897 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400898 .maxlen = sizeof(int),
899 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700900 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800901 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400902 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500903 },
Don Zickus2508ce12010-05-07 17:11:46 -0400904 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700905 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200906 .data = &nmi_watchdog_user_enabled,
907 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200908 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700909 .proc_handler = proc_nmi_watchdog,
910 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700911 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700912 },
913 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700914 .procname = "watchdog_cpumask",
915 .data = &watchdog_cpumask_bits,
916 .maxlen = NR_CPUS,
917 .mode = 0644,
918 .proc_handler = proc_watchdog_cpumask,
919 },
920#ifdef CONFIG_SOFTLOCKUP_DETECTOR
921 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700922 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200923 .data = &soft_watchdog_user_enabled,
924 .maxlen = sizeof(int),
925 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700926 .proc_handler = proc_soft_watchdog,
927 .extra1 = &zero,
928 .extra2 = &one,
929 },
930 {
Don Zickus2508ce12010-05-07 17:11:46 -0400931 .procname = "softlockup_panic",
932 .data = &softlockup_panic,
933 .maxlen = sizeof(int),
934 .mode = 0644,
935 .proc_handler = proc_dointvec_minmax,
936 .extra1 = &zero,
937 .extra2 = &one,
938 },
Aaron Tomlined235872014-06-23 13:22:05 -0700939#ifdef CONFIG_SMP
940 {
941 .procname = "softlockup_all_cpu_backtrace",
942 .data = &sysctl_softlockup_all_cpu_backtrace,
943 .maxlen = sizeof(int),
944 .mode = 0644,
945 .proc_handler = proc_dointvec_minmax,
946 .extra1 = &zero,
947 .extra2 = &one,
948 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700949#endif /* CONFIG_SMP */
950#endif
951#ifdef CONFIG_HARDLOCKUP_DETECTOR
952 {
953 .procname = "hardlockup_panic",
954 .data = &hardlockup_panic,
955 .maxlen = sizeof(int),
956 .mode = 0644,
957 .proc_handler = proc_dointvec_minmax,
958 .extra1 = &zero,
959 .extra2 = &one,
960 },
961#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800962 {
963 .procname = "hardlockup_all_cpu_backtrace",
964 .data = &sysctl_hardlockup_all_cpu_backtrace,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec_minmax,
968 .extra1 = &zero,
969 .extra2 = &one,
970 },
Aaron Tomlined235872014-06-23 13:22:05 -0700971#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500972#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700973#endif
974
Don Zickus5dc30552010-11-29 17:07:17 -0500975#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
976 {
977 .procname = "unknown_nmi_panic",
978 .data = &unknown_nmi_panic,
979 .maxlen = sizeof (int),
980 .mode = 0644,
981 .proc_handler = proc_dointvec,
982 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500983#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984#if defined(CONFIG_X86)
985 {
Don Zickus8da5add2006-09-26 10:52:27 +0200986 .procname = "panic_on_unrecovered_nmi",
987 .data = &panic_on_unrecovered_nmi,
988 .maxlen = sizeof(int),
989 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800990 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200991 },
992 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700993 .procname = "panic_on_io_nmi",
994 .data = &panic_on_io_nmi,
995 .maxlen = sizeof(int),
996 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800997 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700998 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900999#ifdef CONFIG_DEBUG_STACKOVERFLOW
1000 {
1001 .procname = "panic_on_stackoverflow",
1002 .data = &sysctl_panic_on_stackoverflow,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
1005 .proc_handler = proc_dointvec,
1006 },
1007#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001008 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 .procname = "bootloader_type",
1010 .data = &bootloader_type,
1011 .maxlen = sizeof (int),
1012 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001013 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001015 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001016 .procname = "bootloader_version",
1017 .data = &bootloader_version,
1018 .maxlen = sizeof (int),
1019 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001020 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001021 },
1022 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001023 .procname = "io_delay_type",
1024 .data = &io_delay_type,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001027 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001028 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001030#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 .procname = "randomize_va_space",
1033 .data = &randomize_va_space,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001036 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001038#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001039#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001040 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001041 .procname = "spin_retry",
1042 .data = &spin_retry,
1043 .maxlen = sizeof (int),
1044 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001045 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001046 },
1047#endif
Len Brown673d5b42007-07-28 03:33:16 -04001048#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001049 {
Pavel Machekc255d842006-02-20 18:27:58 -08001050 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001051 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001052 .maxlen = sizeof (unsigned long),
1053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001055 },
1056#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301057#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001058 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001059 .procname = "ignore-unaligned-usertrap",
1060 .data = &no_unaligned_warning,
1061 .maxlen = sizeof (int),
1062 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001064 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301065#endif
1066#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001067 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001068 .procname = "unaligned-dump-stack",
1069 .data = &unaligned_dump_stack,
1070 .maxlen = sizeof (int),
1071 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001072 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001073 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001074#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001075#ifdef CONFIG_DETECT_HUNG_TASK
1076 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001077 .procname = "hung_task_panic",
1078 .data = &sysctl_hung_task_panic,
1079 .maxlen = sizeof(int),
1080 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001081 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001082 .extra1 = &zero,
1083 .extra2 = &one,
1084 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001085 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001086 .procname = "hung_task_check_count",
1087 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001088 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001089 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001090 .proc_handler = proc_dointvec_minmax,
1091 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001092 },
1093 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001094 .procname = "hung_task_timeout_secs",
1095 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001096 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001097 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001098 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001099 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001100 },
1101 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001102 .procname = "hung_task_warnings",
1103 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001104 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001105 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001106 .proc_handler = proc_dointvec_minmax,
1107 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001108 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001109#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001110#ifdef CONFIG_RT_MUTEXES
1111 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001112 .procname = "max_lock_depth",
1113 .data = &max_lock_depth,
1114 .maxlen = sizeof(int),
1115 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001116 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001117 },
1118#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001119 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001120 .procname = "poweroff_cmd",
1121 .data = &poweroff_cmd,
1122 .maxlen = POWEROFF_CMD_PATH_LEN,
1123 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001124 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001125 },
David Howells0b77f5b2008-04-29 01:01:32 -07001126#ifdef CONFIG_KEYS
1127 {
David Howells0b77f5b2008-04-29 01:01:32 -07001128 .procname = "keys",
1129 .mode = 0555,
1130 .child = key_sysctls,
1131 },
1132#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001133#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001134 /*
1135 * User-space scripts rely on the existence of this file
1136 * as a feature check for perf_events being enabled.
1137 *
1138 * So it's an ABI, do not remove!
1139 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001140 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001141 .procname = "perf_event_paranoid",
1142 .data = &sysctl_perf_event_paranoid,
1143 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001144 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001145 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001146 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001147 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001148 .procname = "perf_event_mlock_kb",
1149 .data = &sysctl_perf_event_mlock,
1150 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001151 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001152 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001153 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001154 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001155 .procname = "perf_event_max_sample_rate",
1156 .data = &sysctl_perf_event_sample_rate,
1157 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001158 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001159 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001160 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001161 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001162 {
1163 .procname = "perf_cpu_time_max_percent",
1164 .data = &sysctl_perf_cpu_time_max_percent,
1165 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1166 .mode = 0644,
1167 .proc_handler = perf_cpu_time_max_percent_handler,
1168 .extra1 = &zero,
1169 .extra2 = &one_hundred,
1170 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001171 {
1172 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001173 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001174 .maxlen = sizeof(sysctl_perf_event_max_stack),
1175 .mode = 0644,
1176 .proc_handler = perf_event_max_stack_handler,
1177 .extra1 = &zero,
1178 .extra2 = &six_hundred_forty_kb,
1179 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001180 {
1181 .procname = "perf_event_max_contexts_per_stack",
1182 .data = &sysctl_perf_event_max_contexts_per_stack,
1183 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1184 .mode = 0644,
1185 .proc_handler = perf_event_max_stack_handler,
1186 .extra1 = &zero,
1187 .extra2 = &one_thousand,
1188 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001189#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001190 {
1191 .procname = "panic_on_warn",
1192 .data = &panic_on_warn,
1193 .maxlen = sizeof(int),
1194 .mode = 0644,
1195 .proc_handler = proc_dointvec_minmax,
1196 .extra1 = &zero,
1197 .extra2 = &one,
1198 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001199#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1200 {
1201 .procname = "timer_migration",
1202 .data = &sysctl_timer_migration,
1203 .maxlen = sizeof(unsigned int),
1204 .mode = 0644,
1205 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001206 .extra1 = &zero,
1207 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001208 },
1209#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001210#ifdef CONFIG_BPF_SYSCALL
1211 {
1212 .procname = "unprivileged_bpf_disabled",
1213 .data = &sysctl_unprivileged_bpf_disabled,
1214 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1215 .mode = 0644,
1216 /* only handle a transition from default "0" to "1" */
1217 .proc_handler = proc_dointvec_minmax,
1218 .extra1 = &one,
1219 .extra2 = &one,
1220 },
1221#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001222#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1223 {
1224 .procname = "panic_on_rcu_stall",
1225 .data = &sysctl_panic_on_rcu_stall,
1226 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec_minmax,
1229 .extra1 = &zero,
1230 .extra2 = &one,
1231 },
1232#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001233 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234};
1235
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001236static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 .procname = "overcommit_memory",
1239 .data = &sysctl_overcommit_memory,
1240 .maxlen = sizeof(sysctl_overcommit_memory),
1241 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001242 .proc_handler = proc_dointvec_minmax,
1243 .extra1 = &zero,
1244 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 },
1246 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001247 .procname = "panic_on_oom",
1248 .data = &sysctl_panic_on_oom,
1249 .maxlen = sizeof(sysctl_panic_on_oom),
1250 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001251 .proc_handler = proc_dointvec_minmax,
1252 .extra1 = &zero,
1253 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001254 },
1255 {
David Rientjesfe071d72007-10-16 23:25:56 -07001256 .procname = "oom_kill_allocating_task",
1257 .data = &sysctl_oom_kill_allocating_task,
1258 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1259 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001260 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001261 },
1262 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001263 .procname = "oom_dump_tasks",
1264 .data = &sysctl_oom_dump_tasks,
1265 .maxlen = sizeof(sysctl_oom_dump_tasks),
1266 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001267 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001268 },
1269 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 .procname = "overcommit_ratio",
1271 .data = &sysctl_overcommit_ratio,
1272 .maxlen = sizeof(sysctl_overcommit_ratio),
1273 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001274 .proc_handler = overcommit_ratio_handler,
1275 },
1276 {
1277 .procname = "overcommit_kbytes",
1278 .data = &sysctl_overcommit_kbytes,
1279 .maxlen = sizeof(sysctl_overcommit_kbytes),
1280 .mode = 0644,
1281 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 },
1283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 .procname = "page-cluster",
1285 .data = &page_cluster,
1286 .maxlen = sizeof(int),
1287 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001288 .proc_handler = proc_dointvec_minmax,
1289 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 },
1291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 .procname = "dirty_background_ratio",
1293 .data = &dirty_background_ratio,
1294 .maxlen = sizeof(dirty_background_ratio),
1295 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001296 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 .extra1 = &zero,
1298 .extra2 = &one_hundred,
1299 },
1300 {
David Rientjes2da02992009-01-06 14:39:31 -08001301 .procname = "dirty_background_bytes",
1302 .data = &dirty_background_bytes,
1303 .maxlen = sizeof(dirty_background_bytes),
1304 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001305 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001306 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001307 },
1308 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 .procname = "dirty_ratio",
1310 .data = &vm_dirty_ratio,
1311 .maxlen = sizeof(vm_dirty_ratio),
1312 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001313 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 .extra1 = &zero,
1315 .extra2 = &one_hundred,
1316 },
1317 {
David Rientjes2da02992009-01-06 14:39:31 -08001318 .procname = "dirty_bytes",
1319 .data = &vm_dirty_bytes,
1320 .maxlen = sizeof(vm_dirty_bytes),
1321 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001322 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001323 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001324 },
1325 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001327 .data = &dirty_writeback_interval,
1328 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001330 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 },
1332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001334 .data = &dirty_expire_interval,
1335 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 },
1340 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001341 .procname = "dirtytime_expire_seconds",
1342 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001343 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001344 .mode = 0644,
1345 .proc_handler = dirtytime_interval_handler,
1346 .extra1 = &zero,
1347 },
1348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 .procname = "swappiness",
1350 .data = &vm_swappiness,
1351 .maxlen = sizeof(vm_swappiness),
1352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .extra1 = &zero,
1355 .extra2 = &one_hundred,
1356 },
1357#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001358 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001360 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .maxlen = sizeof(unsigned long),
1362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001364 },
1365#ifdef CONFIG_NUMA
1366 {
1367 .procname = "nr_hugepages_mempolicy",
1368 .data = NULL,
1369 .maxlen = sizeof(unsigned long),
1370 .mode = 0644,
1371 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001372 },
Kemi Wang45180852017-11-15 17:38:22 -08001373 {
1374 .procname = "numa_stat",
1375 .data = &sysctl_vm_numa_stat,
1376 .maxlen = sizeof(int),
1377 .mode = 0644,
1378 .proc_handler = sysctl_vm_numa_stat_handler,
1379 .extra1 = &zero,
1380 .extra2 = &one,
1381 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001382#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 .procname = "hugetlb_shm_group",
1385 .data = &sysctl_hugetlb_shm_group,
1386 .maxlen = sizeof(gid_t),
1387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001388 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 },
Adam Litke54f9f802007-10-16 01:26:20 -07001390 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001391 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001392 .data = NULL,
1393 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001395 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001396 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397#endif
1398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "lowmem_reserve_ratio",
1400 .data = &sysctl_lowmem_reserve_ratio,
1401 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 },
1405 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001406 .procname = "drop_caches",
1407 .data = &sysctl_drop_caches,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
1410 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001411 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001412 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001413 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001414#ifdef CONFIG_COMPACTION
1415 {
1416 .procname = "compact_memory",
1417 .data = &sysctl_compact_memory,
1418 .maxlen = sizeof(int),
1419 .mode = 0200,
1420 .proc_handler = sysctl_compaction_handler,
1421 },
Mel Gorman5e771902010-05-24 14:32:31 -07001422 {
1423 .procname = "extfrag_threshold",
1424 .data = &sysctl_extfrag_threshold,
1425 .maxlen = sizeof(int),
1426 .mode = 0644,
1427 .proc_handler = sysctl_extfrag_handler,
1428 .extra1 = &min_extfrag_threshold,
1429 .extra2 = &max_extfrag_threshold,
1430 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001431 {
1432 .procname = "compact_unevictable_allowed",
1433 .data = &sysctl_compact_unevictable_allowed,
1434 .maxlen = sizeof(int),
1435 .mode = 0644,
1436 .proc_handler = proc_dointvec,
1437 .extra1 = &zero,
1438 .extra2 = &one,
1439 },
Mel Gorman5e771902010-05-24 14:32:31 -07001440
Mel Gorman76ab0f52010-05-24 14:32:28 -07001441#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 .procname = "min_free_kbytes",
1444 .data = &min_free_kbytes,
1445 .maxlen = sizeof(min_free_kbytes),
1446 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001447 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .extra1 = &zero,
1449 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001450 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001451 .procname = "watermark_scale_factor",
1452 .data = &watermark_scale_factor,
1453 .maxlen = sizeof(watermark_scale_factor),
1454 .mode = 0644,
1455 .proc_handler = watermark_scale_factor_sysctl_handler,
1456 .extra1 = &one,
1457 .extra2 = &one_thousand,
1458 },
1459 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001460 .procname = "percpu_pagelist_fraction",
1461 .data = &percpu_pagelist_fraction,
1462 .maxlen = sizeof(percpu_pagelist_fraction),
1463 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001464 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001465 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001466 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467#ifdef CONFIG_MMU
1468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 .procname = "max_map_count",
1470 .data = &sysctl_max_map_count,
1471 .maxlen = sizeof(sysctl_max_map_count),
1472 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001473 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001474 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001476#else
1477 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001478 .procname = "nr_trim_pages",
1479 .data = &sysctl_nr_trim_pages,
1480 .maxlen = sizeof(sysctl_nr_trim_pages),
1481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001482 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001483 .extra1 = &zero,
1484 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485#endif
1486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 .procname = "laptop_mode",
1488 .data = &laptop_mode,
1489 .maxlen = sizeof(laptop_mode),
1490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001491 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 },
1493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 .procname = "block_dump",
1495 .data = &block_dump,
1496 .maxlen = sizeof(block_dump),
1497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 .extra1 = &zero,
1500 },
1501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 .procname = "vfs_cache_pressure",
1503 .data = &sysctl_vfs_cache_pressure,
1504 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001506 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 .extra1 = &zero,
1508 },
1509#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1510 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 .procname = "legacy_va_layout",
1512 .data = &sysctl_legacy_va_layout,
1513 .maxlen = sizeof(sysctl_legacy_va_layout),
1514 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001515 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 .extra1 = &zero,
1517 },
1518#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001519#ifdef CONFIG_NUMA
1520 {
Christoph Lameter17436602006-01-18 17:42:32 -08001521 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001522 .data = &node_reclaim_mode,
1523 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001525 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001526 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001527 },
Christoph Lameter96146342006-07-03 00:24:13 -07001528 {
Christoph Lameter96146342006-07-03 00:24:13 -07001529 .procname = "min_unmapped_ratio",
1530 .data = &sysctl_min_unmapped_ratio,
1531 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001533 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001534 .extra1 = &zero,
1535 .extra2 = &one_hundred,
1536 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001537 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001538 .procname = "min_slab_ratio",
1539 .data = &sysctl_min_slab_ratio,
1540 .maxlen = sizeof(sysctl_min_slab_ratio),
1541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001542 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001543 .extra1 = &zero,
1544 .extra2 = &one_hundred,
1545 },
Christoph Lameter17436602006-01-18 17:42:32 -08001546#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001547#ifdef CONFIG_SMP
1548 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001549 .procname = "stat_interval",
1550 .data = &sysctl_stat_interval,
1551 .maxlen = sizeof(sysctl_stat_interval),
1552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001553 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001554 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001555 {
1556 .procname = "stat_refresh",
1557 .data = NULL,
1558 .maxlen = 0,
1559 .mode = 0600,
1560 .proc_handler = vmstat_refresh,
1561 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001562#endif
David Howells6e141542009-12-15 19:27:45 +00001563#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001564 {
Eric Parised032182007-06-28 15:55:21 -04001565 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001566 .data = &dac_mmap_min_addr,
1567 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001569 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001570 },
David Howells6e141542009-12-15 19:27:45 +00001571#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001572#ifdef CONFIG_NUMA
1573 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001574 .procname = "numa_zonelist_order",
1575 .data = &numa_zonelist_order,
1576 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001578 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001579 },
1580#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001581#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001582 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001583 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001584 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001585#ifdef CONFIG_X86_32
1586 .data = &vdso32_enabled,
1587 .maxlen = sizeof(vdso32_enabled),
1588#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001589 .data = &vdso_enabled,
1590 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001591#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001593 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001594 .extra1 = &zero,
1595 },
1596#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001597#ifdef CONFIG_HIGHMEM
1598 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001599 .procname = "highmem_is_dirtyable",
1600 .data = &vm_highmem_is_dirtyable,
1601 .maxlen = sizeof(vm_highmem_is_dirtyable),
1602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001603 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001604 .extra1 = &zero,
1605 .extra2 = &one,
1606 },
1607#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001608#ifdef CONFIG_MEMORY_FAILURE
1609 {
Andi Kleen6a460792009-09-16 11:50:15 +02001610 .procname = "memory_failure_early_kill",
1611 .data = &sysctl_memory_failure_early_kill,
1612 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1613 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001614 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001615 .extra1 = &zero,
1616 .extra2 = &one,
1617 },
1618 {
Andi Kleen6a460792009-09-16 11:50:15 +02001619 .procname = "memory_failure_recovery",
1620 .data = &sysctl_memory_failure_recovery,
1621 .maxlen = sizeof(sysctl_memory_failure_recovery),
1622 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001623 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001624 .extra1 = &zero,
1625 .extra2 = &one,
1626 },
1627#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001628 {
1629 .procname = "user_reserve_kbytes",
1630 .data = &sysctl_user_reserve_kbytes,
1631 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1632 .mode = 0644,
1633 .proc_handler = proc_doulongvec_minmax,
1634 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001635 {
1636 .procname = "admin_reserve_kbytes",
1637 .data = &sysctl_admin_reserve_kbytes,
1638 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1639 .mode = 0644,
1640 .proc_handler = proc_doulongvec_minmax,
1641 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001642#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1643 {
1644 .procname = "mmap_rnd_bits",
1645 .data = &mmap_rnd_bits,
1646 .maxlen = sizeof(mmap_rnd_bits),
1647 .mode = 0600,
1648 .proc_handler = proc_dointvec_minmax,
1649 .extra1 = (void *)&mmap_rnd_bits_min,
1650 .extra2 = (void *)&mmap_rnd_bits_max,
1651 },
1652#endif
1653#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1654 {
1655 .procname = "mmap_rnd_compat_bits",
1656 .data = &mmap_rnd_compat_bits,
1657 .maxlen = sizeof(mmap_rnd_compat_bits),
1658 .mode = 0600,
1659 .proc_handler = proc_dointvec_minmax,
1660 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1661 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1662 },
1663#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001664 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665};
1666
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001667static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 .procname = "inode-nr",
1670 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001671 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001673 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 },
1675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 .procname = "inode-state",
1677 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001678 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001680 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 },
1682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 .procname = "file-nr",
1684 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001685 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001687 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 },
1689 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 .procname = "file-max",
1691 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001692 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001694 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 },
1696 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001697 .procname = "nr_open",
1698 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001699 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001700 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001701 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001702 .extra1 = &sysctl_nr_open_min,
1703 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001704 },
1705 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 .procname = "dentry-state",
1707 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001708 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001710 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 },
1712 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 .procname = "overflowuid",
1714 .data = &fs_overflowuid,
1715 .maxlen = sizeof(int),
1716 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001717 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 .extra1 = &minolduid,
1719 .extra2 = &maxolduid,
1720 },
1721 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 .procname = "overflowgid",
1723 .data = &fs_overflowgid,
1724 .maxlen = sizeof(int),
1725 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001726 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 .extra1 = &minolduid,
1728 .extra2 = &maxolduid,
1729 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001730#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 .procname = "leases-enable",
1733 .data = &leases_enable,
1734 .maxlen = sizeof(int),
1735 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001736 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001738#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739#ifdef CONFIG_DNOTIFY
1740 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 .procname = "dir-notify-enable",
1742 .data = &dir_notify_enable,
1743 .maxlen = sizeof(int),
1744 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001745 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 },
1747#endif
1748#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001749#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 .procname = "lease-break-time",
1752 .data = &lease_break_time,
1753 .maxlen = sizeof(int),
1754 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001755 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001757#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001758#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 .procname = "aio-nr",
1761 .data = &aio_nr,
1762 .maxlen = sizeof(aio_nr),
1763 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001764 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 },
1766 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 .procname = "aio-max-nr",
1768 .data = &aio_max_nr,
1769 .maxlen = sizeof(aio_max_nr),
1770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001771 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001773#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001774#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001775 {
Robert Love0399cb02005-07-13 12:38:18 -04001776 .procname = "inotify",
1777 .mode = 0555,
1778 .child = inotify_table,
1779 },
1780#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001781#ifdef CONFIG_EPOLL
1782 {
1783 .procname = "epoll",
1784 .mode = 0555,
1785 .child = epoll_table,
1786 },
1787#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001789 {
Kees Cook800179c2012-07-25 17:29:07 -07001790 .procname = "protected_symlinks",
1791 .data = &sysctl_protected_symlinks,
1792 .maxlen = sizeof(int),
1793 .mode = 0600,
1794 .proc_handler = proc_dointvec_minmax,
1795 .extra1 = &zero,
1796 .extra2 = &one,
1797 },
1798 {
1799 .procname = "protected_hardlinks",
1800 .data = &sysctl_protected_hardlinks,
1801 .maxlen = sizeof(int),
1802 .mode = 0600,
1803 .proc_handler = proc_dointvec_minmax,
1804 .extra1 = &zero,
1805 .extra2 = &one,
1806 },
1807 {
Alan Coxd6e71142005-06-23 00:09:43 -07001808 .procname = "suid_dumpable",
1809 .data = &suid_dumpable,
1810 .maxlen = sizeof(int),
1811 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001812 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001813 .extra1 = &zero,
1814 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001815 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001816#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1817 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001818 .procname = "binfmt_misc",
1819 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001820 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001821 },
1822#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001823 {
Jens Axboeff9da692010-06-03 14:54:39 +02001824 .procname = "pipe-max-size",
1825 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001826 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001827 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001828 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001829 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001830 {
1831 .procname = "pipe-user-pages-hard",
1832 .data = &pipe_user_pages_hard,
1833 .maxlen = sizeof(pipe_user_pages_hard),
1834 .mode = 0644,
1835 .proc_handler = proc_doulongvec_minmax,
1836 },
1837 {
1838 .procname = "pipe-user-pages-soft",
1839 .data = &pipe_user_pages_soft,
1840 .maxlen = sizeof(pipe_user_pages_soft),
1841 .mode = 0644,
1842 .proc_handler = proc_doulongvec_minmax,
1843 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001844 {
1845 .procname = "mount-max",
1846 .data = &sysctl_mount_max,
1847 .maxlen = sizeof(unsigned int),
1848 .mode = 0644,
1849 .proc_handler = proc_dointvec_minmax,
1850 .extra1 = &one,
1851 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001852 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853};
1854
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001855static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001856#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001857 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001858 .procname = "exception-trace",
1859 .data = &show_unhandled_signals,
1860 .maxlen = sizeof(int),
1861 .mode = 0644,
1862 .proc_handler = proc_dointvec
1863 },
1864#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001865#if defined(CONFIG_OPTPROBES)
1866 {
1867 .procname = "kprobes-optimization",
1868 .data = &sysctl_kprobes_optimization,
1869 .maxlen = sizeof(int),
1870 .mode = 0644,
1871 .proc_handler = proc_kprobes_optimization_handler,
1872 .extra1 = &zero,
1873 .extra2 = &one,
1874 },
1875#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001876 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877};
1878
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001879static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001880 { }
Robert Love0eeca282005-07-12 17:06:03 -04001881};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001883int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001884{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001885 struct ctl_table_header *hdr;
1886
1887 hdr = register_sysctl_table(sysctl_base_table);
1888 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001889 return 0;
1890}
1891
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001892#endif /* CONFIG_SYSCTL */
1893
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894/*
1895 * /proc/sys support
1896 */
1897
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001898#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Kees Cookf8808302014-06-06 14:37:17 -07001900static int _proc_do_string(char *data, int maxlen, int write,
1901 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001902 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001903{
1904 size_t len;
1905 char __user *p;
1906 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001907
1908 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001909 *lenp = 0;
1910 return 0;
1911 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001912
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001913 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001914 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1915 /* Only continue writes not past the end of buffer. */
1916 len = strlen(data);
1917 if (len > maxlen - 1)
1918 len = maxlen - 1;
1919
1920 if (*ppos > len)
1921 return 0;
1922 len = *ppos;
1923 } else {
1924 /* Start writing from beginning of buffer. */
1925 len = 0;
1926 }
1927
Kees Cook2ca9bb42014-06-06 14:37:18 -07001928 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001929 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001930 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001931 if (get_user(c, p++))
1932 return -EFAULT;
1933 if (c == 0 || c == '\n')
1934 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001935 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001936 }
Kees Cookf8808302014-06-06 14:37:17 -07001937 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001938 } else {
1939 len = strlen(data);
1940 if (len > maxlen)
1941 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001942
1943 if (*ppos > len) {
1944 *lenp = 0;
1945 return 0;
1946 }
1947
1948 data += *ppos;
1949 len -= *ppos;
1950
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001951 if (len > *lenp)
1952 len = *lenp;
1953 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001954 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001955 return -EFAULT;
1956 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001957 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001958 return -EFAULT;
1959 len++;
1960 }
1961 *lenp = len;
1962 *ppos += len;
1963 }
1964 return 0;
1965}
1966
Kees Cookf4aacea2014-06-06 14:37:19 -07001967static void warn_sysctl_write(struct ctl_table *table)
1968{
1969 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1970 "This will not be supported in the future. To silence this\n"
1971 "warning, set kernel.sysctl_writes_strict = -1\n",
1972 current->comm, table->procname);
1973}
1974
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975/**
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001976 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1977 * @ppos: file position
1978 * @table: the sysctl table
1979 *
1980 * Returns true if the first position is non-zero and the sysctl_writes_strict
1981 * mode indicates this is not allowed for numeric input types. String proc
1982 * hadlers can ignore the return value.
1983 */
1984static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
1985 struct ctl_table *table)
1986{
1987 if (!*ppos)
1988 return false;
1989
1990 switch (sysctl_writes_strict) {
1991 case SYSCTL_WRITES_STRICT:
1992 return true;
1993 case SYSCTL_WRITES_WARN:
1994 warn_sysctl_write(table);
1995 return false;
1996 default:
1997 return false;
1998 }
1999}
2000
2001/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 * proc_dostring - read a string sysctl
2003 * @table: the sysctl table
2004 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 * @buffer: the user buffer
2006 * @lenp: the size of the user buffer
2007 * @ppos: file position
2008 *
2009 * Reads/writes a string from/to the user buffer. If the kernel
2010 * buffer provided is not large enough to hold the string, the
2011 * string is truncated. The copied string is %NULL-terminated.
2012 * If the string is being read by the user process, it is copied
2013 * and a newline '\n' is added. It is truncated if the buffer is
2014 * not large enough.
2015 *
2016 * Returns 0 on success.
2017 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002018int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 void __user *buffer, size_t *lenp, loff_t *ppos)
2020{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002021 if (write)
2022 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002023
Kees Cookf8808302014-06-06 14:37:17 -07002024 return _proc_do_string((char *)(table->data), table->maxlen, write,
2025 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026}
2027
Amerigo Wang00b7c332010-05-05 00:26:45 +00002028static size_t proc_skip_spaces(char **buf)
2029{
2030 size_t ret;
2031 char *tmp = skip_spaces(*buf);
2032 ret = tmp - *buf;
2033 *buf = tmp;
2034 return ret;
2035}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002037static void proc_skip_char(char **buf, size_t *size, const char v)
2038{
2039 while (*size) {
2040 if (**buf != v)
2041 break;
2042 (*size)--;
2043 (*buf)++;
2044 }
2045}
2046
Amerigo Wang00b7c332010-05-05 00:26:45 +00002047#define TMPBUFLEN 22
2048/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002049 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002050 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002051 * @buf: a kernel buffer
2052 * @size: size of the kernel buffer
2053 * @val: this is where the number will be stored
2054 * @neg: set to %TRUE if number is negative
2055 * @perm_tr: a vector which contains the allowed trailers
2056 * @perm_tr_len: size of the perm_tr vector
2057 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002058 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002059 * In case of success %0 is returned and @buf and @size are updated with
2060 * the amount of bytes read. If @tr is non-NULL and a trailing
2061 * character exists (size is non-zero after returning from this
2062 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002063 */
2064static int proc_get_long(char **buf, size_t *size,
2065 unsigned long *val, bool *neg,
2066 const char *perm_tr, unsigned perm_tr_len, char *tr)
2067{
2068 int len;
2069 char *p, tmp[TMPBUFLEN];
2070
2071 if (!*size)
2072 return -EINVAL;
2073
2074 len = *size;
2075 if (len > TMPBUFLEN - 1)
2076 len = TMPBUFLEN - 1;
2077
2078 memcpy(tmp, *buf, len);
2079
2080 tmp[len] = 0;
2081 p = tmp;
2082 if (*p == '-' && *size > 1) {
2083 *neg = true;
2084 p++;
2085 } else
2086 *neg = false;
2087 if (!isdigit(*p))
2088 return -EINVAL;
2089
2090 *val = simple_strtoul(p, &p, 0);
2091
2092 len = p - tmp;
2093
2094 /* We don't know if the next char is whitespace thus we may accept
2095 * invalid integers (e.g. 1234...a) or two integers instead of one
2096 * (e.g. 123...1). So lets not allow such large numbers. */
2097 if (len == TMPBUFLEN - 1)
2098 return -EINVAL;
2099
2100 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2101 return -EINVAL;
2102
2103 if (tr && (len < *size))
2104 *tr = *p;
2105
2106 *buf += len;
2107 *size -= len;
2108
2109 return 0;
2110}
2111
2112/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002113 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002114 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002115 * @buf: the user buffer
2116 * @size: the size of the user buffer
2117 * @val: the integer to be converted
2118 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002119 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002120 * In case of success %0 is returned and @buf and @size are updated with
2121 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002122 */
2123static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2124 bool neg)
2125{
2126 int len;
2127 char tmp[TMPBUFLEN], *p = tmp;
2128
2129 sprintf(p, "%s%lu", neg ? "-" : "", val);
2130 len = strlen(tmp);
2131 if (len > *size)
2132 len = *size;
2133 if (copy_to_user(*buf, tmp, len))
2134 return -EFAULT;
2135 *size -= len;
2136 *buf += len;
2137 return 0;
2138}
2139#undef TMPBUFLEN
2140
2141static int proc_put_char(void __user **buf, size_t *size, char c)
2142{
2143 if (*size) {
2144 char __user **buffer = (char __user **)buf;
2145 if (put_user(c, *buffer))
2146 return -EFAULT;
2147 (*size)--, (*buffer)++;
2148 *buf = *buffer;
2149 }
2150 return 0;
2151}
2152
2153static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 int *valp,
2155 int write, void *data)
2156{
2157 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002158 if (*negp) {
2159 if (*lvalp > (unsigned long) INT_MAX + 1)
2160 return -EINVAL;
2161 *valp = -*lvalp;
2162 } else {
2163 if (*lvalp > (unsigned long) INT_MAX)
2164 return -EINVAL;
2165 *valp = *lvalp;
2166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 } else {
2168 int val = *valp;
2169 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002170 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002171 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002173 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 *lvalp = (unsigned long)val;
2175 }
2176 }
2177 return 0;
2178}
2179
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002180static int do_proc_douintvec_conv(unsigned long *lvalp,
2181 unsigned int *valp,
2182 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002183{
2184 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002185 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002186 return -EINVAL;
2187 *valp = *lvalp;
2188 } else {
2189 unsigned int val = *valp;
2190 *lvalp = (unsigned long)val;
2191 }
2192 return 0;
2193}
2194
Amerigo Wang00b7c332010-05-05 00:26:45 +00002195static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2196
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002197static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002198 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002199 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002200 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 int write, void *data),
2202 void *data)
2203{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002204 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002205 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002206 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Amerigo Wang00b7c332010-05-05 00:26:45 +00002208 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 *lenp = 0;
2210 return 0;
2211 }
2212
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002213 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 vleft = table->maxlen / sizeof(*i);
2215 left = *lenp;
2216
2217 if (!conv)
2218 conv = do_proc_dointvec_conv;
2219
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002221 if (proc_first_pos_non_zero_ignore(ppos, table))
2222 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002223
Amerigo Wang00b7c332010-05-05 00:26:45 +00002224 if (left > PAGE_SIZE - 1)
2225 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002226 p = kbuf = memdup_user_nul(buffer, left);
2227 if (IS_ERR(kbuf))
2228 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002229 }
2230
2231 for (; left && vleft--; i++, first=0) {
2232 unsigned long lval;
2233 bool neg;
2234
2235 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002236 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002237
J. R. Okajima563b0462010-05-25 16:10:14 -07002238 if (!left)
2239 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002240 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002241 proc_wspace_sep,
2242 sizeof(proc_wspace_sep), NULL);
2243 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002245 if (conv(&neg, &lval, i, 1, data)) {
2246 err = -EINVAL;
2247 break;
2248 }
2249 } else {
2250 if (conv(&neg, &lval, i, 0, data)) {
2251 err = -EINVAL;
2252 break;
2253 }
2254 if (!first)
2255 err = proc_put_char(&buffer, &left, '\t');
2256 if (err)
2257 break;
2258 err = proc_put_long(&buffer, &left, lval, neg);
2259 if (err)
2260 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 }
2262 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263
2264 if (!write && !first && left && !err)
2265 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002266 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002267 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002269 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 if (first)
2271 return err ? : -EINVAL;
2272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002274out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002276 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002279static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002280 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002282 int write, void *data),
2283 void *data)
2284{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002285 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002286 buffer, lenp, ppos, conv, data);
2287}
2288
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002289static int do_proc_douintvec_w(unsigned int *tbl_data,
2290 struct ctl_table *table,
2291 void __user *buffer,
2292 size_t *lenp, loff_t *ppos,
2293 int (*conv)(unsigned long *lvalp,
2294 unsigned int *valp,
2295 int write, void *data),
2296 void *data)
2297{
2298 unsigned long lval;
2299 int err = 0;
2300 size_t left;
2301 bool neg;
2302 char *kbuf = NULL, *p;
2303
2304 left = *lenp;
2305
2306 if (proc_first_pos_non_zero_ignore(ppos, table))
2307 goto bail_early;
2308
2309 if (left > PAGE_SIZE - 1)
2310 left = PAGE_SIZE - 1;
2311
2312 p = kbuf = memdup_user_nul(buffer, left);
2313 if (IS_ERR(kbuf))
2314 return -EINVAL;
2315
2316 left -= proc_skip_spaces(&p);
2317 if (!left) {
2318 err = -EINVAL;
2319 goto out_free;
2320 }
2321
2322 err = proc_get_long(&p, &left, &lval, &neg,
2323 proc_wspace_sep,
2324 sizeof(proc_wspace_sep), NULL);
2325 if (err || neg) {
2326 err = -EINVAL;
2327 goto out_free;
2328 }
2329
2330 if (conv(&lval, tbl_data, 1, data)) {
2331 err = -EINVAL;
2332 goto out_free;
2333 }
2334
2335 if (!err && left)
2336 left -= proc_skip_spaces(&p);
2337
2338out_free:
2339 kfree(kbuf);
2340 if (err)
2341 return -EINVAL;
2342
2343 return 0;
2344
2345 /* This is in keeping with old __do_proc_dointvec() */
2346bail_early:
2347 *ppos += *lenp;
2348 return err;
2349}
2350
2351static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2352 size_t *lenp, loff_t *ppos,
2353 int (*conv)(unsigned long *lvalp,
2354 unsigned int *valp,
2355 int write, void *data),
2356 void *data)
2357{
2358 unsigned long lval;
2359 int err = 0;
2360 size_t left;
2361
2362 left = *lenp;
2363
2364 if (conv(&lval, tbl_data, 0, data)) {
2365 err = -EINVAL;
2366 goto out;
2367 }
2368
2369 err = proc_put_long(&buffer, &left, lval, false);
2370 if (err || !left)
2371 goto out;
2372
2373 err = proc_put_char(&buffer, &left, '\n');
2374
2375out:
2376 *lenp -= left;
2377 *ppos += *lenp;
2378
2379 return err;
2380}
2381
2382static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2383 int write, void __user *buffer,
2384 size_t *lenp, loff_t *ppos,
2385 int (*conv)(unsigned long *lvalp,
2386 unsigned int *valp,
2387 int write, void *data),
2388 void *data)
2389{
2390 unsigned int *i, vleft;
2391
2392 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2393 *lenp = 0;
2394 return 0;
2395 }
2396
2397 i = (unsigned int *) tbl_data;
2398 vleft = table->maxlen / sizeof(*i);
2399
2400 /*
2401 * Arrays are not supported, keep this simple. *Do not* add
2402 * support for them.
2403 */
2404 if (vleft != 1) {
2405 *lenp = 0;
2406 return -EINVAL;
2407 }
2408
2409 if (!conv)
2410 conv = do_proc_douintvec_conv;
2411
2412 if (write)
2413 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2414 conv, data);
2415 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2416}
2417
2418static int do_proc_douintvec(struct ctl_table *table, int write,
2419 void __user *buffer, size_t *lenp, loff_t *ppos,
2420 int (*conv)(unsigned long *lvalp,
2421 unsigned int *valp,
2422 int write, void *data),
2423 void *data)
2424{
2425 return __do_proc_douintvec(table->data, table, write,
2426 buffer, lenp, ppos, conv, data);
2427}
2428
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429/**
2430 * proc_dointvec - read a vector of integers
2431 * @table: the sysctl table
2432 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 * @buffer: the user buffer
2434 * @lenp: the size of the user buffer
2435 * @ppos: file position
2436 *
2437 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2438 * values from/to the user buffer, treated as an ASCII string.
2439 *
2440 * Returns 0 on success.
2441 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002442int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 void __user *buffer, size_t *lenp, loff_t *ppos)
2444{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002445 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2446}
2447
2448/**
2449 * proc_douintvec - read a vector of unsigned integers
2450 * @table: the sysctl table
2451 * @write: %TRUE if this is a write to the sysctl file
2452 * @buffer: the user buffer
2453 * @lenp: the size of the user buffer
2454 * @ppos: file position
2455 *
2456 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2457 * values from/to the user buffer, treated as an ASCII string.
2458 *
2459 * Returns 0 on success.
2460 */
2461int proc_douintvec(struct ctl_table *table, int write,
2462 void __user *buffer, size_t *lenp, loff_t *ppos)
2463{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002464 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2465 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
2467
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002468/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002469 * Taint values can only be increased
2470 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002471 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002472static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002473 void __user *buffer, size_t *lenp, loff_t *ppos)
2474{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002475 struct ctl_table t;
2476 unsigned long tmptaint = get_taint();
2477 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002478
Bastian Blank91fcd412007-04-23 14:41:14 -07002479 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002480 return -EPERM;
2481
Andi Kleen25ddbb12008-10-15 22:01:41 -07002482 t = *table;
2483 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002484 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002485 if (err < 0)
2486 return err;
2487
2488 if (write) {
2489 /*
2490 * Poor man's atomic or. Not worth adding a primitive
2491 * to everyone's atomic.h for this
2492 */
2493 int i;
2494 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2495 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302496 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002497 }
2498 }
2499
2500 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002501}
2502
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002503#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002504static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002505 void __user *buffer, size_t *lenp, loff_t *ppos)
2506{
2507 if (write && !capable(CAP_SYS_ADMIN))
2508 return -EPERM;
2509
2510 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2511}
2512#endif
2513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514struct do_proc_dointvec_minmax_conv_param {
2515 int *min;
2516 int *max;
2517};
2518
Amerigo Wang00b7c332010-05-05 00:26:45 +00002519static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2520 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 int write, void *data)
2522{
2523 struct do_proc_dointvec_minmax_conv_param *param = data;
2524 if (write) {
2525 int val = *negp ? -*lvalp : *lvalp;
2526 if ((param->min && *param->min > val) ||
2527 (param->max && *param->max < val))
2528 return -EINVAL;
2529 *valp = val;
2530 } else {
2531 int val = *valp;
2532 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002533 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002534 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002536 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 *lvalp = (unsigned long)val;
2538 }
2539 }
2540 return 0;
2541}
2542
2543/**
2544 * proc_dointvec_minmax - read a vector of integers with min/max values
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2550 *
2551 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2552 * values from/to the user buffer, treated as an ASCII string.
2553 *
2554 * This routine will ensure the values are within the range specified by
2555 * table->extra1 (min) and table->extra2 (max).
2556 *
2557 * Returns 0 on success.
2558 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002559int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 void __user *buffer, size_t *lenp, loff_t *ppos)
2561{
2562 struct do_proc_dointvec_minmax_conv_param param = {
2563 .min = (int *) table->extra1,
2564 .max = (int *) table->extra2,
2565 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002566 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 do_proc_dointvec_minmax_conv, &param);
2568}
2569
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002570struct do_proc_douintvec_minmax_conv_param {
2571 unsigned int *min;
2572 unsigned int *max;
2573};
2574
2575static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2576 unsigned int *valp,
2577 int write, void *data)
2578{
2579 struct do_proc_douintvec_minmax_conv_param *param = data;
2580
2581 if (write) {
2582 unsigned int val = *lvalp;
2583
Joe Lawrencefb910c42017-11-17 15:29:28 -08002584 if (*lvalp > UINT_MAX)
2585 return -EINVAL;
2586
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002587 if ((param->min && *param->min > val) ||
2588 (param->max && *param->max < val))
2589 return -ERANGE;
2590
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002591 *valp = val;
2592 } else {
2593 unsigned int val = *valp;
2594 *lvalp = (unsigned long) val;
2595 }
2596
2597 return 0;
2598}
2599
2600/**
2601 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2602 * @table: the sysctl table
2603 * @write: %TRUE if this is a write to the sysctl file
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2607 *
2608 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2609 * values from/to the user buffer, treated as an ASCII string. Negative
2610 * strings are not allowed.
2611 *
2612 * This routine will ensure the values are within the range specified by
2613 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2614 * check for UINT_MAX to avoid having to support wrap around uses from
2615 * userspace.
2616 *
2617 * Returns 0 on success.
2618 */
2619int proc_douintvec_minmax(struct ctl_table *table, int write,
2620 void __user *buffer, size_t *lenp, loff_t *ppos)
2621{
2622 struct do_proc_douintvec_minmax_conv_param param = {
2623 .min = (unsigned int *) table->extra1,
2624 .max = (unsigned int *) table->extra2,
2625 };
2626 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2627 do_proc_douintvec_minmax_conv, &param);
2628}
2629
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002630static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2631 unsigned int *valp,
2632 int write, void *data)
2633{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002634 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002635 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002636
Joe Lawrencefb910c42017-11-17 15:29:28 -08002637 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002638 if (val == 0)
2639 return -EINVAL;
2640
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002641 *valp = val;
2642 } else {
2643 unsigned int val = *valp;
2644 *lvalp = (unsigned long) val;
2645 }
2646
2647 return 0;
2648}
2649
Eric Biggers319e0a22018-02-06 15:41:49 -08002650static int proc_dopipe_max_size(struct ctl_table *table, int write,
2651 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002652{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002653 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002654 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002655}
2656
Kees Cook54b50192012-07-30 14:39:18 -07002657static void validate_coredump_safety(void)
2658{
Alex Kelly046d6622012-10-04 17:15:23 -07002659#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002660 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002661 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002662 printk(KERN_WARNING
2663"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2664"Pipe handler or fully qualified core dump path required.\n"
2665"Set kernel.core_pattern before fs.suid_dumpable.\n"
2666 );
Kees Cook54b50192012-07-30 14:39:18 -07002667 }
Alex Kelly046d6622012-10-04 17:15:23 -07002668#endif
Kees Cook54b50192012-07-30 14:39:18 -07002669}
2670
2671static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2672 void __user *buffer, size_t *lenp, loff_t *ppos)
2673{
2674 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2675 if (!error)
2676 validate_coredump_safety();
2677 return error;
2678}
2679
Alex Kelly046d6622012-10-04 17:15:23 -07002680#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002681static int proc_dostring_coredump(struct ctl_table *table, int write,
2682 void __user *buffer, size_t *lenp, loff_t *ppos)
2683{
2684 int error = proc_dostring(table, write, buffer, lenp, ppos);
2685 if (!error)
2686 validate_coredump_safety();
2687 return error;
2688}
Alex Kelly046d6622012-10-04 17:15:23 -07002689#endif
Kees Cook54b50192012-07-30 14:39:18 -07002690
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002691static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 void __user *buffer,
2693 size_t *lenp, loff_t *ppos,
2694 unsigned long convmul,
2695 unsigned long convdiv)
2696{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002697 unsigned long *i, *min, *max;
2698 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002699 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002700 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002701
2702 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 *lenp = 0;
2704 return 0;
2705 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002706
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002707 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 min = (unsigned long *) table->extra1;
2709 max = (unsigned long *) table->extra2;
2710 vleft = table->maxlen / sizeof(unsigned long);
2711 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002712
2713 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002714 if (proc_first_pos_non_zero_ignore(ppos, table))
2715 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002716
Amerigo Wang00b7c332010-05-05 00:26:45 +00002717 if (left > PAGE_SIZE - 1)
2718 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002719 p = kbuf = memdup_user_nul(buffer, left);
2720 if (IS_ERR(kbuf))
2721 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002722 }
2723
Eric Dumazet27b3d802010-10-07 12:59:29 -07002724 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002725 unsigned long val;
2726
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002728 bool neg;
2729
Al Viro70f6cbb2015-12-24 00:13:10 -05002730 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002731
Al Viro70f6cbb2015-12-24 00:13:10 -05002732 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002733 proc_wspace_sep,
2734 sizeof(proc_wspace_sep), NULL);
2735 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 break;
2737 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002739 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 if ((min && val < *min) || (max && val > *max))
2741 continue;
2742 *i = val;
2743 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002744 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002745 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002746 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002747 if (err)
2748 break;
2749 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002750 err = proc_put_long(&buffer, &left, val, false);
2751 if (err)
2752 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 }
2754 }
2755
Amerigo Wang00b7c332010-05-05 00:26:45 +00002756 if (!write && !first && left && !err)
2757 err = proc_put_char(&buffer, &left, '\n');
2758 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002759 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002761 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002762 if (first)
2763 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002766out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002768 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769}
2770
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002771static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002772 void __user *buffer,
2773 size_t *lenp, loff_t *ppos,
2774 unsigned long convmul,
2775 unsigned long convdiv)
2776{
2777 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002778 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002779}
2780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781/**
2782 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2783 * @table: the sysctl table
2784 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 * @buffer: the user buffer
2786 * @lenp: the size of the user buffer
2787 * @ppos: file position
2788 *
2789 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2790 * values from/to the user buffer, treated as an ASCII string.
2791 *
2792 * This routine will ensure the values are within the range specified by
2793 * table->extra1 (min) and table->extra2 (max).
2794 *
2795 * Returns 0 on success.
2796 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002797int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 void __user *buffer, size_t *lenp, loff_t *ppos)
2799{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002800 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801}
2802
2803/**
2804 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2805 * @table: the sysctl table
2806 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 * @buffer: the user buffer
2808 * @lenp: the size of the user buffer
2809 * @ppos: file position
2810 *
2811 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2812 * values from/to the user buffer, treated as an ASCII string. The values
2813 * are treated as milliseconds, and converted to jiffies when they are stored.
2814 *
2815 * This routine will ensure the values are within the range specified by
2816 * table->extra1 (min) and table->extra2 (max).
2817 *
2818 * Returns 0 on success.
2819 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002820int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 void __user *buffer,
2822 size_t *lenp, loff_t *ppos)
2823{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002824 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 lenp, ppos, HZ, 1000l);
2826}
2827
2828
Amerigo Wang00b7c332010-05-05 00:26:45 +00002829static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 int *valp,
2831 int write, void *data)
2832{
2833 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002834 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002835 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2837 } else {
2838 int val = *valp;
2839 unsigned long lval;
2840 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002841 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002842 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002844 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 lval = (unsigned long)val;
2846 }
2847 *lvalp = lval / HZ;
2848 }
2849 return 0;
2850}
2851
Amerigo Wang00b7c332010-05-05 00:26:45 +00002852static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 int *valp,
2854 int write, void *data)
2855{
2856 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002857 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2858 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2860 } else {
2861 int val = *valp;
2862 unsigned long lval;
2863 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002864 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002865 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002867 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 lval = (unsigned long)val;
2869 }
2870 *lvalp = jiffies_to_clock_t(lval);
2871 }
2872 return 0;
2873}
2874
Amerigo Wang00b7c332010-05-05 00:26:45 +00002875static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 int *valp,
2877 int write, void *data)
2878{
2879 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002880 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2881
2882 if (jif > INT_MAX)
2883 return 1;
2884 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 } else {
2886 int val = *valp;
2887 unsigned long lval;
2888 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002889 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002890 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002892 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 lval = (unsigned long)val;
2894 }
2895 *lvalp = jiffies_to_msecs(lval);
2896 }
2897 return 0;
2898}
2899
2900/**
2901 * proc_dointvec_jiffies - read a vector of integers as seconds
2902 * @table: the sysctl table
2903 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 * @buffer: the user buffer
2905 * @lenp: the size of the user buffer
2906 * @ppos: file position
2907 *
2908 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2909 * values from/to the user buffer, treated as an ASCII string.
2910 * The values read are assumed to be in seconds, and are converted into
2911 * jiffies.
2912 *
2913 * Returns 0 on success.
2914 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002915int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 void __user *buffer, size_t *lenp, loff_t *ppos)
2917{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002918 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 do_proc_dointvec_jiffies_conv,NULL);
2920}
2921
2922/**
2923 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2924 * @table: the sysctl table
2925 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 * @buffer: the user buffer
2927 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002928 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 *
2930 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2931 * values from/to the user buffer, treated as an ASCII string.
2932 * The values read are assumed to be in 1/USER_HZ seconds, and
2933 * are converted into jiffies.
2934 *
2935 * Returns 0 on success.
2936 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002937int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 void __user *buffer, size_t *lenp, loff_t *ppos)
2939{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 do_proc_dointvec_userhz_jiffies_conv,NULL);
2942}
2943
2944/**
2945 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2946 * @table: the sysctl table
2947 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 * @buffer: the user buffer
2949 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002950 * @ppos: file position
2951 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 *
2953 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2954 * values from/to the user buffer, treated as an ASCII string.
2955 * The values read are assumed to be in 1/1000 seconds, and
2956 * are converted into jiffies.
2957 *
2958 * Returns 0 on success.
2959 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002960int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 void __user *buffer, size_t *lenp, loff_t *ppos)
2962{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002963 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 do_proc_dointvec_ms_jiffies_conv, NULL);
2965}
2966
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002967static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002968 void __user *buffer, size_t *lenp, loff_t *ppos)
2969{
2970 struct pid *new_pid;
2971 pid_t tmp;
2972 int r;
2973
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002974 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002975
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002976 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002977 lenp, ppos, NULL, NULL);
2978 if (r || !write)
2979 return r;
2980
2981 new_pid = find_get_pid(tmp);
2982 if (!new_pid)
2983 return -ESRCH;
2984
2985 put_pid(xchg(&cad_pid, new_pid));
2986 return 0;
2987}
2988
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002989/**
2990 * proc_do_large_bitmap - read/write from/to a large bitmap
2991 * @table: the sysctl table
2992 * @write: %TRUE if this is a write to the sysctl file
2993 * @buffer: the user buffer
2994 * @lenp: the size of the user buffer
2995 * @ppos: file position
2996 *
2997 * The bitmap is stored at table->data and the bitmap length (in bits)
2998 * in table->maxlen.
2999 *
3000 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3001 * large bitmaps may be represented in a compact manner. Writing into
3002 * the file will clear the bitmap then update it with the given input.
3003 *
3004 * Returns 0 on success.
3005 */
3006int proc_do_large_bitmap(struct ctl_table *table, int write,
3007 void __user *buffer, size_t *lenp, loff_t *ppos)
3008{
3009 int err = 0;
3010 bool first = 1;
3011 size_t left = *lenp;
3012 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003013 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003014 unsigned long *tmp_bitmap = NULL;
3015 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3016
WANG Cong122ff242014-05-12 16:04:53 -07003017 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003018 *lenp = 0;
3019 return 0;
3020 }
3021
3022 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003023 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003024
3025 if (left > PAGE_SIZE - 1)
3026 left = PAGE_SIZE - 1;
3027
Al Viro70f6cbb2015-12-24 00:13:10 -05003028 p = kbuf = memdup_user_nul(buffer, left);
3029 if (IS_ERR(kbuf))
3030 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003031
3032 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
3033 GFP_KERNEL);
3034 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003035 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003036 return -ENOMEM;
3037 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003038 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003039 while (!err && left) {
3040 unsigned long val_a, val_b;
3041 bool neg;
3042
Al Viro70f6cbb2015-12-24 00:13:10 -05003043 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003044 sizeof(tr_a), &c);
3045 if (err)
3046 break;
3047 if (val_a >= bitmap_len || neg) {
3048 err = -EINVAL;
3049 break;
3050 }
3051
3052 val_b = val_a;
3053 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003054 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003055 left--;
3056 }
3057
3058 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003059 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003060 &neg, tr_b, sizeof(tr_b),
3061 &c);
3062 if (err)
3063 break;
3064 if (val_b >= bitmap_len || neg ||
3065 val_a > val_b) {
3066 err = -EINVAL;
3067 break;
3068 }
3069 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003070 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003071 left--;
3072 }
3073 }
3074
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003075 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003076 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003077 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003078 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003079 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003080 } else {
3081 unsigned long bit_a, bit_b = 0;
3082
3083 while (left) {
3084 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3085 if (bit_a >= bitmap_len)
3086 break;
3087 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3088 bit_a + 1) - 1;
3089
3090 if (!first) {
3091 err = proc_put_char(&buffer, &left, ',');
3092 if (err)
3093 break;
3094 }
3095 err = proc_put_long(&buffer, &left, bit_a, false);
3096 if (err)
3097 break;
3098 if (bit_a != bit_b) {
3099 err = proc_put_char(&buffer, &left, '-');
3100 if (err)
3101 break;
3102 err = proc_put_long(&buffer, &left, bit_b, false);
3103 if (err)
3104 break;
3105 }
3106
3107 first = 0; bit_b++;
3108 }
3109 if (!err)
3110 err = proc_put_char(&buffer, &left, '\n');
3111 }
3112
3113 if (!err) {
3114 if (write) {
3115 if (*ppos)
3116 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3117 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003118 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003119 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003120 *lenp -= left;
3121 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003122 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003123
3124 kfree(tmp_bitmap);
3125 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003126}
3127
Jovi Zhang55610502011-01-12 17:00:45 -08003128#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003130int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 void __user *buffer, size_t *lenp, loff_t *ppos)
3132{
3133 return -ENOSYS;
3134}
3135
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003136int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 void __user *buffer, size_t *lenp, loff_t *ppos)
3138{
3139 return -ENOSYS;
3140}
3141
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003142int proc_douintvec(struct ctl_table *table, int write,
3143 void __user *buffer, size_t *lenp, loff_t *ppos)
3144{
3145 return -ENOSYS;
3146}
3147
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003148int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 void __user *buffer, size_t *lenp, loff_t *ppos)
3150{
3151 return -ENOSYS;
3152}
3153
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003154int proc_douintvec_minmax(struct ctl_table *table, int write,
3155 void __user *buffer, size_t *lenp, loff_t *ppos)
3156{
3157 return -ENOSYS;
3158}
3159
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003160int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 void __user *buffer, size_t *lenp, loff_t *ppos)
3162{
3163 return -ENOSYS;
3164}
3165
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003166int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 void __user *buffer, size_t *lenp, loff_t *ppos)
3168{
3169 return -ENOSYS;
3170}
3171
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003172int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 void __user *buffer, size_t *lenp, loff_t *ppos)
3174{
3175 return -ENOSYS;
3176}
3177
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003178int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 void __user *buffer, size_t *lenp, loff_t *ppos)
3180{
3181 return -ENOSYS;
3182}
3183
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003184int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 void __user *buffer,
3186 size_t *lenp, loff_t *ppos)
3187{
3188 return -ENOSYS;
3189}
3190
3191
Jovi Zhang55610502011-01-12 17:00:45 -08003192#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194/*
3195 * No sense putting this after each symbol definition, twice,
3196 * exception granted :-)
3197 */
3198EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003199EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200EXPORT_SYMBOL(proc_dointvec_jiffies);
3201EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003202EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3204EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3205EXPORT_SYMBOL(proc_dostring);
3206EXPORT_SYMBOL(proc_doulongvec_minmax);
3207EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);