blob: f22f76b7a138ceedcc5392a24f493ec04366bc1b [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 },
Mel Gormancb251762016-02-05 09:08:36 +0000371#ifdef CONFIG_SCHEDSTATS
372 {
373 .procname = "sched_schedstats",
374 .data = NULL,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = sysctl_schedstats,
378 .extra1 = &zero,
379 .extra2 = &one,
380 },
381#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200382#endif /* CONFIG_SMP */
383#ifdef CONFIG_NUMA_BALANCING
384 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200385 .procname = "numa_balancing_scan_delay_ms",
386 .data = &sysctl_numa_balancing_scan_delay,
387 .maxlen = sizeof(unsigned int),
388 .mode = 0644,
389 .proc_handler = proc_dointvec,
390 },
391 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200392 .procname = "numa_balancing_scan_period_min_ms",
393 .data = &sysctl_numa_balancing_scan_period_min,
394 .maxlen = sizeof(unsigned int),
395 .mode = 0644,
396 .proc_handler = proc_dointvec,
397 },
398 {
399 .procname = "numa_balancing_scan_period_max_ms",
400 .data = &sysctl_numa_balancing_scan_period_max,
401 .maxlen = sizeof(unsigned int),
402 .mode = 0644,
403 .proc_handler = proc_dointvec,
404 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200405 {
406 .procname = "numa_balancing_scan_size_mb",
407 .data = &sysctl_numa_balancing_scan_size,
408 .maxlen = sizeof(unsigned int),
409 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400410 .proc_handler = proc_dointvec_minmax,
411 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200412 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100413 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800414 .procname = "numa_balancing",
415 .data = NULL, /* filled in by handler */
416 .maxlen = sizeof(unsigned int),
417 .mode = 0644,
418 .proc_handler = sysctl_numa_balancing,
419 .extra1 = &zero,
420 .extra2 = &one,
421 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200422#endif /* CONFIG_NUMA_BALANCING */
423#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200424 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100425 .procname = "sched_rt_period_us",
426 .data = &sysctl_sched_rt_period,
427 .maxlen = sizeof(unsigned int),
428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800429 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100430 },
431 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100432 .procname = "sched_rt_runtime_us",
433 .data = &sysctl_sched_rt_runtime,
434 .maxlen = sizeof(int),
435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100437 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600438 {
439 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800440 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600441 .maxlen = sizeof(int),
442 .mode = 0644,
443 .proc_handler = sched_rr_handler,
444 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100445#ifdef CONFIG_SCHED_AUTOGROUP
446 {
447 .procname = "sched_autogroup_enabled",
448 .data = &sysctl_sched_autogroup_enabled,
449 .maxlen = sizeof(unsigned int),
450 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800451 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100452 .extra1 = &zero,
453 .extra2 = &one,
454 },
455#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700456#ifdef CONFIG_CFS_BANDWIDTH
457 {
458 .procname = "sched_cfs_bandwidth_slice_us",
459 .data = &sysctl_sched_cfs_bandwidth_slice,
460 .maxlen = sizeof(unsigned int),
461 .mode = 0644,
462 .proc_handler = proc_dointvec_minmax,
463 .extra1 = &one,
464 },
465#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700466#ifdef CONFIG_PROVE_LOCKING
467 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700468 .procname = "prove_locking",
469 .data = &prove_locking,
470 .maxlen = sizeof(int),
471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800472 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700473 },
474#endif
475#ifdef CONFIG_LOCK_STAT
476 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700477 .procname = "lock_stat",
478 .data = &lock_stat,
479 .maxlen = sizeof(int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700482 },
483#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200484 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 .procname = "panic",
486 .data = &panic_timeout,
487 .maxlen = sizeof(int),
488 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800489 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 },
Alex Kelly046d6622012-10-04 17:15:23 -0700491#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .procname = "core_uses_pid",
494 .data = &core_uses_pid,
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 },
499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .procname = "core_pattern",
501 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700502 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700504 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 },
Neil Hormana2939802009-09-23 15:56:56 -0700506 {
Neil Hormana2939802009-09-23 15:56:56 -0700507 .procname = "core_pipe_limit",
508 .data = &core_pipe_limit,
509 .maxlen = sizeof(unsigned int),
510 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800511 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700512 },
Alex Kelly046d6622012-10-04 17:15:23 -0700513#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800514#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700517 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800518 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800519 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700521 {
522 .procname = "sysctl_writes_strict",
523 .data = &sysctl_writes_strict,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = proc_dointvec_minmax,
527 .extra1 = &neg_one,
528 .extra2 = &one,
529 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800530#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100531#ifdef CONFIG_LATENCYTOP
532 {
533 .procname = "latencytop",
534 .data = &latencytop_enabled,
535 .maxlen = sizeof(int),
536 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000537 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100538 },
539#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#ifdef CONFIG_BLK_DEV_INITRD
541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .procname = "real-root-dev",
543 .data = &real_root_dev,
544 .maxlen = sizeof(int),
545 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800546 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 },
548#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700549 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700550 .procname = "print-fatal-signals",
551 .data = &print_fatal_signals,
552 .maxlen = sizeof(int),
553 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800554 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700555 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700556#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 .procname = "reboot-cmd",
559 .data = reboot_command,
560 .maxlen = 256,
561 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800562 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 },
564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "stop-a",
566 .data = &stop_a_enabled,
567 .maxlen = sizeof (int),
568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 },
571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "scons-poweroff",
573 .data = &scons_pwroff,
574 .maxlen = sizeof (int),
575 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800576 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
578#endif
David S. Miller08714202008-11-16 23:49:24 -0800579#ifdef CONFIG_SPARC64
580 {
David S. Miller08714202008-11-16 23:49:24 -0800581 .procname = "tsb-ratio",
582 .data = &sysctl_tsb_ratio,
583 .maxlen = sizeof (int),
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800586 },
587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#ifdef __hppa__
589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .procname = "soft-power",
591 .data = &pwrsw_enabled,
592 .maxlen = sizeof (int),
593 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800594 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530596#endif
597#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "unaligned-trap",
600 .data = &unaligned_enabled,
601 .maxlen = sizeof (int),
602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 },
605#endif
606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "ctrl-alt-del",
608 .data = &C_A_D,
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 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400613#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200614 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200615 .procname = "ftrace_enabled",
616 .data = &ftrace_enabled,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800619 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200620 },
621#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500622#ifdef CONFIG_STACK_TRACER
623 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500624 .procname = "stack_tracer_enabled",
625 .data = &stack_tracer_enabled,
626 .maxlen = sizeof(int),
627 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800628 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500629 },
630#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400631#ifdef CONFIG_TRACING
632 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100633 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400634 .data = &ftrace_dump_on_oops,
635 .maxlen = sizeof(int),
636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800637 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400638 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400639 {
640 .procname = "traceoff_on_warning",
641 .data = &__disable_trace_on_warning,
642 .maxlen = sizeof(__disable_trace_on_warning),
643 .mode = 0644,
644 .proc_handler = proc_dointvec,
645 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500646 {
647 .procname = "tracepoint_printk",
648 .data = &tracepoint_printk,
649 .maxlen = sizeof(tracepoint_printk),
650 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500651 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500652 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400653#endif
Dave Young2965faa2015-09-09 15:38:55 -0700654#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800655 {
656 .procname = "kexec_load_disabled",
657 .data = &kexec_load_disabled,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 /* only handle a transition from default "0" to "1" */
661 .proc_handler = proc_dointvec_minmax,
662 .extra1 = &one,
663 .extra2 = &one,
664 },
665#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200666#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "modprobe",
669 .data = &modprobe_path,
670 .maxlen = KMOD_PATH_LEN,
671 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
Kees Cook3d433212009-04-02 15:49:29 -0700674 {
Kees Cook3d433212009-04-02 15:49:29 -0700675 .procname = "modules_disabled",
676 .data = &modules_disabled,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700681 .extra1 = &one,
682 .extra2 = &one,
683 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700685#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100688 .data = &uevent_helper,
689 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800691 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
Michael Marineau86d56132014-04-10 14:09:31 -0700693#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#ifdef CONFIG_CHR_DEV_SG
695 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .procname = "sg-big-buff",
697 .data = &sg_big_buff,
698 .maxlen = sizeof (int),
699 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
702#endif
703#ifdef CONFIG_BSD_PROCESS_ACCT
704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .procname = "acct",
706 .data = &acct_parm,
707 .maxlen = 3*sizeof(int),
708 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800709 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 },
711#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#ifdef CONFIG_MAGIC_SYSRQ
713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800715 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .maxlen = sizeof (int),
717 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700718 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
720#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700721#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700724 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .maxlen = sizeof (int),
726 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800727 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700729#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700732 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 .maxlen = sizeof(int),
734 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700735 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 },
737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .procname = "random",
739 .mode = 0555,
740 .child = random_table,
741 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 {
Eric Paris17f60a72011-04-01 17:07:50 -0400743 .procname = "usermodehelper",
744 .mode = 0555,
745 .child = usermodehelper_table,
746 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800747#ifdef CONFIG_FW_LOADER_USER_HELPER
748 {
749 .procname = "firmware_config",
750 .mode = 0555,
751 .child = firmware_config_table,
752 },
753#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400754 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .procname = "overflowuid",
756 .data = &overflowuid,
757 .maxlen = sizeof(int),
758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800759 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .extra1 = &minolduid,
761 .extra2 = &maxolduid,
762 },
763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .procname = "overflowgid",
765 .data = &overflowgid,
766 .maxlen = sizeof(int),
767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800768 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .extra1 = &minolduid,
770 .extra2 = &maxolduid,
771 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800772#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773#ifdef CONFIG_MATHEMU
774 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .procname = "ieee_emulation_warnings",
776 .data = &sysctl_ieee_emulation_warnings,
777 .maxlen = sizeof(int),
778 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800779 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 },
781#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200784 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 .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
790 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .procname = "pid_max",
792 .data = &pid_max,
793 .maxlen = sizeof (int),
794 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800795 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 .extra1 = &pid_max_min,
797 .extra2 = &pid_max_max,
798 },
799 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .procname = "panic_on_oops",
801 .data = &panic_on_oops,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800804 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800806#if defined CONFIG_PRINTK
807 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800808 .procname = "printk",
809 .data = &console_loglevel,
810 .maxlen = 4*sizeof(int),
811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800812 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800813 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700816 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 .maxlen = sizeof(int),
818 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800819 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 },
821 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700823 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 .maxlen = sizeof(int),
825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 },
Dave Youngaf913222009-09-22 16:43:33 -0700828 {
Dave Youngaf913222009-09-22 16:43:33 -0700829 .procname = "printk_delay",
830 .data = &printk_delay_msec,
831 .maxlen = sizeof(int),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700834 .extra1 = &zero,
835 .extra2 = &ten_thousand,
836 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700838 .procname = "printk_devkmsg",
839 .data = devkmsg_log_str,
840 .maxlen = DEVKMSG_STR_MAX_SIZE,
841 .mode = 0644,
842 .proc_handler = devkmsg_sysctl_set_loglvl,
843 },
844 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800845 .procname = "dmesg_restrict",
846 .data = &dmesg_restrict,
847 .maxlen = sizeof(int),
848 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700849 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800850 .extra1 = &zero,
851 .extra2 = &one,
852 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800853 {
854 .procname = "kptr_restrict",
855 .data = &kptr_restrict,
856 .maxlen = sizeof(int),
857 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700858 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800859 .extra1 = &zero,
860 .extra2 = &two,
861 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800862#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800863 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 .procname = "ngroups_max",
865 .data = &ngroups_max,
866 .maxlen = sizeof (int),
867 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 },
Dan Ballard73efc032011-10-31 17:11:20 -0700870 {
871 .procname = "cap_last_cap",
872 .data = (void *)&cap_last_cap,
873 .maxlen = sizeof(int),
874 .mode = 0444,
875 .proc_handler = proc_dointvec,
876 },
Don Zickus58687ac2010-05-07 17:11:44 -0400877#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500878 {
Don Zickus58687ac2010-05-07 17:11:44 -0400879 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200880 .data = &watchdog_user_enabled,
881 .maxlen = sizeof(int),
882 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700883 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700884 .extra1 = &zero,
885 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400886 },
887 {
888 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700889 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400890 .maxlen = sizeof(int),
891 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700892 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800893 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400894 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500895 },
Don Zickus2508ce12010-05-07 17:11:46 -0400896 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700897 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200898 .data = &nmi_watchdog_user_enabled,
899 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200900 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700901 .proc_handler = proc_nmi_watchdog,
902 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700903 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700904 },
905 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700906 .procname = "watchdog_cpumask",
907 .data = &watchdog_cpumask_bits,
908 .maxlen = NR_CPUS,
909 .mode = 0644,
910 .proc_handler = proc_watchdog_cpumask,
911 },
912#ifdef CONFIG_SOFTLOCKUP_DETECTOR
913 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700914 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200915 .data = &soft_watchdog_user_enabled,
916 .maxlen = sizeof(int),
917 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700918 .proc_handler = proc_soft_watchdog,
919 .extra1 = &zero,
920 .extra2 = &one,
921 },
922 {
Don Zickus2508ce12010-05-07 17:11:46 -0400923 .procname = "softlockup_panic",
924 .data = &softlockup_panic,
925 .maxlen = sizeof(int),
926 .mode = 0644,
927 .proc_handler = proc_dointvec_minmax,
928 .extra1 = &zero,
929 .extra2 = &one,
930 },
Aaron Tomlined235872014-06-23 13:22:05 -0700931#ifdef CONFIG_SMP
932 {
933 .procname = "softlockup_all_cpu_backtrace",
934 .data = &sysctl_softlockup_all_cpu_backtrace,
935 .maxlen = sizeof(int),
936 .mode = 0644,
937 .proc_handler = proc_dointvec_minmax,
938 .extra1 = &zero,
939 .extra2 = &one,
940 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700941#endif /* CONFIG_SMP */
942#endif
943#ifdef CONFIG_HARDLOCKUP_DETECTOR
944 {
945 .procname = "hardlockup_panic",
946 .data = &hardlockup_panic,
947 .maxlen = sizeof(int),
948 .mode = 0644,
949 .proc_handler = proc_dointvec_minmax,
950 .extra1 = &zero,
951 .extra2 = &one,
952 },
953#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800954 {
955 .procname = "hardlockup_all_cpu_backtrace",
956 .data = &sysctl_hardlockup_all_cpu_backtrace,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = proc_dointvec_minmax,
960 .extra1 = &zero,
961 .extra2 = &one,
962 },
Aaron Tomlined235872014-06-23 13:22:05 -0700963#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500964#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700965#endif
966
Don Zickus5dc30552010-11-29 17:07:17 -0500967#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
968 {
969 .procname = "unknown_nmi_panic",
970 .data = &unknown_nmi_panic,
971 .maxlen = sizeof (int),
972 .mode = 0644,
973 .proc_handler = proc_dointvec,
974 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500975#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976#if defined(CONFIG_X86)
977 {
Don Zickus8da5add2006-09-26 10:52:27 +0200978 .procname = "panic_on_unrecovered_nmi",
979 .data = &panic_on_unrecovered_nmi,
980 .maxlen = sizeof(int),
981 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800982 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200983 },
984 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700985 .procname = "panic_on_io_nmi",
986 .data = &panic_on_io_nmi,
987 .maxlen = sizeof(int),
988 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800989 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700990 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900991#ifdef CONFIG_DEBUG_STACKOVERFLOW
992 {
993 .procname = "panic_on_stackoverflow",
994 .data = &sysctl_panic_on_stackoverflow,
995 .maxlen = sizeof(int),
996 .mode = 0644,
997 .proc_handler = proc_dointvec,
998 },
999#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001000 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 .procname = "bootloader_type",
1002 .data = &bootloader_type,
1003 .maxlen = sizeof (int),
1004 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001005 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001007 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001008 .procname = "bootloader_version",
1009 .data = &bootloader_version,
1010 .maxlen = sizeof (int),
1011 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001012 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001013 },
1014 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001015 .procname = "io_delay_type",
1016 .data = &io_delay_type,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001020 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001022#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .procname = "randomize_va_space",
1025 .data = &randomize_va_space,
1026 .maxlen = sizeof(int),
1027 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001028 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001030#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001031#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001032 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001033 .procname = "spin_retry",
1034 .data = &spin_retry,
1035 .maxlen = sizeof (int),
1036 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001037 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001038 },
1039#endif
Len Brown673d5b42007-07-28 03:33:16 -04001040#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001041 {
Pavel Machekc255d842006-02-20 18:27:58 -08001042 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001043 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001044 .maxlen = sizeof (unsigned long),
1045 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001046 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001047 },
1048#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301049#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001050 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001051 .procname = "ignore-unaligned-usertrap",
1052 .data = &no_unaligned_warning,
1053 .maxlen = sizeof (int),
1054 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001055 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001056 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301057#endif
1058#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001059 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001060 .procname = "unaligned-dump-stack",
1061 .data = &unaligned_dump_stack,
1062 .maxlen = sizeof (int),
1063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001065 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001066#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001067#ifdef CONFIG_DETECT_HUNG_TASK
1068 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001069 .procname = "hung_task_panic",
1070 .data = &sysctl_hung_task_panic,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001073 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001074 .extra1 = &zero,
1075 .extra2 = &one,
1076 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001077 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001078 .procname = "hung_task_check_count",
1079 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001080 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001081 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001082 .proc_handler = proc_dointvec_minmax,
1083 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001084 },
1085 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001086 .procname = "hung_task_timeout_secs",
1087 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001088 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001089 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001090 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001091 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001092 },
1093 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001094 .procname = "hung_task_warnings",
1095 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001096 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001097 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001098 .proc_handler = proc_dointvec_minmax,
1099 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001100 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001101#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001102#ifdef CONFIG_RT_MUTEXES
1103 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001104 .procname = "max_lock_depth",
1105 .data = &max_lock_depth,
1106 .maxlen = sizeof(int),
1107 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001108 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001109 },
1110#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001111 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001112 .procname = "poweroff_cmd",
1113 .data = &poweroff_cmd,
1114 .maxlen = POWEROFF_CMD_PATH_LEN,
1115 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001116 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001117 },
David Howells0b77f5b2008-04-29 01:01:32 -07001118#ifdef CONFIG_KEYS
1119 {
David Howells0b77f5b2008-04-29 01:01:32 -07001120 .procname = "keys",
1121 .mode = 0555,
1122 .child = key_sysctls,
1123 },
1124#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001125#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001126 /*
1127 * User-space scripts rely on the existence of this file
1128 * as a feature check for perf_events being enabled.
1129 *
1130 * So it's an ABI, do not remove!
1131 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001132 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001133 .procname = "perf_event_paranoid",
1134 .data = &sysctl_perf_event_paranoid,
1135 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001136 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001137 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001138 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001139 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001140 .procname = "perf_event_mlock_kb",
1141 .data = &sysctl_perf_event_mlock,
1142 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001143 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001144 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001145 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001146 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001147 .procname = "perf_event_max_sample_rate",
1148 .data = &sysctl_perf_event_sample_rate,
1149 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001150 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001151 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001152 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001153 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001154 {
1155 .procname = "perf_cpu_time_max_percent",
1156 .data = &sysctl_perf_cpu_time_max_percent,
1157 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1158 .mode = 0644,
1159 .proc_handler = perf_cpu_time_max_percent_handler,
1160 .extra1 = &zero,
1161 .extra2 = &one_hundred,
1162 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001163 {
1164 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001165 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001166 .maxlen = sizeof(sysctl_perf_event_max_stack),
1167 .mode = 0644,
1168 .proc_handler = perf_event_max_stack_handler,
1169 .extra1 = &zero,
1170 .extra2 = &six_hundred_forty_kb,
1171 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001172 {
1173 .procname = "perf_event_max_contexts_per_stack",
1174 .data = &sysctl_perf_event_max_contexts_per_stack,
1175 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1176 .mode = 0644,
1177 .proc_handler = perf_event_max_stack_handler,
1178 .extra1 = &zero,
1179 .extra2 = &one_thousand,
1180 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001181#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001182 {
1183 .procname = "panic_on_warn",
1184 .data = &panic_on_warn,
1185 .maxlen = sizeof(int),
1186 .mode = 0644,
1187 .proc_handler = proc_dointvec_minmax,
1188 .extra1 = &zero,
1189 .extra2 = &one,
1190 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001191#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1192 {
1193 .procname = "timer_migration",
1194 .data = &sysctl_timer_migration,
1195 .maxlen = sizeof(unsigned int),
1196 .mode = 0644,
1197 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001198 .extra1 = &zero,
1199 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001200 },
1201#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001202#ifdef CONFIG_BPF_SYSCALL
1203 {
1204 .procname = "unprivileged_bpf_disabled",
1205 .data = &sysctl_unprivileged_bpf_disabled,
1206 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1207 .mode = 0644,
1208 /* only handle a transition from default "0" to "1" */
1209 .proc_handler = proc_dointvec_minmax,
1210 .extra1 = &one,
1211 .extra2 = &one,
1212 },
1213#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001214#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1215 {
1216 .procname = "panic_on_rcu_stall",
1217 .data = &sysctl_panic_on_rcu_stall,
1218 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1219 .mode = 0644,
1220 .proc_handler = proc_dointvec_minmax,
1221 .extra1 = &zero,
1222 .extra2 = &one,
1223 },
1224#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001225 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226};
1227
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001228static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 .procname = "overcommit_memory",
1231 .data = &sysctl_overcommit_memory,
1232 .maxlen = sizeof(sysctl_overcommit_memory),
1233 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001234 .proc_handler = proc_dointvec_minmax,
1235 .extra1 = &zero,
1236 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 },
1238 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001239 .procname = "panic_on_oom",
1240 .data = &sysctl_panic_on_oom,
1241 .maxlen = sizeof(sysctl_panic_on_oom),
1242 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001243 .proc_handler = proc_dointvec_minmax,
1244 .extra1 = &zero,
1245 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001246 },
1247 {
David Rientjesfe071d72007-10-16 23:25:56 -07001248 .procname = "oom_kill_allocating_task",
1249 .data = &sysctl_oom_kill_allocating_task,
1250 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1251 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001252 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001253 },
1254 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001255 .procname = "oom_dump_tasks",
1256 .data = &sysctl_oom_dump_tasks,
1257 .maxlen = sizeof(sysctl_oom_dump_tasks),
1258 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001259 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001260 },
1261 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 .procname = "overcommit_ratio",
1263 .data = &sysctl_overcommit_ratio,
1264 .maxlen = sizeof(sysctl_overcommit_ratio),
1265 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001266 .proc_handler = overcommit_ratio_handler,
1267 },
1268 {
1269 .procname = "overcommit_kbytes",
1270 .data = &sysctl_overcommit_kbytes,
1271 .maxlen = sizeof(sysctl_overcommit_kbytes),
1272 .mode = 0644,
1273 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 },
1275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 .procname = "page-cluster",
1277 .data = &page_cluster,
1278 .maxlen = sizeof(int),
1279 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001280 .proc_handler = proc_dointvec_minmax,
1281 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 },
1283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 .procname = "dirty_background_ratio",
1285 .data = &dirty_background_ratio,
1286 .maxlen = sizeof(dirty_background_ratio),
1287 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001288 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 .extra1 = &zero,
1290 .extra2 = &one_hundred,
1291 },
1292 {
David Rientjes2da02992009-01-06 14:39:31 -08001293 .procname = "dirty_background_bytes",
1294 .data = &dirty_background_bytes,
1295 .maxlen = sizeof(dirty_background_bytes),
1296 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001297 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001298 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001299 },
1300 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 .procname = "dirty_ratio",
1302 .data = &vm_dirty_ratio,
1303 .maxlen = sizeof(vm_dirty_ratio),
1304 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001305 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .extra1 = &zero,
1307 .extra2 = &one_hundred,
1308 },
1309 {
David Rientjes2da02992009-01-06 14:39:31 -08001310 .procname = "dirty_bytes",
1311 .data = &vm_dirty_bytes,
1312 .maxlen = sizeof(vm_dirty_bytes),
1313 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001314 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001315 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001316 },
1317 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001319 .data = &dirty_writeback_interval,
1320 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001322 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 },
1324 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001326 .data = &dirty_expire_interval,
1327 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001329 .proc_handler = proc_dointvec_minmax,
1330 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 },
1332 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001333 .procname = "dirtytime_expire_seconds",
1334 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001335 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001336 .mode = 0644,
1337 .proc_handler = dirtytime_interval_handler,
1338 .extra1 = &zero,
1339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "swappiness",
1342 .data = &vm_swappiness,
1343 .maxlen = sizeof(vm_swappiness),
1344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001345 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 .extra1 = &zero,
1347 .extra2 = &one_hundred,
1348 },
1349#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001350 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001352 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 .maxlen = sizeof(unsigned long),
1354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001355 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001356 },
1357#ifdef CONFIG_NUMA
1358 {
1359 .procname = "nr_hugepages_mempolicy",
1360 .data = NULL,
1361 .maxlen = sizeof(unsigned long),
1362 .mode = 0644,
1363 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001364 },
Kemi Wang45180852017-11-15 17:38:22 -08001365 {
1366 .procname = "numa_stat",
1367 .data = &sysctl_vm_numa_stat,
1368 .maxlen = sizeof(int),
1369 .mode = 0644,
1370 .proc_handler = sysctl_vm_numa_stat_handler,
1371 .extra1 = &zero,
1372 .extra2 = &one,
1373 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001374#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .procname = "hugetlb_shm_group",
1377 .data = &sysctl_hugetlb_shm_group,
1378 .maxlen = sizeof(gid_t),
1379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001380 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 },
Adam Litke54f9f802007-10-16 01:26:20 -07001382 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001383 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001384 .data = NULL,
1385 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001388 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389#endif
1390 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 .procname = "lowmem_reserve_ratio",
1392 .data = &sysctl_lowmem_reserve_ratio,
1393 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001395 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 },
1397 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001398 .procname = "drop_caches",
1399 .data = &sysctl_drop_caches,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
1402 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001403 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001404 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001405 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001406#ifdef CONFIG_COMPACTION
1407 {
1408 .procname = "compact_memory",
1409 .data = &sysctl_compact_memory,
1410 .maxlen = sizeof(int),
1411 .mode = 0200,
1412 .proc_handler = sysctl_compaction_handler,
1413 },
Mel Gorman5e771902010-05-24 14:32:31 -07001414 {
1415 .procname = "extfrag_threshold",
1416 .data = &sysctl_extfrag_threshold,
1417 .maxlen = sizeof(int),
1418 .mode = 0644,
1419 .proc_handler = sysctl_extfrag_handler,
1420 .extra1 = &min_extfrag_threshold,
1421 .extra2 = &max_extfrag_threshold,
1422 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001423 {
1424 .procname = "compact_unevictable_allowed",
1425 .data = &sysctl_compact_unevictable_allowed,
1426 .maxlen = sizeof(int),
1427 .mode = 0644,
1428 .proc_handler = proc_dointvec,
1429 .extra1 = &zero,
1430 .extra2 = &one,
1431 },
Mel Gorman5e771902010-05-24 14:32:31 -07001432
Mel Gorman76ab0f52010-05-24 14:32:28 -07001433#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001434 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 .procname = "min_free_kbytes",
1436 .data = &min_free_kbytes,
1437 .maxlen = sizeof(min_free_kbytes),
1438 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001439 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 .extra1 = &zero,
1441 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001442 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001443 .procname = "watermark_scale_factor",
1444 .data = &watermark_scale_factor,
1445 .maxlen = sizeof(watermark_scale_factor),
1446 .mode = 0644,
1447 .proc_handler = watermark_scale_factor_sysctl_handler,
1448 .extra1 = &one,
1449 .extra2 = &one_thousand,
1450 },
1451 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001452 .procname = "percpu_pagelist_fraction",
1453 .data = &percpu_pagelist_fraction,
1454 .maxlen = sizeof(percpu_pagelist_fraction),
1455 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001456 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001457 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001458 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459#ifdef CONFIG_MMU
1460 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 .procname = "max_map_count",
1462 .data = &sysctl_max_map_count,
1463 .maxlen = sizeof(sysctl_max_map_count),
1464 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001465 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001466 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001468#else
1469 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001470 .procname = "nr_trim_pages",
1471 .data = &sysctl_nr_trim_pages,
1472 .maxlen = sizeof(sysctl_nr_trim_pages),
1473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001474 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001475 .extra1 = &zero,
1476 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477#endif
1478 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 .procname = "laptop_mode",
1480 .data = &laptop_mode,
1481 .maxlen = sizeof(laptop_mode),
1482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001483 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 },
1485 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 .procname = "block_dump",
1487 .data = &block_dump,
1488 .maxlen = sizeof(block_dump),
1489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001490 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 .extra1 = &zero,
1492 },
1493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 .procname = "vfs_cache_pressure",
1495 .data = &sysctl_vfs_cache_pressure,
1496 .maxlen = sizeof(sysctl_vfs_cache_pressure),
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#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1502 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 .procname = "legacy_va_layout",
1504 .data = &sysctl_legacy_va_layout,
1505 .maxlen = sizeof(sysctl_legacy_va_layout),
1506 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001507 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 .extra1 = &zero,
1509 },
1510#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001511#ifdef CONFIG_NUMA
1512 {
Christoph Lameter17436602006-01-18 17:42:32 -08001513 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001514 .data = &node_reclaim_mode,
1515 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001517 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001518 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001519 },
Christoph Lameter96146342006-07-03 00:24:13 -07001520 {
Christoph Lameter96146342006-07-03 00:24:13 -07001521 .procname = "min_unmapped_ratio",
1522 .data = &sysctl_min_unmapped_ratio,
1523 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001525 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001526 .extra1 = &zero,
1527 .extra2 = &one_hundred,
1528 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001529 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001530 .procname = "min_slab_ratio",
1531 .data = &sysctl_min_slab_ratio,
1532 .maxlen = sizeof(sysctl_min_slab_ratio),
1533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001534 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001535 .extra1 = &zero,
1536 .extra2 = &one_hundred,
1537 },
Christoph Lameter17436602006-01-18 17:42:32 -08001538#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001539#ifdef CONFIG_SMP
1540 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001541 .procname = "stat_interval",
1542 .data = &sysctl_stat_interval,
1543 .maxlen = sizeof(sysctl_stat_interval),
1544 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001545 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001546 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001547 {
1548 .procname = "stat_refresh",
1549 .data = NULL,
1550 .maxlen = 0,
1551 .mode = 0600,
1552 .proc_handler = vmstat_refresh,
1553 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001554#endif
David Howells6e141542009-12-15 19:27:45 +00001555#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001556 {
Eric Parised032182007-06-28 15:55:21 -04001557 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001558 .data = &dac_mmap_min_addr,
1559 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001560 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001561 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001562 },
David Howells6e141542009-12-15 19:27:45 +00001563#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001564#ifdef CONFIG_NUMA
1565 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001566 .procname = "numa_zonelist_order",
1567 .data = &numa_zonelist_order,
1568 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001570 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001571 },
1572#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001573#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001574 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001575 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001576 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001577#ifdef CONFIG_X86_32
1578 .data = &vdso32_enabled,
1579 .maxlen = sizeof(vdso32_enabled),
1580#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001581 .data = &vdso_enabled,
1582 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001583#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001585 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001586 .extra1 = &zero,
1587 },
1588#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001589#ifdef CONFIG_HIGHMEM
1590 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001591 .procname = "highmem_is_dirtyable",
1592 .data = &vm_highmem_is_dirtyable,
1593 .maxlen = sizeof(vm_highmem_is_dirtyable),
1594 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001595 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001596 .extra1 = &zero,
1597 .extra2 = &one,
1598 },
1599#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001600#ifdef CONFIG_MEMORY_FAILURE
1601 {
Andi Kleen6a460792009-09-16 11:50:15 +02001602 .procname = "memory_failure_early_kill",
1603 .data = &sysctl_memory_failure_early_kill,
1604 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1605 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001606 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001607 .extra1 = &zero,
1608 .extra2 = &one,
1609 },
1610 {
Andi Kleen6a460792009-09-16 11:50:15 +02001611 .procname = "memory_failure_recovery",
1612 .data = &sysctl_memory_failure_recovery,
1613 .maxlen = sizeof(sysctl_memory_failure_recovery),
1614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001615 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001616 .extra1 = &zero,
1617 .extra2 = &one,
1618 },
1619#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001620 {
1621 .procname = "user_reserve_kbytes",
1622 .data = &sysctl_user_reserve_kbytes,
1623 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1624 .mode = 0644,
1625 .proc_handler = proc_doulongvec_minmax,
1626 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001627 {
1628 .procname = "admin_reserve_kbytes",
1629 .data = &sysctl_admin_reserve_kbytes,
1630 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1631 .mode = 0644,
1632 .proc_handler = proc_doulongvec_minmax,
1633 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001634#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1635 {
1636 .procname = "mmap_rnd_bits",
1637 .data = &mmap_rnd_bits,
1638 .maxlen = sizeof(mmap_rnd_bits),
1639 .mode = 0600,
1640 .proc_handler = proc_dointvec_minmax,
1641 .extra1 = (void *)&mmap_rnd_bits_min,
1642 .extra2 = (void *)&mmap_rnd_bits_max,
1643 },
1644#endif
1645#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1646 {
1647 .procname = "mmap_rnd_compat_bits",
1648 .data = &mmap_rnd_compat_bits,
1649 .maxlen = sizeof(mmap_rnd_compat_bits),
1650 .mode = 0600,
1651 .proc_handler = proc_dointvec_minmax,
1652 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1653 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1654 },
1655#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001656 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657};
1658
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001659static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 .procname = "inode-nr",
1662 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001663 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001665 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 },
1667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 .procname = "inode-state",
1669 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001670 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001672 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 },
1674 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 .procname = "file-nr",
1676 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001677 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001679 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 },
1681 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 .procname = "file-max",
1683 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001684 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001686 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 },
1688 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001689 .procname = "nr_open",
1690 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001691 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001693 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001694 .extra1 = &sysctl_nr_open_min,
1695 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001696 },
1697 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 .procname = "dentry-state",
1699 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001700 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001702 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 },
1704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .procname = "overflowuid",
1706 .data = &fs_overflowuid,
1707 .maxlen = sizeof(int),
1708 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001709 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 .extra1 = &minolduid,
1711 .extra2 = &maxolduid,
1712 },
1713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 .procname = "overflowgid",
1715 .data = &fs_overflowgid,
1716 .maxlen = sizeof(int),
1717 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001718 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 .extra1 = &minolduid,
1720 .extra2 = &maxolduid,
1721 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001722#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 .procname = "leases-enable",
1725 .data = &leases_enable,
1726 .maxlen = sizeof(int),
1727 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001728 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001730#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731#ifdef CONFIG_DNOTIFY
1732 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 .procname = "dir-notify-enable",
1734 .data = &dir_notify_enable,
1735 .maxlen = sizeof(int),
1736 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001737 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 },
1739#endif
1740#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001741#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .procname = "lease-break-time",
1744 .data = &lease_break_time,
1745 .maxlen = sizeof(int),
1746 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001747 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001749#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001750#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 .procname = "aio-nr",
1753 .data = &aio_nr,
1754 .maxlen = sizeof(aio_nr),
1755 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001756 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 },
1758 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 .procname = "aio-max-nr",
1760 .data = &aio_max_nr,
1761 .maxlen = sizeof(aio_max_nr),
1762 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001763 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001765#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001766#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001767 {
Robert Love0399cb02005-07-13 12:38:18 -04001768 .procname = "inotify",
1769 .mode = 0555,
1770 .child = inotify_table,
1771 },
1772#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001773#ifdef CONFIG_EPOLL
1774 {
1775 .procname = "epoll",
1776 .mode = 0555,
1777 .child = epoll_table,
1778 },
1779#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001781 {
Kees Cook800179c2012-07-25 17:29:07 -07001782 .procname = "protected_symlinks",
1783 .data = &sysctl_protected_symlinks,
1784 .maxlen = sizeof(int),
1785 .mode = 0600,
1786 .proc_handler = proc_dointvec_minmax,
1787 .extra1 = &zero,
1788 .extra2 = &one,
1789 },
1790 {
1791 .procname = "protected_hardlinks",
1792 .data = &sysctl_protected_hardlinks,
1793 .maxlen = sizeof(int),
1794 .mode = 0600,
1795 .proc_handler = proc_dointvec_minmax,
1796 .extra1 = &zero,
1797 .extra2 = &one,
1798 },
1799 {
Alan Coxd6e71142005-06-23 00:09:43 -07001800 .procname = "suid_dumpable",
1801 .data = &suid_dumpable,
1802 .maxlen = sizeof(int),
1803 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001804 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001805 .extra1 = &zero,
1806 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001807 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001808#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1809 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001810 .procname = "binfmt_misc",
1811 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001812 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001813 },
1814#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001815 {
Jens Axboeff9da692010-06-03 14:54:39 +02001816 .procname = "pipe-max-size",
1817 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001818 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001819 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001820 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001821 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001822 {
1823 .procname = "pipe-user-pages-hard",
1824 .data = &pipe_user_pages_hard,
1825 .maxlen = sizeof(pipe_user_pages_hard),
1826 .mode = 0644,
1827 .proc_handler = proc_doulongvec_minmax,
1828 },
1829 {
1830 .procname = "pipe-user-pages-soft",
1831 .data = &pipe_user_pages_soft,
1832 .maxlen = sizeof(pipe_user_pages_soft),
1833 .mode = 0644,
1834 .proc_handler = proc_doulongvec_minmax,
1835 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001836 {
1837 .procname = "mount-max",
1838 .data = &sysctl_mount_max,
1839 .maxlen = sizeof(unsigned int),
1840 .mode = 0644,
1841 .proc_handler = proc_dointvec_minmax,
1842 .extra1 = &one,
1843 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001844 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845};
1846
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001847static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001848#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001849 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001850 .procname = "exception-trace",
1851 .data = &show_unhandled_signals,
1852 .maxlen = sizeof(int),
1853 .mode = 0644,
1854 .proc_handler = proc_dointvec
1855 },
1856#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001857#if defined(CONFIG_OPTPROBES)
1858 {
1859 .procname = "kprobes-optimization",
1860 .data = &sysctl_kprobes_optimization,
1861 .maxlen = sizeof(int),
1862 .mode = 0644,
1863 .proc_handler = proc_kprobes_optimization_handler,
1864 .extra1 = &zero,
1865 .extra2 = &one,
1866 },
1867#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001868 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869};
1870
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001871static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001872 { }
Robert Love0eeca282005-07-12 17:06:03 -04001873};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001875int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001876{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001877 struct ctl_table_header *hdr;
1878
1879 hdr = register_sysctl_table(sysctl_base_table);
1880 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001881 return 0;
1882}
1883
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001884#endif /* CONFIG_SYSCTL */
1885
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886/*
1887 * /proc/sys support
1888 */
1889
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001890#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
Kees Cookf8808302014-06-06 14:37:17 -07001892static int _proc_do_string(char *data, int maxlen, int write,
1893 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001894 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001895{
1896 size_t len;
1897 char __user *p;
1898 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001899
1900 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001901 *lenp = 0;
1902 return 0;
1903 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001904
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001905 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001906 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1907 /* Only continue writes not past the end of buffer. */
1908 len = strlen(data);
1909 if (len > maxlen - 1)
1910 len = maxlen - 1;
1911
1912 if (*ppos > len)
1913 return 0;
1914 len = *ppos;
1915 } else {
1916 /* Start writing from beginning of buffer. */
1917 len = 0;
1918 }
1919
Kees Cook2ca9bb42014-06-06 14:37:18 -07001920 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001921 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001922 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001923 if (get_user(c, p++))
1924 return -EFAULT;
1925 if (c == 0 || c == '\n')
1926 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001927 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001928 }
Kees Cookf8808302014-06-06 14:37:17 -07001929 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001930 } else {
1931 len = strlen(data);
1932 if (len > maxlen)
1933 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001934
1935 if (*ppos > len) {
1936 *lenp = 0;
1937 return 0;
1938 }
1939
1940 data += *ppos;
1941 len -= *ppos;
1942
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001943 if (len > *lenp)
1944 len = *lenp;
1945 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001946 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001947 return -EFAULT;
1948 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001949 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001950 return -EFAULT;
1951 len++;
1952 }
1953 *lenp = len;
1954 *ppos += len;
1955 }
1956 return 0;
1957}
1958
Kees Cookf4aacea2014-06-06 14:37:19 -07001959static void warn_sysctl_write(struct ctl_table *table)
1960{
1961 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1962 "This will not be supported in the future. To silence this\n"
1963 "warning, set kernel.sysctl_writes_strict = -1\n",
1964 current->comm, table->procname);
1965}
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967/**
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001968 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1969 * @ppos: file position
1970 * @table: the sysctl table
1971 *
1972 * Returns true if the first position is non-zero and the sysctl_writes_strict
1973 * mode indicates this is not allowed for numeric input types. String proc
1974 * hadlers can ignore the return value.
1975 */
1976static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
1977 struct ctl_table *table)
1978{
1979 if (!*ppos)
1980 return false;
1981
1982 switch (sysctl_writes_strict) {
1983 case SYSCTL_WRITES_STRICT:
1984 return true;
1985 case SYSCTL_WRITES_WARN:
1986 warn_sysctl_write(table);
1987 return false;
1988 default:
1989 return false;
1990 }
1991}
1992
1993/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 * proc_dostring - read a string sysctl
1995 * @table: the sysctl table
1996 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 * @buffer: the user buffer
1998 * @lenp: the size of the user buffer
1999 * @ppos: file position
2000 *
2001 * Reads/writes a string from/to the user buffer. If the kernel
2002 * buffer provided is not large enough to hold the string, the
2003 * string is truncated. The copied string is %NULL-terminated.
2004 * If the string is being read by the user process, it is copied
2005 * and a newline '\n' is added. It is truncated if the buffer is
2006 * not large enough.
2007 *
2008 * Returns 0 on success.
2009 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002010int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 void __user *buffer, size_t *lenp, loff_t *ppos)
2012{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002013 if (write)
2014 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002015
Kees Cookf8808302014-06-06 14:37:17 -07002016 return _proc_do_string((char *)(table->data), table->maxlen, write,
2017 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018}
2019
Amerigo Wang00b7c332010-05-05 00:26:45 +00002020static size_t proc_skip_spaces(char **buf)
2021{
2022 size_t ret;
2023 char *tmp = skip_spaces(*buf);
2024 ret = tmp - *buf;
2025 *buf = tmp;
2026 return ret;
2027}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002029static void proc_skip_char(char **buf, size_t *size, const char v)
2030{
2031 while (*size) {
2032 if (**buf != v)
2033 break;
2034 (*size)--;
2035 (*buf)++;
2036 }
2037}
2038
Amerigo Wang00b7c332010-05-05 00:26:45 +00002039#define TMPBUFLEN 22
2040/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002041 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002042 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002043 * @buf: a kernel buffer
2044 * @size: size of the kernel buffer
2045 * @val: this is where the number will be stored
2046 * @neg: set to %TRUE if number is negative
2047 * @perm_tr: a vector which contains the allowed trailers
2048 * @perm_tr_len: size of the perm_tr vector
2049 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002050 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002051 * In case of success %0 is returned and @buf and @size are updated with
2052 * the amount of bytes read. If @tr is non-NULL and a trailing
2053 * character exists (size is non-zero after returning from this
2054 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002055 */
2056static int proc_get_long(char **buf, size_t *size,
2057 unsigned long *val, bool *neg,
2058 const char *perm_tr, unsigned perm_tr_len, char *tr)
2059{
2060 int len;
2061 char *p, tmp[TMPBUFLEN];
2062
2063 if (!*size)
2064 return -EINVAL;
2065
2066 len = *size;
2067 if (len > TMPBUFLEN - 1)
2068 len = TMPBUFLEN - 1;
2069
2070 memcpy(tmp, *buf, len);
2071
2072 tmp[len] = 0;
2073 p = tmp;
2074 if (*p == '-' && *size > 1) {
2075 *neg = true;
2076 p++;
2077 } else
2078 *neg = false;
2079 if (!isdigit(*p))
2080 return -EINVAL;
2081
2082 *val = simple_strtoul(p, &p, 0);
2083
2084 len = p - tmp;
2085
2086 /* We don't know if the next char is whitespace thus we may accept
2087 * invalid integers (e.g. 1234...a) or two integers instead of one
2088 * (e.g. 123...1). So lets not allow such large numbers. */
2089 if (len == TMPBUFLEN - 1)
2090 return -EINVAL;
2091
2092 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2093 return -EINVAL;
2094
2095 if (tr && (len < *size))
2096 *tr = *p;
2097
2098 *buf += len;
2099 *size -= len;
2100
2101 return 0;
2102}
2103
2104/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002105 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002106 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002107 * @buf: the user buffer
2108 * @size: the size of the user buffer
2109 * @val: the integer to be converted
2110 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002111 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002112 * In case of success %0 is returned and @buf and @size are updated with
2113 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002114 */
2115static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2116 bool neg)
2117{
2118 int len;
2119 char tmp[TMPBUFLEN], *p = tmp;
2120
2121 sprintf(p, "%s%lu", neg ? "-" : "", val);
2122 len = strlen(tmp);
2123 if (len > *size)
2124 len = *size;
2125 if (copy_to_user(*buf, tmp, len))
2126 return -EFAULT;
2127 *size -= len;
2128 *buf += len;
2129 return 0;
2130}
2131#undef TMPBUFLEN
2132
2133static int proc_put_char(void __user **buf, size_t *size, char c)
2134{
2135 if (*size) {
2136 char __user **buffer = (char __user **)buf;
2137 if (put_user(c, *buffer))
2138 return -EFAULT;
2139 (*size)--, (*buffer)++;
2140 *buf = *buffer;
2141 }
2142 return 0;
2143}
2144
2145static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 int *valp,
2147 int write, void *data)
2148{
2149 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002150 if (*negp) {
2151 if (*lvalp > (unsigned long) INT_MAX + 1)
2152 return -EINVAL;
2153 *valp = -*lvalp;
2154 } else {
2155 if (*lvalp > (unsigned long) INT_MAX)
2156 return -EINVAL;
2157 *valp = *lvalp;
2158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 } else {
2160 int val = *valp;
2161 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002162 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002163 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002165 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 *lvalp = (unsigned long)val;
2167 }
2168 }
2169 return 0;
2170}
2171
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002172static int do_proc_douintvec_conv(unsigned long *lvalp,
2173 unsigned int *valp,
2174 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002175{
2176 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002177 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002178 return -EINVAL;
2179 *valp = *lvalp;
2180 } else {
2181 unsigned int val = *valp;
2182 *lvalp = (unsigned long)val;
2183 }
2184 return 0;
2185}
2186
Amerigo Wang00b7c332010-05-05 00:26:45 +00002187static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2188
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002189static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002190 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002191 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002192 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 int write, void *data),
2194 void *data)
2195{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002197 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002198 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Amerigo Wang00b7c332010-05-05 00:26:45 +00002200 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 *lenp = 0;
2202 return 0;
2203 }
2204
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002205 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 vleft = table->maxlen / sizeof(*i);
2207 left = *lenp;
2208
2209 if (!conv)
2210 conv = do_proc_dointvec_conv;
2211
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002213 if (proc_first_pos_non_zero_ignore(ppos, table))
2214 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002215
Amerigo Wang00b7c332010-05-05 00:26:45 +00002216 if (left > PAGE_SIZE - 1)
2217 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002218 p = kbuf = memdup_user_nul(buffer, left);
2219 if (IS_ERR(kbuf))
2220 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002221 }
2222
2223 for (; left && vleft--; i++, first=0) {
2224 unsigned long lval;
2225 bool neg;
2226
2227 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002228 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002229
J. R. Okajima563b0462010-05-25 16:10:14 -07002230 if (!left)
2231 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002232 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233 proc_wspace_sep,
2234 sizeof(proc_wspace_sep), NULL);
2235 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002237 if (conv(&neg, &lval, i, 1, data)) {
2238 err = -EINVAL;
2239 break;
2240 }
2241 } else {
2242 if (conv(&neg, &lval, i, 0, data)) {
2243 err = -EINVAL;
2244 break;
2245 }
2246 if (!first)
2247 err = proc_put_char(&buffer, &left, '\t');
2248 if (err)
2249 break;
2250 err = proc_put_long(&buffer, &left, lval, neg);
2251 if (err)
2252 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 }
2254 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255
2256 if (!write && !first && left && !err)
2257 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002258 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002259 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002260 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002261 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 if (first)
2263 return err ? : -EINVAL;
2264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002266out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002271static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002272 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002274 int write, void *data),
2275 void *data)
2276{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002277 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002278 buffer, lenp, ppos, conv, data);
2279}
2280
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002281static int do_proc_douintvec_w(unsigned int *tbl_data,
2282 struct ctl_table *table,
2283 void __user *buffer,
2284 size_t *lenp, loff_t *ppos,
2285 int (*conv)(unsigned long *lvalp,
2286 unsigned int *valp,
2287 int write, void *data),
2288 void *data)
2289{
2290 unsigned long lval;
2291 int err = 0;
2292 size_t left;
2293 bool neg;
2294 char *kbuf = NULL, *p;
2295
2296 left = *lenp;
2297
2298 if (proc_first_pos_non_zero_ignore(ppos, table))
2299 goto bail_early;
2300
2301 if (left > PAGE_SIZE - 1)
2302 left = PAGE_SIZE - 1;
2303
2304 p = kbuf = memdup_user_nul(buffer, left);
2305 if (IS_ERR(kbuf))
2306 return -EINVAL;
2307
2308 left -= proc_skip_spaces(&p);
2309 if (!left) {
2310 err = -EINVAL;
2311 goto out_free;
2312 }
2313
2314 err = proc_get_long(&p, &left, &lval, &neg,
2315 proc_wspace_sep,
2316 sizeof(proc_wspace_sep), NULL);
2317 if (err || neg) {
2318 err = -EINVAL;
2319 goto out_free;
2320 }
2321
2322 if (conv(&lval, tbl_data, 1, data)) {
2323 err = -EINVAL;
2324 goto out_free;
2325 }
2326
2327 if (!err && left)
2328 left -= proc_skip_spaces(&p);
2329
2330out_free:
2331 kfree(kbuf);
2332 if (err)
2333 return -EINVAL;
2334
2335 return 0;
2336
2337 /* This is in keeping with old __do_proc_dointvec() */
2338bail_early:
2339 *ppos += *lenp;
2340 return err;
2341}
2342
2343static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2344 size_t *lenp, loff_t *ppos,
2345 int (*conv)(unsigned long *lvalp,
2346 unsigned int *valp,
2347 int write, void *data),
2348 void *data)
2349{
2350 unsigned long lval;
2351 int err = 0;
2352 size_t left;
2353
2354 left = *lenp;
2355
2356 if (conv(&lval, tbl_data, 0, data)) {
2357 err = -EINVAL;
2358 goto out;
2359 }
2360
2361 err = proc_put_long(&buffer, &left, lval, false);
2362 if (err || !left)
2363 goto out;
2364
2365 err = proc_put_char(&buffer, &left, '\n');
2366
2367out:
2368 *lenp -= left;
2369 *ppos += *lenp;
2370
2371 return err;
2372}
2373
2374static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2375 int write, void __user *buffer,
2376 size_t *lenp, loff_t *ppos,
2377 int (*conv)(unsigned long *lvalp,
2378 unsigned int *valp,
2379 int write, void *data),
2380 void *data)
2381{
2382 unsigned int *i, vleft;
2383
2384 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2385 *lenp = 0;
2386 return 0;
2387 }
2388
2389 i = (unsigned int *) tbl_data;
2390 vleft = table->maxlen / sizeof(*i);
2391
2392 /*
2393 * Arrays are not supported, keep this simple. *Do not* add
2394 * support for them.
2395 */
2396 if (vleft != 1) {
2397 *lenp = 0;
2398 return -EINVAL;
2399 }
2400
2401 if (!conv)
2402 conv = do_proc_douintvec_conv;
2403
2404 if (write)
2405 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2406 conv, data);
2407 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2408}
2409
2410static int do_proc_douintvec(struct ctl_table *table, int write,
2411 void __user *buffer, size_t *lenp, loff_t *ppos,
2412 int (*conv)(unsigned long *lvalp,
2413 unsigned int *valp,
2414 int write, void *data),
2415 void *data)
2416{
2417 return __do_proc_douintvec(table->data, table, write,
2418 buffer, lenp, ppos, conv, data);
2419}
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421/**
2422 * proc_dointvec - read a vector of integers
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2428 *
2429 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2430 * values from/to the user buffer, treated as an ASCII string.
2431 *
2432 * Returns 0 on success.
2433 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002434int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 void __user *buffer, size_t *lenp, loff_t *ppos)
2436{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002437 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2438}
2439
2440/**
2441 * proc_douintvec - read a vector of unsigned integers
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2447 *
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 *
2451 * Returns 0 on success.
2452 */
2453int proc_douintvec(struct ctl_table *table, int write,
2454 void __user *buffer, size_t *lenp, loff_t *ppos)
2455{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002456 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2457 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458}
2459
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002460/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002461 * Taint values can only be increased
2462 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002463 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002464static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002465 void __user *buffer, size_t *lenp, loff_t *ppos)
2466{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002467 struct ctl_table t;
2468 unsigned long tmptaint = get_taint();
2469 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002470
Bastian Blank91fcd412007-04-23 14:41:14 -07002471 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002472 return -EPERM;
2473
Andi Kleen25ddbb12008-10-15 22:01:41 -07002474 t = *table;
2475 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002476 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002477 if (err < 0)
2478 return err;
2479
2480 if (write) {
2481 /*
2482 * Poor man's atomic or. Not worth adding a primitive
2483 * to everyone's atomic.h for this
2484 */
2485 int i;
2486 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2487 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302488 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002489 }
2490 }
2491
2492 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002493}
2494
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002495#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002496static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002497 void __user *buffer, size_t *lenp, loff_t *ppos)
2498{
2499 if (write && !capable(CAP_SYS_ADMIN))
2500 return -EPERM;
2501
2502 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2503}
2504#endif
2505
Waiman Long24704f32018-04-10 16:35:38 -07002506/**
2507 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2508 * @min: pointer to minimum allowable value
2509 * @max: pointer to maximum allowable value
2510 *
2511 * The do_proc_dointvec_minmax_conv_param structure provides the
2512 * minimum and maximum values for doing range checking for those sysctl
2513 * parameters that use the proc_dointvec_minmax() handler.
2514 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515struct do_proc_dointvec_minmax_conv_param {
2516 int *min;
2517 int *max;
2518};
2519
Amerigo Wang00b7c332010-05-05 00:26:45 +00002520static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2521 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 int write, void *data)
2523{
2524 struct do_proc_dointvec_minmax_conv_param *param = data;
2525 if (write) {
2526 int val = *negp ? -*lvalp : *lvalp;
2527 if ((param->min && *param->min > val) ||
2528 (param->max && *param->max < val))
2529 return -EINVAL;
2530 *valp = val;
2531 } else {
2532 int val = *valp;
2533 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002534 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002535 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002537 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 *lvalp = (unsigned long)val;
2539 }
2540 }
2541 return 0;
2542}
2543
2544/**
2545 * proc_dointvec_minmax - read a vector of integers with min/max values
2546 * @table: the sysctl table
2547 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 * @buffer: the user buffer
2549 * @lenp: the size of the user buffer
2550 * @ppos: file position
2551 *
2552 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2553 * values from/to the user buffer, treated as an ASCII string.
2554 *
2555 * This routine will ensure the values are within the range specified by
2556 * table->extra1 (min) and table->extra2 (max).
2557 *
Waiman Long24704f32018-04-10 16:35:38 -07002558 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002560int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 void __user *buffer, size_t *lenp, loff_t *ppos)
2562{
2563 struct do_proc_dointvec_minmax_conv_param param = {
2564 .min = (int *) table->extra1,
2565 .max = (int *) table->extra2,
2566 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002567 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 do_proc_dointvec_minmax_conv, &param);
2569}
2570
Waiman Long24704f32018-04-10 16:35:38 -07002571/**
2572 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2573 * @min: pointer to minimum allowable value
2574 * @max: pointer to maximum allowable value
2575 *
2576 * The do_proc_douintvec_minmax_conv_param structure provides the
2577 * minimum and maximum values for doing range checking for those sysctl
2578 * parameters that use the proc_douintvec_minmax() handler.
2579 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002580struct do_proc_douintvec_minmax_conv_param {
2581 unsigned int *min;
2582 unsigned int *max;
2583};
2584
2585static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2586 unsigned int *valp,
2587 int write, void *data)
2588{
2589 struct do_proc_douintvec_minmax_conv_param *param = data;
2590
2591 if (write) {
2592 unsigned int val = *lvalp;
2593
Joe Lawrencefb910c42017-11-17 15:29:28 -08002594 if (*lvalp > UINT_MAX)
2595 return -EINVAL;
2596
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002597 if ((param->min && *param->min > val) ||
2598 (param->max && *param->max < val))
2599 return -ERANGE;
2600
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002601 *valp = val;
2602 } else {
2603 unsigned int val = *valp;
2604 *lvalp = (unsigned long) val;
2605 }
2606
2607 return 0;
2608}
2609
2610/**
2611 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2612 * @table: the sysctl table
2613 * @write: %TRUE if this is a write to the sysctl file
2614 * @buffer: the user buffer
2615 * @lenp: the size of the user buffer
2616 * @ppos: file position
2617 *
2618 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2619 * values from/to the user buffer, treated as an ASCII string. Negative
2620 * strings are not allowed.
2621 *
2622 * This routine will ensure the values are within the range specified by
2623 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2624 * check for UINT_MAX to avoid having to support wrap around uses from
2625 * userspace.
2626 *
Waiman Long24704f32018-04-10 16:35:38 -07002627 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002628 */
2629int proc_douintvec_minmax(struct ctl_table *table, int write,
2630 void __user *buffer, size_t *lenp, loff_t *ppos)
2631{
2632 struct do_proc_douintvec_minmax_conv_param param = {
2633 .min = (unsigned int *) table->extra1,
2634 .max = (unsigned int *) table->extra2,
2635 };
2636 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2637 do_proc_douintvec_minmax_conv, &param);
2638}
2639
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002640static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2641 unsigned int *valp,
2642 int write, void *data)
2643{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002644 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002645 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002646
Joe Lawrencefb910c42017-11-17 15:29:28 -08002647 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002648 if (val == 0)
2649 return -EINVAL;
2650
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002651 *valp = val;
2652 } else {
2653 unsigned int val = *valp;
2654 *lvalp = (unsigned long) val;
2655 }
2656
2657 return 0;
2658}
2659
Eric Biggers319e0a22018-02-06 15:41:49 -08002660static int proc_dopipe_max_size(struct ctl_table *table, int write,
2661 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002662{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002663 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002664 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002665}
2666
Kees Cook54b50192012-07-30 14:39:18 -07002667static void validate_coredump_safety(void)
2668{
Alex Kelly046d6622012-10-04 17:15:23 -07002669#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002670 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002671 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002672 printk(KERN_WARNING
2673"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2674"Pipe handler or fully qualified core dump path required.\n"
2675"Set kernel.core_pattern before fs.suid_dumpable.\n"
2676 );
Kees Cook54b50192012-07-30 14:39:18 -07002677 }
Alex Kelly046d6622012-10-04 17:15:23 -07002678#endif
Kees Cook54b50192012-07-30 14:39:18 -07002679}
2680
2681static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2682 void __user *buffer, size_t *lenp, loff_t *ppos)
2683{
2684 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2685 if (!error)
2686 validate_coredump_safety();
2687 return error;
2688}
2689
Alex Kelly046d6622012-10-04 17:15:23 -07002690#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002691static int proc_dostring_coredump(struct ctl_table *table, int write,
2692 void __user *buffer, size_t *lenp, loff_t *ppos)
2693{
2694 int error = proc_dostring(table, write, buffer, lenp, ppos);
2695 if (!error)
2696 validate_coredump_safety();
2697 return error;
2698}
Alex Kelly046d6622012-10-04 17:15:23 -07002699#endif
Kees Cook54b50192012-07-30 14:39:18 -07002700
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002701static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 void __user *buffer,
2703 size_t *lenp, loff_t *ppos,
2704 unsigned long convmul,
2705 unsigned long convdiv)
2706{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002707 unsigned long *i, *min, *max;
2708 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002709 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002710 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002711
2712 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 *lenp = 0;
2714 return 0;
2715 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002716
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002717 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 min = (unsigned long *) table->extra1;
2719 max = (unsigned long *) table->extra2;
2720 vleft = table->maxlen / sizeof(unsigned long);
2721 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002722
2723 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002724 if (proc_first_pos_non_zero_ignore(ppos, table))
2725 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002726
Amerigo Wang00b7c332010-05-05 00:26:45 +00002727 if (left > PAGE_SIZE - 1)
2728 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002729 p = kbuf = memdup_user_nul(buffer, left);
2730 if (IS_ERR(kbuf))
2731 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002732 }
2733
Eric Dumazet27b3d802010-10-07 12:59:29 -07002734 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002735 unsigned long val;
2736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002738 bool neg;
2739
Al Viro70f6cbb2015-12-24 00:13:10 -05002740 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002741
Al Viro70f6cbb2015-12-24 00:13:10 -05002742 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002743 proc_wspace_sep,
2744 sizeof(proc_wspace_sep), NULL);
2745 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 break;
2747 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002749 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if ((min && val < *min) || (max && val > *max))
2751 continue;
2752 *i = val;
2753 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002754 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002755 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002756 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002757 if (err)
2758 break;
2759 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002760 err = proc_put_long(&buffer, &left, val, false);
2761 if (err)
2762 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 }
2764 }
2765
Amerigo Wang00b7c332010-05-05 00:26:45 +00002766 if (!write && !first && left && !err)
2767 err = proc_put_char(&buffer, &left, '\n');
2768 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002769 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002771 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002772 if (first)
2773 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002776out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002778 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779}
2780
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002781static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002782 void __user *buffer,
2783 size_t *lenp, loff_t *ppos,
2784 unsigned long convmul,
2785 unsigned long convdiv)
2786{
2787 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002788 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002789}
2790
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791/**
2792 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2793 * @table: the sysctl table
2794 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 * @buffer: the user buffer
2796 * @lenp: the size of the user buffer
2797 * @ppos: file position
2798 *
2799 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2800 * values from/to the user buffer, treated as an ASCII string.
2801 *
2802 * This routine will ensure the values are within the range specified by
2803 * table->extra1 (min) and table->extra2 (max).
2804 *
2805 * Returns 0 on success.
2806 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002807int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 void __user *buffer, size_t *lenp, loff_t *ppos)
2809{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002810 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811}
2812
2813/**
2814 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2815 * @table: the sysctl table
2816 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 * @buffer: the user buffer
2818 * @lenp: the size of the user buffer
2819 * @ppos: file position
2820 *
2821 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2822 * values from/to the user buffer, treated as an ASCII string. The values
2823 * are treated as milliseconds, and converted to jiffies when they are stored.
2824 *
2825 * This routine will ensure the values are within the range specified by
2826 * table->extra1 (min) and table->extra2 (max).
2827 *
2828 * Returns 0 on success.
2829 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002830int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 void __user *buffer,
2832 size_t *lenp, loff_t *ppos)
2833{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002834 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 lenp, ppos, HZ, 1000l);
2836}
2837
2838
Amerigo Wang00b7c332010-05-05 00:26:45 +00002839static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 int *valp,
2841 int write, void *data)
2842{
2843 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002844 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002845 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2847 } else {
2848 int val = *valp;
2849 unsigned long lval;
2850 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002851 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002852 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002854 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 lval = (unsigned long)val;
2856 }
2857 *lvalp = lval / HZ;
2858 }
2859 return 0;
2860}
2861
Amerigo Wang00b7c332010-05-05 00:26:45 +00002862static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 int *valp,
2864 int write, void *data)
2865{
2866 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002867 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2868 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2870 } else {
2871 int val = *valp;
2872 unsigned long lval;
2873 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002874 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002875 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002877 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 lval = (unsigned long)val;
2879 }
2880 *lvalp = jiffies_to_clock_t(lval);
2881 }
2882 return 0;
2883}
2884
Amerigo Wang00b7c332010-05-05 00:26:45 +00002885static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 int *valp,
2887 int write, void *data)
2888{
2889 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002890 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2891
2892 if (jif > INT_MAX)
2893 return 1;
2894 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 } else {
2896 int val = *valp;
2897 unsigned long lval;
2898 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002899 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002900 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002902 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 lval = (unsigned long)val;
2904 }
2905 *lvalp = jiffies_to_msecs(lval);
2906 }
2907 return 0;
2908}
2909
2910/**
2911 * proc_dointvec_jiffies - read a vector of integers as seconds
2912 * @table: the sysctl table
2913 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 * @buffer: the user buffer
2915 * @lenp: the size of the user buffer
2916 * @ppos: file position
2917 *
2918 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2919 * values from/to the user buffer, treated as an ASCII string.
2920 * The values read are assumed to be in seconds, and are converted into
2921 * jiffies.
2922 *
2923 * Returns 0 on success.
2924 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002925int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 void __user *buffer, size_t *lenp, loff_t *ppos)
2927{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 do_proc_dointvec_jiffies_conv,NULL);
2930}
2931
2932/**
2933 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2934 * @table: the sysctl table
2935 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 * @buffer: the user buffer
2937 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002938 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 *
2940 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2941 * values from/to the user buffer, treated as an ASCII string.
2942 * The values read are assumed to be in 1/USER_HZ seconds, and
2943 * are converted into jiffies.
2944 *
2945 * Returns 0 on success.
2946 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002947int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 void __user *buffer, size_t *lenp, loff_t *ppos)
2949{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002950 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 do_proc_dointvec_userhz_jiffies_conv,NULL);
2952}
2953
2954/**
2955 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2956 * @table: the sysctl table
2957 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 * @buffer: the user buffer
2959 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002960 * @ppos: file position
2961 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 *
2963 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2964 * values from/to the user buffer, treated as an ASCII string.
2965 * The values read are assumed to be in 1/1000 seconds, and
2966 * are converted into jiffies.
2967 *
2968 * Returns 0 on success.
2969 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002970int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 void __user *buffer, size_t *lenp, loff_t *ppos)
2972{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002973 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 do_proc_dointvec_ms_jiffies_conv, NULL);
2975}
2976
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002977static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002978 void __user *buffer, size_t *lenp, loff_t *ppos)
2979{
2980 struct pid *new_pid;
2981 pid_t tmp;
2982 int r;
2983
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002984 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002985
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002986 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002987 lenp, ppos, NULL, NULL);
2988 if (r || !write)
2989 return r;
2990
2991 new_pid = find_get_pid(tmp);
2992 if (!new_pid)
2993 return -ESRCH;
2994
2995 put_pid(xchg(&cad_pid, new_pid));
2996 return 0;
2997}
2998
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002999/**
3000 * proc_do_large_bitmap - read/write from/to a large bitmap
3001 * @table: the sysctl table
3002 * @write: %TRUE if this is a write to the sysctl file
3003 * @buffer: the user buffer
3004 * @lenp: the size of the user buffer
3005 * @ppos: file position
3006 *
3007 * The bitmap is stored at table->data and the bitmap length (in bits)
3008 * in table->maxlen.
3009 *
3010 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3011 * large bitmaps may be represented in a compact manner. Writing into
3012 * the file will clear the bitmap then update it with the given input.
3013 *
3014 * Returns 0 on success.
3015 */
3016int proc_do_large_bitmap(struct ctl_table *table, int write,
3017 void __user *buffer, size_t *lenp, loff_t *ppos)
3018{
3019 int err = 0;
3020 bool first = 1;
3021 size_t left = *lenp;
3022 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003023 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003024 unsigned long *tmp_bitmap = NULL;
3025 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3026
WANG Cong122ff242014-05-12 16:04:53 -07003027 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003028 *lenp = 0;
3029 return 0;
3030 }
3031
3032 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003033 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003034
3035 if (left > PAGE_SIZE - 1)
3036 left = PAGE_SIZE - 1;
3037
Al Viro70f6cbb2015-12-24 00:13:10 -05003038 p = kbuf = memdup_user_nul(buffer, left);
3039 if (IS_ERR(kbuf))
3040 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003041
Kees Cook6396bb22018-06-12 14:03:40 -07003042 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3043 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003044 GFP_KERNEL);
3045 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003046 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003047 return -ENOMEM;
3048 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003049 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003050 while (!err && left) {
3051 unsigned long val_a, val_b;
3052 bool neg;
3053
Al Viro70f6cbb2015-12-24 00:13:10 -05003054 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003055 sizeof(tr_a), &c);
3056 if (err)
3057 break;
3058 if (val_a >= bitmap_len || neg) {
3059 err = -EINVAL;
3060 break;
3061 }
3062
3063 val_b = val_a;
3064 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003065 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003066 left--;
3067 }
3068
3069 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003070 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003071 &neg, tr_b, sizeof(tr_b),
3072 &c);
3073 if (err)
3074 break;
3075 if (val_b >= bitmap_len || neg ||
3076 val_a > val_b) {
3077 err = -EINVAL;
3078 break;
3079 }
3080 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003081 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003082 left--;
3083 }
3084 }
3085
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003086 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003087 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003088 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003089 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003090 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003091 } else {
3092 unsigned long bit_a, bit_b = 0;
3093
3094 while (left) {
3095 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3096 if (bit_a >= bitmap_len)
3097 break;
3098 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3099 bit_a + 1) - 1;
3100
3101 if (!first) {
3102 err = proc_put_char(&buffer, &left, ',');
3103 if (err)
3104 break;
3105 }
3106 err = proc_put_long(&buffer, &left, bit_a, false);
3107 if (err)
3108 break;
3109 if (bit_a != bit_b) {
3110 err = proc_put_char(&buffer, &left, '-');
3111 if (err)
3112 break;
3113 err = proc_put_long(&buffer, &left, bit_b, false);
3114 if (err)
3115 break;
3116 }
3117
3118 first = 0; bit_b++;
3119 }
3120 if (!err)
3121 err = proc_put_char(&buffer, &left, '\n');
3122 }
3123
3124 if (!err) {
3125 if (write) {
3126 if (*ppos)
3127 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3128 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003129 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003130 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003131 *lenp -= left;
3132 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003133 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003134
3135 kfree(tmp_bitmap);
3136 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003137}
3138
Jovi Zhang55610502011-01-12 17:00:45 -08003139#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003141int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 void __user *buffer, size_t *lenp, loff_t *ppos)
3143{
3144 return -ENOSYS;
3145}
3146
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003147int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 void __user *buffer, size_t *lenp, loff_t *ppos)
3149{
3150 return -ENOSYS;
3151}
3152
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003153int proc_douintvec(struct ctl_table *table, int write,
3154 void __user *buffer, size_t *lenp, loff_t *ppos)
3155{
3156 return -ENOSYS;
3157}
3158
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003159int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 void __user *buffer, size_t *lenp, loff_t *ppos)
3161{
3162 return -ENOSYS;
3163}
3164
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003165int proc_douintvec_minmax(struct ctl_table *table, int write,
3166 void __user *buffer, size_t *lenp, loff_t *ppos)
3167{
3168 return -ENOSYS;
3169}
3170
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003171int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 void __user *buffer, size_t *lenp, loff_t *ppos)
3173{
3174 return -ENOSYS;
3175}
3176
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003177int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 void __user *buffer, size_t *lenp, loff_t *ppos)
3179{
3180 return -ENOSYS;
3181}
3182
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003183int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 void __user *buffer, size_t *lenp, loff_t *ppos)
3185{
3186 return -ENOSYS;
3187}
3188
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003189int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 void __user *buffer, size_t *lenp, loff_t *ppos)
3191{
3192 return -ENOSYS;
3193}
3194
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003195int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 void __user *buffer,
3197 size_t *lenp, loff_t *ppos)
3198{
3199 return -ENOSYS;
3200}
3201
3202
Jovi Zhang55610502011-01-12 17:00:45 -08003203#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205/*
3206 * No sense putting this after each symbol definition, twice,
3207 * exception granted :-)
3208 */
3209EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003210EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211EXPORT_SYMBOL(proc_dointvec_jiffies);
3212EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003213EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3215EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3216EXPORT_SYMBOL(proc_dostring);
3217EXPORT_SYMBOL(proc_doulongvec_minmax);
3218EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);