blob: b9ff323e1d261dcb4282c9d44686f73ba635ef54 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl.c: General linux system control interface
4 *
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Horn.
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * Wendling.
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080023#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/mm.h>
25#include <linux/swap.h>
26#include <linux/slab.h>
27#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070028#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080029#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080030#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070032#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010066#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080067#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070068#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050069#include <linux/mount.h>
Peter Xucefdca02019-05-13 17:16:41 -070070#include <linux/userfaultfd_k.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Christian Brauner7f2923c2019-03-07 16:29:40 -080072#include "../lib/kstrtox.h"
73
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080074#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <asm/processor.h>
76
Andi Kleen29cbc782006-09-30 01:47:55 +020077#ifdef CONFIG_X86
78#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010079#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010080#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020081#endif
David Howellsd550bbd2012-03-28 18:30:03 +010082#ifdef CONFIG_SPARC
83#include <asm/setup.h>
84#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080085#ifdef CONFIG_BSD_PROCESS_ACCT
86#include <linux/acct.h>
87#endif
Dave Young4f0e0562010-03-10 15:24:09 -080088#ifdef CONFIG_RT_MUTEXES
89#include <linux/rtmutex.h>
90#endif
Dave Young2edf5e42010-03-10 15:24:10 -080091#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92#include <linux/lockdep.h>
93#endif
Dave Young15485a42010-03-10 15:24:07 -080094#ifdef CONFIG_CHR_DEV_SG
95#include <scsi/sg.h>
96#endif
Alexander Popov964c9df2018-08-17 01:17:03 +030097#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98#include <linux/stackleak.h>
99#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400100#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -0500101#include <linux/nmi.h>
102#endif
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#if defined(CONFIG_SYSCTL)
105
106/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700107extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700108#ifdef CONFIG_COREDUMP
109extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700111extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800115extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100116extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300117extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000118#ifndef CONFIG_MMU
119extern int sysctl_nr_trim_pages;
120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400123#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int sixty = 60;
125#endif
126
Aaron Tomlin270750db2014-01-20 17:34:13 +0000127static int __maybe_unused neg_one = -1;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700128static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700129static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700130static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800131static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800132static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700133static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700134static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700135#ifdef CONFIG_PRINTK
136static int ten_thousand = 10000;
137#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300138#ifdef CONFIG_PERF_EVENTS
139static int six_hundred_forty_kb = 640 * 1024;
140#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700141
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700142/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146static int maxolduid = 65535;
147static int minolduid;
148
149static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700150static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700152/*
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
155 */
Liu Hua80df2842014-04-07 15:38:57 -0700156#ifdef CONFIG_DETECT_HUNG_TASK
157static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
158#endif
159
Dave Youngd14f1722010-02-25 20:28:57 -0500160#ifdef CONFIG_INOTIFY_USER
161#include <linux/inotify.h>
162#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700163#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#endif
165
Helge Dellerb67114d2019-10-04 13:10:09 +0200166#ifdef CONFIG_PARISC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530168#endif
169
170#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171extern int unaligned_enabled;
172#endif
173
Jes Sorensend2b176e2006-02-28 09:42:23 -0800174#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800175extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800176#endif
177
Vineet Guptab6fca722013-01-09 20:06:28 +0530178#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179extern int no_unaligned_warning;
180#endif
181
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700182#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700183
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700184/**
185 * enum sysctl_writes_mode - supported sysctl write modes
186 *
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700192 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max length will be ignored. Multiple writes will append
198 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700199 *
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
202 */
203enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
207};
Kees Cookf4aacea2014-06-06 14:37:19 -0700208
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700209static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700210
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700211static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700212 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700213static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800214 void __user *buffer, size_t *lenp, loff_t *ppos);
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700215#ifdef CONFIG_COMPACTION
216static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
217 int write, void __user *buffer,
218 size_t *lenp, loff_t *ppos);
219#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700220#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700221
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700222#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700223static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700224 void __user *buffer, size_t *lenp, loff_t *ppos);
225#endif
226
Kees Cook54b50192012-07-30 14:39:18 -0700227static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
228 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700229#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700230static int proc_dostring_coredump(struct ctl_table *table, int write,
231 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700232#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800233static int proc_dopipe_max_size(struct ctl_table *table, int write,
234 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700235
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700236#ifdef CONFIG_MAGIC_SYSRQ
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700237static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Safonoveaee4172020-03-02 17:51:34 +0000238 void __user *buffer, size_t *lenp, loff_t *ppos);
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700239#endif
240
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700241static struct ctl_table kern_table[];
242static struct ctl_table vm_table[];
243static struct ctl_table fs_table[];
244static struct ctl_table debug_table[];
245static struct ctl_table dev_table[];
246extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800247#ifdef CONFIG_EPOLL
248extern struct ctl_table epoll_table[];
249#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800251#ifdef CONFIG_FW_LOADER_USER_HELPER
252extern struct ctl_table firmware_config_table[];
253#endif
254
Alexandre Ghiti67f39772019-09-23 15:38:47 -0700255#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
256 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257int sysctl_legacy_va_layout;
258#endif
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/* The default sysctl tables: */
261
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800262static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 .procname = "kernel",
265 .mode = 0555,
266 .child = kern_table,
267 },
268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 .procname = "vm",
270 .mode = 0555,
271 .child = vm_table,
272 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .procname = "fs",
275 .mode = 0555,
276 .child = fs_table,
277 },
278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 .procname = "debug",
280 .mode = 0555,
281 .child = debug_table,
282 },
283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 .procname = "dev",
285 .mode = 0555,
286 .child = dev_table,
287 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700288 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289};
290
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100292static int min_sched_granularity_ns = 100000; /* 100 usecs */
293static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
294static int min_wakeup_granularity_ns; /* 0 usecs */
295static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200296#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100297static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
298static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200299#endif /* CONFIG_SMP */
300#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301
Mel Gorman5e771902010-05-24 14:32:31 -0700302#ifdef CONFIG_COMPACTION
303static int min_extfrag_threshold;
304static int max_extfrag_threshold = 1000;
305#endif
306
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700307static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200308 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200309 .procname = "sched_child_runs_first",
310 .data = &sysctl_sched_child_runs_first,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800313 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200314 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200315#ifdef CONFIG_SCHED_DEBUG
316 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100317 .procname = "sched_min_granularity_ns",
318 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800321 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100322 .extra1 = &min_sched_granularity_ns,
323 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200324 },
325 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200326 .procname = "sched_latency_ns",
327 .data = &sysctl_sched_latency,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800330 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200331 .extra1 = &min_sched_granularity_ns,
332 .extra2 = &max_sched_granularity_ns,
333 },
334 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200335 .procname = "sched_wakeup_granularity_ns",
336 .data = &sysctl_sched_wakeup_granularity,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800339 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200340 .extra1 = &min_wakeup_granularity_ns,
341 .extra2 = &max_wakeup_granularity_ns,
342 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200343#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200344 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100345 .procname = "sched_tunable_scaling",
346 .data = &sysctl_sched_tunable_scaling,
347 .maxlen = sizeof(enum sched_tunable_scaling),
348 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800349 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100350 .extra1 = &min_sched_tunable_scaling,
351 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200352 },
353 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900354 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200355 .data = &sysctl_sched_migration_cost,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800358 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200359 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100360 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100361 .procname = "sched_nr_migrate",
362 .data = &sysctl_sched_nr_migrate,
363 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800365 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100366 },
Mel Gormancb251762016-02-05 09:08:36 +0000367#ifdef CONFIG_SCHEDSTATS
368 {
369 .procname = "sched_schedstats",
370 .data = NULL,
371 .maxlen = sizeof(unsigned int),
372 .mode = 0644,
373 .proc_handler = sysctl_schedstats,
Matteo Croceeec48442019-07-18 15:58:50 -0700374 .extra1 = SYSCTL_ZERO,
375 .extra2 = SYSCTL_ONE,
Mel Gormancb251762016-02-05 09:08:36 +0000376 },
377#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200378#endif /* CONFIG_SMP */
379#ifdef CONFIG_NUMA_BALANCING
380 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200381 .procname = "numa_balancing_scan_delay_ms",
382 .data = &sysctl_numa_balancing_scan_delay,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = proc_dointvec,
386 },
387 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200388 .procname = "numa_balancing_scan_period_min_ms",
389 .data = &sysctl_numa_balancing_scan_period_min,
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
392 .proc_handler = proc_dointvec,
393 },
394 {
395 .procname = "numa_balancing_scan_period_max_ms",
396 .data = &sysctl_numa_balancing_scan_period_max,
397 .maxlen = sizeof(unsigned int),
398 .mode = 0644,
399 .proc_handler = proc_dointvec,
400 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200401 {
402 .procname = "numa_balancing_scan_size_mb",
403 .data = &sysctl_numa_balancing_scan_size,
404 .maxlen = sizeof(unsigned int),
405 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400406 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700407 .extra1 = SYSCTL_ONE,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200408 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100409 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800410 .procname = "numa_balancing",
411 .data = NULL, /* filled in by handler */
412 .maxlen = sizeof(unsigned int),
413 .mode = 0644,
414 .proc_handler = sysctl_numa_balancing,
Matteo Croceeec48442019-07-18 15:58:50 -0700415 .extra1 = SYSCTL_ZERO,
416 .extra2 = SYSCTL_ONE,
Andi Kleen54a43d52014-01-23 15:53:13 -0800417 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200418#endif /* CONFIG_NUMA_BALANCING */
419#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200420 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100421 .procname = "sched_rt_period_us",
422 .data = &sysctl_sched_rt_period,
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800425 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100426 },
427 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100428 .procname = "sched_rt_runtime_us",
429 .data = &sysctl_sched_rt_runtime,
430 .maxlen = sizeof(int),
431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800432 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100433 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600434 {
435 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800436 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600437 .maxlen = sizeof(int),
438 .mode = 0644,
439 .proc_handler = sched_rr_handler,
440 },
Patrick Bellasie8f14172019-06-21 09:42:05 +0100441#ifdef CONFIG_UCLAMP_TASK
442 {
443 .procname = "sched_util_clamp_min",
444 .data = &sysctl_sched_uclamp_util_min,
445 .maxlen = sizeof(unsigned int),
446 .mode = 0644,
447 .proc_handler = sysctl_sched_uclamp_handler,
448 },
449 {
450 .procname = "sched_util_clamp_max",
451 .data = &sysctl_sched_uclamp_util_max,
452 .maxlen = sizeof(unsigned int),
453 .mode = 0644,
454 .proc_handler = sysctl_sched_uclamp_handler,
455 },
456#endif
Mike Galbraith5091faa2010-11-30 14:18:03 +0100457#ifdef CONFIG_SCHED_AUTOGROUP
458 {
459 .procname = "sched_autogroup_enabled",
460 .data = &sysctl_sched_autogroup_enabled,
461 .maxlen = sizeof(unsigned int),
462 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800463 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700464 .extra1 = SYSCTL_ZERO,
465 .extra2 = SYSCTL_ONE,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100466 },
467#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700468#ifdef CONFIG_CFS_BANDWIDTH
469 {
470 .procname = "sched_cfs_bandwidth_slice_us",
471 .data = &sysctl_sched_cfs_bandwidth_slice,
472 .maxlen = sizeof(unsigned int),
473 .mode = 0644,
474 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700475 .extra1 = SYSCTL_ONE,
Paul Turnerec12cb72011-07-21 09:43:30 -0700476 },
477#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000478#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
479 {
480 .procname = "sched_energy_aware",
481 .data = &sysctl_sched_energy_aware,
482 .maxlen = sizeof(unsigned int),
483 .mode = 0644,
484 .proc_handler = sched_energy_aware_handler,
Matteo Croceeec48442019-07-18 15:58:50 -0700485 .extra1 = SYSCTL_ZERO,
486 .extra2 = SYSCTL_ONE,
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000487 },
488#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700489#ifdef CONFIG_PROVE_LOCKING
490 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700491 .procname = "prove_locking",
492 .data = &prove_locking,
493 .maxlen = sizeof(int),
494 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800495 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700496 },
497#endif
498#ifdef CONFIG_LOCK_STAT
499 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700500 .procname = "lock_stat",
501 .data = &lock_stat,
502 .maxlen = sizeof(int),
503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800504 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700505 },
506#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .procname = "panic",
509 .data = &panic_timeout,
510 .maxlen = sizeof(int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
Alex Kelly046d6622012-10-04 17:15:23 -0700514#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .procname = "core_uses_pid",
517 .data = &core_uses_pid,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
522 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .procname = "core_pattern",
524 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700525 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700527 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 },
Neil Hormana2939802009-09-23 15:56:56 -0700529 {
Neil Hormana2939802009-09-23 15:56:56 -0700530 .procname = "core_pipe_limit",
531 .data = &core_pipe_limit,
532 .maxlen = sizeof(unsigned int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700535 },
Alex Kelly046d6622012-10-04 17:15:23 -0700536#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800537#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700540 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800542 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700544 {
545 .procname = "sysctl_writes_strict",
546 .data = &sysctl_writes_strict,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec_minmax,
550 .extra1 = &neg_one,
Matteo Croceeec48442019-07-18 15:58:50 -0700551 .extra2 = SYSCTL_ONE,
Kees Cookf4aacea2014-06-06 14:37:19 -0700552 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800553#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100554#ifdef CONFIG_LATENCYTOP
555 {
556 .procname = "latencytop",
557 .data = &latencytop_enabled,
558 .maxlen = sizeof(int),
559 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000560 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100561 },
562#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#ifdef CONFIG_BLK_DEV_INITRD
564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "real-root-dev",
566 .data = &real_root_dev,
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#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700572 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700573 .procname = "print-fatal-signals",
574 .data = &print_fatal_signals,
575 .maxlen = sizeof(int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700578 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700579#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "reboot-cmd",
582 .data = reboot_command,
583 .maxlen = 256,
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "stop-a",
589 .data = &stop_a_enabled,
590 .maxlen = sizeof (int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .procname = "scons-poweroff",
596 .data = &scons_pwroff,
597 .maxlen = sizeof (int),
598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800599 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 },
601#endif
David S. Miller08714202008-11-16 23:49:24 -0800602#ifdef CONFIG_SPARC64
603 {
David S. Miller08714202008-11-16 23:49:24 -0800604 .procname = "tsb-ratio",
605 .data = &sysctl_tsb_ratio,
606 .maxlen = sizeof (int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800609 },
610#endif
Helge Dellerb67114d2019-10-04 13:10:09 +0200611#ifdef CONFIG_PARISC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .procname = "soft-power",
614 .data = &pwrsw_enabled,
615 .maxlen = sizeof (int),
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530619#endif
620#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "unaligned-trap",
623 .data = &unaligned_enabled,
624 .maxlen = sizeof (int),
625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800626 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 },
628#endif
629 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 .procname = "ctrl-alt-del",
631 .data = &C_A_D,
632 .maxlen = sizeof(int),
633 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800634 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400636#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200637 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200638 .procname = "ftrace_enabled",
639 .data = &ftrace_enabled,
640 .maxlen = sizeof(int),
641 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800642 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200643 },
644#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500645#ifdef CONFIG_STACK_TRACER
646 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500647 .procname = "stack_tracer_enabled",
648 .data = &stack_tracer_enabled,
649 .maxlen = sizeof(int),
650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500652 },
653#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400654#ifdef CONFIG_TRACING
655 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100656 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400657 .data = &ftrace_dump_on_oops,
658 .maxlen = sizeof(int),
659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800660 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400661 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400662 {
663 .procname = "traceoff_on_warning",
664 .data = &__disable_trace_on_warning,
665 .maxlen = sizeof(__disable_trace_on_warning),
666 .mode = 0644,
667 .proc_handler = proc_dointvec,
668 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500669 {
670 .procname = "tracepoint_printk",
671 .data = &tracepoint_printk,
672 .maxlen = sizeof(tracepoint_printk),
673 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500674 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500675 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400676#endif
Dave Young2965faa2015-09-09 15:38:55 -0700677#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800678 {
679 .procname = "kexec_load_disabled",
680 .data = &kexec_load_disabled,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 /* only handle a transition from default "0" to "1" */
684 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700685 .extra1 = SYSCTL_ONE,
686 .extra2 = SYSCTL_ONE,
Kees Cook79847542014-01-23 15:55:59 -0800687 },
688#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200689#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .procname = "modprobe",
692 .data = &modprobe_path,
693 .maxlen = KMOD_PATH_LEN,
694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800695 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
Kees Cook3d433212009-04-02 15:49:29 -0700697 {
Kees Cook3d433212009-04-02 15:49:29 -0700698 .procname = "modules_disabled",
699 .data = &modules_disabled,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800703 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700704 .extra1 = SYSCTL_ONE,
705 .extra2 = SYSCTL_ONE,
Kees Cook3d433212009-04-02 15:49:29 -0700706 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700708#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100711 .data = &uevent_helper,
712 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800714 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 },
Michael Marineau86d56132014-04-10 14:09:31 -0700716#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#ifdef CONFIG_CHR_DEV_SG
718 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .procname = "sg-big-buff",
720 .data = &sg_big_buff,
721 .maxlen = sizeof (int),
722 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800723 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 },
725#endif
726#ifdef CONFIG_BSD_PROCESS_ACCT
727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .procname = "acct",
729 .data = &acct_parm,
730 .maxlen = 3*sizeof(int),
731 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800732 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 },
734#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#ifdef CONFIG_MAGIC_SYSRQ
736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .procname = "sysrq",
Dmitry Safonoveaee4172020-03-02 17:51:34 +0000738 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .maxlen = sizeof (int),
740 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700741 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 },
743#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700744#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700747 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .maxlen = sizeof (int),
749 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700752#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700755 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 .maxlen = sizeof(int),
757 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700758 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 },
760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .procname = "random",
762 .mode = 0555,
763 .child = random_table,
764 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 {
Eric Paris17f60a72011-04-01 17:07:50 -0400766 .procname = "usermodehelper",
767 .mode = 0555,
768 .child = usermodehelper_table,
769 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800770#ifdef CONFIG_FW_LOADER_USER_HELPER
771 {
772 .procname = "firmware_config",
773 .mode = 0555,
774 .child = firmware_config_table,
775 },
776#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400777 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 .procname = "overflowuid",
779 .data = &overflowuid,
780 .maxlen = sizeof(int),
781 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800782 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .extra1 = &minolduid,
784 .extra2 = &maxolduid,
785 },
786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "overflowgid",
788 .data = &overflowgid,
789 .maxlen = sizeof(int),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .extra1 = &minolduid,
793 .extra2 = &maxolduid,
794 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800795#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200798 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .maxlen = sizeof(int),
800 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 },
803#endif
804 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 .procname = "pid_max",
806 .data = &pid_max,
807 .maxlen = sizeof (int),
808 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800809 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 .extra1 = &pid_max_min,
811 .extra2 = &pid_max_max,
812 },
813 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 .procname = "panic_on_oops",
815 .data = &panic_on_oops,
816 .maxlen = sizeof(int),
817 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800818 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 },
Feng Tang81c9d432019-01-03 15:28:20 -0800820 {
821 .procname = "panic_print",
822 .data = &panic_print,
823 .maxlen = sizeof(unsigned long),
824 .mode = 0644,
825 .proc_handler = proc_doulongvec_minmax,
826 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800827#if defined CONFIG_PRINTK
828 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800829 .procname = "printk",
830 .data = &console_loglevel,
831 .maxlen = 4*sizeof(int),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800834 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700837 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 .maxlen = sizeof(int),
839 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800840 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 },
842 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700844 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 .maxlen = sizeof(int),
846 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800847 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 },
Dave Youngaf913222009-09-22 16:43:33 -0700849 {
Dave Youngaf913222009-09-22 16:43:33 -0700850 .procname = "printk_delay",
851 .data = &printk_delay_msec,
852 .maxlen = sizeof(int),
853 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800854 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700855 .extra1 = SYSCTL_ZERO,
Dave Youngaf913222009-09-22 16:43:33 -0700856 .extra2 = &ten_thousand,
857 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700859 .procname = "printk_devkmsg",
860 .data = devkmsg_log_str,
861 .maxlen = DEVKMSG_STR_MAX_SIZE,
862 .mode = 0644,
863 .proc_handler = devkmsg_sysctl_set_loglvl,
864 },
865 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800866 .procname = "dmesg_restrict",
867 .data = &dmesg_restrict,
868 .maxlen = sizeof(int),
869 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700870 .proc_handler = proc_dointvec_minmax_sysadmin,
Matteo Croceeec48442019-07-18 15:58:50 -0700871 .extra1 = SYSCTL_ZERO,
872 .extra2 = SYSCTL_ONE,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800873 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800874 {
875 .procname = "kptr_restrict",
876 .data = &kptr_restrict,
877 .maxlen = sizeof(int),
878 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700879 .proc_handler = proc_dointvec_minmax_sysadmin,
Matteo Croceeec48442019-07-18 15:58:50 -0700880 .extra1 = SYSCTL_ZERO,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800881 .extra2 = &two,
882 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800883#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800884 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 .procname = "ngroups_max",
886 .data = &ngroups_max,
887 .maxlen = sizeof (int),
888 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800889 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 },
Dan Ballard73efc032011-10-31 17:11:20 -0700891 {
892 .procname = "cap_last_cap",
893 .data = (void *)&cap_last_cap,
894 .maxlen = sizeof(int),
895 .mode = 0444,
896 .proc_handler = proc_dointvec,
897 },
Don Zickus58687ac2010-05-07 17:11:44 -0400898#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500899 {
Don Zickus58687ac2010-05-07 17:11:44 -0400900 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200901 .data = &watchdog_user_enabled,
902 .maxlen = sizeof(int),
903 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700904 .proc_handler = proc_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -0700905 .extra1 = SYSCTL_ZERO,
906 .extra2 = SYSCTL_ONE,
Don Zickus58687ac2010-05-07 17:11:44 -0400907 },
908 {
909 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700910 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400911 .maxlen = sizeof(int),
912 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700913 .proc_handler = proc_watchdog_thresh,
Matteo Croceeec48442019-07-18 15:58:50 -0700914 .extra1 = SYSCTL_ZERO,
Don Zickus58687ac2010-05-07 17:11:44 -0400915 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500916 },
Don Zickus2508ce12010-05-07 17:11:46 -0400917 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700918 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200919 .data = &nmi_watchdog_user_enabled,
920 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200921 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700922 .proc_handler = proc_nmi_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -0700923 .extra1 = SYSCTL_ZERO,
924 .extra2 = SYSCTL_ONE,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700925 },
926 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700927 .procname = "watchdog_cpumask",
928 .data = &watchdog_cpumask_bits,
929 .maxlen = NR_CPUS,
930 .mode = 0644,
931 .proc_handler = proc_watchdog_cpumask,
932 },
933#ifdef CONFIG_SOFTLOCKUP_DETECTOR
934 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700935 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200936 .data = &soft_watchdog_user_enabled,
937 .maxlen = sizeof(int),
938 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700939 .proc_handler = proc_soft_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -0700940 .extra1 = SYSCTL_ZERO,
941 .extra2 = SYSCTL_ONE,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700942 },
943 {
Don Zickus2508ce12010-05-07 17:11:46 -0400944 .procname = "softlockup_panic",
945 .data = &softlockup_panic,
946 .maxlen = sizeof(int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700949 .extra1 = SYSCTL_ZERO,
950 .extra2 = SYSCTL_ONE,
Don Zickus2508ce12010-05-07 17:11:46 -0400951 },
Aaron Tomlined235872014-06-23 13:22:05 -0700952#ifdef CONFIG_SMP
953 {
954 .procname = "softlockup_all_cpu_backtrace",
955 .data = &sysctl_softlockup_all_cpu_backtrace,
956 .maxlen = sizeof(int),
957 .mode = 0644,
958 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700959 .extra1 = SYSCTL_ZERO,
960 .extra2 = SYSCTL_ONE,
Aaron Tomlined235872014-06-23 13:22:05 -0700961 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700962#endif /* CONFIG_SMP */
963#endif
964#ifdef CONFIG_HARDLOCKUP_DETECTOR
965 {
966 .procname = "hardlockup_panic",
967 .data = &hardlockup_panic,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700971 .extra1 = SYSCTL_ZERO,
972 .extra2 = SYSCTL_ONE,
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700973 },
974#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800975 {
976 .procname = "hardlockup_all_cpu_backtrace",
977 .data = &sysctl_hardlockup_all_cpu_backtrace,
978 .maxlen = sizeof(int),
979 .mode = 0644,
980 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700981 .extra1 = SYSCTL_ZERO,
982 .extra2 = SYSCTL_ONE,
Jiri Kosina55537872015-11-05 18:44:41 -0800983 },
Aaron Tomlined235872014-06-23 13:22:05 -0700984#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500985#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700986#endif
987
Don Zickus5dc30552010-11-29 17:07:17 -0500988#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
989 {
990 .procname = "unknown_nmi_panic",
991 .data = &unknown_nmi_panic,
992 .maxlen = sizeof (int),
993 .mode = 0644,
994 .proc_handler = proc_dointvec,
995 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500996#endif
Xiaoming Nib6522fa2020-04-11 21:06:19 +0800997
998#if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
999 defined(CONFIG_DEBUG_STACKOVERFLOW)
1000 {
1001 .procname = "panic_on_stackoverflow",
1002 .data = &sysctl_panic_on_stackoverflow,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
1005 .proc_handler = proc_dointvec,
1006 },
1007#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008#if defined(CONFIG_X86)
1009 {
Don Zickus8da5add2006-09-26 10:52:27 +02001010 .procname = "panic_on_unrecovered_nmi",
1011 .data = &panic_on_unrecovered_nmi,
1012 .maxlen = sizeof(int),
1013 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001014 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001015 },
1016 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001017 .procname = "panic_on_io_nmi",
1018 .data = &panic_on_io_nmi,
1019 .maxlen = sizeof(int),
1020 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001021 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001022 },
1023 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .procname = "bootloader_type",
1025 .data = &bootloader_type,
1026 .maxlen = sizeof (int),
1027 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001028 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001030 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001031 .procname = "bootloader_version",
1032 .data = &bootloader_version,
1033 .maxlen = sizeof (int),
1034 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001036 },
1037 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001038 .procname = "io_delay_type",
1039 .data = &io_delay_type,
1040 .maxlen = sizeof(int),
1041 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001042 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001043 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001045#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 .procname = "randomize_va_space",
1048 .data = &randomize_va_space,
1049 .maxlen = sizeof(int),
1050 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001051 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001053#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001054#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001055 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001056 .procname = "spin_retry",
1057 .data = &spin_retry,
1058 .maxlen = sizeof (int),
1059 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001060 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001061 },
1062#endif
Len Brown673d5b42007-07-28 03:33:16 -04001063#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001064 {
Pavel Machekc255d842006-02-20 18:27:58 -08001065 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001066 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001067 .maxlen = sizeof (unsigned long),
1068 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001069 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001070 },
1071#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301072#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001073 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001074 .procname = "ignore-unaligned-usertrap",
1075 .data = &no_unaligned_warning,
1076 .maxlen = sizeof (int),
1077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001079 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301080#endif
1081#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001082 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001083 .procname = "unaligned-dump-stack",
1084 .data = &unaligned_dump_stack,
1085 .maxlen = sizeof (int),
1086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001088 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001089#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001090#ifdef CONFIG_DETECT_HUNG_TASK
1091 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001092 .procname = "hung_task_panic",
1093 .data = &sysctl_hung_task_panic,
1094 .maxlen = sizeof(int),
1095 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001096 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001097 .extra1 = SYSCTL_ZERO,
1098 .extra2 = SYSCTL_ONE,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001099 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001100 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001101 .procname = "hung_task_check_count",
1102 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001103 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001104 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001105 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001106 .extra1 = SYSCTL_ZERO,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001107 },
1108 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001109 .procname = "hung_task_timeout_secs",
1110 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001111 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001112 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001113 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001114 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001115 },
1116 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001117 .procname = "hung_task_check_interval_secs",
1118 .data = &sysctl_hung_task_check_interval_secs,
1119 .maxlen = sizeof(unsigned long),
1120 .mode = 0644,
1121 .proc_handler = proc_dohung_task_timeout_secs,
1122 .extra2 = &hung_task_timeout_max,
1123 },
1124 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001125 .procname = "hung_task_warnings",
1126 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001127 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001128 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001129 .proc_handler = proc_dointvec_minmax,
1130 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001131 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001132#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001133#ifdef CONFIG_RT_MUTEXES
1134 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001135 .procname = "max_lock_depth",
1136 .data = &max_lock_depth,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001140 },
1141#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001142 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001143 .procname = "poweroff_cmd",
1144 .data = &poweroff_cmd,
1145 .maxlen = POWEROFF_CMD_PATH_LEN,
1146 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001147 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001148 },
David Howells0b77f5b2008-04-29 01:01:32 -07001149#ifdef CONFIG_KEYS
1150 {
David Howells0b77f5b2008-04-29 01:01:32 -07001151 .procname = "keys",
1152 .mode = 0555,
1153 .child = key_sysctls,
1154 },
1155#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001156#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001157 /*
1158 * User-space scripts rely on the existence of this file
1159 * as a feature check for perf_events being enabled.
1160 *
1161 * So it's an ABI, do not remove!
1162 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001163 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001164 .procname = "perf_event_paranoid",
1165 .data = &sysctl_perf_event_paranoid,
1166 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001167 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001168 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001169 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001170 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001171 .procname = "perf_event_mlock_kb",
1172 .data = &sysctl_perf_event_mlock,
1173 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001174 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001175 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001176 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001177 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001178 .procname = "perf_event_max_sample_rate",
1179 .data = &sysctl_perf_event_sample_rate,
1180 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001181 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001182 .proc_handler = perf_proc_update_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001183 .extra1 = SYSCTL_ONE,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001184 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001185 {
1186 .procname = "perf_cpu_time_max_percent",
1187 .data = &sysctl_perf_cpu_time_max_percent,
1188 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1189 .mode = 0644,
1190 .proc_handler = perf_cpu_time_max_percent_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001191 .extra1 = SYSCTL_ZERO,
Dave Hansen14c63f12013-06-21 08:51:36 -07001192 .extra2 = &one_hundred,
1193 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001194 {
1195 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001196 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001197 .maxlen = sizeof(sysctl_perf_event_max_stack),
1198 .mode = 0644,
1199 .proc_handler = perf_event_max_stack_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001200 .extra1 = SYSCTL_ZERO,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001201 .extra2 = &six_hundred_forty_kb,
1202 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001203 {
1204 .procname = "perf_event_max_contexts_per_stack",
1205 .data = &sysctl_perf_event_max_contexts_per_stack,
1206 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1207 .mode = 0644,
1208 .proc_handler = perf_event_max_stack_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001209 .extra1 = SYSCTL_ZERO,
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001210 .extra2 = &one_thousand,
1211 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001212#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001213 {
1214 .procname = "panic_on_warn",
1215 .data = &panic_on_warn,
1216 .maxlen = sizeof(int),
1217 .mode = 0644,
1218 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001219 .extra1 = SYSCTL_ZERO,
1220 .extra2 = SYSCTL_ONE,
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001221 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001222#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1223 {
1224 .procname = "timer_migration",
1225 .data = &sysctl_timer_migration,
1226 .maxlen = sizeof(unsigned int),
1227 .mode = 0644,
1228 .proc_handler = timer_migration_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001229 .extra1 = SYSCTL_ZERO,
1230 .extra2 = SYSCTL_ONE,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001231 },
1232#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001233#ifdef CONFIG_BPF_SYSCALL
1234 {
1235 .procname = "unprivileged_bpf_disabled",
1236 .data = &sysctl_unprivileged_bpf_disabled,
1237 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1238 .mode = 0644,
1239 /* only handle a transition from default "0" to "1" */
1240 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001241 .extra1 = SYSCTL_ONE,
1242 .extra2 = SYSCTL_ONE,
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001243 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001244 {
1245 .procname = "bpf_stats_enabled",
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001246 .data = &bpf_stats_enabled_key.key,
1247 .maxlen = sizeof(bpf_stats_enabled_key),
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001248 .mode = 0644,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001249 .proc_handler = proc_do_static_key,
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001250 },
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08001251#endif
Lai Jiangshanb3e627d2019-10-15 02:55:57 +00001252#if defined(CONFIG_TREE_RCU)
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001253 {
1254 .procname = "panic_on_rcu_stall",
1255 .data = &sysctl_panic_on_rcu_stall,
1256 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1257 .mode = 0644,
1258 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001259 .extra1 = SYSCTL_ZERO,
1260 .extra2 = SYSCTL_ONE,
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001261 },
1262#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001263#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1264 {
1265 .procname = "stack_erasing",
1266 .data = NULL,
1267 .maxlen = sizeof(int),
1268 .mode = 0600,
1269 .proc_handler = stack_erasing_sysctl,
Matteo Croceeec48442019-07-18 15:58:50 -07001270 .extra1 = SYSCTL_ZERO,
1271 .extra2 = SYSCTL_ONE,
Alexander Popov964c9df2018-08-17 01:17:03 +03001272 },
1273#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001274 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275};
1276
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001277static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 .procname = "overcommit_memory",
1280 .data = &sysctl_overcommit_memory,
1281 .maxlen = sizeof(sysctl_overcommit_memory),
1282 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001283 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001284 .extra1 = SYSCTL_ZERO,
Petr Holasekcb16e952011-03-23 16:43:09 -07001285 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 },
1287 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001288 .procname = "panic_on_oom",
1289 .data = &sysctl_panic_on_oom,
1290 .maxlen = sizeof(sysctl_panic_on_oom),
1291 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001292 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001293 .extra1 = SYSCTL_ZERO,
Petr Holasekcb16e952011-03-23 16:43:09 -07001294 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001295 },
1296 {
David Rientjesfe071d72007-10-16 23:25:56 -07001297 .procname = "oom_kill_allocating_task",
1298 .data = &sysctl_oom_kill_allocating_task,
1299 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001302 },
1303 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001304 .procname = "oom_dump_tasks",
1305 .data = &sysctl_oom_dump_tasks,
1306 .maxlen = sizeof(sysctl_oom_dump_tasks),
1307 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001308 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001309 },
1310 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 .procname = "overcommit_ratio",
1312 .data = &sysctl_overcommit_ratio,
1313 .maxlen = sizeof(sysctl_overcommit_ratio),
1314 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001315 .proc_handler = overcommit_ratio_handler,
1316 },
1317 {
1318 .procname = "overcommit_kbytes",
1319 .data = &sysctl_overcommit_kbytes,
1320 .maxlen = sizeof(sysctl_overcommit_kbytes),
1321 .mode = 0644,
1322 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 },
1324 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 .procname = "page-cluster",
1326 .data = &page_cluster,
1327 .maxlen = sizeof(int),
1328 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001329 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001330 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 },
1332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .procname = "dirty_background_ratio",
1334 .data = &dirty_background_ratio,
1335 .maxlen = sizeof(dirty_background_ratio),
1336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001337 .proc_handler = dirty_background_ratio_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001338 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 .extra2 = &one_hundred,
1340 },
1341 {
David Rientjes2da02992009-01-06 14:39:31 -08001342 .procname = "dirty_background_bytes",
1343 .data = &dirty_background_bytes,
1344 .maxlen = sizeof(dirty_background_bytes),
1345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001346 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001347 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001348 },
1349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .procname = "dirty_ratio",
1351 .data = &vm_dirty_ratio,
1352 .maxlen = sizeof(vm_dirty_ratio),
1353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001354 .proc_handler = dirty_ratio_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001355 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 .extra2 = &one_hundred,
1357 },
1358 {
David Rientjes2da02992009-01-06 14:39:31 -08001359 .procname = "dirty_bytes",
1360 .data = &vm_dirty_bytes,
1361 .maxlen = sizeof(vm_dirty_bytes),
1362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001364 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001365 },
1366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001368 .data = &dirty_writeback_interval,
1369 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001371 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 },
1373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001375 .data = &dirty_expire_interval,
1376 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001378 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001379 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 },
1381 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001382 .procname = "dirtytime_expire_seconds",
1383 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001384 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001385 .mode = 0644,
1386 .proc_handler = dirtytime_interval_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001387 .extra1 = SYSCTL_ZERO,
Theodore Ts'o1efff912015-03-17 12:23:32 -04001388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "swappiness",
1391 .data = &vm_swappiness,
1392 .maxlen = sizeof(vm_swappiness),
1393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001395 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 .extra2 = &one_hundred,
1397 },
1398#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001401 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 .maxlen = sizeof(unsigned long),
1403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001404 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001405 },
1406#ifdef CONFIG_NUMA
1407 {
1408 .procname = "nr_hugepages_mempolicy",
1409 .data = NULL,
1410 .maxlen = sizeof(unsigned long),
1411 .mode = 0644,
1412 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001413 },
Kemi Wang45180852017-11-15 17:38:22 -08001414 {
1415 .procname = "numa_stat",
1416 .data = &sysctl_vm_numa_stat,
1417 .maxlen = sizeof(int),
1418 .mode = 0644,
1419 .proc_handler = sysctl_vm_numa_stat_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001420 .extra1 = SYSCTL_ZERO,
1421 .extra2 = SYSCTL_ONE,
Kemi Wang45180852017-11-15 17:38:22 -08001422 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001423#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 .procname = "hugetlb_shm_group",
1426 .data = &sysctl_hugetlb_shm_group,
1427 .maxlen = sizeof(gid_t),
1428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 },
Adam Litke54f9f802007-10-16 01:26:20 -07001431 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001432 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001433 .data = NULL,
1434 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001437 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438#endif
1439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 .procname = "lowmem_reserve_ratio",
1441 .data = &sysctl_lowmem_reserve_ratio,
1442 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001444 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 },
1446 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001447 .procname = "drop_caches",
1448 .data = &sysctl_drop_caches,
1449 .maxlen = sizeof(int),
Johannes Weiner204cb792019-11-30 17:56:08 -08001450 .mode = 0200,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001451 .proc_handler = drop_caches_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001452 .extra1 = SYSCTL_ONE,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001453 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001454 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001455#ifdef CONFIG_COMPACTION
1456 {
1457 .procname = "compact_memory",
1458 .data = &sysctl_compact_memory,
1459 .maxlen = sizeof(int),
1460 .mode = 0200,
1461 .proc_handler = sysctl_compaction_handler,
1462 },
Mel Gorman5e771902010-05-24 14:32:31 -07001463 {
1464 .procname = "extfrag_threshold",
1465 .data = &sysctl_extfrag_threshold,
1466 .maxlen = sizeof(int),
1467 .mode = 0644,
Matthew Wilcox6b7e5ca2019-03-05 15:43:41 -08001468 .proc_handler = proc_dointvec_minmax,
Mel Gorman5e771902010-05-24 14:32:31 -07001469 .extra1 = &min_extfrag_threshold,
1470 .extra2 = &max_extfrag_threshold,
1471 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001472 {
1473 .procname = "compact_unevictable_allowed",
1474 .data = &sysctl_compact_unevictable_allowed,
1475 .maxlen = sizeof(int),
1476 .mode = 0644,
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -07001477 .proc_handler = proc_dointvec_minmax_warn_RT_change,
Matteo Croceeec48442019-07-18 15:58:50 -07001478 .extra1 = SYSCTL_ZERO,
1479 .extra2 = SYSCTL_ONE,
Eric B Munson5bbe3542015-04-15 16:13:20 -07001480 },
Mel Gorman5e771902010-05-24 14:32:31 -07001481
Mel Gorman76ab0f52010-05-24 14:32:28 -07001482#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001483 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 .procname = "min_free_kbytes",
1485 .data = &min_free_kbytes,
1486 .maxlen = sizeof(min_free_kbytes),
1487 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001488 .proc_handler = min_free_kbytes_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001489 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001491 {
Mel Gorman1c308442018-12-28 00:35:52 -08001492 .procname = "watermark_boost_factor",
1493 .data = &watermark_boost_factor,
1494 .maxlen = sizeof(watermark_boost_factor),
1495 .mode = 0644,
1496 .proc_handler = watermark_boost_factor_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001497 .extra1 = SYSCTL_ZERO,
Mel Gorman1c308442018-12-28 00:35:52 -08001498 },
1499 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001500 .procname = "watermark_scale_factor",
1501 .data = &watermark_scale_factor,
1502 .maxlen = sizeof(watermark_scale_factor),
1503 .mode = 0644,
1504 .proc_handler = watermark_scale_factor_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001505 .extra1 = SYSCTL_ONE,
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001506 .extra2 = &one_thousand,
1507 },
1508 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001509 .procname = "percpu_pagelist_fraction",
1510 .data = &percpu_pagelist_fraction,
1511 .maxlen = sizeof(percpu_pagelist_fraction),
1512 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001513 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001514 .extra1 = SYSCTL_ZERO,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001515 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516#ifdef CONFIG_MMU
1517 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 .procname = "max_map_count",
1519 .data = &sysctl_max_map_count,
1520 .maxlen = sizeof(sysctl_max_map_count),
1521 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001522 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001523 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001525#else
1526 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001527 .procname = "nr_trim_pages",
1528 .data = &sysctl_nr_trim_pages,
1529 .maxlen = sizeof(sysctl_nr_trim_pages),
1530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001531 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001532 .extra1 = SYSCTL_ZERO,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001533 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534#endif
1535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 .procname = "laptop_mode",
1537 .data = &laptop_mode,
1538 .maxlen = sizeof(laptop_mode),
1539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001540 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 },
1542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 .procname = "block_dump",
1544 .data = &block_dump,
1545 .maxlen = sizeof(block_dump),
1546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001547 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001548 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 },
1550 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 .procname = "vfs_cache_pressure",
1552 .data = &sysctl_vfs_cache_pressure,
1553 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001555 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001556 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 },
Alexandre Ghiti67f39772019-09-23 15:38:47 -07001558#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1559 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 .procname = "legacy_va_layout",
1562 .data = &sysctl_legacy_va_layout,
1563 .maxlen = sizeof(sysctl_legacy_va_layout),
1564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001565 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001566 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 },
1568#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001569#ifdef CONFIG_NUMA
1570 {
Christoph Lameter17436602006-01-18 17:42:32 -08001571 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001572 .data = &node_reclaim_mode,
1573 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001575 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001576 .extra1 = SYSCTL_ZERO,
Christoph Lameter17436602006-01-18 17:42:32 -08001577 },
Christoph Lameter96146342006-07-03 00:24:13 -07001578 {
Christoph Lameter96146342006-07-03 00:24:13 -07001579 .procname = "min_unmapped_ratio",
1580 .data = &sysctl_min_unmapped_ratio,
1581 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001583 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001584 .extra1 = SYSCTL_ZERO,
Christoph Lameter96146342006-07-03 00:24:13 -07001585 .extra2 = &one_hundred,
1586 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001587 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001588 .procname = "min_slab_ratio",
1589 .data = &sysctl_min_slab_ratio,
1590 .maxlen = sizeof(sysctl_min_slab_ratio),
1591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001592 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001593 .extra1 = SYSCTL_ZERO,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001594 .extra2 = &one_hundred,
1595 },
Christoph Lameter17436602006-01-18 17:42:32 -08001596#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001597#ifdef CONFIG_SMP
1598 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001599 .procname = "stat_interval",
1600 .data = &sysctl_stat_interval,
1601 .maxlen = sizeof(sysctl_stat_interval),
1602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001603 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001604 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001605 {
1606 .procname = "stat_refresh",
1607 .data = NULL,
1608 .maxlen = 0,
1609 .mode = 0600,
1610 .proc_handler = vmstat_refresh,
1611 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001612#endif
David Howells6e141542009-12-15 19:27:45 +00001613#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001614 {
Eric Parised032182007-06-28 15:55:21 -04001615 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001616 .data = &dac_mmap_min_addr,
1617 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001619 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001620 },
David Howells6e141542009-12-15 19:27:45 +00001621#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001622#ifdef CONFIG_NUMA
1623 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001624 .procname = "numa_zonelist_order",
1625 .data = &numa_zonelist_order,
1626 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1627 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001628 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001629 },
1630#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001631#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001632 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001633 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001634 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001635#ifdef CONFIG_X86_32
1636 .data = &vdso32_enabled,
1637 .maxlen = sizeof(vdso32_enabled),
1638#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001639 .data = &vdso_enabled,
1640 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001641#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001643 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001644 .extra1 = SYSCTL_ZERO,
Ingo Molnare6e54942006-06-27 02:53:50 -07001645 },
1646#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001647#ifdef CONFIG_HIGHMEM
1648 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001649 .procname = "highmem_is_dirtyable",
1650 .data = &vm_highmem_is_dirtyable,
1651 .maxlen = sizeof(vm_highmem_is_dirtyable),
1652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001653 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001654 .extra1 = SYSCTL_ZERO,
1655 .extra2 = SYSCTL_ONE,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001656 },
1657#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001658#ifdef CONFIG_MEMORY_FAILURE
1659 {
Andi Kleen6a460792009-09-16 11:50:15 +02001660 .procname = "memory_failure_early_kill",
1661 .data = &sysctl_memory_failure_early_kill,
1662 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1663 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001664 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001665 .extra1 = SYSCTL_ZERO,
1666 .extra2 = SYSCTL_ONE,
Andi Kleen6a460792009-09-16 11:50:15 +02001667 },
1668 {
Andi Kleen6a460792009-09-16 11:50:15 +02001669 .procname = "memory_failure_recovery",
1670 .data = &sysctl_memory_failure_recovery,
1671 .maxlen = sizeof(sysctl_memory_failure_recovery),
1672 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001673 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001674 .extra1 = SYSCTL_ZERO,
1675 .extra2 = SYSCTL_ONE,
Andi Kleen6a460792009-09-16 11:50:15 +02001676 },
1677#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001678 {
1679 .procname = "user_reserve_kbytes",
1680 .data = &sysctl_user_reserve_kbytes,
1681 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1682 .mode = 0644,
1683 .proc_handler = proc_doulongvec_minmax,
1684 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001685 {
1686 .procname = "admin_reserve_kbytes",
1687 .data = &sysctl_admin_reserve_kbytes,
1688 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1689 .mode = 0644,
1690 .proc_handler = proc_doulongvec_minmax,
1691 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001692#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1693 {
1694 .procname = "mmap_rnd_bits",
1695 .data = &mmap_rnd_bits,
1696 .maxlen = sizeof(mmap_rnd_bits),
1697 .mode = 0600,
1698 .proc_handler = proc_dointvec_minmax,
1699 .extra1 = (void *)&mmap_rnd_bits_min,
1700 .extra2 = (void *)&mmap_rnd_bits_max,
1701 },
1702#endif
1703#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1704 {
1705 .procname = "mmap_rnd_compat_bits",
1706 .data = &mmap_rnd_compat_bits,
1707 .maxlen = sizeof(mmap_rnd_compat_bits),
1708 .mode = 0600,
1709 .proc_handler = proc_dointvec_minmax,
1710 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1711 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1712 },
1713#endif
Peter Xucefdca02019-05-13 17:16:41 -07001714#ifdef CONFIG_USERFAULTFD
1715 {
1716 .procname = "unprivileged_userfaultfd",
1717 .data = &sysctl_unprivileged_userfaultfd,
1718 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1719 .mode = 0644,
1720 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001721 .extra1 = SYSCTL_ZERO,
1722 .extra2 = SYSCTL_ONE,
Peter Xucefdca02019-05-13 17:16:41 -07001723 },
1724#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001725 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726};
1727
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001728static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 .procname = "inode-nr",
1731 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001732 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001734 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 },
1736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 .procname = "inode-state",
1738 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001739 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001741 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 },
1743 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 .procname = "file-nr",
1745 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001746 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001748 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 },
1750 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 .procname = "file-max",
1752 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001753 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001755 .proc_handler = proc_doulongvec_minmax,
Will Deacon9002b212019-04-05 18:39:38 -07001756 .extra1 = &zero_ul,
Christian Brauner32a5ad92019-03-07 16:29:43 -08001757 .extra2 = &long_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 },
1759 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001760 .procname = "nr_open",
1761 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001762 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001763 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001764 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001765 .extra1 = &sysctl_nr_open_min,
1766 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001767 },
1768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 .procname = "dentry-state",
1770 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001771 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001773 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 },
1775 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 .procname = "overflowuid",
1777 .data = &fs_overflowuid,
1778 .maxlen = sizeof(int),
1779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001780 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 .extra1 = &minolduid,
1782 .extra2 = &maxolduid,
1783 },
1784 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 .procname = "overflowgid",
1786 .data = &fs_overflowgid,
1787 .maxlen = sizeof(int),
1788 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001789 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 .extra1 = &minolduid,
1791 .extra2 = &maxolduid,
1792 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001793#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 .procname = "leases-enable",
1796 .data = &leases_enable,
1797 .maxlen = sizeof(int),
1798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001801#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802#ifdef CONFIG_DNOTIFY
1803 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 .procname = "dir-notify-enable",
1805 .data = &dir_notify_enable,
1806 .maxlen = sizeof(int),
1807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001808 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 },
1810#endif
1811#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001812#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 .procname = "lease-break-time",
1815 .data = &lease_break_time,
1816 .maxlen = sizeof(int),
1817 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001818 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001820#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001821#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 .procname = "aio-nr",
1824 .data = &aio_nr,
1825 .maxlen = sizeof(aio_nr),
1826 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001827 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 },
1829 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 .procname = "aio-max-nr",
1831 .data = &aio_max_nr,
1832 .maxlen = sizeof(aio_max_nr),
1833 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001834 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001836#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001837#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001838 {
Robert Love0399cb02005-07-13 12:38:18 -04001839 .procname = "inotify",
1840 .mode = 0555,
1841 .child = inotify_table,
1842 },
1843#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001844#ifdef CONFIG_EPOLL
1845 {
1846 .procname = "epoll",
1847 .mode = 0555,
1848 .child = epoll_table,
1849 },
1850#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001852 {
Kees Cook800179c2012-07-25 17:29:07 -07001853 .procname = "protected_symlinks",
1854 .data = &sysctl_protected_symlinks,
1855 .maxlen = sizeof(int),
1856 .mode = 0600,
1857 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001858 .extra1 = SYSCTL_ZERO,
1859 .extra2 = SYSCTL_ONE,
Kees Cook800179c2012-07-25 17:29:07 -07001860 },
1861 {
1862 .procname = "protected_hardlinks",
1863 .data = &sysctl_protected_hardlinks,
1864 .maxlen = sizeof(int),
1865 .mode = 0600,
1866 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001867 .extra1 = SYSCTL_ZERO,
1868 .extra2 = SYSCTL_ONE,
Kees Cook800179c2012-07-25 17:29:07 -07001869 },
1870 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001871 .procname = "protected_fifos",
1872 .data = &sysctl_protected_fifos,
1873 .maxlen = sizeof(int),
1874 .mode = 0600,
1875 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001876 .extra1 = SYSCTL_ZERO,
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001877 .extra2 = &two,
1878 },
1879 {
1880 .procname = "protected_regular",
1881 .data = &sysctl_protected_regular,
1882 .maxlen = sizeof(int),
1883 .mode = 0600,
1884 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001885 .extra1 = SYSCTL_ZERO,
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001886 .extra2 = &two,
1887 },
1888 {
Alan Coxd6e71142005-06-23 00:09:43 -07001889 .procname = "suid_dumpable",
1890 .data = &suid_dumpable,
1891 .maxlen = sizeof(int),
1892 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001893 .proc_handler = proc_dointvec_minmax_coredump,
Matteo Croceeec48442019-07-18 15:58:50 -07001894 .extra1 = SYSCTL_ZERO,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001895 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001896 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001897#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1898 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001899 .procname = "binfmt_misc",
1900 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001901 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001902 },
1903#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001904 {
Jens Axboeff9da692010-06-03 14:54:39 +02001905 .procname = "pipe-max-size",
1906 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001907 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001908 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001909 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001910 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001911 {
1912 .procname = "pipe-user-pages-hard",
1913 .data = &pipe_user_pages_hard,
1914 .maxlen = sizeof(pipe_user_pages_hard),
1915 .mode = 0644,
1916 .proc_handler = proc_doulongvec_minmax,
1917 },
1918 {
1919 .procname = "pipe-user-pages-soft",
1920 .data = &pipe_user_pages_soft,
1921 .maxlen = sizeof(pipe_user_pages_soft),
1922 .mode = 0644,
1923 .proc_handler = proc_doulongvec_minmax,
1924 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001925 {
1926 .procname = "mount-max",
1927 .data = &sysctl_mount_max,
1928 .maxlen = sizeof(unsigned int),
1929 .mode = 0644,
1930 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001931 .extra1 = SYSCTL_ONE,
Eric W. Biedermand2921682016-09-28 00:27:17 -05001932 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001933 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934};
1935
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001936static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001937#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001938 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001939 .procname = "exception-trace",
1940 .data = &show_unhandled_signals,
1941 .maxlen = sizeof(int),
1942 .mode = 0644,
1943 .proc_handler = proc_dointvec
1944 },
1945#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001946#if defined(CONFIG_OPTPROBES)
1947 {
1948 .procname = "kprobes-optimization",
1949 .data = &sysctl_kprobes_optimization,
1950 .maxlen = sizeof(int),
1951 .mode = 0644,
1952 .proc_handler = proc_kprobes_optimization_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001953 .extra1 = SYSCTL_ZERO,
1954 .extra2 = SYSCTL_ONE,
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001955 },
1956#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001957 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958};
1959
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001960static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001961 { }
Robert Love0eeca282005-07-12 17:06:03 -04001962};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001964int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001965{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001966 struct ctl_table_header *hdr;
1967
1968 hdr = register_sysctl_table(sysctl_base_table);
1969 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001970 return 0;
1971}
1972
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001973#endif /* CONFIG_SYSCTL */
1974
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975/*
1976 * /proc/sys support
1977 */
1978
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001979#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
Kees Cookf8808302014-06-06 14:37:17 -07001981static int _proc_do_string(char *data, int maxlen, int write,
1982 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001983 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001984{
1985 size_t len;
1986 char __user *p;
1987 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001988
1989 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001990 *lenp = 0;
1991 return 0;
1992 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001993
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001994 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001995 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1996 /* Only continue writes not past the end of buffer. */
1997 len = strlen(data);
1998 if (len > maxlen - 1)
1999 len = maxlen - 1;
2000
2001 if (*ppos > len)
2002 return 0;
2003 len = *ppos;
2004 } else {
2005 /* Start writing from beginning of buffer. */
2006 len = 0;
2007 }
2008
Kees Cook2ca9bb42014-06-06 14:37:18 -07002009 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002010 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002011 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002012 if (get_user(c, p++))
2013 return -EFAULT;
2014 if (c == 0 || c == '\n')
2015 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002016 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002017 }
Kees Cookf8808302014-06-06 14:37:17 -07002018 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002019 } else {
2020 len = strlen(data);
2021 if (len > maxlen)
2022 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002023
2024 if (*ppos > len) {
2025 *lenp = 0;
2026 return 0;
2027 }
2028
2029 data += *ppos;
2030 len -= *ppos;
2031
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002032 if (len > *lenp)
2033 len = *lenp;
2034 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002035 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 return -EFAULT;
2037 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002038 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002039 return -EFAULT;
2040 len++;
2041 }
2042 *lenp = len;
2043 *ppos += len;
2044 }
2045 return 0;
2046}
2047
Kees Cookf4aacea2014-06-06 14:37:19 -07002048static void warn_sysctl_write(struct ctl_table *table)
2049{
2050 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2051 "This will not be supported in the future. To silence this\n"
2052 "warning, set kernel.sysctl_writes_strict = -1\n",
2053 current->comm, table->procname);
2054}
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002057 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002058 * @ppos: file position
2059 * @table: the sysctl table
2060 *
2061 * Returns true if the first position is non-zero and the sysctl_writes_strict
2062 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002063 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002064 */
2065static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2066 struct ctl_table *table)
2067{
2068 if (!*ppos)
2069 return false;
2070
2071 switch (sysctl_writes_strict) {
2072 case SYSCTL_WRITES_STRICT:
2073 return true;
2074 case SYSCTL_WRITES_WARN:
2075 warn_sysctl_write(table);
2076 return false;
2077 default:
2078 return false;
2079 }
2080}
2081
2082/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 * proc_dostring - read a string sysctl
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 * @buffer: the user buffer
2087 * @lenp: the size of the user buffer
2088 * @ppos: file position
2089 *
2090 * Reads/writes a string from/to the user buffer. If the kernel
2091 * buffer provided is not large enough to hold the string, the
2092 * string is truncated. The copied string is %NULL-terminated.
2093 * If the string is being read by the user process, it is copied
2094 * and a newline '\n' is added. It is truncated if the buffer is
2095 * not large enough.
2096 *
2097 * Returns 0 on success.
2098 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002099int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 void __user *buffer, size_t *lenp, loff_t *ppos)
2101{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002102 if (write)
2103 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002104
Kees Cookf8808302014-06-06 14:37:17 -07002105 return _proc_do_string((char *)(table->data), table->maxlen, write,
2106 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109static size_t proc_skip_spaces(char **buf)
2110{
2111 size_t ret;
2112 char *tmp = skip_spaces(*buf);
2113 ret = tmp - *buf;
2114 *buf = tmp;
2115 return ret;
2116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002118static void proc_skip_char(char **buf, size_t *size, const char v)
2119{
2120 while (*size) {
2121 if (**buf != v)
2122 break;
2123 (*size)--;
2124 (*buf)++;
2125 }
2126}
2127
Christian Brauner7f2923c2019-03-07 16:29:40 -08002128/**
2129 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2130 * fail on overflow
2131 *
2132 * @cp: kernel buffer containing the string to parse
2133 * @endp: pointer to store the trailing characters
2134 * @base: the base to use
2135 * @res: where the parsed integer will be stored
2136 *
2137 * In case of success 0 is returned and @res will contain the parsed integer,
2138 * @endp will hold any trailing characters.
2139 * This function will fail the parse on overflow. If there wasn't an overflow
2140 * the function will defer the decision what characters count as invalid to the
2141 * caller.
2142 */
2143static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2144 unsigned long *res)
2145{
2146 unsigned long long result;
2147 unsigned int rv;
2148
2149 cp = _parse_integer_fixup_radix(cp, &base);
2150 rv = _parse_integer(cp, base, &result);
2151 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2152 return -ERANGE;
2153
2154 cp += rv;
2155
2156 if (endp)
2157 *endp = (char *)cp;
2158
2159 *res = (unsigned long)result;
2160 return 0;
2161}
2162
Amerigo Wang00b7c332010-05-05 00:26:45 +00002163#define TMPBUFLEN 22
2164/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002165 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002166 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002167 * @buf: a kernel buffer
2168 * @size: size of the kernel buffer
2169 * @val: this is where the number will be stored
2170 * @neg: set to %TRUE if number is negative
2171 * @perm_tr: a vector which contains the allowed trailers
2172 * @perm_tr_len: size of the perm_tr vector
2173 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002174 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002175 * In case of success %0 is returned and @buf and @size are updated with
2176 * the amount of bytes read. If @tr is non-NULL and a trailing
2177 * character exists (size is non-zero after returning from this
2178 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002179 */
2180static int proc_get_long(char **buf, size_t *size,
2181 unsigned long *val, bool *neg,
2182 const char *perm_tr, unsigned perm_tr_len, char *tr)
2183{
2184 int len;
2185 char *p, tmp[TMPBUFLEN];
2186
2187 if (!*size)
2188 return -EINVAL;
2189
2190 len = *size;
2191 if (len > TMPBUFLEN - 1)
2192 len = TMPBUFLEN - 1;
2193
2194 memcpy(tmp, *buf, len);
2195
2196 tmp[len] = 0;
2197 p = tmp;
2198 if (*p == '-' && *size > 1) {
2199 *neg = true;
2200 p++;
2201 } else
2202 *neg = false;
2203 if (!isdigit(*p))
2204 return -EINVAL;
2205
Christian Brauner7f2923c2019-03-07 16:29:40 -08002206 if (strtoul_lenient(p, &p, 0, val))
2207 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002208
2209 len = p - tmp;
2210
2211 /* We don't know if the next char is whitespace thus we may accept
2212 * invalid integers (e.g. 1234...a) or two integers instead of one
2213 * (e.g. 123...1). So lets not allow such large numbers. */
2214 if (len == TMPBUFLEN - 1)
2215 return -EINVAL;
2216
2217 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2218 return -EINVAL;
2219
2220 if (tr && (len < *size))
2221 *tr = *p;
2222
2223 *buf += len;
2224 *size -= len;
2225
2226 return 0;
2227}
2228
2229/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002230 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002231 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002232 * @buf: the user buffer
2233 * @size: the size of the user buffer
2234 * @val: the integer to be converted
2235 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002236 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002237 * In case of success %0 is returned and @buf and @size are updated with
2238 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 */
2240static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2241 bool neg)
2242{
2243 int len;
2244 char tmp[TMPBUFLEN], *p = tmp;
2245
2246 sprintf(p, "%s%lu", neg ? "-" : "", val);
2247 len = strlen(tmp);
2248 if (len > *size)
2249 len = *size;
2250 if (copy_to_user(*buf, tmp, len))
2251 return -EFAULT;
2252 *size -= len;
2253 *buf += len;
2254 return 0;
2255}
2256#undef TMPBUFLEN
2257
2258static int proc_put_char(void __user **buf, size_t *size, char c)
2259{
2260 if (*size) {
2261 char __user **buffer = (char __user **)buf;
2262 if (put_user(c, *buffer))
2263 return -EFAULT;
2264 (*size)--, (*buffer)++;
2265 *buf = *buffer;
2266 }
2267 return 0;
2268}
2269
2270static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 int *valp,
2272 int write, void *data)
2273{
2274 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002275 if (*negp) {
2276 if (*lvalp > (unsigned long) INT_MAX + 1)
2277 return -EINVAL;
2278 *valp = -*lvalp;
2279 } else {
2280 if (*lvalp > (unsigned long) INT_MAX)
2281 return -EINVAL;
2282 *valp = *lvalp;
2283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 } else {
2285 int val = *valp;
2286 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002288 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002290 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 *lvalp = (unsigned long)val;
2292 }
2293 }
2294 return 0;
2295}
2296
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002297static int do_proc_douintvec_conv(unsigned long *lvalp,
2298 unsigned int *valp,
2299 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002300{
2301 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002302 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002303 return -EINVAL;
2304 *valp = *lvalp;
2305 } else {
2306 unsigned int val = *valp;
2307 *lvalp = (unsigned long)val;
2308 }
2309 return 0;
2310}
2311
Amerigo Wang00b7c332010-05-05 00:26:45 +00002312static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2313
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002314static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002315 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002316 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002317 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 int write, void *data),
2319 void *data)
2320{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002321 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002323 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 *lenp = 0;
2327 return 0;
2328 }
2329
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002330 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 vleft = table->maxlen / sizeof(*i);
2332 left = *lenp;
2333
2334 if (!conv)
2335 conv = do_proc_dointvec_conv;
2336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002338 if (proc_first_pos_non_zero_ignore(ppos, table))
2339 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002340
Amerigo Wang00b7c332010-05-05 00:26:45 +00002341 if (left > PAGE_SIZE - 1)
2342 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002343 p = kbuf = memdup_user_nul(buffer, left);
2344 if (IS_ERR(kbuf))
2345 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002346 }
2347
2348 for (; left && vleft--; i++, first=0) {
2349 unsigned long lval;
2350 bool neg;
2351
2352 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002353 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002354
J. R. Okajima563b0462010-05-25 16:10:14 -07002355 if (!left)
2356 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002357 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 proc_wspace_sep,
2359 sizeof(proc_wspace_sep), NULL);
2360 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002362 if (conv(&neg, &lval, i, 1, data)) {
2363 err = -EINVAL;
2364 break;
2365 }
2366 } else {
2367 if (conv(&neg, &lval, i, 0, data)) {
2368 err = -EINVAL;
2369 break;
2370 }
2371 if (!first)
2372 err = proc_put_char(&buffer, &left, '\t');
2373 if (err)
2374 break;
2375 err = proc_put_long(&buffer, &left, lval, neg);
2376 if (err)
2377 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 }
2379 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002380
2381 if (!write && !first && left && !err)
2382 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002383 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002384 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002385 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002386 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002387 if (first)
2388 return err ? : -EINVAL;
2389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002391out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002393 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394}
2395
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002396static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002397 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002398 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002399 int write, void *data),
2400 void *data)
2401{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002402 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002403 buffer, lenp, ppos, conv, data);
2404}
2405
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002406static int do_proc_douintvec_w(unsigned int *tbl_data,
2407 struct ctl_table *table,
2408 void __user *buffer,
2409 size_t *lenp, loff_t *ppos,
2410 int (*conv)(unsigned long *lvalp,
2411 unsigned int *valp,
2412 int write, void *data),
2413 void *data)
2414{
2415 unsigned long lval;
2416 int err = 0;
2417 size_t left;
2418 bool neg;
2419 char *kbuf = NULL, *p;
2420
2421 left = *lenp;
2422
2423 if (proc_first_pos_non_zero_ignore(ppos, table))
2424 goto bail_early;
2425
2426 if (left > PAGE_SIZE - 1)
2427 left = PAGE_SIZE - 1;
2428
2429 p = kbuf = memdup_user_nul(buffer, left);
2430 if (IS_ERR(kbuf))
2431 return -EINVAL;
2432
2433 left -= proc_skip_spaces(&p);
2434 if (!left) {
2435 err = -EINVAL;
2436 goto out_free;
2437 }
2438
2439 err = proc_get_long(&p, &left, &lval, &neg,
2440 proc_wspace_sep,
2441 sizeof(proc_wspace_sep), NULL);
2442 if (err || neg) {
2443 err = -EINVAL;
2444 goto out_free;
2445 }
2446
2447 if (conv(&lval, tbl_data, 1, data)) {
2448 err = -EINVAL;
2449 goto out_free;
2450 }
2451
2452 if (!err && left)
2453 left -= proc_skip_spaces(&p);
2454
2455out_free:
2456 kfree(kbuf);
2457 if (err)
2458 return -EINVAL;
2459
2460 return 0;
2461
2462 /* This is in keeping with old __do_proc_dointvec() */
2463bail_early:
2464 *ppos += *lenp;
2465 return err;
2466}
2467
2468static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2469 size_t *lenp, loff_t *ppos,
2470 int (*conv)(unsigned long *lvalp,
2471 unsigned int *valp,
2472 int write, void *data),
2473 void *data)
2474{
2475 unsigned long lval;
2476 int err = 0;
2477 size_t left;
2478
2479 left = *lenp;
2480
2481 if (conv(&lval, tbl_data, 0, data)) {
2482 err = -EINVAL;
2483 goto out;
2484 }
2485
2486 err = proc_put_long(&buffer, &left, lval, false);
2487 if (err || !left)
2488 goto out;
2489
2490 err = proc_put_char(&buffer, &left, '\n');
2491
2492out:
2493 *lenp -= left;
2494 *ppos += *lenp;
2495
2496 return err;
2497}
2498
2499static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2500 int write, void __user *buffer,
2501 size_t *lenp, loff_t *ppos,
2502 int (*conv)(unsigned long *lvalp,
2503 unsigned int *valp,
2504 int write, void *data),
2505 void *data)
2506{
2507 unsigned int *i, vleft;
2508
2509 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2510 *lenp = 0;
2511 return 0;
2512 }
2513
2514 i = (unsigned int *) tbl_data;
2515 vleft = table->maxlen / sizeof(*i);
2516
2517 /*
2518 * Arrays are not supported, keep this simple. *Do not* add
2519 * support for them.
2520 */
2521 if (vleft != 1) {
2522 *lenp = 0;
2523 return -EINVAL;
2524 }
2525
2526 if (!conv)
2527 conv = do_proc_douintvec_conv;
2528
2529 if (write)
2530 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2531 conv, data);
2532 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2533}
2534
2535static int do_proc_douintvec(struct ctl_table *table, int write,
2536 void __user *buffer, size_t *lenp, loff_t *ppos,
2537 int (*conv)(unsigned long *lvalp,
2538 unsigned int *valp,
2539 int write, void *data),
2540 void *data)
2541{
2542 return __do_proc_douintvec(table->data, table, write,
2543 buffer, lenp, ppos, conv, data);
2544}
2545
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546/**
2547 * proc_dointvec - read a vector of integers
2548 * @table: the sysctl table
2549 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 * @buffer: the user buffer
2551 * @lenp: the size of the user buffer
2552 * @ppos: file position
2553 *
2554 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2555 * values from/to the user buffer, treated as an ASCII string.
2556 *
2557 * Returns 0 on success.
2558 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002559int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 void __user *buffer, size_t *lenp, loff_t *ppos)
2561{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002562 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2563}
2564
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -07002565#ifdef CONFIG_COMPACTION
2566static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
2567 int write, void __user *buffer,
2568 size_t *lenp, loff_t *ppos)
2569{
2570 int ret, old;
2571
2572 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
2573 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2574
2575 old = *(int *)table->data;
2576 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2577 if (ret)
2578 return ret;
2579 if (old != *(int *)table->data)
2580 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
2581 table->procname, current->comm,
2582 task_pid_nr(current));
2583 return ret;
2584}
2585#endif
2586
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002587/**
2588 * proc_douintvec - read a vector of unsigned integers
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @buffer: the user buffer
2592 * @lenp: the size of the user buffer
2593 * @ppos: file position
2594 *
2595 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2596 * values from/to the user buffer, treated as an ASCII string.
2597 *
2598 * Returns 0 on success.
2599 */
2600int proc_douintvec(struct ctl_table *table, int write,
2601 void __user *buffer, size_t *lenp, loff_t *ppos)
2602{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002603 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2604 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002607/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002608 * Taint values can only be increased
2609 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002610 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002611static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002612 void __user *buffer, size_t *lenp, loff_t *ppos)
2613{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002614 struct ctl_table t;
2615 unsigned long tmptaint = get_taint();
2616 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002617
Bastian Blank91fcd412007-04-23 14:41:14 -07002618 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002619 return -EPERM;
2620
Andi Kleen25ddbb12008-10-15 22:01:41 -07002621 t = *table;
2622 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002623 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002624 if (err < 0)
2625 return err;
2626
2627 if (write) {
2628 /*
2629 * Poor man's atomic or. Not worth adding a primitive
2630 * to everyone's atomic.h for this
2631 */
2632 int i;
2633 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2634 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302635 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002636 }
2637 }
2638
2639 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002640}
2641
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002642#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002643static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002644 void __user *buffer, size_t *lenp, loff_t *ppos)
2645{
2646 if (write && !capable(CAP_SYS_ADMIN))
2647 return -EPERM;
2648
2649 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2650}
2651#endif
2652
Waiman Long24704f32018-04-10 16:35:38 -07002653/**
2654 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2655 * @min: pointer to minimum allowable value
2656 * @max: pointer to maximum allowable value
2657 *
2658 * The do_proc_dointvec_minmax_conv_param structure provides the
2659 * minimum and maximum values for doing range checking for those sysctl
2660 * parameters that use the proc_dointvec_minmax() handler.
2661 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662struct do_proc_dointvec_minmax_conv_param {
2663 int *min;
2664 int *max;
2665};
2666
Amerigo Wang00b7c332010-05-05 00:26:45 +00002667static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2668 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 int write, void *data)
2670{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002671 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002673 /*
2674 * If writing, first do so via a temporary local int so we can
2675 * bounds-check it before touching *valp.
2676 */
2677 int *ip = write ? &tmp : valp;
2678
2679 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2680 if (ret)
2681 return ret;
2682
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002684 if ((param->min && *param->min > tmp) ||
2685 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002687 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002689
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 return 0;
2691}
2692
2693/**
2694 * proc_dointvec_minmax - read a vector of integers with min/max values
2695 * @table: the sysctl table
2696 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 * @buffer: the user buffer
2698 * @lenp: the size of the user buffer
2699 * @ppos: file position
2700 *
2701 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2702 * values from/to the user buffer, treated as an ASCII string.
2703 *
2704 * This routine will ensure the values are within the range specified by
2705 * table->extra1 (min) and table->extra2 (max).
2706 *
Waiman Long24704f32018-04-10 16:35:38 -07002707 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002709int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 void __user *buffer, size_t *lenp, loff_t *ppos)
2711{
2712 struct do_proc_dointvec_minmax_conv_param param = {
2713 .min = (int *) table->extra1,
2714 .max = (int *) table->extra2,
2715 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002716 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 do_proc_dointvec_minmax_conv, &param);
2718}
2719
Waiman Long24704f32018-04-10 16:35:38 -07002720/**
2721 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2722 * @min: pointer to minimum allowable value
2723 * @max: pointer to maximum allowable value
2724 *
2725 * The do_proc_douintvec_minmax_conv_param structure provides the
2726 * minimum and maximum values for doing range checking for those sysctl
2727 * parameters that use the proc_douintvec_minmax() handler.
2728 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002729struct do_proc_douintvec_minmax_conv_param {
2730 unsigned int *min;
2731 unsigned int *max;
2732};
2733
2734static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2735 unsigned int *valp,
2736 int write, void *data)
2737{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002738 int ret;
2739 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002740 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002741 /* write via temporary local uint for bounds-checking */
2742 unsigned int *up = write ? &tmp : valp;
2743
2744 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2745 if (ret)
2746 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002747
2748 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002749 if ((param->min && *param->min > tmp) ||
2750 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002751 return -ERANGE;
2752
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002753 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002754 }
2755
2756 return 0;
2757}
2758
2759/**
2760 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2761 * @table: the sysctl table
2762 * @write: %TRUE if this is a write to the sysctl file
2763 * @buffer: the user buffer
2764 * @lenp: the size of the user buffer
2765 * @ppos: file position
2766 *
2767 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2768 * values from/to the user buffer, treated as an ASCII string. Negative
2769 * strings are not allowed.
2770 *
2771 * This routine will ensure the values are within the range specified by
2772 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2773 * check for UINT_MAX to avoid having to support wrap around uses from
2774 * userspace.
2775 *
Waiman Long24704f32018-04-10 16:35:38 -07002776 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002777 */
2778int proc_douintvec_minmax(struct ctl_table *table, int write,
2779 void __user *buffer, size_t *lenp, loff_t *ppos)
2780{
2781 struct do_proc_douintvec_minmax_conv_param param = {
2782 .min = (unsigned int *) table->extra1,
2783 .max = (unsigned int *) table->extra2,
2784 };
2785 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2786 do_proc_douintvec_minmax_conv, &param);
2787}
2788
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002789static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2790 unsigned int *valp,
2791 int write, void *data)
2792{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002793 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002794 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002795
Joe Lawrencefb910c42017-11-17 15:29:28 -08002796 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002797 if (val == 0)
2798 return -EINVAL;
2799
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002800 *valp = val;
2801 } else {
2802 unsigned int val = *valp;
2803 *lvalp = (unsigned long) val;
2804 }
2805
2806 return 0;
2807}
2808
Eric Biggers319e0a22018-02-06 15:41:49 -08002809static int proc_dopipe_max_size(struct ctl_table *table, int write,
2810 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002811{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002812 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002813 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002814}
2815
Kees Cook54b50192012-07-30 14:39:18 -07002816static void validate_coredump_safety(void)
2817{
Alex Kelly046d6622012-10-04 17:15:23 -07002818#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002819 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002820 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002821 printk(KERN_WARNING
2822"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2823"Pipe handler or fully qualified core dump path required.\n"
2824"Set kernel.core_pattern before fs.suid_dumpable.\n"
2825 );
Kees Cook54b50192012-07-30 14:39:18 -07002826 }
Alex Kelly046d6622012-10-04 17:15:23 -07002827#endif
Kees Cook54b50192012-07-30 14:39:18 -07002828}
2829
2830static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2831 void __user *buffer, size_t *lenp, loff_t *ppos)
2832{
2833 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2834 if (!error)
2835 validate_coredump_safety();
2836 return error;
2837}
2838
Alex Kelly046d6622012-10-04 17:15:23 -07002839#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002840static int proc_dostring_coredump(struct ctl_table *table, int write,
2841 void __user *buffer, size_t *lenp, loff_t *ppos)
2842{
2843 int error = proc_dostring(table, write, buffer, lenp, ppos);
2844 if (!error)
2845 validate_coredump_safety();
2846 return error;
2847}
Alex Kelly046d6622012-10-04 17:15:23 -07002848#endif
Kees Cook54b50192012-07-30 14:39:18 -07002849
Dmitry Safonoveaee4172020-03-02 17:51:34 +00002850#ifdef CONFIG_MAGIC_SYSRQ
2851static int sysrq_sysctl_handler(struct ctl_table *table, int write,
2852 void __user *buffer, size_t *lenp, loff_t *ppos)
2853{
2854 int tmp, ret;
2855
2856 tmp = sysrq_mask();
2857
2858 ret = __do_proc_dointvec(&tmp, table, write, buffer,
2859 lenp, ppos, NULL, NULL);
2860 if (ret || !write)
2861 return ret;
2862
2863 if (write)
2864 sysrq_toggle_support(tmp);
2865
2866 return 0;
2867}
2868#endif
2869
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002870static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 void __user *buffer,
2872 size_t *lenp, loff_t *ppos,
2873 unsigned long convmul,
2874 unsigned long convdiv)
2875{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002876 unsigned long *i, *min, *max;
2877 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002878 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002879 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002880
2881 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 *lenp = 0;
2883 return 0;
2884 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002885
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002886 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 min = (unsigned long *) table->extra1;
2888 max = (unsigned long *) table->extra2;
2889 vleft = table->maxlen / sizeof(unsigned long);
2890 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002891
2892 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002893 if (proc_first_pos_non_zero_ignore(ppos, table))
2894 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002895
Amerigo Wang00b7c332010-05-05 00:26:45 +00002896 if (left > PAGE_SIZE - 1)
2897 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002898 p = kbuf = memdup_user_nul(buffer, left);
2899 if (IS_ERR(kbuf))
2900 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002901 }
2902
Eric Dumazet27b3d802010-10-07 12:59:29 -07002903 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002904 unsigned long val;
2905
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002907 bool neg;
2908
Al Viro70f6cbb2015-12-24 00:13:10 -05002909 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002910 if (!left)
2911 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002912
Al Viro70f6cbb2015-12-24 00:13:10 -05002913 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002914 proc_wspace_sep,
2915 sizeof(proc_wspace_sep), NULL);
2916 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 break;
2918 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002920 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07002921 if ((min && val < *min) || (max && val > *max)) {
2922 err = -EINVAL;
2923 break;
2924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 *i = val;
2926 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002927 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002928 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002929 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002930 if (err)
2931 break;
2932 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002933 err = proc_put_long(&buffer, &left, val, false);
2934 if (err)
2935 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
2937 }
2938
Amerigo Wang00b7c332010-05-05 00:26:45 +00002939 if (!write && !first && left && !err)
2940 err = proc_put_char(&buffer, &left, '\n');
2941 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002942 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002944 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002945 if (first)
2946 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002949out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002951 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952}
2953
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002954static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002955 void __user *buffer,
2956 size_t *lenp, loff_t *ppos,
2957 unsigned long convmul,
2958 unsigned long convdiv)
2959{
2960 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002961 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002962}
2963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964/**
2965 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2966 * @table: the sysctl table
2967 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 * @buffer: the user buffer
2969 * @lenp: the size of the user buffer
2970 * @ppos: file position
2971 *
2972 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2973 * values from/to the user buffer, treated as an ASCII string.
2974 *
2975 * This routine will ensure the values are within the range specified by
2976 * table->extra1 (min) and table->extra2 (max).
2977 *
2978 * Returns 0 on success.
2979 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002980int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 void __user *buffer, size_t *lenp, loff_t *ppos)
2982{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002983 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984}
2985
2986/**
2987 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2988 * @table: the sysctl table
2989 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 * @buffer: the user buffer
2991 * @lenp: the size of the user buffer
2992 * @ppos: file position
2993 *
2994 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2995 * values from/to the user buffer, treated as an ASCII string. The values
2996 * are treated as milliseconds, and converted to jiffies when they are stored.
2997 *
2998 * This routine will ensure the values are within the range specified by
2999 * table->extra1 (min) and table->extra2 (max).
3000 *
3001 * Returns 0 on success.
3002 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003003int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 void __user *buffer,
3005 size_t *lenp, loff_t *ppos)
3006{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003007 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 lenp, ppos, HZ, 1000l);
3009}
3010
3011
Amerigo Wang00b7c332010-05-05 00:26:45 +00003012static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 int *valp,
3014 int write, void *data)
3015{
3016 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07003017 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08003018 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3020 } else {
3021 int val = *valp;
3022 unsigned long lval;
3023 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003024 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003025 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003027 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 lval = (unsigned long)val;
3029 }
3030 *lvalp = lval / HZ;
3031 }
3032 return 0;
3033}
3034
Amerigo Wang00b7c332010-05-05 00:26:45 +00003035static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 int *valp,
3037 int write, void *data)
3038{
3039 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08003040 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3041 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3043 } else {
3044 int val = *valp;
3045 unsigned long lval;
3046 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003047 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003048 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003050 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 lval = (unsigned long)val;
3052 }
3053 *lvalp = jiffies_to_clock_t(lval);
3054 }
3055 return 0;
3056}
3057
Amerigo Wang00b7c332010-05-05 00:26:45 +00003058static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 int *valp,
3060 int write, void *data)
3061{
3062 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02003063 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3064
3065 if (jif > INT_MAX)
3066 return 1;
3067 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 } else {
3069 int val = *valp;
3070 unsigned long lval;
3071 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003072 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003073 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003075 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 lval = (unsigned long)val;
3077 }
3078 *lvalp = jiffies_to_msecs(lval);
3079 }
3080 return 0;
3081}
3082
3083/**
3084 * proc_dointvec_jiffies - read a vector of integers as seconds
3085 * @table: the sysctl table
3086 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 * @buffer: the user buffer
3088 * @lenp: the size of the user buffer
3089 * @ppos: file position
3090 *
3091 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3092 * values from/to the user buffer, treated as an ASCII string.
3093 * The values read are assumed to be in seconds, and are converted into
3094 * jiffies.
3095 *
3096 * Returns 0 on success.
3097 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003098int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 void __user *buffer, size_t *lenp, loff_t *ppos)
3100{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003101 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 do_proc_dointvec_jiffies_conv,NULL);
3103}
3104
3105/**
3106 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3107 * @table: the sysctl table
3108 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 * @buffer: the user buffer
3110 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003111 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 *
3113 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3114 * values from/to the user buffer, treated as an ASCII string.
3115 * The values read are assumed to be in 1/USER_HZ seconds, and
3116 * are converted into jiffies.
3117 *
3118 * Returns 0 on success.
3119 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003120int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 void __user *buffer, size_t *lenp, loff_t *ppos)
3122{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003123 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 do_proc_dointvec_userhz_jiffies_conv,NULL);
3125}
3126
3127/**
3128 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3129 * @table: the sysctl table
3130 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 * @buffer: the user buffer
3132 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003133 * @ppos: file position
3134 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 *
3136 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3137 * values from/to the user buffer, treated as an ASCII string.
3138 * The values read are assumed to be in 1/1000 seconds, and
3139 * are converted into jiffies.
3140 *
3141 * Returns 0 on success.
3142 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003143int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 void __user *buffer, size_t *lenp, loff_t *ppos)
3145{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003146 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 do_proc_dointvec_ms_jiffies_conv, NULL);
3148}
3149
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003150static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003151 void __user *buffer, size_t *lenp, loff_t *ppos)
3152{
3153 struct pid *new_pid;
3154 pid_t tmp;
3155 int r;
3156
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003157 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003158
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003159 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003160 lenp, ppos, NULL, NULL);
3161 if (r || !write)
3162 return r;
3163
3164 new_pid = find_get_pid(tmp);
3165 if (!new_pid)
3166 return -ESRCH;
3167
3168 put_pid(xchg(&cad_pid, new_pid));
3169 return 0;
3170}
3171
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003172/**
3173 * proc_do_large_bitmap - read/write from/to a large bitmap
3174 * @table: the sysctl table
3175 * @write: %TRUE if this is a write to the sysctl file
3176 * @buffer: the user buffer
3177 * @lenp: the size of the user buffer
3178 * @ppos: file position
3179 *
3180 * The bitmap is stored at table->data and the bitmap length (in bits)
3181 * in table->maxlen.
3182 *
3183 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3184 * large bitmaps may be represented in a compact manner. Writing into
3185 * the file will clear the bitmap then update it with the given input.
3186 *
3187 * Returns 0 on success.
3188 */
3189int proc_do_large_bitmap(struct ctl_table *table, int write,
3190 void __user *buffer, size_t *lenp, loff_t *ppos)
3191{
3192 int err = 0;
3193 bool first = 1;
3194 size_t left = *lenp;
3195 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003196 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003197 unsigned long *tmp_bitmap = NULL;
3198 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3199
WANG Cong122ff242014-05-12 16:04:53 -07003200 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003201 *lenp = 0;
3202 return 0;
3203 }
3204
3205 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003206 char *kbuf, *p;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003207 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003208
Eric Sandeen3116ad32019-05-14 15:45:13 -07003209 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003210 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003211 /* How much of the buffer we'll skip this pass */
3212 skipped = *lenp - left;
3213 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003214
Al Viro70f6cbb2015-12-24 00:13:10 -05003215 p = kbuf = memdup_user_nul(buffer, left);
3216 if (IS_ERR(kbuf))
3217 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003218
Andy Shevchenko475dae32019-05-14 15:44:52 -07003219 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003220 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003221 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003222 return -ENOMEM;
3223 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003224 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003225 while (!err && left) {
3226 unsigned long val_a, val_b;
3227 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003228 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003229
Eric Sandeen3116ad32019-05-14 15:45:13 -07003230 /* In case we stop parsing mid-number, we can reset */
3231 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05003232 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003233 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003234 /*
3235 * If we consumed the entirety of a truncated buffer or
3236 * only one char is left (may be a "-"), then stop here,
3237 * reset, & come back for more.
3238 */
3239 if ((left <= 1) && skipped) {
3240 left = saved_left;
3241 break;
3242 }
3243
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003244 if (err)
3245 break;
3246 if (val_a >= bitmap_len || neg) {
3247 err = -EINVAL;
3248 break;
3249 }
3250
3251 val_b = val_a;
3252 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003253 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003254 left--;
3255 }
3256
3257 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003258 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003259 &neg, tr_b, sizeof(tr_b),
3260 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003261 /*
3262 * If we consumed all of a truncated buffer or
3263 * then stop here, reset, & come back for more.
3264 */
3265 if (!left && skipped) {
3266 left = saved_left;
3267 break;
3268 }
3269
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003270 if (err)
3271 break;
3272 if (val_b >= bitmap_len || neg ||
3273 val_a > val_b) {
3274 err = -EINVAL;
3275 break;
3276 }
3277 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003278 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003279 left--;
3280 }
3281 }
3282
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003283 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003284 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003285 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003286 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003287 kfree(kbuf);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003288 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003289 } else {
3290 unsigned long bit_a, bit_b = 0;
3291
3292 while (left) {
3293 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3294 if (bit_a >= bitmap_len)
3295 break;
3296 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3297 bit_a + 1) - 1;
3298
3299 if (!first) {
3300 err = proc_put_char(&buffer, &left, ',');
3301 if (err)
3302 break;
3303 }
3304 err = proc_put_long(&buffer, &left, bit_a, false);
3305 if (err)
3306 break;
3307 if (bit_a != bit_b) {
3308 err = proc_put_char(&buffer, &left, '-');
3309 if (err)
3310 break;
3311 err = proc_put_long(&buffer, &left, bit_b, false);
3312 if (err)
3313 break;
3314 }
3315
3316 first = 0; bit_b++;
3317 }
3318 if (!err)
3319 err = proc_put_char(&buffer, &left, '\n');
3320 }
3321
3322 if (!err) {
3323 if (write) {
3324 if (*ppos)
3325 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3326 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003327 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003328 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003329 *lenp -= left;
3330 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003331 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003332
Andy Shevchenko475dae32019-05-14 15:44:52 -07003333 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003334 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003335}
3336
Jovi Zhang55610502011-01-12 17:00:45 -08003337#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003339int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 void __user *buffer, size_t *lenp, loff_t *ppos)
3341{
3342 return -ENOSYS;
3343}
3344
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003345int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 void __user *buffer, size_t *lenp, loff_t *ppos)
3347{
3348 return -ENOSYS;
3349}
3350
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003351int proc_douintvec(struct ctl_table *table, int write,
3352 void __user *buffer, size_t *lenp, loff_t *ppos)
3353{
3354 return -ENOSYS;
3355}
3356
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003357int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 void __user *buffer, size_t *lenp, loff_t *ppos)
3359{
3360 return -ENOSYS;
3361}
3362
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003363int proc_douintvec_minmax(struct ctl_table *table, int write,
3364 void __user *buffer, size_t *lenp, loff_t *ppos)
3365{
3366 return -ENOSYS;
3367}
3368
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003369int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 void __user *buffer, size_t *lenp, loff_t *ppos)
3371{
3372 return -ENOSYS;
3373}
3374
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003375int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 void __user *buffer, size_t *lenp, loff_t *ppos)
3377{
3378 return -ENOSYS;
3379}
3380
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003381int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 void __user *buffer, size_t *lenp, loff_t *ppos)
3383{
3384 return -ENOSYS;
3385}
3386
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003387int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 void __user *buffer, size_t *lenp, loff_t *ppos)
3389{
3390 return -ENOSYS;
3391}
3392
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003393int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 void __user *buffer,
3395 size_t *lenp, loff_t *ppos)
3396{
3397 return -ENOSYS;
3398}
3399
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003400int proc_do_large_bitmap(struct ctl_table *table, int write,
3401 void __user *buffer, size_t *lenp, loff_t *ppos)
3402{
3403 return -ENOSYS;
3404}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
Jovi Zhang55610502011-01-12 17:00:45 -08003406#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003408#if defined(CONFIG_SYSCTL)
3409int proc_do_static_key(struct ctl_table *table, int write,
3410 void __user *buffer, size_t *lenp,
3411 loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003412{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003413 struct static_key *key = (struct static_key *)table->data;
3414 static DEFINE_MUTEX(static_key_mutex);
3415 int val, ret;
3416 struct ctl_table tmp = {
3417 .data = &val,
3418 .maxlen = sizeof(val),
3419 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07003420 .extra1 = SYSCTL_ZERO,
3421 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003422 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003423
3424 if (write && !capable(CAP_SYS_ADMIN))
3425 return -EPERM;
3426
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003427 mutex_lock(&static_key_mutex);
3428 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003429 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3430 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003431 if (val)
3432 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003433 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003434 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003435 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003436 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003437 return ret;
3438}
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003439#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440/*
3441 * No sense putting this after each symbol definition, twice,
3442 * exception granted :-)
3443 */
3444EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003445EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446EXPORT_SYMBOL(proc_dointvec_jiffies);
3447EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003448EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3450EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3451EXPORT_SYMBOL(proc_dostring);
3452EXPORT_SYMBOL(proc_doulongvec_minmax);
3453EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003454EXPORT_SYMBOL(proc_do_large_bitmap);