1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * sysctl.c: General linux system control interface
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Begun 24 March 1995, Stephen Tweedie
61da177e4SLinus Torvalds * Added /proc support, Dec 1995
71da177e4SLinus Torvalds * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
81da177e4SLinus Torvalds * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
91da177e4SLinus Torvalds * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
101da177e4SLinus Torvalds * Dynamic registration fixes, Stephen Tweedie.
111da177e4SLinus Torvalds * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
121da177e4SLinus Torvalds * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
131da177e4SLinus Torvalds * Horn.
141da177e4SLinus Torvalds * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
151da177e4SLinus Torvalds * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
161da177e4SLinus Torvalds * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
171da177e4SLinus Torvalds * Wendling.
181da177e4SLinus Torvalds * The list_for_each() macro wasn't appropriate for the sysctl loop.
191da177e4SLinus Torvalds * Removed it and replaced it with older style, 03/23/00, Bill Wendling
201da177e4SLinus Torvalds */
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds #include <linux/module.h>
231da177e4SLinus Torvalds #include <linux/mm.h>
241da177e4SLinus Torvalds #include <linux/swap.h>
251da177e4SLinus Torvalds #include <linux/slab.h>
261da177e4SLinus Torvalds #include <linux/sysctl.h>
275a04cca6SAkinobu Mita #include <linux/bitmap.h>
28d33ed52dSDave Young #include <linux/signal.h>
29f39650deSAndy Shevchenko #include <linux/panic.h>
30455cd5abSDan Rosenberg #include <linux/printk.h>
311da177e4SLinus Torvalds #include <linux/proc_fs.h>
3272c2d582SAndrew Morgan #include <linux/security.h>
331da177e4SLinus Torvalds #include <linux/ctype.h>
34fd4b616bSSteven Rostedt #include <linux/kmemleak.h>
35b6459415SJakub Kicinski #include <linux/filter.h>
3662239ac2SAdrian Bunk #include <linux/fs.h>
371da177e4SLinus Torvalds #include <linux/init.h>
381da177e4SLinus Torvalds #include <linux/kernel.h>
390296b228SKay Sievers #include <linux/kobject.h>
4020380731SArnaldo Carvalho de Melo #include <linux/net.h>
411da177e4SLinus Torvalds #include <linux/sysrq.h>
421da177e4SLinus Torvalds #include <linux/highuid.h>
431da177e4SLinus Torvalds #include <linux/writeback.h>
443fff4c42SIngo Molnar #include <linux/ratelimit.h>
451da177e4SLinus Torvalds #include <linux/hugetlb.h>
461da177e4SLinus Torvalds #include <linux/initrd.h>
470b77f5bfSDavid Howells #include <linux/key.h>
481da177e4SLinus Torvalds #include <linux/times.h>
491da177e4SLinus Torvalds #include <linux/limits.h>
501da177e4SLinus Torvalds #include <linux/dcache.h>
511da177e4SLinus Torvalds #include <linux/syscalls.h>
52c748e134SAdrian Bunk #include <linux/vmstat.h>
53c255d844SPavel Machek #include <linux/nfs_fs.h>
54c255d844SPavel Machek #include <linux/acpi.h>
5510a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h>
56b0fc494fSSteven Rostedt #include <linux/ftrace.h>
57cdd6c482SIngo Molnar #include <linux/perf_event.h>
588e4228e1SDavid Rientjes #include <linux/oom.h>
5917f60a7dSEric Paris #include <linux/kmod.h>
6073efc039SDan Ballard #include <linux/capability.h>
6140401530SAl Viro #include <linux/binfmts.h>
62cf4aebc2SClark Williams #include <linux/sched/sysctl.h>
63d2921684SEric W. Biederman #include <linux/mount.h>
64cefdca0aSPeter Xu #include <linux/userfaultfd_k.h>
652374c09bSChristoph Hellwig #include <linux/pid.h>
661da177e4SLinus Torvalds
677f2923c4SChristian Brauner #include "../lib/kstrtox.h"
687f2923c4SChristian Brauner
697c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
701da177e4SLinus Torvalds #include <asm/processor.h>
711da177e4SLinus Torvalds
7229cbc78bSAndi Kleen #ifdef CONFIG_X86
7329cbc78bSAndi Kleen #include <asm/nmi.h>
740741f4d2SChuck Ebbert #include <asm/stacktrace.h>
756e7c4025SIngo Molnar #include <asm/io.h>
7629cbc78bSAndi Kleen #endif
77d550bbd4SDavid Howells #ifdef CONFIG_SPARC
78d550bbd4SDavid Howells #include <asm/setup.h>
79d550bbd4SDavid Howells #endif
804f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES
814f0e056fSDave Young #include <linux/rtmutex.h>
824f0e056fSDave Young #endif
83504d7cf1SDon Zickus
84b13bc7cbSLiu Shixin /* shared constants to be used in various sysctls */
85b13bc7cbSLiu Shixin const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
86b13bc7cbSLiu Shixin EXPORT_SYMBOL(sysctl_vals);
87b13bc7cbSLiu Shixin
88b13bc7cbSLiu Shixin const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
89b13bc7cbSLiu Shixin EXPORT_SYMBOL_GPL(sysctl_long_vals);
90b13bc7cbSLiu Shixin
911da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
921da177e4SLinus Torvalds
93c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */
94c4f3b63fSRavikiran G Thirumalai
95c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS
96d73840ecSXiaoming Ni static const int six_hundred_forty_kb = 640 * 1024;
97c5dfd78eSArnaldo Carvalho de Melo #endif
98c4f3b63fSRavikiran G Thirumalai
999e4a5bdaSAndrea Righi
100f628867dSStephen Kitt static const int ngroups_max = NGROUPS_MAX;
10173efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP;
1021da177e4SLinus Torvalds
103d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
104f4aacea2SKees Cook
105a19ac337SLuis R. Rodriguez /**
106a19ac337SLuis R. Rodriguez * enum sysctl_writes_mode - supported sysctl write modes
107a19ac337SLuis R. Rodriguez *
108a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
109a19ac337SLuis R. Rodriguez * to be written, and multiple writes on the same sysctl file descriptor
110a19ac337SLuis R. Rodriguez * will rewrite the sysctl value, regardless of file position. No warning
111a19ac337SLuis R. Rodriguez * is issued when the initial position is not 0.
112a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
113a19ac337SLuis R. Rodriguez * not 0.
114a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
115a19ac337SLuis R. Rodriguez * file position 0 and the value must be fully contained in the buffer
116a19ac337SLuis R. Rodriguez * sent to the write syscall. If dealing with strings respect the file
117a19ac337SLuis R. Rodriguez * position, but restrict this to the max length of the buffer, anything
11865f50f25SWeitao Hou * passed the max length will be ignored. Multiple writes will append
119a19ac337SLuis R. Rodriguez * to the buffer.
120a19ac337SLuis R. Rodriguez *
121a19ac337SLuis R. Rodriguez * These write modes control how current file position affects the behavior of
122a19ac337SLuis R. Rodriguez * updating sysctl values through the proc interface on each write.
123a19ac337SLuis R. Rodriguez */
124a19ac337SLuis R. Rodriguez enum sysctl_writes_mode {
125a19ac337SLuis R. Rodriguez SYSCTL_WRITES_LEGACY = -1,
126a19ac337SLuis R. Rodriguez SYSCTL_WRITES_WARN = 0,
127a19ac337SLuis R. Rodriguez SYSCTL_WRITES_STRICT = 1,
128a19ac337SLuis R. Rodriguez };
129f4aacea2SKees Cook
130a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
131f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
132ceb18132SLuis R. Rodriguez
13367f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
13467f3977fSAlexandre Ghiti defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1351da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1361da177e4SLinus Torvalds #endif
1371da177e4SLinus Torvalds
138f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */
139f461d2dcSChristoph Hellwig
140f461d2dcSChristoph Hellwig /*
141f461d2dcSChristoph Hellwig * /proc/sys support
142f461d2dcSChristoph Hellwig */
143f461d2dcSChristoph Hellwig
144f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL
145f461d2dcSChristoph Hellwig
_proc_do_string(char * data,int maxlen,int write,char * buffer,size_t * lenp,loff_t * ppos)146f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write,
14732927393SChristoph Hellwig char *buffer, size_t *lenp, loff_t *ppos)
148f461d2dcSChristoph Hellwig {
149f461d2dcSChristoph Hellwig size_t len;
15032927393SChristoph Hellwig char c, *p;
151f461d2dcSChristoph Hellwig
152f461d2dcSChristoph Hellwig if (!data || !maxlen || !*lenp) {
153f461d2dcSChristoph Hellwig *lenp = 0;
154f461d2dcSChristoph Hellwig return 0;
155f461d2dcSChristoph Hellwig }
156f461d2dcSChristoph Hellwig
157f461d2dcSChristoph Hellwig if (write) {
158f461d2dcSChristoph Hellwig if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
159f461d2dcSChristoph Hellwig /* Only continue writes not past the end of buffer. */
160f461d2dcSChristoph Hellwig len = strlen(data);
161f461d2dcSChristoph Hellwig if (len > maxlen - 1)
162f461d2dcSChristoph Hellwig len = maxlen - 1;
163f461d2dcSChristoph Hellwig
164f461d2dcSChristoph Hellwig if (*ppos > len)
165f461d2dcSChristoph Hellwig return 0;
166f461d2dcSChristoph Hellwig len = *ppos;
167f461d2dcSChristoph Hellwig } else {
168f461d2dcSChristoph Hellwig /* Start writing from beginning of buffer. */
169f461d2dcSChristoph Hellwig len = 0;
170f461d2dcSChristoph Hellwig }
171f461d2dcSChristoph Hellwig
172f461d2dcSChristoph Hellwig *ppos += *lenp;
173f461d2dcSChristoph Hellwig p = buffer;
174f461d2dcSChristoph Hellwig while ((p - buffer) < *lenp && len < maxlen - 1) {
17532927393SChristoph Hellwig c = *(p++);
176f461d2dcSChristoph Hellwig if (c == 0 || c == '\n')
177f461d2dcSChristoph Hellwig break;
178f461d2dcSChristoph Hellwig data[len++] = c;
179f461d2dcSChristoph Hellwig }
180f461d2dcSChristoph Hellwig data[len] = 0;
181f461d2dcSChristoph Hellwig } else {
182f461d2dcSChristoph Hellwig len = strlen(data);
183f461d2dcSChristoph Hellwig if (len > maxlen)
184f461d2dcSChristoph Hellwig len = maxlen;
185f461d2dcSChristoph Hellwig
186f461d2dcSChristoph Hellwig if (*ppos > len) {
187f461d2dcSChristoph Hellwig *lenp = 0;
188f461d2dcSChristoph Hellwig return 0;
189f461d2dcSChristoph Hellwig }
190f461d2dcSChristoph Hellwig
191f461d2dcSChristoph Hellwig data += *ppos;
192f461d2dcSChristoph Hellwig len -= *ppos;
193f461d2dcSChristoph Hellwig
194f461d2dcSChristoph Hellwig if (len > *lenp)
195f461d2dcSChristoph Hellwig len = *lenp;
196f461d2dcSChristoph Hellwig if (len)
19732927393SChristoph Hellwig memcpy(buffer, data, len);
198f461d2dcSChristoph Hellwig if (len < *lenp) {
19932927393SChristoph Hellwig buffer[len] = '\n';
200f461d2dcSChristoph Hellwig len++;
201f461d2dcSChristoph Hellwig }
202f461d2dcSChristoph Hellwig *lenp = len;
203f461d2dcSChristoph Hellwig *ppos += len;
204f461d2dcSChristoph Hellwig }
205f461d2dcSChristoph Hellwig return 0;
206f461d2dcSChristoph Hellwig }
207f461d2dcSChristoph Hellwig
warn_sysctl_write(struct ctl_table * table)208f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table)
209f461d2dcSChristoph Hellwig {
210f461d2dcSChristoph Hellwig pr_warn_once("%s wrote to %s when file position was not 0!\n"
211f461d2dcSChristoph Hellwig "This will not be supported in the future. To silence this\n"
212f461d2dcSChristoph Hellwig "warning, set kernel.sysctl_writes_strict = -1\n",
213f461d2dcSChristoph Hellwig current->comm, table->procname);
214f461d2dcSChristoph Hellwig }
215f461d2dcSChristoph Hellwig
216f461d2dcSChristoph Hellwig /**
217f461d2dcSChristoph Hellwig * proc_first_pos_non_zero_ignore - check if first position is allowed
218f461d2dcSChristoph Hellwig * @ppos: file position
219f461d2dcSChristoph Hellwig * @table: the sysctl table
220f461d2dcSChristoph Hellwig *
221f461d2dcSChristoph Hellwig * Returns true if the first position is non-zero and the sysctl_writes_strict
222f461d2dcSChristoph Hellwig * mode indicates this is not allowed for numeric input types. String proc
223f461d2dcSChristoph Hellwig * handlers can ignore the return value.
224f461d2dcSChristoph Hellwig */
proc_first_pos_non_zero_ignore(loff_t * ppos,struct ctl_table * table)225f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
226f461d2dcSChristoph Hellwig struct ctl_table *table)
227f461d2dcSChristoph Hellwig {
228f461d2dcSChristoph Hellwig if (!*ppos)
229f461d2dcSChristoph Hellwig return false;
230f461d2dcSChristoph Hellwig
231f461d2dcSChristoph Hellwig switch (sysctl_writes_strict) {
232f461d2dcSChristoph Hellwig case SYSCTL_WRITES_STRICT:
233f461d2dcSChristoph Hellwig return true;
234f461d2dcSChristoph Hellwig case SYSCTL_WRITES_WARN:
235f461d2dcSChristoph Hellwig warn_sysctl_write(table);
236f461d2dcSChristoph Hellwig return false;
237f461d2dcSChristoph Hellwig default:
238f461d2dcSChristoph Hellwig return false;
239f461d2dcSChristoph Hellwig }
240f461d2dcSChristoph Hellwig }
241f461d2dcSChristoph Hellwig
242f461d2dcSChristoph Hellwig /**
243f461d2dcSChristoph Hellwig * proc_dostring - read a string sysctl
244f461d2dcSChristoph Hellwig * @table: the sysctl table
245f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
246f461d2dcSChristoph Hellwig * @buffer: the user buffer
247f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
248f461d2dcSChristoph Hellwig * @ppos: file position
249f461d2dcSChristoph Hellwig *
250f461d2dcSChristoph Hellwig * Reads/writes a string from/to the user buffer. If the kernel
251f461d2dcSChristoph Hellwig * buffer provided is not large enough to hold the string, the
252f461d2dcSChristoph Hellwig * string is truncated. The copied string is %NULL-terminated.
253f461d2dcSChristoph Hellwig * If the string is being read by the user process, it is copied
254f461d2dcSChristoph Hellwig * and a newline '\n' is added. It is truncated if the buffer is
255f461d2dcSChristoph Hellwig * not large enough.
256f461d2dcSChristoph Hellwig *
257f461d2dcSChristoph Hellwig * Returns 0 on success.
258f461d2dcSChristoph Hellwig */
proc_dostring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)259f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
26032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
261f461d2dcSChristoph Hellwig {
262f461d2dcSChristoph Hellwig if (write)
263f461d2dcSChristoph Hellwig proc_first_pos_non_zero_ignore(ppos, table);
264f461d2dcSChristoph Hellwig
26532927393SChristoph Hellwig return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
26632927393SChristoph Hellwig ppos);
267f461d2dcSChristoph Hellwig }
268f461d2dcSChristoph Hellwig
proc_skip_spaces(char ** buf,size_t * size)269bce93322SLinus Torvalds static void proc_skip_spaces(char **buf, size_t *size)
270f461d2dcSChristoph Hellwig {
271bce93322SLinus Torvalds while (*size) {
272bce93322SLinus Torvalds if (!isspace(**buf))
273bce93322SLinus Torvalds break;
274bce93322SLinus Torvalds (*size)--;
275bce93322SLinus Torvalds (*buf)++;
276bce93322SLinus Torvalds }
277f461d2dcSChristoph Hellwig }
278f461d2dcSChristoph Hellwig
proc_skip_char(char ** buf,size_t * size,const char v)279f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v)
280f461d2dcSChristoph Hellwig {
281f461d2dcSChristoph Hellwig while (*size) {
282f461d2dcSChristoph Hellwig if (**buf != v)
283f461d2dcSChristoph Hellwig break;
284f461d2dcSChristoph Hellwig (*size)--;
285f461d2dcSChristoph Hellwig (*buf)++;
286f461d2dcSChristoph Hellwig }
287f461d2dcSChristoph Hellwig }
288f461d2dcSChristoph Hellwig
289f461d2dcSChristoph Hellwig /**
290f461d2dcSChristoph Hellwig * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
291f461d2dcSChristoph Hellwig * fail on overflow
292f461d2dcSChristoph Hellwig *
293f461d2dcSChristoph Hellwig * @cp: kernel buffer containing the string to parse
294f461d2dcSChristoph Hellwig * @endp: pointer to store the trailing characters
295f461d2dcSChristoph Hellwig * @base: the base to use
296f461d2dcSChristoph Hellwig * @res: where the parsed integer will be stored
297f461d2dcSChristoph Hellwig *
298f461d2dcSChristoph Hellwig * In case of success 0 is returned and @res will contain the parsed integer,
299f461d2dcSChristoph Hellwig * @endp will hold any trailing characters.
300f461d2dcSChristoph Hellwig * This function will fail the parse on overflow. If there wasn't an overflow
301f461d2dcSChristoph Hellwig * the function will defer the decision what characters count as invalid to the
302f461d2dcSChristoph Hellwig * caller.
303f461d2dcSChristoph Hellwig */
strtoul_lenient(const char * cp,char ** endp,unsigned int base,unsigned long * res)304f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
305f461d2dcSChristoph Hellwig unsigned long *res)
306f461d2dcSChristoph Hellwig {
307f461d2dcSChristoph Hellwig unsigned long long result;
308f461d2dcSChristoph Hellwig unsigned int rv;
309f461d2dcSChristoph Hellwig
310f461d2dcSChristoph Hellwig cp = _parse_integer_fixup_radix(cp, &base);
311f461d2dcSChristoph Hellwig rv = _parse_integer(cp, base, &result);
312f461d2dcSChristoph Hellwig if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
313f461d2dcSChristoph Hellwig return -ERANGE;
314f461d2dcSChristoph Hellwig
315f461d2dcSChristoph Hellwig cp += rv;
316f461d2dcSChristoph Hellwig
317f461d2dcSChristoph Hellwig if (endp)
318f461d2dcSChristoph Hellwig *endp = (char *)cp;
319f461d2dcSChristoph Hellwig
320f461d2dcSChristoph Hellwig *res = (unsigned long)result;
321f461d2dcSChristoph Hellwig return 0;
322f461d2dcSChristoph Hellwig }
323f461d2dcSChristoph Hellwig
324f461d2dcSChristoph Hellwig #define TMPBUFLEN 22
325f461d2dcSChristoph Hellwig /**
326f461d2dcSChristoph Hellwig * proc_get_long - reads an ASCII formatted integer from a user buffer
327f461d2dcSChristoph Hellwig *
328f461d2dcSChristoph Hellwig * @buf: a kernel buffer
329f461d2dcSChristoph Hellwig * @size: size of the kernel buffer
330f461d2dcSChristoph Hellwig * @val: this is where the number will be stored
331f461d2dcSChristoph Hellwig * @neg: set to %TRUE if number is negative
332f461d2dcSChristoph Hellwig * @perm_tr: a vector which contains the allowed trailers
333f461d2dcSChristoph Hellwig * @perm_tr_len: size of the perm_tr vector
334f461d2dcSChristoph Hellwig * @tr: pointer to store the trailer character
335f461d2dcSChristoph Hellwig *
336f461d2dcSChristoph Hellwig * In case of success %0 is returned and @buf and @size are updated with
337f461d2dcSChristoph Hellwig * the amount of bytes read. If @tr is non-NULL and a trailing
338f461d2dcSChristoph Hellwig * character exists (size is non-zero after returning from this
339f461d2dcSChristoph Hellwig * function), @tr is updated with the trailing character.
340f461d2dcSChristoph Hellwig */
proc_get_long(char ** buf,size_t * size,unsigned long * val,bool * neg,const char * perm_tr,unsigned perm_tr_len,char * tr)341f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size,
342f461d2dcSChristoph Hellwig unsigned long *val, bool *neg,
343f461d2dcSChristoph Hellwig const char *perm_tr, unsigned perm_tr_len, char *tr)
344f461d2dcSChristoph Hellwig {
345f461d2dcSChristoph Hellwig char *p, tmp[TMPBUFLEN];
346e6cfaf34SLinus Torvalds ssize_t len = *size;
347f461d2dcSChristoph Hellwig
348e6cfaf34SLinus Torvalds if (len <= 0)
349f461d2dcSChristoph Hellwig return -EINVAL;
350f461d2dcSChristoph Hellwig
351f461d2dcSChristoph Hellwig if (len > TMPBUFLEN - 1)
352f461d2dcSChristoph Hellwig len = TMPBUFLEN - 1;
353f461d2dcSChristoph Hellwig
354f461d2dcSChristoph Hellwig memcpy(tmp, *buf, len);
355f461d2dcSChristoph Hellwig
356f461d2dcSChristoph Hellwig tmp[len] = 0;
357f461d2dcSChristoph Hellwig p = tmp;
358f461d2dcSChristoph Hellwig if (*p == '-' && *size > 1) {
359f461d2dcSChristoph Hellwig *neg = true;
360f461d2dcSChristoph Hellwig p++;
361f461d2dcSChristoph Hellwig } else
362f461d2dcSChristoph Hellwig *neg = false;
363f461d2dcSChristoph Hellwig if (!isdigit(*p))
364f461d2dcSChristoph Hellwig return -EINVAL;
365f461d2dcSChristoph Hellwig
366f461d2dcSChristoph Hellwig if (strtoul_lenient(p, &p, 0, val))
367f461d2dcSChristoph Hellwig return -EINVAL;
368f461d2dcSChristoph Hellwig
369f461d2dcSChristoph Hellwig len = p - tmp;
370f461d2dcSChristoph Hellwig
371f461d2dcSChristoph Hellwig /* We don't know if the next char is whitespace thus we may accept
372f461d2dcSChristoph Hellwig * invalid integers (e.g. 1234...a) or two integers instead of one
373f461d2dcSChristoph Hellwig * (e.g. 123...1). So lets not allow such large numbers. */
374f461d2dcSChristoph Hellwig if (len == TMPBUFLEN - 1)
375f461d2dcSChristoph Hellwig return -EINVAL;
376f461d2dcSChristoph Hellwig
377f461d2dcSChristoph Hellwig if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
378f461d2dcSChristoph Hellwig return -EINVAL;
379f461d2dcSChristoph Hellwig
380f461d2dcSChristoph Hellwig if (tr && (len < *size))
381f461d2dcSChristoph Hellwig *tr = *p;
382f461d2dcSChristoph Hellwig
383f461d2dcSChristoph Hellwig *buf += len;
384f461d2dcSChristoph Hellwig *size -= len;
385f461d2dcSChristoph Hellwig
386f461d2dcSChristoph Hellwig return 0;
387f461d2dcSChristoph Hellwig }
388f461d2dcSChristoph Hellwig
389f461d2dcSChristoph Hellwig /**
390f461d2dcSChristoph Hellwig * proc_put_long - converts an integer to a decimal ASCII formatted string
391f461d2dcSChristoph Hellwig *
392f461d2dcSChristoph Hellwig * @buf: the user buffer
393f461d2dcSChristoph Hellwig * @size: the size of the user buffer
394f461d2dcSChristoph Hellwig * @val: the integer to be converted
395f461d2dcSChristoph Hellwig * @neg: sign of the number, %TRUE for negative
396f461d2dcSChristoph Hellwig *
39732927393SChristoph Hellwig * In case of success @buf and @size are updated with the amount of bytes
39832927393SChristoph Hellwig * written.
399f461d2dcSChristoph Hellwig */
proc_put_long(void ** buf,size_t * size,unsigned long val,bool neg)40032927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
401f461d2dcSChristoph Hellwig {
402f461d2dcSChristoph Hellwig int len;
403f461d2dcSChristoph Hellwig char tmp[TMPBUFLEN], *p = tmp;
404f461d2dcSChristoph Hellwig
405f461d2dcSChristoph Hellwig sprintf(p, "%s%lu", neg ? "-" : "", val);
406f461d2dcSChristoph Hellwig len = strlen(tmp);
407f461d2dcSChristoph Hellwig if (len > *size)
408f461d2dcSChristoph Hellwig len = *size;
40932927393SChristoph Hellwig memcpy(*buf, tmp, len);
410f461d2dcSChristoph Hellwig *size -= len;
411f461d2dcSChristoph Hellwig *buf += len;
412f461d2dcSChristoph Hellwig }
413f461d2dcSChristoph Hellwig #undef TMPBUFLEN
414f461d2dcSChristoph Hellwig
proc_put_char(void ** buf,size_t * size,char c)41532927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c)
416f461d2dcSChristoph Hellwig {
417f461d2dcSChristoph Hellwig if (*size) {
41832927393SChristoph Hellwig char **buffer = (char **)buf;
41932927393SChristoph Hellwig **buffer = c;
42032927393SChristoph Hellwig
42132927393SChristoph Hellwig (*size)--;
42232927393SChristoph Hellwig (*buffer)++;
423f461d2dcSChristoph Hellwig *buf = *buffer;
424f461d2dcSChristoph Hellwig }
425f461d2dcSChristoph Hellwig }
426f461d2dcSChristoph Hellwig
do_proc_dointvec_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)427f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
428f461d2dcSChristoph Hellwig int *valp,
429f461d2dcSChristoph Hellwig int write, void *data)
430f461d2dcSChristoph Hellwig {
431f461d2dcSChristoph Hellwig if (write) {
432f461d2dcSChristoph Hellwig if (*negp) {
433f461d2dcSChristoph Hellwig if (*lvalp > (unsigned long) INT_MAX + 1)
434f461d2dcSChristoph Hellwig return -EINVAL;
4351f1be04bSKuniyuki Iwashima WRITE_ONCE(*valp, -*lvalp);
436f461d2dcSChristoph Hellwig } else {
437f461d2dcSChristoph Hellwig if (*lvalp > (unsigned long) INT_MAX)
438f461d2dcSChristoph Hellwig return -EINVAL;
4391f1be04bSKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp);
440f461d2dcSChristoph Hellwig }
441f461d2dcSChristoph Hellwig } else {
4421f1be04bSKuniyuki Iwashima int val = READ_ONCE(*valp);
443f461d2dcSChristoph Hellwig if (val < 0) {
444f461d2dcSChristoph Hellwig *negp = true;
445f461d2dcSChristoph Hellwig *lvalp = -(unsigned long)val;
446f461d2dcSChristoph Hellwig } else {
447f461d2dcSChristoph Hellwig *negp = false;
448f461d2dcSChristoph Hellwig *lvalp = (unsigned long)val;
449f461d2dcSChristoph Hellwig }
450f461d2dcSChristoph Hellwig }
451f461d2dcSChristoph Hellwig return 0;
452f461d2dcSChristoph Hellwig }
453f461d2dcSChristoph Hellwig
do_proc_douintvec_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)454f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp,
455f461d2dcSChristoph Hellwig unsigned int *valp,
456f461d2dcSChristoph Hellwig int write, void *data)
457f461d2dcSChristoph Hellwig {
458f461d2dcSChristoph Hellwig if (write) {
459f461d2dcSChristoph Hellwig if (*lvalp > UINT_MAX)
460f461d2dcSChristoph Hellwig return -EINVAL;
4614762b532SKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp);
462f461d2dcSChristoph Hellwig } else {
4634762b532SKuniyuki Iwashima unsigned int val = READ_ONCE(*valp);
464f461d2dcSChristoph Hellwig *lvalp = (unsigned long)val;
465f461d2dcSChristoph Hellwig }
466f461d2dcSChristoph Hellwig return 0;
467f461d2dcSChristoph Hellwig }
468f461d2dcSChristoph Hellwig
469f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
470f461d2dcSChristoph Hellwig
__do_proc_dointvec(void * tbl_data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(bool * negp,unsigned long * lvalp,int * valp,int write,void * data),void * data)471f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
47232927393SChristoph Hellwig int write, void *buffer,
473f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos,
474f461d2dcSChristoph Hellwig int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
475f461d2dcSChristoph Hellwig int write, void *data),
476f461d2dcSChristoph Hellwig void *data)
477f461d2dcSChristoph Hellwig {
478f461d2dcSChristoph Hellwig int *i, vleft, first = 1, err = 0;
479f461d2dcSChristoph Hellwig size_t left;
48032927393SChristoph Hellwig char *p;
481f461d2dcSChristoph Hellwig
482f461d2dcSChristoph Hellwig if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
483f461d2dcSChristoph Hellwig *lenp = 0;
484f461d2dcSChristoph Hellwig return 0;
485f461d2dcSChristoph Hellwig }
486f461d2dcSChristoph Hellwig
487f461d2dcSChristoph Hellwig i = (int *) tbl_data;
488f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(*i);
489f461d2dcSChristoph Hellwig left = *lenp;
490f461d2dcSChristoph Hellwig
491f461d2dcSChristoph Hellwig if (!conv)
492f461d2dcSChristoph Hellwig conv = do_proc_dointvec_conv;
493f461d2dcSChristoph Hellwig
494f461d2dcSChristoph Hellwig if (write) {
495f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table))
496f461d2dcSChristoph Hellwig goto out;
497f461d2dcSChristoph Hellwig
498f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1)
499f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1;
50032927393SChristoph Hellwig p = buffer;
501f461d2dcSChristoph Hellwig }
502f461d2dcSChristoph Hellwig
503f461d2dcSChristoph Hellwig for (; left && vleft--; i++, first=0) {
504f461d2dcSChristoph Hellwig unsigned long lval;
505f461d2dcSChristoph Hellwig bool neg;
506f461d2dcSChristoph Hellwig
507f461d2dcSChristoph Hellwig if (write) {
508bce93322SLinus Torvalds proc_skip_spaces(&p, &left);
509f461d2dcSChristoph Hellwig
510f461d2dcSChristoph Hellwig if (!left)
511f461d2dcSChristoph Hellwig break;
512f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &lval, &neg,
513f461d2dcSChristoph Hellwig proc_wspace_sep,
514f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL);
515f461d2dcSChristoph Hellwig if (err)
516f461d2dcSChristoph Hellwig break;
517f461d2dcSChristoph Hellwig if (conv(&neg, &lval, i, 1, data)) {
518f461d2dcSChristoph Hellwig err = -EINVAL;
519f461d2dcSChristoph Hellwig break;
520f461d2dcSChristoph Hellwig }
521f461d2dcSChristoph Hellwig } else {
522f461d2dcSChristoph Hellwig if (conv(&neg, &lval, i, 0, data)) {
523f461d2dcSChristoph Hellwig err = -EINVAL;
524f461d2dcSChristoph Hellwig break;
525f461d2dcSChristoph Hellwig }
526f461d2dcSChristoph Hellwig if (!first)
52732927393SChristoph Hellwig proc_put_char(&buffer, &left, '\t');
52832927393SChristoph Hellwig proc_put_long(&buffer, &left, lval, neg);
529f461d2dcSChristoph Hellwig }
530f461d2dcSChristoph Hellwig }
531f461d2dcSChristoph Hellwig
532f461d2dcSChristoph Hellwig if (!write && !first && left && !err)
53332927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n');
534f461d2dcSChristoph Hellwig if (write && !err && left)
535bce93322SLinus Torvalds proc_skip_spaces(&p, &left);
53632927393SChristoph Hellwig if (write && first)
537f461d2dcSChristoph Hellwig return err ? : -EINVAL;
538f461d2dcSChristoph Hellwig *lenp -= left;
539f461d2dcSChristoph Hellwig out:
540f461d2dcSChristoph Hellwig *ppos += *lenp;
541f461d2dcSChristoph Hellwig return err;
542f461d2dcSChristoph Hellwig }
543f461d2dcSChristoph Hellwig
do_proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(bool * negp,unsigned long * lvalp,int * valp,int write,void * data),void * data)544f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write,
54532927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos,
546f461d2dcSChristoph Hellwig int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
547f461d2dcSChristoph Hellwig int write, void *data),
548f461d2dcSChristoph Hellwig void *data)
549f461d2dcSChristoph Hellwig {
550f461d2dcSChristoph Hellwig return __do_proc_dointvec(table->data, table, write,
551f461d2dcSChristoph Hellwig buffer, lenp, ppos, conv, data);
552f461d2dcSChristoph Hellwig }
553f461d2dcSChristoph Hellwig
do_proc_douintvec_w(unsigned int * tbl_data,struct ctl_table * table,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)554f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data,
555f461d2dcSChristoph Hellwig struct ctl_table *table,
55632927393SChristoph Hellwig void *buffer,
557f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos,
558f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp,
559f461d2dcSChristoph Hellwig unsigned int *valp,
560f461d2dcSChristoph Hellwig int write, void *data),
561f461d2dcSChristoph Hellwig void *data)
562f461d2dcSChristoph Hellwig {
563f461d2dcSChristoph Hellwig unsigned long lval;
564f461d2dcSChristoph Hellwig int err = 0;
565f461d2dcSChristoph Hellwig size_t left;
566f461d2dcSChristoph Hellwig bool neg;
56732927393SChristoph Hellwig char *p = buffer;
568f461d2dcSChristoph Hellwig
569f461d2dcSChristoph Hellwig left = *lenp;
570f461d2dcSChristoph Hellwig
571f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table))
572f461d2dcSChristoph Hellwig goto bail_early;
573f461d2dcSChristoph Hellwig
574f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1)
575f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1;
576f461d2dcSChristoph Hellwig
577bce93322SLinus Torvalds proc_skip_spaces(&p, &left);
578f461d2dcSChristoph Hellwig if (!left) {
579f461d2dcSChristoph Hellwig err = -EINVAL;
580f461d2dcSChristoph Hellwig goto out_free;
581f461d2dcSChristoph Hellwig }
582f461d2dcSChristoph Hellwig
583f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &lval, &neg,
584f461d2dcSChristoph Hellwig proc_wspace_sep,
585f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL);
586f461d2dcSChristoph Hellwig if (err || neg) {
587f461d2dcSChristoph Hellwig err = -EINVAL;
588f461d2dcSChristoph Hellwig goto out_free;
589f461d2dcSChristoph Hellwig }
590f461d2dcSChristoph Hellwig
591f461d2dcSChristoph Hellwig if (conv(&lval, tbl_data, 1, data)) {
592f461d2dcSChristoph Hellwig err = -EINVAL;
593f461d2dcSChristoph Hellwig goto out_free;
594f461d2dcSChristoph Hellwig }
595f461d2dcSChristoph Hellwig
596f461d2dcSChristoph Hellwig if (!err && left)
597bce93322SLinus Torvalds proc_skip_spaces(&p, &left);
598f461d2dcSChristoph Hellwig
599f461d2dcSChristoph Hellwig out_free:
600f461d2dcSChristoph Hellwig if (err)
601f461d2dcSChristoph Hellwig return -EINVAL;
602f461d2dcSChristoph Hellwig
603f461d2dcSChristoph Hellwig return 0;
604f461d2dcSChristoph Hellwig
605f461d2dcSChristoph Hellwig /* This is in keeping with old __do_proc_dointvec() */
606f461d2dcSChristoph Hellwig bail_early:
607f461d2dcSChristoph Hellwig *ppos += *lenp;
608f461d2dcSChristoph Hellwig return err;
609f461d2dcSChristoph Hellwig }
610f461d2dcSChristoph Hellwig
do_proc_douintvec_r(unsigned int * tbl_data,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)61132927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
612f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos,
613f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp,
614f461d2dcSChristoph Hellwig unsigned int *valp,
615f461d2dcSChristoph Hellwig int write, void *data),
616f461d2dcSChristoph Hellwig void *data)
617f461d2dcSChristoph Hellwig {
618f461d2dcSChristoph Hellwig unsigned long lval;
619f461d2dcSChristoph Hellwig int err = 0;
620f461d2dcSChristoph Hellwig size_t left;
621f461d2dcSChristoph Hellwig
622f461d2dcSChristoph Hellwig left = *lenp;
623f461d2dcSChristoph Hellwig
624f461d2dcSChristoph Hellwig if (conv(&lval, tbl_data, 0, data)) {
625f461d2dcSChristoph Hellwig err = -EINVAL;
626f461d2dcSChristoph Hellwig goto out;
627f461d2dcSChristoph Hellwig }
628f461d2dcSChristoph Hellwig
62932927393SChristoph Hellwig proc_put_long(&buffer, &left, lval, false);
63032927393SChristoph Hellwig if (!left)
631f461d2dcSChristoph Hellwig goto out;
632f461d2dcSChristoph Hellwig
63332927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n');
634f461d2dcSChristoph Hellwig
635f461d2dcSChristoph Hellwig out:
636f461d2dcSChristoph Hellwig *lenp -= left;
637f461d2dcSChristoph Hellwig *ppos += *lenp;
638f461d2dcSChristoph Hellwig
639f461d2dcSChristoph Hellwig return err;
640f461d2dcSChristoph Hellwig }
641f461d2dcSChristoph Hellwig
__do_proc_douintvec(void * tbl_data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)642f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
64332927393SChristoph Hellwig int write, void *buffer,
644f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos,
645f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp,
646f461d2dcSChristoph Hellwig unsigned int *valp,
647f461d2dcSChristoph Hellwig int write, void *data),
648f461d2dcSChristoph Hellwig void *data)
649f461d2dcSChristoph Hellwig {
650f461d2dcSChristoph Hellwig unsigned int *i, vleft;
651f461d2dcSChristoph Hellwig
652f461d2dcSChristoph Hellwig if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
653f461d2dcSChristoph Hellwig *lenp = 0;
654f461d2dcSChristoph Hellwig return 0;
655f461d2dcSChristoph Hellwig }
656f461d2dcSChristoph Hellwig
657f461d2dcSChristoph Hellwig i = (unsigned int *) tbl_data;
658f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(*i);
659f461d2dcSChristoph Hellwig
660f461d2dcSChristoph Hellwig /*
661f461d2dcSChristoph Hellwig * Arrays are not supported, keep this simple. *Do not* add
662f461d2dcSChristoph Hellwig * support for them.
663f461d2dcSChristoph Hellwig */
664f461d2dcSChristoph Hellwig if (vleft != 1) {
665f461d2dcSChristoph Hellwig *lenp = 0;
666f461d2dcSChristoph Hellwig return -EINVAL;
667f461d2dcSChristoph Hellwig }
668f461d2dcSChristoph Hellwig
669f461d2dcSChristoph Hellwig if (!conv)
670f461d2dcSChristoph Hellwig conv = do_proc_douintvec_conv;
671f461d2dcSChristoph Hellwig
672f461d2dcSChristoph Hellwig if (write)
673f461d2dcSChristoph Hellwig return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
674f461d2dcSChristoph Hellwig conv, data);
675f461d2dcSChristoph Hellwig return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
676f461d2dcSChristoph Hellwig }
677f461d2dcSChristoph Hellwig
do_proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)6781998f193SLuis Chamberlain int do_proc_douintvec(struct ctl_table *table, int write,
67932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos,
680f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp,
681f461d2dcSChristoph Hellwig unsigned int *valp,
682f461d2dcSChristoph Hellwig int write, void *data),
683f461d2dcSChristoph Hellwig void *data)
684f461d2dcSChristoph Hellwig {
685f461d2dcSChristoph Hellwig return __do_proc_douintvec(table->data, table, write,
686f461d2dcSChristoph Hellwig buffer, lenp, ppos, conv, data);
687f461d2dcSChristoph Hellwig }
688f461d2dcSChristoph Hellwig
689f461d2dcSChristoph Hellwig /**
690a2071573SJia He * proc_dobool - read/write a bool
691a2071573SJia He * @table: the sysctl table
692a2071573SJia He * @write: %TRUE if this is a write to the sysctl file
693a2071573SJia He * @buffer: the user buffer
694a2071573SJia He * @lenp: the size of the user buffer
695a2071573SJia He * @ppos: file position
696a2071573SJia He *
697*f1aa2eb5SOndrej Mosnacek * Reads/writes one integer value from/to the user buffer,
698*f1aa2eb5SOndrej Mosnacek * treated as an ASCII string.
699*f1aa2eb5SOndrej Mosnacek *
700*f1aa2eb5SOndrej Mosnacek * table->data must point to a bool variable and table->maxlen must
701*f1aa2eb5SOndrej Mosnacek * be sizeof(bool).
702a2071573SJia He *
703a2071573SJia He * Returns 0 on success.
704a2071573SJia He */
proc_dobool(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)705a2071573SJia He int proc_dobool(struct ctl_table *table, int write, void *buffer,
706a2071573SJia He size_t *lenp, loff_t *ppos)
707a2071573SJia He {
708*f1aa2eb5SOndrej Mosnacek struct ctl_table tmp;
709*f1aa2eb5SOndrej Mosnacek bool *data = table->data;
710*f1aa2eb5SOndrej Mosnacek int res, val;
711*f1aa2eb5SOndrej Mosnacek
712*f1aa2eb5SOndrej Mosnacek /* Do not support arrays yet. */
713*f1aa2eb5SOndrej Mosnacek if (table->maxlen != sizeof(bool))
714*f1aa2eb5SOndrej Mosnacek return -EINVAL;
715*f1aa2eb5SOndrej Mosnacek
716*f1aa2eb5SOndrej Mosnacek tmp = *table;
717*f1aa2eb5SOndrej Mosnacek tmp.maxlen = sizeof(val);
718*f1aa2eb5SOndrej Mosnacek tmp.data = &val;
719*f1aa2eb5SOndrej Mosnacek
720*f1aa2eb5SOndrej Mosnacek val = READ_ONCE(*data);
721*f1aa2eb5SOndrej Mosnacek res = proc_dointvec(&tmp, write, buffer, lenp, ppos);
722*f1aa2eb5SOndrej Mosnacek if (res)
723*f1aa2eb5SOndrej Mosnacek return res;
724*f1aa2eb5SOndrej Mosnacek if (write)
725*f1aa2eb5SOndrej Mosnacek WRITE_ONCE(*data, val);
726*f1aa2eb5SOndrej Mosnacek return 0;
727a2071573SJia He }
728a2071573SJia He
729a2071573SJia He /**
730f461d2dcSChristoph Hellwig * proc_dointvec - read a vector of integers
731f461d2dcSChristoph Hellwig * @table: the sysctl table
732f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
733f461d2dcSChristoph Hellwig * @buffer: the user buffer
734f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
735f461d2dcSChristoph Hellwig * @ppos: file position
736f461d2dcSChristoph Hellwig *
737f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
738f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
739f461d2dcSChristoph Hellwig *
740f461d2dcSChristoph Hellwig * Returns 0 on success.
741f461d2dcSChristoph Hellwig */
proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)74232927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer,
74332927393SChristoph Hellwig size_t *lenp, loff_t *ppos)
744f461d2dcSChristoph Hellwig {
745f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
746f461d2dcSChristoph Hellwig }
747f461d2dcSChristoph Hellwig
748f461d2dcSChristoph Hellwig /**
749f461d2dcSChristoph Hellwig * proc_douintvec - read a vector of unsigned integers
750f461d2dcSChristoph Hellwig * @table: the sysctl table
751f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
752f461d2dcSChristoph Hellwig * @buffer: the user buffer
753f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
754f461d2dcSChristoph Hellwig * @ppos: file position
755f461d2dcSChristoph Hellwig *
756f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
757f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
758f461d2dcSChristoph Hellwig *
759f461d2dcSChristoph Hellwig * Returns 0 on success.
760f461d2dcSChristoph Hellwig */
proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)76132927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer,
76232927393SChristoph Hellwig size_t *lenp, loff_t *ppos)
763f461d2dcSChristoph Hellwig {
764f461d2dcSChristoph Hellwig return do_proc_douintvec(table, write, buffer, lenp, ppos,
765f461d2dcSChristoph Hellwig do_proc_douintvec_conv, NULL);
766f461d2dcSChristoph Hellwig }
767f461d2dcSChristoph Hellwig
768f461d2dcSChristoph Hellwig /*
769f461d2dcSChristoph Hellwig * Taint values can only be increased
770f461d2dcSChristoph Hellwig * This means we can safely use a temporary.
771f461d2dcSChristoph Hellwig */
proc_taint(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)772f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write,
77332927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
774f461d2dcSChristoph Hellwig {
775f461d2dcSChristoph Hellwig struct ctl_table t;
776f461d2dcSChristoph Hellwig unsigned long tmptaint = get_taint();
777f461d2dcSChristoph Hellwig int err;
778f461d2dcSChristoph Hellwig
779f461d2dcSChristoph Hellwig if (write && !capable(CAP_SYS_ADMIN))
780f461d2dcSChristoph Hellwig return -EPERM;
781f461d2dcSChristoph Hellwig
782f461d2dcSChristoph Hellwig t = *table;
783f461d2dcSChristoph Hellwig t.data = &tmptaint;
784f461d2dcSChristoph Hellwig err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
785f461d2dcSChristoph Hellwig if (err < 0)
786f461d2dcSChristoph Hellwig return err;
787f461d2dcSChristoph Hellwig
788f461d2dcSChristoph Hellwig if (write) {
789db38d5c1SRafael Aquini int i;
790db38d5c1SRafael Aquini
791db38d5c1SRafael Aquini /*
792db38d5c1SRafael Aquini * If we are relying on panic_on_taint not producing
793db38d5c1SRafael Aquini * false positives due to userspace input, bail out
794db38d5c1SRafael Aquini * before setting the requested taint flags.
795db38d5c1SRafael Aquini */
796db38d5c1SRafael Aquini if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
797db38d5c1SRafael Aquini return -EINVAL;
798db38d5c1SRafael Aquini
799f461d2dcSChristoph Hellwig /*
800f461d2dcSChristoph Hellwig * Poor man's atomic or. Not worth adding a primitive
801f461d2dcSChristoph Hellwig * to everyone's atomic.h for this
802f461d2dcSChristoph Hellwig */
803e77132e7SRafael Aquini for (i = 0; i < TAINT_FLAGS_COUNT; i++)
804e77132e7SRafael Aquini if ((1UL << i) & tmptaint)
805f461d2dcSChristoph Hellwig add_taint(i, LOCKDEP_STILL_OK);
806f461d2dcSChristoph Hellwig }
807f461d2dcSChristoph Hellwig
808f461d2dcSChristoph Hellwig return err;
809f461d2dcSChristoph Hellwig }
810f461d2dcSChristoph Hellwig
811f461d2dcSChristoph Hellwig /**
812f461d2dcSChristoph Hellwig * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
813f461d2dcSChristoph Hellwig * @min: pointer to minimum allowable value
814f461d2dcSChristoph Hellwig * @max: pointer to maximum allowable value
815f461d2dcSChristoph Hellwig *
816f461d2dcSChristoph Hellwig * The do_proc_dointvec_minmax_conv_param structure provides the
817f461d2dcSChristoph Hellwig * minimum and maximum values for doing range checking for those sysctl
818f461d2dcSChristoph Hellwig * parameters that use the proc_dointvec_minmax() handler.
819f461d2dcSChristoph Hellwig */
820f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param {
821f461d2dcSChristoph Hellwig int *min;
822f461d2dcSChristoph Hellwig int *max;
823f461d2dcSChristoph Hellwig };
824f461d2dcSChristoph Hellwig
do_proc_dointvec_minmax_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)825f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
826f461d2dcSChristoph Hellwig int *valp,
827f461d2dcSChristoph Hellwig int write, void *data)
828f461d2dcSChristoph Hellwig {
829f461d2dcSChristoph Hellwig int tmp, ret;
830f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param *param = data;
831f461d2dcSChristoph Hellwig /*
832f461d2dcSChristoph Hellwig * If writing, first do so via a temporary local int so we can
833f461d2dcSChristoph Hellwig * bounds-check it before touching *valp.
834f461d2dcSChristoph Hellwig */
835f461d2dcSChristoph Hellwig int *ip = write ? &tmp : valp;
836f461d2dcSChristoph Hellwig
837f461d2dcSChristoph Hellwig ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
838f461d2dcSChristoph Hellwig if (ret)
839f461d2dcSChristoph Hellwig return ret;
840f461d2dcSChristoph Hellwig
841f461d2dcSChristoph Hellwig if (write) {
842f461d2dcSChristoph Hellwig if ((param->min && *param->min > tmp) ||
843f461d2dcSChristoph Hellwig (param->max && *param->max < tmp))
844f461d2dcSChristoph Hellwig return -EINVAL;
845f613d86dSKuniyuki Iwashima WRITE_ONCE(*valp, tmp);
846f461d2dcSChristoph Hellwig }
847f461d2dcSChristoph Hellwig
848f461d2dcSChristoph Hellwig return 0;
849f461d2dcSChristoph Hellwig }
850f461d2dcSChristoph Hellwig
851f461d2dcSChristoph Hellwig /**
852f461d2dcSChristoph Hellwig * proc_dointvec_minmax - read a vector of integers with min/max values
853f461d2dcSChristoph Hellwig * @table: the sysctl table
854f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
855f461d2dcSChristoph Hellwig * @buffer: the user buffer
856f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
857f461d2dcSChristoph Hellwig * @ppos: file position
858f461d2dcSChristoph Hellwig *
859f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
860f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
861f461d2dcSChristoph Hellwig *
862f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by
863f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max).
864f461d2dcSChristoph Hellwig *
865f461d2dcSChristoph Hellwig * Returns 0 on success or -EINVAL on write when the range check fails.
866f461d2dcSChristoph Hellwig */
proc_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)867f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
86832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
869f461d2dcSChristoph Hellwig {
870f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param param = {
871f461d2dcSChristoph Hellwig .min = (int *) table->extra1,
872f461d2dcSChristoph Hellwig .max = (int *) table->extra2,
873f461d2dcSChristoph Hellwig };
874f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos,
875f461d2dcSChristoph Hellwig do_proc_dointvec_minmax_conv, ¶m);
876f461d2dcSChristoph Hellwig }
877f461d2dcSChristoph Hellwig
878f461d2dcSChristoph Hellwig /**
879f461d2dcSChristoph Hellwig * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
880f461d2dcSChristoph Hellwig * @min: pointer to minimum allowable value
881f461d2dcSChristoph Hellwig * @max: pointer to maximum allowable value
882f461d2dcSChristoph Hellwig *
883f461d2dcSChristoph Hellwig * The do_proc_douintvec_minmax_conv_param structure provides the
884f461d2dcSChristoph Hellwig * minimum and maximum values for doing range checking for those sysctl
885f461d2dcSChristoph Hellwig * parameters that use the proc_douintvec_minmax() handler.
886f461d2dcSChristoph Hellwig */
887f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param {
888f461d2dcSChristoph Hellwig unsigned int *min;
889f461d2dcSChristoph Hellwig unsigned int *max;
890f461d2dcSChristoph Hellwig };
891f461d2dcSChristoph Hellwig
do_proc_douintvec_minmax_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)892f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
893f461d2dcSChristoph Hellwig unsigned int *valp,
894f461d2dcSChristoph Hellwig int write, void *data)
895f461d2dcSChristoph Hellwig {
896f461d2dcSChristoph Hellwig int ret;
897f461d2dcSChristoph Hellwig unsigned int tmp;
898f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param *param = data;
899f461d2dcSChristoph Hellwig /* write via temporary local uint for bounds-checking */
900f461d2dcSChristoph Hellwig unsigned int *up = write ? &tmp : valp;
901f461d2dcSChristoph Hellwig
902f461d2dcSChristoph Hellwig ret = do_proc_douintvec_conv(lvalp, up, write, data);
903f461d2dcSChristoph Hellwig if (ret)
904f461d2dcSChristoph Hellwig return ret;
905f461d2dcSChristoph Hellwig
906f461d2dcSChristoph Hellwig if (write) {
907f461d2dcSChristoph Hellwig if ((param->min && *param->min > tmp) ||
908f461d2dcSChristoph Hellwig (param->max && *param->max < tmp))
909f461d2dcSChristoph Hellwig return -ERANGE;
910f461d2dcSChristoph Hellwig
9112d3b559dSKuniyuki Iwashima WRITE_ONCE(*valp, tmp);
912f461d2dcSChristoph Hellwig }
913f461d2dcSChristoph Hellwig
914f461d2dcSChristoph Hellwig return 0;
915f461d2dcSChristoph Hellwig }
916f461d2dcSChristoph Hellwig
917f461d2dcSChristoph Hellwig /**
918f461d2dcSChristoph Hellwig * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
919f461d2dcSChristoph Hellwig * @table: the sysctl table
920f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
921f461d2dcSChristoph Hellwig * @buffer: the user buffer
922f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
923f461d2dcSChristoph Hellwig * @ppos: file position
924f461d2dcSChristoph Hellwig *
925f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
926f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. Negative
927f461d2dcSChristoph Hellwig * strings are not allowed.
928f461d2dcSChristoph Hellwig *
929f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by
930f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). There is a final sanity
931f461d2dcSChristoph Hellwig * check for UINT_MAX to avoid having to support wrap around uses from
932f461d2dcSChristoph Hellwig * userspace.
933f461d2dcSChristoph Hellwig *
934f461d2dcSChristoph Hellwig * Returns 0 on success or -ERANGE on write when the range check fails.
935f461d2dcSChristoph Hellwig */
proc_douintvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)936f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
93732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
938f461d2dcSChristoph Hellwig {
939f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param param = {
940f461d2dcSChristoph Hellwig .min = (unsigned int *) table->extra1,
941f461d2dcSChristoph Hellwig .max = (unsigned int *) table->extra2,
942f461d2dcSChristoph Hellwig };
943f461d2dcSChristoph Hellwig return do_proc_douintvec(table, write, buffer, lenp, ppos,
944f461d2dcSChristoph Hellwig do_proc_douintvec_minmax_conv, ¶m);
945f461d2dcSChristoph Hellwig }
946f461d2dcSChristoph Hellwig
947cb944413SEric Dumazet /**
948cb944413SEric Dumazet * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
949cb944413SEric Dumazet * @table: the sysctl table
950cb944413SEric Dumazet * @write: %TRUE if this is a write to the sysctl file
951cb944413SEric Dumazet * @buffer: the user buffer
952cb944413SEric Dumazet * @lenp: the size of the user buffer
953cb944413SEric Dumazet * @ppos: file position
954cb944413SEric Dumazet *
955cb944413SEric Dumazet * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
956cb944413SEric Dumazet * values from/to the user buffer, treated as an ASCII string. Negative
957cb944413SEric Dumazet * strings are not allowed.
958cb944413SEric Dumazet *
959cb944413SEric Dumazet * This routine will ensure the values are within the range specified by
960cb944413SEric Dumazet * table->extra1 (min) and table->extra2 (max).
961cb944413SEric Dumazet *
962cb944413SEric Dumazet * Returns 0 on success or an error on write when the range check fails.
963cb944413SEric Dumazet */
proc_dou8vec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)964cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
965cb944413SEric Dumazet void *buffer, size_t *lenp, loff_t *ppos)
966cb944413SEric Dumazet {
967cb944413SEric Dumazet struct ctl_table tmp;
968cb944413SEric Dumazet unsigned int min = 0, max = 255U, val;
969cb944413SEric Dumazet u8 *data = table->data;
970cb944413SEric Dumazet struct do_proc_douintvec_minmax_conv_param param = {
971cb944413SEric Dumazet .min = &min,
972cb944413SEric Dumazet .max = &max,
973cb944413SEric Dumazet };
974cb944413SEric Dumazet int res;
975cb944413SEric Dumazet
976cb944413SEric Dumazet /* Do not support arrays yet. */
977cb944413SEric Dumazet if (table->maxlen != sizeof(u8))
978cb944413SEric Dumazet return -EINVAL;
979cb944413SEric Dumazet
980cb944413SEric Dumazet if (table->extra1) {
981cb944413SEric Dumazet min = *(unsigned int *) table->extra1;
982cb944413SEric Dumazet if (min > 255U)
983cb944413SEric Dumazet return -EINVAL;
984cb944413SEric Dumazet }
985cb944413SEric Dumazet if (table->extra2) {
986cb944413SEric Dumazet max = *(unsigned int *) table->extra2;
987cb944413SEric Dumazet if (max > 255U)
988cb944413SEric Dumazet return -EINVAL;
989cb944413SEric Dumazet }
990cb944413SEric Dumazet
991cb944413SEric Dumazet tmp = *table;
992cb944413SEric Dumazet
993cb944413SEric Dumazet tmp.maxlen = sizeof(val);
994cb944413SEric Dumazet tmp.data = &val;
9957dee5d77SKuniyuki Iwashima val = READ_ONCE(*data);
996cb944413SEric Dumazet res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
997cb944413SEric Dumazet do_proc_douintvec_minmax_conv, ¶m);
998cb944413SEric Dumazet if (res)
999cb944413SEric Dumazet return res;
1000cb944413SEric Dumazet if (write)
10017dee5d77SKuniyuki Iwashima WRITE_ONCE(*data, val);
1002cb944413SEric Dumazet return 0;
1003cb944413SEric Dumazet }
1004cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1005cb944413SEric Dumazet
1006f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ
sysrq_sysctl_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1007f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write,
100832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1009f461d2dcSChristoph Hellwig {
1010f461d2dcSChristoph Hellwig int tmp, ret;
1011f461d2dcSChristoph Hellwig
1012f461d2dcSChristoph Hellwig tmp = sysrq_mask();
1013f461d2dcSChristoph Hellwig
1014f461d2dcSChristoph Hellwig ret = __do_proc_dointvec(&tmp, table, write, buffer,
1015f461d2dcSChristoph Hellwig lenp, ppos, NULL, NULL);
1016f461d2dcSChristoph Hellwig if (ret || !write)
1017f461d2dcSChristoph Hellwig return ret;
1018f461d2dcSChristoph Hellwig
1019f461d2dcSChristoph Hellwig if (write)
1020f461d2dcSChristoph Hellwig sysrq_toggle_support(tmp);
1021f461d2dcSChristoph Hellwig
1022f461d2dcSChristoph Hellwig return 0;
1023f461d2dcSChristoph Hellwig }
1024f461d2dcSChristoph Hellwig #endif
1025f461d2dcSChristoph Hellwig
__do_proc_doulongvec_minmax(void * data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,unsigned long convmul,unsigned long convdiv)102632927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
102732927393SChristoph Hellwig int write, void *buffer, size_t *lenp, loff_t *ppos,
102832927393SChristoph Hellwig unsigned long convmul, unsigned long convdiv)
1029f461d2dcSChristoph Hellwig {
1030f461d2dcSChristoph Hellwig unsigned long *i, *min, *max;
1031f461d2dcSChristoph Hellwig int vleft, first = 1, err = 0;
1032f461d2dcSChristoph Hellwig size_t left;
103332927393SChristoph Hellwig char *p;
1034f461d2dcSChristoph Hellwig
1035f461d2dcSChristoph Hellwig if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1036f461d2dcSChristoph Hellwig *lenp = 0;
1037f461d2dcSChristoph Hellwig return 0;
1038f461d2dcSChristoph Hellwig }
1039f461d2dcSChristoph Hellwig
10408ebc4123SDong Chuanjian i = data;
10418ebc4123SDong Chuanjian min = table->extra1;
10428ebc4123SDong Chuanjian max = table->extra2;
1043f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(unsigned long);
1044f461d2dcSChristoph Hellwig left = *lenp;
1045f461d2dcSChristoph Hellwig
1046f461d2dcSChristoph Hellwig if (write) {
1047f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table))
1048f461d2dcSChristoph Hellwig goto out;
1049f461d2dcSChristoph Hellwig
1050f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1)
1051f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1;
105232927393SChristoph Hellwig p = buffer;
1053f461d2dcSChristoph Hellwig }
1054f461d2dcSChristoph Hellwig
1055f461d2dcSChristoph Hellwig for (; left && vleft--; i++, first = 0) {
1056f461d2dcSChristoph Hellwig unsigned long val;
1057f461d2dcSChristoph Hellwig
1058f461d2dcSChristoph Hellwig if (write) {
1059f461d2dcSChristoph Hellwig bool neg;
1060f461d2dcSChristoph Hellwig
1061bce93322SLinus Torvalds proc_skip_spaces(&p, &left);
1062f461d2dcSChristoph Hellwig if (!left)
1063f461d2dcSChristoph Hellwig break;
1064f461d2dcSChristoph Hellwig
1065f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val, &neg,
1066f461d2dcSChristoph Hellwig proc_wspace_sep,
1067f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL);
10681622ed7dSBaokun Li if (err || neg) {
10691622ed7dSBaokun Li err = -EINVAL;
1070f461d2dcSChristoph Hellwig break;
10711622ed7dSBaokun Li }
10721622ed7dSBaokun Li
1073f461d2dcSChristoph Hellwig val = convmul * val / convdiv;
1074f461d2dcSChristoph Hellwig if ((min && val < *min) || (max && val > *max)) {
1075f461d2dcSChristoph Hellwig err = -EINVAL;
1076f461d2dcSChristoph Hellwig break;
1077f461d2dcSChristoph Hellwig }
1078c31bcc8fSKuniyuki Iwashima WRITE_ONCE(*i, val);
1079f461d2dcSChristoph Hellwig } else {
1080c31bcc8fSKuniyuki Iwashima val = convdiv * READ_ONCE(*i) / convmul;
108132927393SChristoph Hellwig if (!first)
108232927393SChristoph Hellwig proc_put_char(&buffer, &left, '\t');
108332927393SChristoph Hellwig proc_put_long(&buffer, &left, val, false);
1084f461d2dcSChristoph Hellwig }
1085f461d2dcSChristoph Hellwig }
1086f461d2dcSChristoph Hellwig
1087f461d2dcSChristoph Hellwig if (!write && !first && left && !err)
108832927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n');
1089f461d2dcSChristoph Hellwig if (write && !err)
1090bce93322SLinus Torvalds proc_skip_spaces(&p, &left);
109132927393SChristoph Hellwig if (write && first)
1092f461d2dcSChristoph Hellwig return err ? : -EINVAL;
1093f461d2dcSChristoph Hellwig *lenp -= left;
1094f461d2dcSChristoph Hellwig out:
1095f461d2dcSChristoph Hellwig *ppos += *lenp;
1096f461d2dcSChristoph Hellwig return err;
1097f461d2dcSChristoph Hellwig }
1098f461d2dcSChristoph Hellwig
do_proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,unsigned long convmul,unsigned long convdiv)1099f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
110032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1101f461d2dcSChristoph Hellwig unsigned long convdiv)
1102f461d2dcSChristoph Hellwig {
1103f461d2dcSChristoph Hellwig return __do_proc_doulongvec_minmax(table->data, table, write,
1104f461d2dcSChristoph Hellwig buffer, lenp, ppos, convmul, convdiv);
1105f461d2dcSChristoph Hellwig }
1106f461d2dcSChristoph Hellwig
1107f461d2dcSChristoph Hellwig /**
1108f461d2dcSChristoph Hellwig * proc_doulongvec_minmax - read a vector of long integers with min/max values
1109f461d2dcSChristoph Hellwig * @table: the sysctl table
1110f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
1111f461d2dcSChristoph Hellwig * @buffer: the user buffer
1112f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
1113f461d2dcSChristoph Hellwig * @ppos: file position
1114f461d2dcSChristoph Hellwig *
1115f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1116f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
1117f461d2dcSChristoph Hellwig *
1118f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by
1119f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max).
1120f461d2dcSChristoph Hellwig *
1121f461d2dcSChristoph Hellwig * Returns 0 on success.
1122f461d2dcSChristoph Hellwig */
proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1123f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
112432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1125f461d2dcSChristoph Hellwig {
1126f461d2dcSChristoph Hellwig return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1127f461d2dcSChristoph Hellwig }
1128f461d2dcSChristoph Hellwig
1129f461d2dcSChristoph Hellwig /**
1130f461d2dcSChristoph Hellwig * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1131f461d2dcSChristoph Hellwig * @table: the sysctl table
1132f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
1133f461d2dcSChristoph Hellwig * @buffer: the user buffer
1134f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
1135f461d2dcSChristoph Hellwig * @ppos: file position
1136f461d2dcSChristoph Hellwig *
1137f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1138f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. The values
1139f461d2dcSChristoph Hellwig * are treated as milliseconds, and converted to jiffies when they are stored.
1140f461d2dcSChristoph Hellwig *
1141f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by
1142f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max).
1143f461d2dcSChristoph Hellwig *
1144f461d2dcSChristoph Hellwig * Returns 0 on success.
1145f461d2dcSChristoph Hellwig */
proc_doulongvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1146f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
114732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1148f461d2dcSChristoph Hellwig {
1149f461d2dcSChristoph Hellwig return do_proc_doulongvec_minmax(table, write, buffer,
1150f461d2dcSChristoph Hellwig lenp, ppos, HZ, 1000l);
1151f461d2dcSChristoph Hellwig }
1152f461d2dcSChristoph Hellwig
1153f461d2dcSChristoph Hellwig
do_proc_dointvec_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1154f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1155f461d2dcSChristoph Hellwig int *valp,
1156f461d2dcSChristoph Hellwig int write, void *data)
1157f461d2dcSChristoph Hellwig {
1158f461d2dcSChristoph Hellwig if (write) {
1159f461d2dcSChristoph Hellwig if (*lvalp > INT_MAX / HZ)
1160f461d2dcSChristoph Hellwig return 1;
1161e8778208SKuniyuki Iwashima if (*negp)
1162e8778208SKuniyuki Iwashima WRITE_ONCE(*valp, -*lvalp * HZ);
1163e8778208SKuniyuki Iwashima else
1164e8778208SKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp * HZ);
1165f461d2dcSChristoph Hellwig } else {
1166e8778208SKuniyuki Iwashima int val = READ_ONCE(*valp);
1167f461d2dcSChristoph Hellwig unsigned long lval;
1168f461d2dcSChristoph Hellwig if (val < 0) {
1169f461d2dcSChristoph Hellwig *negp = true;
1170f461d2dcSChristoph Hellwig lval = -(unsigned long)val;
1171f461d2dcSChristoph Hellwig } else {
1172f461d2dcSChristoph Hellwig *negp = false;
1173f461d2dcSChristoph Hellwig lval = (unsigned long)val;
1174f461d2dcSChristoph Hellwig }
1175f461d2dcSChristoph Hellwig *lvalp = lval / HZ;
1176f461d2dcSChristoph Hellwig }
1177f461d2dcSChristoph Hellwig return 0;
1178f461d2dcSChristoph Hellwig }
1179f461d2dcSChristoph Hellwig
do_proc_dointvec_userhz_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1180f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1181f461d2dcSChristoph Hellwig int *valp,
1182f461d2dcSChristoph Hellwig int write, void *data)
1183f461d2dcSChristoph Hellwig {
1184f461d2dcSChristoph Hellwig if (write) {
1185f461d2dcSChristoph Hellwig if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1186f461d2dcSChristoph Hellwig return 1;
1187f461d2dcSChristoph Hellwig *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1188f461d2dcSChristoph Hellwig } else {
1189f461d2dcSChristoph Hellwig int val = *valp;
1190f461d2dcSChristoph Hellwig unsigned long lval;
1191f461d2dcSChristoph Hellwig if (val < 0) {
1192f461d2dcSChristoph Hellwig *negp = true;
1193f461d2dcSChristoph Hellwig lval = -(unsigned long)val;
1194f461d2dcSChristoph Hellwig } else {
1195f461d2dcSChristoph Hellwig *negp = false;
1196f461d2dcSChristoph Hellwig lval = (unsigned long)val;
1197f461d2dcSChristoph Hellwig }
1198f461d2dcSChristoph Hellwig *lvalp = jiffies_to_clock_t(lval);
1199f461d2dcSChristoph Hellwig }
1200f461d2dcSChristoph Hellwig return 0;
1201f461d2dcSChristoph Hellwig }
1202f461d2dcSChristoph Hellwig
do_proc_dointvec_ms_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1203f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1204f461d2dcSChristoph Hellwig int *valp,
1205f461d2dcSChristoph Hellwig int write, void *data)
1206f461d2dcSChristoph Hellwig {
1207f461d2dcSChristoph Hellwig if (write) {
1208f461d2dcSChristoph Hellwig unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1209f461d2dcSChristoph Hellwig
1210f461d2dcSChristoph Hellwig if (jif > INT_MAX)
1211f461d2dcSChristoph Hellwig return 1;
12127d1025e5SKuniyuki Iwashima WRITE_ONCE(*valp, (int)jif);
1213f461d2dcSChristoph Hellwig } else {
12147d1025e5SKuniyuki Iwashima int val = READ_ONCE(*valp);
1215f461d2dcSChristoph Hellwig unsigned long lval;
1216f461d2dcSChristoph Hellwig if (val < 0) {
1217f461d2dcSChristoph Hellwig *negp = true;
1218f461d2dcSChristoph Hellwig lval = -(unsigned long)val;
1219f461d2dcSChristoph Hellwig } else {
1220f461d2dcSChristoph Hellwig *negp = false;
1221f461d2dcSChristoph Hellwig lval = (unsigned long)val;
1222f461d2dcSChristoph Hellwig }
1223f461d2dcSChristoph Hellwig *lvalp = jiffies_to_msecs(lval);
1224f461d2dcSChristoph Hellwig }
1225f461d2dcSChristoph Hellwig return 0;
1226f461d2dcSChristoph Hellwig }
1227f461d2dcSChristoph Hellwig
do_proc_dointvec_ms_jiffies_minmax_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1228c381d02bSYuwei Wang static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp,
1229c381d02bSYuwei Wang int *valp, int write, void *data)
1230c381d02bSYuwei Wang {
1231c381d02bSYuwei Wang int tmp, ret;
1232c381d02bSYuwei Wang struct do_proc_dointvec_minmax_conv_param *param = data;
1233c381d02bSYuwei Wang /*
1234c381d02bSYuwei Wang * If writing, first do so via a temporary local int so we can
1235c381d02bSYuwei Wang * bounds-check it before touching *valp.
1236c381d02bSYuwei Wang */
1237c381d02bSYuwei Wang int *ip = write ? &tmp : valp;
1238c381d02bSYuwei Wang
1239c381d02bSYuwei Wang ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data);
1240c381d02bSYuwei Wang if (ret)
1241c381d02bSYuwei Wang return ret;
1242c381d02bSYuwei Wang
1243c381d02bSYuwei Wang if (write) {
1244c381d02bSYuwei Wang if ((param->min && *param->min > tmp) ||
1245c381d02bSYuwei Wang (param->max && *param->max < tmp))
1246c381d02bSYuwei Wang return -EINVAL;
1247c381d02bSYuwei Wang *valp = tmp;
1248c381d02bSYuwei Wang }
1249c381d02bSYuwei Wang return 0;
1250c381d02bSYuwei Wang }
1251c381d02bSYuwei Wang
1252f461d2dcSChristoph Hellwig /**
1253f461d2dcSChristoph Hellwig * proc_dointvec_jiffies - read a vector of integers as seconds
1254f461d2dcSChristoph Hellwig * @table: the sysctl table
1255f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
1256f461d2dcSChristoph Hellwig * @buffer: the user buffer
1257f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
1258f461d2dcSChristoph Hellwig * @ppos: file position
1259f461d2dcSChristoph Hellwig *
1260f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1261f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
1262f461d2dcSChristoph Hellwig * The values read are assumed to be in seconds, and are converted into
1263f461d2dcSChristoph Hellwig * jiffies.
1264f461d2dcSChristoph Hellwig *
1265f461d2dcSChristoph Hellwig * Returns 0 on success.
1266f461d2dcSChristoph Hellwig */
proc_dointvec_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1267f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
126832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1269f461d2dcSChristoph Hellwig {
1270f461d2dcSChristoph Hellwig return do_proc_dointvec(table,write,buffer,lenp,ppos,
1271f461d2dcSChristoph Hellwig do_proc_dointvec_jiffies_conv,NULL);
1272f461d2dcSChristoph Hellwig }
1273f461d2dcSChristoph Hellwig
proc_dointvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1274c381d02bSYuwei Wang int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1275c381d02bSYuwei Wang void *buffer, size_t *lenp, loff_t *ppos)
1276c381d02bSYuwei Wang {
1277c381d02bSYuwei Wang struct do_proc_dointvec_minmax_conv_param param = {
1278c381d02bSYuwei Wang .min = (int *) table->extra1,
1279c381d02bSYuwei Wang .max = (int *) table->extra2,
1280c381d02bSYuwei Wang };
1281c381d02bSYuwei Wang return do_proc_dointvec(table, write, buffer, lenp, ppos,
1282c381d02bSYuwei Wang do_proc_dointvec_ms_jiffies_minmax_conv, ¶m);
1283c381d02bSYuwei Wang }
1284c381d02bSYuwei Wang
1285f461d2dcSChristoph Hellwig /**
1286f461d2dcSChristoph Hellwig * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1287f461d2dcSChristoph Hellwig * @table: the sysctl table
1288f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
1289f461d2dcSChristoph Hellwig * @buffer: the user buffer
1290f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
1291f461d2dcSChristoph Hellwig * @ppos: pointer to the file position
1292f461d2dcSChristoph Hellwig *
1293f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1294f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
1295f461d2dcSChristoph Hellwig * The values read are assumed to be in 1/USER_HZ seconds, and
1296f461d2dcSChristoph Hellwig * are converted into jiffies.
1297f461d2dcSChristoph Hellwig *
1298f461d2dcSChristoph Hellwig * Returns 0 on success.
1299f461d2dcSChristoph Hellwig */
proc_dointvec_userhz_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1300f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
130132927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1302f461d2dcSChristoph Hellwig {
1303f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos,
1304f461d2dcSChristoph Hellwig do_proc_dointvec_userhz_jiffies_conv, NULL);
1305f461d2dcSChristoph Hellwig }
1306f461d2dcSChristoph Hellwig
1307f461d2dcSChristoph Hellwig /**
1308f461d2dcSChristoph Hellwig * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1309f461d2dcSChristoph Hellwig * @table: the sysctl table
1310f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
1311f461d2dcSChristoph Hellwig * @buffer: the user buffer
1312f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
1313f461d2dcSChristoph Hellwig * @ppos: file position
1314f461d2dcSChristoph Hellwig * @ppos: the current position in the file
1315f461d2dcSChristoph Hellwig *
1316f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1317f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string.
1318f461d2dcSChristoph Hellwig * The values read are assumed to be in 1/1000 seconds, and
1319f461d2dcSChristoph Hellwig * are converted into jiffies.
1320f461d2dcSChristoph Hellwig *
1321f461d2dcSChristoph Hellwig * Returns 0 on success.
1322f461d2dcSChristoph Hellwig */
proc_dointvec_ms_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)132332927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
132432927393SChristoph Hellwig size_t *lenp, loff_t *ppos)
1325f461d2dcSChristoph Hellwig {
1326f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos,
1327f461d2dcSChristoph Hellwig do_proc_dointvec_ms_jiffies_conv, NULL);
1328f461d2dcSChristoph Hellwig }
1329f461d2dcSChristoph Hellwig
proc_do_cad_pid(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)133032927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
133132927393SChristoph Hellwig size_t *lenp, loff_t *ppos)
1332f461d2dcSChristoph Hellwig {
1333f461d2dcSChristoph Hellwig struct pid *new_pid;
1334f461d2dcSChristoph Hellwig pid_t tmp;
1335f461d2dcSChristoph Hellwig int r;
1336f461d2dcSChristoph Hellwig
1337f461d2dcSChristoph Hellwig tmp = pid_vnr(cad_pid);
1338f461d2dcSChristoph Hellwig
1339f461d2dcSChristoph Hellwig r = __do_proc_dointvec(&tmp, table, write, buffer,
1340f461d2dcSChristoph Hellwig lenp, ppos, NULL, NULL);
1341f461d2dcSChristoph Hellwig if (r || !write)
1342f461d2dcSChristoph Hellwig return r;
1343f461d2dcSChristoph Hellwig
1344f461d2dcSChristoph Hellwig new_pid = find_get_pid(tmp);
1345f461d2dcSChristoph Hellwig if (!new_pid)
1346f461d2dcSChristoph Hellwig return -ESRCH;
1347f461d2dcSChristoph Hellwig
1348f461d2dcSChristoph Hellwig put_pid(xchg(&cad_pid, new_pid));
1349f461d2dcSChristoph Hellwig return 0;
1350f461d2dcSChristoph Hellwig }
1351f461d2dcSChristoph Hellwig
1352f461d2dcSChristoph Hellwig /**
1353f461d2dcSChristoph Hellwig * proc_do_large_bitmap - read/write from/to a large bitmap
1354f461d2dcSChristoph Hellwig * @table: the sysctl table
1355f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file
1356f461d2dcSChristoph Hellwig * @buffer: the user buffer
1357f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer
1358f461d2dcSChristoph Hellwig * @ppos: file position
1359f461d2dcSChristoph Hellwig *
1360f461d2dcSChristoph Hellwig * The bitmap is stored at table->data and the bitmap length (in bits)
1361f461d2dcSChristoph Hellwig * in table->maxlen.
1362f461d2dcSChristoph Hellwig *
1363f461d2dcSChristoph Hellwig * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1364f461d2dcSChristoph Hellwig * large bitmaps may be represented in a compact manner. Writing into
1365f461d2dcSChristoph Hellwig * the file will clear the bitmap then update it with the given input.
1366f461d2dcSChristoph Hellwig *
1367f461d2dcSChristoph Hellwig * Returns 0 on success.
1368f461d2dcSChristoph Hellwig */
proc_do_large_bitmap(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1369f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
137032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1371f461d2dcSChristoph Hellwig {
1372f461d2dcSChristoph Hellwig int err = 0;
1373f461d2dcSChristoph Hellwig size_t left = *lenp;
1374f461d2dcSChristoph Hellwig unsigned long bitmap_len = table->maxlen;
1375f461d2dcSChristoph Hellwig unsigned long *bitmap = *(unsigned long **) table->data;
1376f461d2dcSChristoph Hellwig unsigned long *tmp_bitmap = NULL;
1377f461d2dcSChristoph Hellwig char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1378f461d2dcSChristoph Hellwig
1379f461d2dcSChristoph Hellwig if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1380f461d2dcSChristoph Hellwig *lenp = 0;
1381f461d2dcSChristoph Hellwig return 0;
1382f461d2dcSChristoph Hellwig }
1383f461d2dcSChristoph Hellwig
1384f461d2dcSChristoph Hellwig if (write) {
138532927393SChristoph Hellwig char *p = buffer;
1386f461d2dcSChristoph Hellwig size_t skipped = 0;
1387f461d2dcSChristoph Hellwig
1388f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) {
1389f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1;
1390f461d2dcSChristoph Hellwig /* How much of the buffer we'll skip this pass */
1391f461d2dcSChristoph Hellwig skipped = *lenp - left;
1392f461d2dcSChristoph Hellwig }
1393f461d2dcSChristoph Hellwig
1394f461d2dcSChristoph Hellwig tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
139532927393SChristoph Hellwig if (!tmp_bitmap)
1396f461d2dcSChristoph Hellwig return -ENOMEM;
1397f461d2dcSChristoph Hellwig proc_skip_char(&p, &left, '\n');
1398f461d2dcSChristoph Hellwig while (!err && left) {
1399f461d2dcSChristoph Hellwig unsigned long val_a, val_b;
1400f461d2dcSChristoph Hellwig bool neg;
1401f461d2dcSChristoph Hellwig size_t saved_left;
1402f461d2dcSChristoph Hellwig
1403f461d2dcSChristoph Hellwig /* In case we stop parsing mid-number, we can reset */
1404f461d2dcSChristoph Hellwig saved_left = left;
1405f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1406f461d2dcSChristoph Hellwig sizeof(tr_a), &c);
1407f461d2dcSChristoph Hellwig /*
1408f461d2dcSChristoph Hellwig * If we consumed the entirety of a truncated buffer or
1409f461d2dcSChristoph Hellwig * only one char is left (may be a "-"), then stop here,
1410f461d2dcSChristoph Hellwig * reset, & come back for more.
1411f461d2dcSChristoph Hellwig */
1412f461d2dcSChristoph Hellwig if ((left <= 1) && skipped) {
1413f461d2dcSChristoph Hellwig left = saved_left;
1414f461d2dcSChristoph Hellwig break;
1415f461d2dcSChristoph Hellwig }
1416f461d2dcSChristoph Hellwig
1417f461d2dcSChristoph Hellwig if (err)
1418f461d2dcSChristoph Hellwig break;
1419f461d2dcSChristoph Hellwig if (val_a >= bitmap_len || neg) {
1420f461d2dcSChristoph Hellwig err = -EINVAL;
1421f461d2dcSChristoph Hellwig break;
1422f461d2dcSChristoph Hellwig }
1423f461d2dcSChristoph Hellwig
1424f461d2dcSChristoph Hellwig val_b = val_a;
1425f461d2dcSChristoph Hellwig if (left) {
1426f461d2dcSChristoph Hellwig p++;
1427f461d2dcSChristoph Hellwig left--;
1428f461d2dcSChristoph Hellwig }
1429f461d2dcSChristoph Hellwig
1430f461d2dcSChristoph Hellwig if (c == '-') {
1431f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val_b,
1432f461d2dcSChristoph Hellwig &neg, tr_b, sizeof(tr_b),
1433f461d2dcSChristoph Hellwig &c);
1434f461d2dcSChristoph Hellwig /*
1435f461d2dcSChristoph Hellwig * If we consumed all of a truncated buffer or
1436f461d2dcSChristoph Hellwig * then stop here, reset, & come back for more.
1437f461d2dcSChristoph Hellwig */
1438f461d2dcSChristoph Hellwig if (!left && skipped) {
1439f461d2dcSChristoph Hellwig left = saved_left;
1440f461d2dcSChristoph Hellwig break;
1441f461d2dcSChristoph Hellwig }
1442f461d2dcSChristoph Hellwig
1443f461d2dcSChristoph Hellwig if (err)
1444f461d2dcSChristoph Hellwig break;
1445f461d2dcSChristoph Hellwig if (val_b >= bitmap_len || neg ||
1446f461d2dcSChristoph Hellwig val_a > val_b) {
1447f461d2dcSChristoph Hellwig err = -EINVAL;
1448f461d2dcSChristoph Hellwig break;
1449f461d2dcSChristoph Hellwig }
1450f461d2dcSChristoph Hellwig if (left) {
1451f461d2dcSChristoph Hellwig p++;
1452f461d2dcSChristoph Hellwig left--;
1453f461d2dcSChristoph Hellwig }
1454f461d2dcSChristoph Hellwig }
1455f461d2dcSChristoph Hellwig
1456f461d2dcSChristoph Hellwig bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1457f461d2dcSChristoph Hellwig proc_skip_char(&p, &left, '\n');
1458f461d2dcSChristoph Hellwig }
1459f461d2dcSChristoph Hellwig left += skipped;
1460f461d2dcSChristoph Hellwig } else {
1461f461d2dcSChristoph Hellwig unsigned long bit_a, bit_b = 0;
14629a52c5f3SJiapeng Chong bool first = 1;
1463f461d2dcSChristoph Hellwig
1464f461d2dcSChristoph Hellwig while (left) {
1465f461d2dcSChristoph Hellwig bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1466f461d2dcSChristoph Hellwig if (bit_a >= bitmap_len)
1467f461d2dcSChristoph Hellwig break;
1468f461d2dcSChristoph Hellwig bit_b = find_next_zero_bit(bitmap, bitmap_len,
1469f461d2dcSChristoph Hellwig bit_a + 1) - 1;
1470f461d2dcSChristoph Hellwig
147132927393SChristoph Hellwig if (!first)
147232927393SChristoph Hellwig proc_put_char(&buffer, &left, ',');
147332927393SChristoph Hellwig proc_put_long(&buffer, &left, bit_a, false);
1474f461d2dcSChristoph Hellwig if (bit_a != bit_b) {
147532927393SChristoph Hellwig proc_put_char(&buffer, &left, '-');
147632927393SChristoph Hellwig proc_put_long(&buffer, &left, bit_b, false);
1477f461d2dcSChristoph Hellwig }
1478f461d2dcSChristoph Hellwig
1479f461d2dcSChristoph Hellwig first = 0; bit_b++;
1480f461d2dcSChristoph Hellwig }
148132927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n');
1482f461d2dcSChristoph Hellwig }
1483f461d2dcSChristoph Hellwig
1484f461d2dcSChristoph Hellwig if (!err) {
1485f461d2dcSChristoph Hellwig if (write) {
1486f461d2dcSChristoph Hellwig if (*ppos)
1487f461d2dcSChristoph Hellwig bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1488f461d2dcSChristoph Hellwig else
1489f461d2dcSChristoph Hellwig bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1490f461d2dcSChristoph Hellwig }
1491f461d2dcSChristoph Hellwig *lenp -= left;
1492f461d2dcSChristoph Hellwig *ppos += *lenp;
1493f461d2dcSChristoph Hellwig }
1494f461d2dcSChristoph Hellwig
1495f461d2dcSChristoph Hellwig bitmap_free(tmp_bitmap);
1496f461d2dcSChristoph Hellwig return err;
1497f461d2dcSChristoph Hellwig }
1498f461d2dcSChristoph Hellwig
1499f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */
1500f461d2dcSChristoph Hellwig
proc_dostring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1501f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
150232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1503f461d2dcSChristoph Hellwig {
1504f461d2dcSChristoph Hellwig return -ENOSYS;
1505f461d2dcSChristoph Hellwig }
1506f461d2dcSChristoph Hellwig
proc_dobool(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1507a2071573SJia He int proc_dobool(struct ctl_table *table, int write,
1508a2071573SJia He void *buffer, size_t *lenp, loff_t *ppos)
1509a2071573SJia He {
1510a2071573SJia He return -ENOSYS;
1511a2071573SJia He }
1512a2071573SJia He
proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1513f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write,
151432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1515f461d2dcSChristoph Hellwig {
1516f461d2dcSChristoph Hellwig return -ENOSYS;
1517f461d2dcSChristoph Hellwig }
1518f461d2dcSChristoph Hellwig
proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1519f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write,
152032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1521f461d2dcSChristoph Hellwig {
1522f461d2dcSChristoph Hellwig return -ENOSYS;
1523f461d2dcSChristoph Hellwig }
1524f461d2dcSChristoph Hellwig
proc_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1525f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
152632927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1527f461d2dcSChristoph Hellwig {
1528f461d2dcSChristoph Hellwig return -ENOSYS;
1529f461d2dcSChristoph Hellwig }
1530f461d2dcSChristoph Hellwig
proc_douintvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1531f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
153232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1533f461d2dcSChristoph Hellwig {
1534f461d2dcSChristoph Hellwig return -ENOSYS;
1535f461d2dcSChristoph Hellwig }
1536f461d2dcSChristoph Hellwig
proc_dou8vec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1537cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1538cb944413SEric Dumazet void *buffer, size_t *lenp, loff_t *ppos)
1539cb944413SEric Dumazet {
1540cb944413SEric Dumazet return -ENOSYS;
1541cb944413SEric Dumazet }
1542cb944413SEric Dumazet
proc_dointvec_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1543f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
154432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1545f461d2dcSChristoph Hellwig {
1546f461d2dcSChristoph Hellwig return -ENOSYS;
1547f461d2dcSChristoph Hellwig }
1548f461d2dcSChristoph Hellwig
proc_dointvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1549c381d02bSYuwei Wang int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1550c381d02bSYuwei Wang void *buffer, size_t *lenp, loff_t *ppos)
1551c381d02bSYuwei Wang {
1552c381d02bSYuwei Wang return -ENOSYS;
1553c381d02bSYuwei Wang }
1554c381d02bSYuwei Wang
proc_dointvec_userhz_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1555f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
155632927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1557f461d2dcSChristoph Hellwig {
1558f461d2dcSChristoph Hellwig return -ENOSYS;
1559f461d2dcSChristoph Hellwig }
1560f461d2dcSChristoph Hellwig
proc_dointvec_ms_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1561f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
156232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1563f461d2dcSChristoph Hellwig {
1564f461d2dcSChristoph Hellwig return -ENOSYS;
1565f461d2dcSChristoph Hellwig }
1566f461d2dcSChristoph Hellwig
proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1567f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
156832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1569f461d2dcSChristoph Hellwig {
1570f461d2dcSChristoph Hellwig return -ENOSYS;
1571f461d2dcSChristoph Hellwig }
1572f461d2dcSChristoph Hellwig
proc_doulongvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1573f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
157432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1575f461d2dcSChristoph Hellwig {
1576f461d2dcSChristoph Hellwig return -ENOSYS;
1577f461d2dcSChristoph Hellwig }
1578f461d2dcSChristoph Hellwig
proc_do_large_bitmap(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1579f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
158032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1581f461d2dcSChristoph Hellwig {
1582f461d2dcSChristoph Hellwig return -ENOSYS;
1583f461d2dcSChristoph Hellwig }
1584f461d2dcSChristoph Hellwig
1585f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
1586f461d2dcSChristoph Hellwig
1587f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL)
proc_do_static_key(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1588f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write,
158932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos)
1590f461d2dcSChristoph Hellwig {
1591f461d2dcSChristoph Hellwig struct static_key *key = (struct static_key *)table->data;
1592f461d2dcSChristoph Hellwig static DEFINE_MUTEX(static_key_mutex);
1593f461d2dcSChristoph Hellwig int val, ret;
1594f461d2dcSChristoph Hellwig struct ctl_table tmp = {
1595f461d2dcSChristoph Hellwig .data = &val,
1596f461d2dcSChristoph Hellwig .maxlen = sizeof(val),
1597f461d2dcSChristoph Hellwig .mode = table->mode,
1598f461d2dcSChristoph Hellwig .extra1 = SYSCTL_ZERO,
1599f461d2dcSChristoph Hellwig .extra2 = SYSCTL_ONE,
1600f461d2dcSChristoph Hellwig };
1601f461d2dcSChristoph Hellwig
1602f461d2dcSChristoph Hellwig if (write && !capable(CAP_SYS_ADMIN))
1603f461d2dcSChristoph Hellwig return -EPERM;
1604f461d2dcSChristoph Hellwig
1605f461d2dcSChristoph Hellwig mutex_lock(&static_key_mutex);
1606f461d2dcSChristoph Hellwig val = static_key_enabled(key);
1607f461d2dcSChristoph Hellwig ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1608f461d2dcSChristoph Hellwig if (write && !ret) {
1609f461d2dcSChristoph Hellwig if (val)
1610f461d2dcSChristoph Hellwig static_key_enable(key);
1611f461d2dcSChristoph Hellwig else
1612f461d2dcSChristoph Hellwig static_key_disable(key);
1613f461d2dcSChristoph Hellwig }
1614f461d2dcSChristoph Hellwig mutex_unlock(&static_key_mutex);
1615f461d2dcSChristoph Hellwig return ret;
1616f461d2dcSChristoph Hellwig }
1617f461d2dcSChristoph Hellwig
1618d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
16191799e35dSIngo Molnar {
16201da177e4SLinus Torvalds .procname = "panic",
16211da177e4SLinus Torvalds .data = &panic_timeout,
16221da177e4SLinus Torvalds .maxlen = sizeof(int),
16231da177e4SLinus Torvalds .mode = 0644,
16246d456111SEric W. Biederman .proc_handler = proc_dointvec,
16251da177e4SLinus Torvalds },
162634f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
16271da177e4SLinus Torvalds {
16281da177e4SLinus Torvalds .procname = "tainted",
162925ddbb18SAndi Kleen .maxlen = sizeof(long),
163034f5a398STheodore Ts'o .mode = 0644,
16316d456111SEric W. Biederman .proc_handler = proc_taint,
16321da177e4SLinus Torvalds },
1633f4aacea2SKees Cook {
1634f4aacea2SKees Cook .procname = "sysctl_writes_strict",
1635f4aacea2SKees Cook .data = &sysctl_writes_strict,
1636f4aacea2SKees Cook .maxlen = sizeof(int),
1637f4aacea2SKees Cook .mode = 0644,
1638f4aacea2SKees Cook .proc_handler = proc_dointvec_minmax,
163978e36f3bSXiaoming Ni .extra1 = SYSCTL_NEG_ONE,
1640eec4844fSMatteo Croce .extra2 = SYSCTL_ONE,
1641f4aacea2SKees Cook },
164234f5a398STheodore Ts'o #endif
164345807a1dSIngo Molnar {
164445807a1dSIngo Molnar .procname = "print-fatal-signals",
164545807a1dSIngo Molnar .data = &print_fatal_signals,
164645807a1dSIngo Molnar .maxlen = sizeof(int),
164745807a1dSIngo Molnar .mode = 0644,
16486d456111SEric W. Biederman .proc_handler = proc_dointvec,
164945807a1dSIngo Molnar },
165072c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
16511da177e4SLinus Torvalds {
16521da177e4SLinus Torvalds .procname = "reboot-cmd",
16531da177e4SLinus Torvalds .data = reboot_command,
16541da177e4SLinus Torvalds .maxlen = 256,
16551da177e4SLinus Torvalds .mode = 0644,
16566d456111SEric W. Biederman .proc_handler = proc_dostring,
16571da177e4SLinus Torvalds },
16581da177e4SLinus Torvalds {
16591da177e4SLinus Torvalds .procname = "stop-a",
16601da177e4SLinus Torvalds .data = &stop_a_enabled,
16611da177e4SLinus Torvalds .maxlen = sizeof (int),
16621da177e4SLinus Torvalds .mode = 0644,
16636d456111SEric W. Biederman .proc_handler = proc_dointvec,
16641da177e4SLinus Torvalds },
16651da177e4SLinus Torvalds {
16661da177e4SLinus Torvalds .procname = "scons-poweroff",
16671da177e4SLinus Torvalds .data = &scons_pwroff,
16681da177e4SLinus Torvalds .maxlen = sizeof (int),
16691da177e4SLinus Torvalds .mode = 0644,
16706d456111SEric W. Biederman .proc_handler = proc_dointvec,
16711da177e4SLinus Torvalds },
16721da177e4SLinus Torvalds #endif
16730871420fSDavid S. Miller #ifdef CONFIG_SPARC64
16740871420fSDavid S. Miller {
16750871420fSDavid S. Miller .procname = "tsb-ratio",
16760871420fSDavid S. Miller .data = &sysctl_tsb_ratio,
16770871420fSDavid S. Miller .maxlen = sizeof (int),
16780871420fSDavid S. Miller .mode = 0644,
16796d456111SEric W. Biederman .proc_handler = proc_dointvec,
16800871420fSDavid S. Miller },
16810871420fSDavid S. Miller #endif
1682b67114dbSHelge Deller #ifdef CONFIG_PARISC
16831da177e4SLinus Torvalds {
16841da177e4SLinus Torvalds .procname = "soft-power",
16851da177e4SLinus Torvalds .data = &pwrsw_enabled,
16861da177e4SLinus Torvalds .maxlen = sizeof (int),
16871da177e4SLinus Torvalds .mode = 0644,
16886d456111SEric W. Biederman .proc_handler = proc_dointvec,
16891da177e4SLinus Torvalds },
1690bf14e3b9SVineet Gupta #endif
1691bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
16921da177e4SLinus Torvalds {
16931da177e4SLinus Torvalds .procname = "unaligned-trap",
16941da177e4SLinus Torvalds .data = &unaligned_enabled,
16951da177e4SLinus Torvalds .maxlen = sizeof (int),
16961da177e4SLinus Torvalds .mode = 0644,
16976d456111SEric W. Biederman .proc_handler = proc_dointvec,
16981da177e4SLinus Torvalds },
16991da177e4SLinus Torvalds #endif
1700f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
1701f38f1d2aSSteven Rostedt {
1702f38f1d2aSSteven Rostedt .procname = "stack_tracer_enabled",
1703f38f1d2aSSteven Rostedt .data = &stack_tracer_enabled,
1704f38f1d2aSSteven Rostedt .maxlen = sizeof(int),
1705f38f1d2aSSteven Rostedt .mode = 0644,
17066d456111SEric W. Biederman .proc_handler = stack_trace_sysctl,
1707f38f1d2aSSteven Rostedt },
1708f38f1d2aSSteven Rostedt #endif
1709944ac425SSteven Rostedt #ifdef CONFIG_TRACING
1710944ac425SSteven Rostedt {
17113299b4ddSPeter Zijlstra .procname = "ftrace_dump_on_oops",
1712944ac425SSteven Rostedt .data = &ftrace_dump_on_oops,
1713944ac425SSteven Rostedt .maxlen = sizeof(int),
1714944ac425SSteven Rostedt .mode = 0644,
17156d456111SEric W. Biederman .proc_handler = proc_dointvec,
1716944ac425SSteven Rostedt },
1717de7edd31SSteven Rostedt (Red Hat) {
1718de7edd31SSteven Rostedt (Red Hat) .procname = "traceoff_on_warning",
1719de7edd31SSteven Rostedt (Red Hat) .data = &__disable_trace_on_warning,
1720de7edd31SSteven Rostedt (Red Hat) .maxlen = sizeof(__disable_trace_on_warning),
1721de7edd31SSteven Rostedt (Red Hat) .mode = 0644,
1722de7edd31SSteven Rostedt (Red Hat) .proc_handler = proc_dointvec,
1723de7edd31SSteven Rostedt (Red Hat) },
17240daa2302SSteven Rostedt (Red Hat) {
17250daa2302SSteven Rostedt (Red Hat) .procname = "tracepoint_printk",
17260daa2302SSteven Rostedt (Red Hat) .data = &tracepoint_printk,
17270daa2302SSteven Rostedt (Red Hat) .maxlen = sizeof(tracepoint_printk),
17280daa2302SSteven Rostedt (Red Hat) .mode = 0644,
172942391745SSteven Rostedt (Red Hat) .proc_handler = tracepoint_printk_sysctl,
17300daa2302SSteven Rostedt (Red Hat) },
1731944ac425SSteven Rostedt #endif
1732a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
17331da177e4SLinus Torvalds {
17341da177e4SLinus Torvalds .procname = "modprobe",
17351da177e4SLinus Torvalds .data = &modprobe_path,
17361da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN,
17371da177e4SLinus Torvalds .mode = 0644,
17386d456111SEric W. Biederman .proc_handler = proc_dostring,
17391da177e4SLinus Torvalds },
17403d43321bSKees Cook {
17413d43321bSKees Cook .procname = "modules_disabled",
17423d43321bSKees Cook .data = &modules_disabled,
17433d43321bSKees Cook .maxlen = sizeof(int),
17443d43321bSKees Cook .mode = 0644,
17453d43321bSKees Cook /* only handle a transition from default "0" to "1" */
17466d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax,
1747eec4844fSMatteo Croce .extra1 = SYSCTL_ONE,
1748eec4844fSMatteo Croce .extra2 = SYSCTL_ONE,
17493d43321bSKees Cook },
17501da177e4SLinus Torvalds #endif
175186d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER
17521da177e4SLinus Torvalds {
17531da177e4SLinus Torvalds .procname = "hotplug",
1754312c004dSKay Sievers .data = &uevent_helper,
1755312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN,
17561da177e4SLinus Torvalds .mode = 0644,
17576d456111SEric W. Biederman .proc_handler = proc_dostring,
17581da177e4SLinus Torvalds },
175986d56134SMichael Marineau #endif
17601da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
17611da177e4SLinus Torvalds {
17621da177e4SLinus Torvalds .procname = "sysrq",
1763eaee4172SDmitry Safonov .data = NULL,
17641da177e4SLinus Torvalds .maxlen = sizeof (int),
17651da177e4SLinus Torvalds .mode = 0644,
176697f5f0cdSDmitry Torokhov .proc_handler = sysrq_sysctl_handler,
17671da177e4SLinus Torvalds },
17681da177e4SLinus Torvalds #endif
1769d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
17701da177e4SLinus Torvalds {
17711da177e4SLinus Torvalds .procname = "cad_pid",
17729ec52099SCedric Le Goater .data = NULL,
17731da177e4SLinus Torvalds .maxlen = sizeof (int),
17741da177e4SLinus Torvalds .mode = 0600,
17756d456111SEric W. Biederman .proc_handler = proc_do_cad_pid,
17761da177e4SLinus Torvalds },
1777d6f8ff73SRandy Dunlap #endif
17781da177e4SLinus Torvalds {
17791da177e4SLinus Torvalds .procname = "threads-max",
178016db3d3fSHeinrich Schuchardt .data = NULL,
17811da177e4SLinus Torvalds .maxlen = sizeof(int),
17821da177e4SLinus Torvalds .mode = 0644,
178316db3d3fSHeinrich Schuchardt .proc_handler = sysctl_max_threads,
17841da177e4SLinus Torvalds },
17851da177e4SLinus Torvalds {
178617f60a7dSEric Paris .procname = "overflowuid",
178717f60a7dSEric Paris .data = &overflowuid,
178817f60a7dSEric Paris .maxlen = sizeof(int),
178917f60a7dSEric Paris .mode = 0644,
179017f60a7dSEric Paris .proc_handler = proc_dointvec_minmax,
17911da177e4SLinus Torvalds .extra1 = SYSCTL_ZERO,
17921da177e4SLinus Torvalds .extra2 = SYSCTL_MAXOLDUID,
17931da177e4SLinus Torvalds },
17941da177e4SLinus Torvalds {
17956d456111SEric W. Biederman .procname = "overflowgid",
17962452dcb9SXiaoming Ni .data = &overflowgid,
179754771613SLuis Chamberlain .maxlen = sizeof(int),
17981da177e4SLinus Torvalds .mode = 0644,
17991da177e4SLinus Torvalds .proc_handler = proc_dointvec_minmax,
18001da177e4SLinus Torvalds .extra1 = SYSCTL_ZERO,
18011da177e4SLinus Torvalds .extra2 = SYSCTL_MAXOLDUID,
18021da177e4SLinus Torvalds },
18031da177e4SLinus Torvalds #ifdef CONFIG_S390
18046d456111SEric W. Biederman {
18052452dcb9SXiaoming Ni .procname = "userprocess_debug",
180654771613SLuis Chamberlain .data = &show_unhandled_signals,
18071da177e4SLinus Torvalds .maxlen = sizeof(int),
1808347a8dc3SMartin Schwidefsky .mode = 0644,
18091da177e4SLinus Torvalds .proc_handler = proc_dointvec,
18101da177e4SLinus Torvalds },
1811ab3c68eeSHeiko Carstens #endif
18121da177e4SLinus Torvalds {
18131da177e4SLinus Torvalds .procname = "pid_max",
18146d456111SEric W. Biederman .data = &pid_max,
18151da177e4SLinus Torvalds .maxlen = sizeof (int),
18161da177e4SLinus Torvalds .mode = 0644,
18171da177e4SLinus Torvalds .proc_handler = proc_dointvec_minmax,
18181da177e4SLinus Torvalds .extra1 = &pid_max_min,
18191da177e4SLinus Torvalds .extra2 = &pid_max_max,
18201da177e4SLinus Torvalds },
18211da177e4SLinus Torvalds {
18226d456111SEric W. Biederman .procname = "panic_on_oops",
18231da177e4SLinus Torvalds .data = &panic_on_oops,
18241da177e4SLinus Torvalds .maxlen = sizeof(int),
18251da177e4SLinus Torvalds .mode = 0644,
18261da177e4SLinus Torvalds .proc_handler = proc_dointvec,
18271da177e4SLinus Torvalds },
18281da177e4SLinus Torvalds {
18291da177e4SLinus Torvalds .procname = "panic_print",
18301da177e4SLinus Torvalds .data = &panic_print,
18316d456111SEric W. Biederman .maxlen = sizeof(unsigned long),
18321da177e4SLinus Torvalds .mode = 0644,
183381c9d43fSFeng Tang .proc_handler = proc_doulongvec_minmax,
183481c9d43fSFeng Tang },
183581c9d43fSFeng Tang {
183681c9d43fSFeng Tang .procname = "ngroups_max",
183781c9d43fSFeng Tang .data = (void *)&ngroups_max,
183881c9d43fSFeng Tang .maxlen = sizeof (int),
183981c9d43fSFeng Tang .mode = 0444,
1840eaf06b24SDan Rosenberg .proc_handler = proc_dointvec,
18411da177e4SLinus Torvalds },
1842f628867dSStephen Kitt {
18431da177e4SLinus Torvalds .procname = "cap_last_cap",
18441da177e4SLinus Torvalds .data = (void *)&cap_last_cap,
18456d456111SEric W. Biederman .maxlen = sizeof(int),
18461da177e4SLinus Torvalds .mode = 0444,
184773efc039SDan Ballard .proc_handler = proc_dointvec,
184873efc039SDan Ballard },
184973efc039SDan Ballard #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
185073efc039SDan Ballard {
185173efc039SDan Ballard .procname = "unknown_nmi_panic",
185273efc039SDan Ballard .data = &unknown_nmi_panic,
185373efc039SDan Ballard .maxlen = sizeof (int),
18545dc30558SDon Zickus .mode = 0644,
18555dc30558SDon Zickus .proc_handler = proc_dointvec,
18565dc30558SDon Zickus },
18575dc30558SDon Zickus #endif
18585dc30558SDon Zickus
18595dc30558SDon Zickus #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
18605dc30558SDon Zickus defined(CONFIG_DEBUG_STACKOVERFLOW)
18615dc30558SDon Zickus {
1862504d7cf1SDon Zickus .procname = "panic_on_stackoverflow",
1863b6522fa4SXiaoming Ni .data = &sysctl_panic_on_stackoverflow,
1864b6522fa4SXiaoming Ni .maxlen = sizeof(int),
1865b6522fa4SXiaoming Ni .mode = 0644,
1866b6522fa4SXiaoming Ni .proc_handler = proc_dointvec,
1867b6522fa4SXiaoming Ni },
1868b6522fa4SXiaoming Ni #endif
1869b6522fa4SXiaoming Ni #if defined(CONFIG_X86)
1870b6522fa4SXiaoming Ni {
1871b6522fa4SXiaoming Ni .procname = "panic_on_unrecovered_nmi",
1872b6522fa4SXiaoming Ni .data = &panic_on_unrecovered_nmi,
1873b6522fa4SXiaoming Ni .maxlen = sizeof(int),
18741da177e4SLinus Torvalds .mode = 0644,
18751da177e4SLinus Torvalds .proc_handler = proc_dointvec,
18768da5addaSDon Zickus },
18778da5addaSDon Zickus {
18788da5addaSDon Zickus .procname = "panic_on_io_nmi",
18798da5addaSDon Zickus .data = &panic_on_io_nmi,
18806d456111SEric W. Biederman .maxlen = sizeof(int),
18818da5addaSDon Zickus .mode = 0644,
18828da5addaSDon Zickus .proc_handler = proc_dointvec,
18835211a242SKurt Garloff },
18845211a242SKurt Garloff {
18855211a242SKurt Garloff .procname = "bootloader_type",
18865211a242SKurt Garloff .data = &bootloader_type,
18876d456111SEric W. Biederman .maxlen = sizeof (int),
18885211a242SKurt Garloff .mode = 0444,
18895211a242SKurt Garloff .proc_handler = proc_dointvec,
18901da177e4SLinus Torvalds },
18911da177e4SLinus Torvalds {
18921da177e4SLinus Torvalds .procname = "bootloader_version",
18931da177e4SLinus Torvalds .data = &bootloader_version,
18946d456111SEric W. Biederman .maxlen = sizeof (int),
18951da177e4SLinus Torvalds .mode = 0444,
18960741f4d2SChuck Ebbert .proc_handler = proc_dointvec,
18975031296cSH. Peter Anvin },
18985031296cSH. Peter Anvin {
18995031296cSH. Peter Anvin .procname = "io_delay_type",
19005031296cSH. Peter Anvin .data = &io_delay_type,
19016d456111SEric W. Biederman .maxlen = sizeof(int),
19025031296cSH. Peter Anvin .mode = 0644,
19035031296cSH. Peter Anvin .proc_handler = proc_dointvec,
19046e7c4025SIngo Molnar },
19056e7c4025SIngo Molnar #endif
19066e7c4025SIngo Molnar #if defined(CONFIG_MMU)
19076e7c4025SIngo Molnar {
19086d456111SEric W. Biederman .procname = "randomize_va_space",
19096e7c4025SIngo Molnar .data = &randomize_va_space,
19101da177e4SLinus Torvalds .maxlen = sizeof(int),
19117a9166e3SLuke Yang .mode = 0644,
19121da177e4SLinus Torvalds .proc_handler = proc_dointvec,
19131da177e4SLinus Torvalds },
19141da177e4SLinus Torvalds #endif
19151da177e4SLinus Torvalds #if defined(CONFIG_S390) && defined(CONFIG_SMP)
19161da177e4SLinus Torvalds {
19176d456111SEric W. Biederman .procname = "spin_retry",
19181da177e4SLinus Torvalds .data = &spin_retry,
19197a9166e3SLuke Yang .maxlen = sizeof (int),
19200152fb37SMartin Schwidefsky .mode = 0644,
1921951f22d5SMartin Schwidefsky .proc_handler = proc_dointvec,
1922951f22d5SMartin Schwidefsky },
1923951f22d5SMartin Schwidefsky #endif
1924951f22d5SMartin Schwidefsky #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1925951f22d5SMartin Schwidefsky {
19266d456111SEric W. Biederman .procname = "acpi_video_flags",
1927951f22d5SMartin Schwidefsky .data = &acpi_realmode_flags,
1928951f22d5SMartin Schwidefsky .maxlen = sizeof (unsigned long),
1929673d5b43SLen Brown .mode = 0644,
1930c255d844SPavel Machek .proc_handler = proc_doulongvec_minmax,
1931c255d844SPavel Machek },
193277afcf78SPavel Machek #endif
1933c255d844SPavel Machek #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1934c255d844SPavel Machek {
19356d456111SEric W. Biederman .procname = "ignore-unaligned-usertrap",
1936c255d844SPavel Machek .data = &no_unaligned_warning,
1937c255d844SPavel Machek .maxlen = sizeof (int),
1938b6fca725SVineet Gupta .mode = 0644,
1939d2b176edSJes Sorensen .proc_handler = proc_dointvec,
1940d2b176edSJes Sorensen },
1941d2b176edSJes Sorensen #endif
1942d2b176edSJes Sorensen #ifdef CONFIG_IA64
1943d2b176edSJes Sorensen {
19446d456111SEric W. Biederman .procname = "unaligned-dump-stack",
1945d2b176edSJes Sorensen .data = &unaligned_dump_stack,
1946b6fca725SVineet Gupta .maxlen = sizeof (int),
1947b6fca725SVineet Gupta .mode = 0644,
194888fc241fSDoug Chapman .proc_handler = proc_dointvec,
194988fc241fSDoug Chapman },
195088fc241fSDoug Chapman #endif
195188fc241fSDoug Chapman #ifdef CONFIG_RT_MUTEXES
195288fc241fSDoug Chapman {
19536d456111SEric W. Biederman .procname = "max_lock_depth",
195488fc241fSDoug Chapman .data = &max_lock_depth,
1955d2b176edSJes Sorensen .maxlen = sizeof(int),
195623f78d4aSIngo Molnar .mode = 0644,
195723f78d4aSIngo Molnar .proc_handler = proc_dointvec,
195823f78d4aSIngo Molnar },
195923f78d4aSIngo Molnar #endif
196023f78d4aSIngo Molnar #ifdef CONFIG_PERF_EVENTS
196123f78d4aSIngo Molnar /*
19626d456111SEric W. Biederman * User-space scripts rely on the existence of this file
196323f78d4aSIngo Molnar * as a feature check for perf_events being enabled.
196423f78d4aSIngo Molnar *
19650b77f5bfSDavid Howells * So it's an ABI, do not remove!
19660b77f5bfSDavid Howells */
19670b77f5bfSDavid Howells {
19680b77f5bfSDavid Howells .procname = "perf_event_paranoid",
19690b77f5bfSDavid Howells .data = &sysctl_perf_event_paranoid,
19700b77f5bfSDavid Howells .maxlen = sizeof(sysctl_perf_event_paranoid),
19710b77f5bfSDavid Howells .mode = 0644,
1972cdd6c482SIngo Molnar .proc_handler = proc_dointvec,
1973aa4a2218SVince Weaver },
1974aa4a2218SVince Weaver {
1975aa4a2218SVince Weaver .procname = "perf_event_mlock_kb",
1976aa4a2218SVince Weaver .data = &sysctl_perf_event_mlock,
1977aa4a2218SVince Weaver .maxlen = sizeof(sysctl_perf_event_mlock),
1978aa4a2218SVince Weaver .mode = 0644,
19791ccd1549SPeter Zijlstra .proc_handler = proc_dointvec,
1980cdd6c482SIngo Molnar },
1981cdd6c482SIngo Molnar {
1982cdd6c482SIngo Molnar .procname = "perf_event_max_sample_rate",
19831ccd1549SPeter Zijlstra .data = &sysctl_perf_event_sample_rate,
19846d456111SEric W. Biederman .maxlen = sizeof(sysctl_perf_event_sample_rate),
19851ccd1549SPeter Zijlstra .mode = 0644,
1986c5078f78SPeter Zijlstra .proc_handler = perf_proc_update_handler,
1987cdd6c482SIngo Molnar .extra1 = SYSCTL_ONE,
1988cdd6c482SIngo Molnar },
1989cdd6c482SIngo Molnar {
1990c5078f78SPeter Zijlstra .procname = "perf_cpu_time_max_percent",
19916d456111SEric W. Biederman .data = &sysctl_perf_cpu_time_max_percent,
1992c5078f78SPeter Zijlstra .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1993a78ac325SPeter Zijlstra .mode = 0644,
1994cdd6c482SIngo Molnar .proc_handler = perf_cpu_time_max_percent_handler,
1995cdd6c482SIngo Molnar .extra1 = SYSCTL_ZERO,
1996cdd6c482SIngo Molnar .extra2 = SYSCTL_ONE_HUNDRED,
1997a78ac325SPeter Zijlstra },
1998163ec435SPeter Zijlstra {
1999eec4844fSMatteo Croce .procname = "perf_event_max_stack",
2000a78ac325SPeter Zijlstra .data = &sysctl_perf_event_max_stack,
200114c63f17SDave Hansen .maxlen = sizeof(sysctl_perf_event_max_stack),
200214c63f17SDave Hansen .mode = 0644,
200314c63f17SDave Hansen .proc_handler = perf_event_max_stack_handler,
200414c63f17SDave Hansen .extra1 = SYSCTL_ZERO,
200514c63f17SDave Hansen .extra2 = (void *)&six_hundred_forty_kb,
200614c63f17SDave Hansen },
2007eec4844fSMatteo Croce {
200878e36f3bSXiaoming Ni .procname = "perf_event_max_contexts_per_stack",
200914c63f17SDave Hansen .data = &sysctl_perf_event_max_contexts_per_stack,
2010c5dfd78eSArnaldo Carvalho de Melo .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2011c5dfd78eSArnaldo Carvalho de Melo .mode = 0644,
2012a831100aSArnaldo Carvalho de Melo .proc_handler = perf_event_max_stack_handler,
2013c5dfd78eSArnaldo Carvalho de Melo .extra1 = SYSCTL_ZERO,
2014c5dfd78eSArnaldo Carvalho de Melo .extra2 = SYSCTL_ONE_THOUSAND,
2015c5dfd78eSArnaldo Carvalho de Melo },
2016eec4844fSMatteo Croce #endif
2017d73840ecSXiaoming Ni {
2018c5dfd78eSArnaldo Carvalho de Melo .procname = "panic_on_warn",
2019c85b0334SArnaldo Carvalho de Melo .data = &panic_on_warn,
2020c85b0334SArnaldo Carvalho de Melo .maxlen = sizeof(int),
2021c85b0334SArnaldo Carvalho de Melo .mode = 0644,
2022c85b0334SArnaldo Carvalho de Melo .proc_handler = proc_dointvec_minmax,
2023c85b0334SArnaldo Carvalho de Melo .extra1 = SYSCTL_ZERO,
2024c85b0334SArnaldo Carvalho de Melo .extra2 = SYSCTL_ONE,
2025eec4844fSMatteo Croce },
202678e36f3bSXiaoming Ni #ifdef CONFIG_TREE_RCU
2027c85b0334SArnaldo Carvalho de Melo {
20281ccd1549SPeter Zijlstra .procname = "panic_on_rcu_stall",
20299e3961a0SPrarit Bhargava .data = &sysctl_panic_on_rcu_stall,
20309e3961a0SPrarit Bhargava .maxlen = sizeof(sysctl_panic_on_rcu_stall),
20319e3961a0SPrarit Bhargava .mode = 0644,
20329e3961a0SPrarit Bhargava .proc_handler = proc_dointvec_minmax,
20339e3961a0SPrarit Bhargava .extra1 = SYSCTL_ZERO,
20349e3961a0SPrarit Bhargava .extra2 = SYSCTL_ONE,
2035eec4844fSMatteo Croce },
2036eec4844fSMatteo Croce {
20379e3961a0SPrarit Bhargava .procname = "max_rcu_stall_to_panic",
20387251ceb5SGeert Uytterhoeven .data = &sysctl_max_rcu_stall_to_panic,
2039088e9d25SDaniel Bristot de Oliveira .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2040088e9d25SDaniel Bristot de Oliveira .mode = 0644,
2041088e9d25SDaniel Bristot de Oliveira .proc_handler = proc_dointvec_minmax,
2042088e9d25SDaniel Bristot de Oliveira .extra1 = SYSCTL_ONE,
2043088e9d25SDaniel Bristot de Oliveira .extra2 = SYSCTL_INT_MAX,
2044088e9d25SDaniel Bristot de Oliveira },
2045eec4844fSMatteo Croce #endif
2046eec4844fSMatteo Croce { }
2047088e9d25SDaniel Bristot de Oliveira };
2048dfe56404Schao
2049dfe56404Schao static struct ctl_table vm_table[] = {
2050dfe56404Schao {
2051dfe56404Schao .procname = "overcommit_memory",
2052dfe56404Schao .data = &sysctl_overcommit_memory,
2053dfe56404Schao .maxlen = sizeof(sysctl_overcommit_memory),
2054dfe56404Schao .mode = 0644,
2055dfe56404Schao .proc_handler = overcommit_policy_handler,
2056dfe56404Schao .extra1 = SYSCTL_ZERO,
2057dfe56404Schao .extra2 = SYSCTL_TWO,
20586fce56ecSEric W. Biederman },
20591da177e4SLinus Torvalds {
20601da177e4SLinus Torvalds .procname = "overcommit_ratio",
2061d8217f07SEric W. Biederman .data = &sysctl_overcommit_ratio,
20621da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio),
20631da177e4SLinus Torvalds .mode = 0644,
20641da177e4SLinus Torvalds .proc_handler = overcommit_ratio_handler,
20651da177e4SLinus Torvalds },
20661da177e4SLinus Torvalds {
206756f3547bSFeng Tang .procname = "overcommit_kbytes",
2068eec4844fSMatteo Croce .data = &sysctl_overcommit_kbytes,
206978e36f3bSXiaoming Ni .maxlen = sizeof(sysctl_overcommit_kbytes),
20701da177e4SLinus Torvalds .mode = 0644,
20711da177e4SLinus Torvalds .proc_handler = overcommit_kbytes_handler,
20721da177e4SLinus Torvalds },
20731da177e4SLinus Torvalds {
20741da177e4SLinus Torvalds .procname = "page-cluster",
20751da177e4SLinus Torvalds .data = &page_cluster,
207649f0ce5fSJerome Marchand .maxlen = sizeof(int),
207749f0ce5fSJerome Marchand .mode = 0644,
207849f0ce5fSJerome Marchand .proc_handler = proc_dointvec_minmax,
207949f0ce5fSJerome Marchand .extra1 = SYSCTL_ZERO,
208049f0ce5fSJerome Marchand .extra2 = (void *)&page_cluster_max,
208149f0ce5fSJerome Marchand },
208249f0ce5fSJerome Marchand {
208349f0ce5fSJerome Marchand .procname = "dirtytime_expire_seconds",
20841da177e4SLinus Torvalds .data = &dirtytime_expire_interval,
20851da177e4SLinus Torvalds .maxlen = sizeof(dirtytime_expire_interval),
20861da177e4SLinus Torvalds .mode = 0644,
20871da177e4SLinus Torvalds .proc_handler = dirtytime_interval_handler,
20881da177e4SLinus Torvalds .extra1 = SYSCTL_ZERO,
20891da177e4SLinus Torvalds },
2090cb16e95fSPetr Holasek {
2091eec4844fSMatteo Croce .procname = "swappiness",
2092ea0ffd0cSKairui Song .data = &vm_swappiness,
20931da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness),
20941da177e4SLinus Torvalds .mode = 0644,
20951efff914STheodore Ts'o .proc_handler = proc_dointvec_minmax,
20961efff914STheodore Ts'o .extra1 = SYSCTL_ZERO,
20972d87b309SRandy Dunlap .extra2 = SYSCTL_TWO_HUNDRED,
20981efff914STheodore Ts'o },
20991efff914STheodore Ts'o #ifdef CONFIG_NUMA
2100eec4844fSMatteo Croce {
21011efff914STheodore Ts'o .procname = "numa_stat",
21021efff914STheodore Ts'o .data = &sysctl_vm_numa_stat,
21031da177e4SLinus Torvalds .maxlen = sizeof(int),
21041da177e4SLinus Torvalds .mode = 0644,
21051da177e4SLinus Torvalds .proc_handler = sysctl_vm_numa_stat_handler,
21061da177e4SLinus Torvalds .extra1 = SYSCTL_ZERO,
21076d456111SEric W. Biederman .extra2 = SYSCTL_ONE,
2108eec4844fSMatteo Croce },
210978e36f3bSXiaoming Ni #endif
21101da177e4SLinus Torvalds {
211143b5240cSMuchun Song .procname = "drop_caches",
211243b5240cSMuchun Song .data = &sysctl_drop_caches,
211343b5240cSMuchun Song .maxlen = sizeof(int),
211443b5240cSMuchun Song .mode = 0200,
211543b5240cSMuchun Song .proc_handler = drop_caches_sysctl_handler,
211643b5240cSMuchun Song .extra1 = SYSCTL_ONE,
211743b5240cSMuchun Song .extra2 = SYSCTL_FOUR,
211843b5240cSMuchun Song },
211943b5240cSMuchun Song {
212043b5240cSMuchun Song .procname = "page_lock_unfairness",
212143b5240cSMuchun Song .data = &sysctl_page_lock_unfairness,
21221da177e4SLinus Torvalds .maxlen = sizeof(sysctl_page_lock_unfairness),
21231da177e4SLinus Torvalds .mode = 0644,
21241da177e4SLinus Torvalds .proc_handler = proc_dointvec_minmax,
21251da177e4SLinus Torvalds .extra1 = SYSCTL_ZERO,
21261da177e4SLinus Torvalds },
21276d456111SEric W. Biederman #ifdef CONFIG_MMU
21281da177e4SLinus Torvalds {
21291da177e4SLinus Torvalds .procname = "max_map_count",
21309d0243bcSAndrew Morton .data = &sysctl_max_map_count,
21319d0243bcSAndrew Morton .maxlen = sizeof(sysctl_max_map_count),
21329d0243bcSAndrew Morton .mode = 0644,
2133204cb79aSJohannes Weiner .proc_handler = proc_dointvec_minmax,
21349d0243bcSAndrew Morton .extra1 = SYSCTL_ZERO,
2135eec4844fSMatteo Croce },
213678e36f3bSXiaoming Ni #else
21379d0243bcSAndrew Morton {
21389d0243bcSAndrew Morton .procname = "nr_trim_pages",
21391da177e4SLinus Torvalds .data = &sysctl_nr_trim_pages,
21401da177e4SLinus Torvalds .maxlen = sizeof(sysctl_nr_trim_pages),
21411da177e4SLinus Torvalds .mode = 0644,
21421da177e4SLinus Torvalds .proc_handler = proc_dointvec_minmax,
21436d456111SEric W. Biederman .extra1 = SYSCTL_ZERO,
2144eec4844fSMatteo Croce },
21451da177e4SLinus Torvalds #endif
21468ad4b1fbSRohit Seth {
21471c30844dSMel Gorman .procname = "vfs_cache_pressure",
21481c30844dSMel Gorman .data = &sysctl_vfs_cache_pressure,
21491c30844dSMel Gorman .maxlen = sizeof(sysctl_vfs_cache_pressure),
21501c30844dSMel Gorman .mode = 0644,
215126363af5SChristoph Hellwig .proc_handler = proc_dointvec_minmax,
2152eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO,
21531c30844dSMel Gorman },
21541c30844dSMel Gorman #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2155795ae7a0SJohannes Weiner defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2156795ae7a0SJohannes Weiner {
2157795ae7a0SJohannes Weiner .procname = "legacy_va_layout",
2158795ae7a0SJohannes Weiner .data = &sysctl_legacy_va_layout,
2159795ae7a0SJohannes Weiner .maxlen = sizeof(sysctl_legacy_va_layout),
2160eec4844fSMatteo Croce .mode = 0644,
216178e36f3bSXiaoming Ni .proc_handler = proc_dointvec_minmax,
2162795ae7a0SJohannes Weiner .extra1 = SYSCTL_ZERO,
2163795ae7a0SJohannes Weiner },
216474f44822SMel Gorman #endif
216574f44822SMel Gorman #ifdef CONFIG_NUMA
216674f44822SMel Gorman {
21678ad4b1fbSRohit Seth .procname = "zone_reclaim_mode",
216874f44822SMel Gorman .data = &node_reclaim_mode,
2169eec4844fSMatteo Croce .maxlen = sizeof(node_reclaim_mode),
21708ad4b1fbSRohit Seth .mode = 0644,
21715ef64cc8SLinus Torvalds .proc_handler = proc_dointvec_minmax,
21725ef64cc8SLinus Torvalds .extra1 = SYSCTL_ZERO,
21735ef64cc8SLinus Torvalds },
21745ef64cc8SLinus Torvalds #endif
21755ef64cc8SLinus Torvalds #ifdef CONFIG_SMP
21765ef64cc8SLinus Torvalds {
21775ef64cc8SLinus Torvalds .procname = "stat_interval",
21785ef64cc8SLinus Torvalds .data = &sysctl_stat_interval,
21791da177e4SLinus Torvalds .maxlen = sizeof(sysctl_stat_interval),
21801da177e4SLinus Torvalds .mode = 0644,
21811da177e4SLinus Torvalds .proc_handler = proc_dointvec_jiffies,
21821da177e4SLinus Torvalds },
21831da177e4SLinus Torvalds {
21841da177e4SLinus Torvalds .procname = "stat_refresh",
21853e26120cSWANG Cong .data = NULL,
2186eec4844fSMatteo Croce .maxlen = 0,
21871da177e4SLinus Torvalds .mode = 0600,
2188dd8632a1SPaul Mundt .proc_handler = vmstat_refresh,
2189dd8632a1SPaul Mundt },
2190dd8632a1SPaul Mundt #endif
2191dd8632a1SPaul Mundt #ifdef CONFIG_MMU
2192dd8632a1SPaul Mundt {
2193dd8632a1SPaul Mundt .procname = "mmap_min_addr",
21946d456111SEric W. Biederman .data = &dac_mmap_min_addr,
2195eec4844fSMatteo Croce .maxlen = sizeof(unsigned long),
2196dd8632a1SPaul Mundt .mode = 0644,
21971da177e4SLinus Torvalds .proc_handler = mmap_min_addr_handler,
21981da177e4SLinus Torvalds },
21991da177e4SLinus Torvalds #endif
22001da177e4SLinus Torvalds #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
22011da177e4SLinus Torvalds (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
22021da177e4SLinus Torvalds {
22033b3376f2SLin Feng .procname = "vdso_enabled",
2204eec4844fSMatteo Croce #ifdef CONFIG_X86_32
22051da177e4SLinus Torvalds .data = &vdso32_enabled,
220667f3977fSAlexandre Ghiti .maxlen = sizeof(vdso32_enabled),
220767f3977fSAlexandre Ghiti #else
22081da177e4SLinus Torvalds .data = &vdso_enabled,
22091da177e4SLinus Torvalds .maxlen = sizeof(vdso_enabled),
22101da177e4SLinus Torvalds #endif
22111da177e4SLinus Torvalds .mode = 0644,
22121da177e4SLinus Torvalds .proc_handler = proc_dointvec,
22133b3376f2SLin Feng .extra1 = SYSCTL_ZERO,
2214eec4844fSMatteo Croce },
22151da177e4SLinus Torvalds #endif
22161da177e4SLinus Torvalds {
22171743660bSChristoph Lameter .procname = "user_reserve_kbytes",
22181743660bSChristoph Lameter .data = &sysctl_user_reserve_kbytes,
22191743660bSChristoph Lameter .maxlen = sizeof(sysctl_user_reserve_kbytes),
2220a5f5f91dSMel Gorman .mode = 0644,
2221a5f5f91dSMel Gorman .proc_handler = proc_doulongvec_minmax,
22221743660bSChristoph Lameter },
22233b3376f2SLin Feng {
2224eec4844fSMatteo Croce .procname = "admin_reserve_kbytes",
22251743660bSChristoph Lameter .data = &sysctl_admin_reserve_kbytes,
22269614634fSChristoph Lameter .maxlen = sizeof(sysctl_admin_reserve_kbytes),
22279614634fSChristoph Lameter .mode = 0644,
22289614634fSChristoph Lameter .proc_handler = proc_doulongvec_minmax,
22299614634fSChristoph Lameter },
22309614634fSChristoph Lameter #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
22316d456111SEric W. Biederman {
2232eec4844fSMatteo Croce .procname = "mmap_rnd_bits",
223378e36f3bSXiaoming Ni .data = &mmap_rnd_bits,
22349614634fSChristoph Lameter .maxlen = sizeof(mmap_rnd_bits),
22350ff38490SChristoph Lameter .mode = 0600,
22360ff38490SChristoph Lameter .proc_handler = proc_dointvec_minmax,
22370ff38490SChristoph Lameter .extra1 = (void *)&mmap_rnd_bits_min,
22380ff38490SChristoph Lameter .extra2 = (void *)&mmap_rnd_bits_max,
22390ff38490SChristoph Lameter },
22406d456111SEric W. Biederman #endif
2241eec4844fSMatteo Croce #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
224278e36f3bSXiaoming Ni {
22430ff38490SChristoph Lameter .procname = "mmap_rnd_compat_bits",
22441743660bSChristoph Lameter .data = &mmap_rnd_compat_bits,
224577461ab3SChristoph Lameter .maxlen = sizeof(mmap_rnd_compat_bits),
224677461ab3SChristoph Lameter .mode = 0600,
224777461ab3SChristoph Lameter .proc_handler = proc_dointvec_minmax,
224877461ab3SChristoph Lameter .extra1 = (void *)&mmap_rnd_compat_bits_min,
224977461ab3SChristoph Lameter .extra2 = (void *)&mmap_rnd_compat_bits_max,
225077461ab3SChristoph Lameter },
22516d456111SEric W. Biederman #endif
225277461ab3SChristoph Lameter { }
225352b6f46bSHugh Dickins };
225452b6f46bSHugh Dickins
sysctl_init_bases(void)225552b6f46bSHugh Dickins int __init sysctl_init_bases(void)
225652b6f46bSHugh Dickins {
225752b6f46bSHugh Dickins register_sysctl_init("kernel", kern_table);
225852b6f46bSHugh Dickins register_sysctl_init("vm", vm_table);
225952b6f46bSHugh Dickins
226077461ab3SChristoph Lameter return 0;
22616e141546SDavid Howells }
2262ed032189SEric Paris #endif /* CONFIG_SYSCTL */
2263ed032189SEric Paris /*
2264788084abSEric Paris * No sense putting this after each symbol definition, twice,
2265ed032189SEric Paris * exception granted :-)
2266ed032189SEric Paris */
22676d456111SEric W. Biederman EXPORT_SYMBOL(proc_dobool);
2268ed032189SEric Paris EXPORT_SYMBOL(proc_dointvec);
22696e141546SDavid Howells EXPORT_SYMBOL(proc_douintvec);
2270f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_dointvec_jiffies);
2271f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_dointvec_minmax);
2272f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2273f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2274f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2275f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_dostring);
22766d456111SEric W. Biederman EXPORT_SYMBOL(proc_doulongvec_minmax);
2277f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2278f0c0b2b8SKAMEZAWA Hiroyuki EXPORT_SYMBOL(proc_do_large_bitmap);
22792b8232ceSAl Viro