Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * sysctl.c: General linux system control interface
  3  *
  4  * Begun 24 March 1995, Stephen Tweedie
  5  * Added /proc support, Dec 1995
  6  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
  7  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
  8  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
  9  * Dynamic registration fixes, Stephen Tweedie.
 10  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
 11  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
 12  *  Horn.
 13  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
 14  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
 15  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
 16  *  Wendling.
 17  * The list_for_each() macro wasn't appropriate for the sysctl loop.
 18  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
 19  */
 20 
 21 #include <linux/module.h>
 22 #include <linux/mm.h>
 23 #include <linux/swap.h>
 24 #include <linux/slab.h>
 25 #include <linux/sysctl.h>
 26 #include <linux/proc_fs.h>
 27 #include <linux/security.h>
 28 #include <linux/ctype.h>
 29 #include <linux/utsname.h>
 30 #include <linux/smp_lock.h>
 31 #include <linux/fs.h>
 32 #include <linux/init.h>
 33 #include <linux/kernel.h>
 34 #include <linux/kobject.h>
 35 #include <linux/net.h>
 36 #include <linux/sysrq.h>
 37 #include <linux/highuid.h>
 38 #include <linux/writeback.h>
 39 #include <linux/hugetlb.h>
 40 #include <linux/initrd.h>
 41 #include <linux/times.h>
 42 #include <linux/limits.h>
 43 #include <linux/dcache.h>
 44 #include <linux/syscalls.h>
 45 #include <linux/nfs_fs.h>
 46 #include <linux/acpi.h>
 47 #include <linux/reboot.h>
 48 #include <linux/ftrace.h>
 49 #include <linux/profile.h>
 50 
 51 #include <asm/uaccess.h>
 52 #include <asm/processor.h>
 53 
 54 #ifdef CONFIG_X86
 55 #include <asm/nmi.h>
 56 #include <asm/stacktrace.h>
 57 #include <asm/io.h>
 58 #endif
 59 
 60 static int deprecated_sysctl_warning(struct __sysctl_args *args);
 61 
 62 #if defined(CONFIG_SYSCTL)
 63 
 64 /* External variables not in a header file. */
 65 extern int C_A_D;
 66 extern int print_fatal_signals;
 67 extern int sysctl_overcommit_memory;
 68 extern int sysctl_overcommit_ratio;
 69 extern int sysctl_panic_on_oom;
 70 extern int sysctl_oom_kill_allocating_task;
 71 extern int sysctl_oom_dump_tasks;
 72 extern int futex_performance_hack;
 73 extern int max_threads;
 74 extern int core_uses_pid;
 75 extern int suid_dumpable;
 76 extern char core_pattern[];
 77 extern int pid_max;
 78 extern int min_free_kbytes;
 79 extern int pid_max_min, pid_max_max;
 80 extern int sysctl_drop_caches;
 81 extern int percpu_pagelist_fraction;
 82 extern int compat_log;
 83 extern int maps_protect;
 84 extern int sysctl_stat_interval;
 85 extern int latencytop_enabled;
 86 
 87 /* Constants used for minimum and  maximum */
 88 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
 89 static int one = 1;
 90 #endif
 91 
 92 #ifdef CONFIG_DETECT_SOFTLOCKUP
 93 static int sixty = 60;
 94 #endif
 95 
 96 #ifdef CONFIG_MMU
 97 static int two = 2;
 98 #endif
 99 
100 static int zero;
101 static int one_hundred = 100;
102 
103 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104 static int maxolduid = 65535;
105 static int minolduid;
106 static int min_percpu_pagelist_fract = 8;
107 
108 static int ngroups_max = NGROUPS_MAX;
109 
110 #ifdef CONFIG_KMOD
111 extern char modprobe_path[];
112 #endif
113 #ifdef CONFIG_CHR_DEV_SG
114 extern int sg_big_buff;
115 #endif
116 
117 #ifdef __sparc__
118 extern char reboot_command [];
119 extern int stop_a_enabled;
120 extern int scons_pwroff;
121 #endif
122 
123 #ifdef __hppa__
124 extern int pwrsw_enabled;
125 extern int unaligned_enabled;
126 #endif
127 
128 #ifdef CONFIG_S390
129 #ifdef CONFIG_MATHEMU
130 extern int sysctl_ieee_emulation_warnings;
131 #endif
132 extern int sysctl_userprocess_debug;
133 extern int spin_retry;
134 #endif
135 
136 extern int sysctl_hz_timer;
137 
138 #ifdef CONFIG_BSD_PROCESS_ACCT
139 extern int acct_parm[];
140 #endif
141 
142 #ifdef CONFIG_IA64
143 extern int no_unaligned_warning;
144 #endif
145 
146 #ifdef CONFIG_RT_MUTEXES
147 extern int max_lock_depth;
148 #endif
149 
150 #ifdef CONFIG_SYSCTL_SYSCALL
151 static int parse_table(int __user *, int, void __user *, size_t __user *,
152                 void __user *, size_t, struct ctl_table *);
153 #endif
154 
155 #ifdef CONFIG_PREEMPT_RT
156 extern int rt_rwlock_limit;
157 #endif
158 
159 
160 #ifdef CONFIG_PROC_SYSCTL
161 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
162                   void __user *buffer, size_t *lenp, loff_t *ppos);
163 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
164                                void __user *buffer, size_t *lenp, loff_t *ppos);
165 #endif
166 
167 static struct ctl_table root_table[];
168 static struct ctl_table_root sysctl_table_root;
169 static struct ctl_table_header root_table_header = {
170         .ctl_table = root_table,
171         .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
172         .root = &sysctl_table_root,
173 };
174 static struct ctl_table_root sysctl_table_root = {
175         .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
176         .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
177 };
178 
179 static struct ctl_table kern_table[];
180 static struct ctl_table vm_table[];
181 static struct ctl_table fs_table[];
182 static struct ctl_table debug_table[];
183 static struct ctl_table dev_table[];
184 extern struct ctl_table random_table[];
185 #ifdef CONFIG_INOTIFY_USER
186 extern struct ctl_table inotify_table[];
187 #endif
188 
189 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
190 int sysctl_legacy_va_layout;
191 #endif
192 
193 extern int prove_locking;
194 extern int lock_stat;
195 
196 /* The default sysctl tables: */
197 
198 static struct ctl_table root_table[] = {
199         {
200                 .ctl_name       = CTL_KERN,
201                 .procname       = "kernel",
202                 .mode           = 0555,
203                 .child          = kern_table,
204         },
205         {
206                 .ctl_name       = CTL_VM,
207                 .procname       = "vm",
208                 .mode           = 0555,
209                 .child          = vm_table,
210         },
211         {
212                 .ctl_name       = CTL_FS,
213                 .procname       = "fs",
214                 .mode           = 0555,
215                 .child          = fs_table,
216         },
217         {
218                 .ctl_name       = CTL_DEBUG,
219                 .procname       = "debug",
220                 .mode           = 0555,
221                 .child          = debug_table,
222         },
223         {
224                 .ctl_name       = CTL_DEV,
225                 .procname       = "dev",
226                 .mode           = 0555,
227                 .child          = dev_table,
228         },
229 /*
230  * NOTE: do not add new entries to this table unless you have read
231  * Documentation/sysctl/ctl_unnumbered.txt
232  */
233         { .ctl_name = 0 }
234 };
235 
236 #ifdef CONFIG_SCHED_DEBUG
237 static int min_sched_granularity_ns = 100000;           /* 100 usecs */
238 static int max_sched_granularity_ns = NSEC_PER_SEC;     /* 1 second */
239 static int min_wakeup_granularity_ns;                   /* 0 usecs */
240 static int max_wakeup_granularity_ns = NSEC_PER_SEC;    /* 1 second */
241 #endif
242 
243 static struct ctl_table kern_table[] = {
244 #ifdef CONFIG_SCHED_DEBUG
245         {
246                 .ctl_name       = CTL_UNNUMBERED,
247                 .procname       = "sched_min_granularity_ns",
248                 .data           = &sysctl_sched_min_granularity,
249                 .maxlen         = sizeof(unsigned int),
250                 .mode           = 0644,
251                 .proc_handler   = &sched_nr_latency_handler,
252                 .strategy       = &sysctl_intvec,
253                 .extra1         = &min_sched_granularity_ns,
254                 .extra2         = &max_sched_granularity_ns,
255         },
256         {
257                 .ctl_name       = CTL_UNNUMBERED,
258                 .procname       = "sched_latency_ns",
259                 .data           = &sysctl_sched_latency,
260                 .maxlen         = sizeof(unsigned int),
261                 .mode           = 0644,
262                 .proc_handler   = &sched_nr_latency_handler,
263                 .strategy       = &sysctl_intvec,
264                 .extra1         = &min_sched_granularity_ns,
265                 .extra2         = &max_sched_granularity_ns,
266         },
267         {
268                 .ctl_name       = CTL_UNNUMBERED,
269                 .procname       = "sched_wakeup_granularity_ns",
270                 .data           = &sysctl_sched_wakeup_granularity,
271                 .maxlen         = sizeof(unsigned int),
272                 .mode           = 0644,
273                 .proc_handler   = &proc_dointvec_minmax,
274                 .strategy       = &sysctl_intvec,
275                 .extra1         = &min_wakeup_granularity_ns,
276                 .extra2         = &max_wakeup_granularity_ns,
277         },
278         {
279                 .ctl_name       = CTL_UNNUMBERED,
280                 .procname       = "sched_batch_wakeup_granularity_ns",
281                 .data           = &sysctl_sched_batch_wakeup_granularity,
282                 .maxlen         = sizeof(unsigned int),
283                 .mode           = 0644,
284                 .proc_handler   = &proc_dointvec_minmax,
285                 .strategy       = &sysctl_intvec,
286                 .extra1         = &min_wakeup_granularity_ns,
287                 .extra2         = &max_wakeup_granularity_ns,
288         },
289         {
290                 .ctl_name       = CTL_UNNUMBERED,
291                 .procname       = "sched_child_runs_first",
292                 .data           = &sysctl_sched_child_runs_first,
293                 .maxlen         = sizeof(unsigned int),
294                 .mode           = 0644,
295                 .proc_handler   = &proc_dointvec,
296         },
297         {
298                 .ctl_name       = CTL_UNNUMBERED,
299                 .procname       = "sched_features",
300                 .data           = &sysctl_sched_features,
301                 .maxlen         = sizeof(unsigned int),
302                 .mode           = 0644,
303                 .proc_handler   = &proc_dointvec,
304         },
305         {
306                 .ctl_name       = CTL_UNNUMBERED,
307                 .procname       = "sched_migration_cost",
308                 .data           = &sysctl_sched_migration_cost,
309                 .maxlen         = sizeof(unsigned int),
310                 .mode           = 0644,
311                 .proc_handler   = &proc_dointvec,
312         },
313         {
314                 .ctl_name       = CTL_UNNUMBERED,
315                 .procname       = "sched_nr_migrate",
316                 .data           = &sysctl_sched_nr_migrate,
317                 .maxlen         = sizeof(unsigned int),
318                 .mode           = 0644,
319                 .proc_handler   = &proc_dointvec,
320         },
321 #endif
322         {
323                 .ctl_name       = CTL_UNNUMBERED,
324                 .procname       = "sched_rt_period_us",
325                 .data           = &sysctl_sched_rt_period,
326                 .maxlen         = sizeof(unsigned int),
327                 .mode           = 0644,
328                 .proc_handler   = &proc_dointvec,
329         },
330         {
331                 .ctl_name       = CTL_UNNUMBERED,
332                 .procname       = "sched_rt_runtime_us",
333                 .data           = &sysctl_sched_rt_runtime,
334                 .maxlen         = sizeof(int),
335                 .mode           = 0644,
336                 .proc_handler   = &proc_dointvec,
337         },
338         {
339                 .ctl_name       = CTL_UNNUMBERED,
340                 .procname       = "sched_compat_yield",
341                 .data           = &sysctl_sched_compat_yield,
342                 .maxlen         = sizeof(unsigned int),
343                 .mode           = 0644,
344                 .proc_handler   = &proc_dointvec,
345         },
346 #ifdef CONFIG_PROVE_LOCKING
347         {
348                 .ctl_name       = CTL_UNNUMBERED,
349                 .procname       = "prove_locking",
350                 .data           = &prove_locking,
351                 .maxlen         = sizeof(int),
352                 .mode           = 0644,
353                 .proc_handler   = &proc_dointvec,
354         },
355 #endif
356 #ifdef CONFIG_LOCK_STAT
357         {
358                 .ctl_name       = CTL_UNNUMBERED,
359                 .procname       = "lock_stat",
360                 .data           = &lock_stat,
361                 .maxlen         = sizeof(int),
362                 .mode           = 0644,
363                 .proc_handler   = &proc_dointvec,
364         },
365 #endif
366 #ifdef CONFIG_FUTEX
367         {
368                 .ctl_name       = CTL_UNNUMBERED,
369                 .procname       = "futex_performance_hack",
370                 .data           = &futex_performance_hack,
371                 .maxlen         = sizeof(int),
372                 .mode           = 0644,
373                 .proc_handler   = &proc_dointvec,
374         },
375 #endif
376         {
377                 .ctl_name       = CTL_UNNUMBERED,
378                 .procname       = "prof_pid",
379                 .data           = &prof_pid,
380                 .maxlen         = sizeof(int),
381                 .mode           = 0644,
382                 .proc_handler   = &proc_dointvec,
383         },
384 #ifdef CONFIG_PREEMPT
385         {
386                 .ctl_name       = CTL_UNNUMBERED,
387                 .procname       = "kernel_preemption",
388                 .data           = &kernel_preemption,
389                 .maxlen         = sizeof(int),
390                 .mode           = 0644,
391                 .proc_handler   = &proc_dointvec,
392         },
393 #endif
394 #ifdef CONFIG_PREEMPT_VOLUNTARY
395         {
396                 .ctl_name       = CTL_UNNUMBERED,
397                 .procname       = "voluntary_preemption",
398                 .data           = &voluntary_preemption,
399                 .maxlen         = sizeof(int),
400                 .mode           = 0644,
401                 .proc_handler   = &proc_dointvec,
402         },
403 #endif
404 #if defined(CONFIG_PREEMPT_SOFTIRQS) && !defined(CONFIG_PREEMPT_RT)
405         {
406                 .ctl_name       = CTL_UNNUMBERED,
407                 .procname       = "softirq_preemption",
408                 .data           = &softirq_preemption,
409                 .maxlen         = sizeof(int),
410                 .mode           = 0644,
411                 .proc_handler   = &proc_dointvec,
412         },
413 #endif
414 #if defined(CONFIG_PREEMPT_HARDIRQS) && !defined(CONFIG_PREEMPT_RT)
415         {
416                 .ctl_name       = CTL_UNNUMBERED,
417                 .procname       = "hardirq_preemption",
418                 .data           = &hardirq_preemption,
419                 .maxlen         = sizeof(int),
420                 .mode           = 0644,
421                 .proc_handler   = &proc_dointvec,
422         },
423 #endif
424 #ifdef CONFIG_PREEMPT_RT
425         {
426                 .ctl_name       = CTL_UNNUMBERED,
427                 .procname       = "rwlock_reader_limit",
428                 .data           = &rt_rwlock_limit,
429                 .maxlen         = sizeof(int),
430                 .mode           = 0644,
431                 .proc_handler   = &proc_dointvec,
432         },
433 #endif
434         {
435                 .ctl_name       = KERN_PANIC,
436                 .procname       = "panic",
437                 .data           = &panic_timeout,
438                 .maxlen         = sizeof(int),
439                 .mode           = 0644,
440                 .proc_handler   = &proc_dointvec,
441         },
442 #ifdef CONFIG_GENERIC_HARDIRQS
443         {
444                 .ctl_name       = CTL_UNNUMBERED,
445                 .procname       = "debug_direct_keyboard",
446                 .data           = &debug_direct_keyboard,
447                 .maxlen         = sizeof(int),
448                 .mode           = 0644,
449                 .proc_handler   = &proc_dointvec,
450         },
451 #endif
452         {
453                 .ctl_name       = KERN_CORE_USES_PID,
454                 .procname       = "core_uses_pid",
455                 .data           = &core_uses_pid,
456                 .maxlen         = sizeof(int),
457                 .mode           = 0644,
458                 .proc_handler   = &proc_dointvec,
459         },
460         {
461                 .ctl_name       = KERN_CORE_PATTERN,
462                 .procname       = "core_pattern",
463                 .data           = core_pattern,
464                 .maxlen         = CORENAME_MAX_SIZE,
465                 .mode           = 0644,
466                 .proc_handler   = &proc_dostring,
467                 .strategy       = &sysctl_string,
468         },
469 #ifdef CONFIG_PROC_SYSCTL
470         {
471                 .procname       = "tainted",
472                 .data           = &tainted,
473                 .maxlen         = sizeof(int),
474                 .mode           = 0644,
475                 .proc_handler   = &proc_dointvec_taint,
476         },
477 #endif
478 #ifdef CONFIG_LATENCYTOP
479         {
480                 .procname       = "latencytop",
481                 .data           = &latencytop_enabled,
482                 .maxlen         = sizeof(int),
483                 .mode           = 0644,
484                 .proc_handler   = &proc_dointvec,
485         },
486 #endif
487 #ifdef CONFIG_BLK_DEV_INITRD
488         {
489                 .ctl_name       = KERN_REALROOTDEV,
490                 .procname       = "real-root-dev",
491                 .data           = &real_root_dev,
492                 .maxlen         = sizeof(int),
493                 .mode           = 0644,
494                 .proc_handler   = &proc_dointvec,
495         },
496 #endif
497         {
498                 .ctl_name       = CTL_UNNUMBERED,
499                 .procname       = "print-fatal-signals",
500                 .data           = &print_fatal_signals,
501                 .maxlen         = sizeof(int),
502                 .mode           = 0644,
503                 .proc_handler   = &proc_dointvec,
504         },
505 #ifdef __sparc__
506         {
507                 .ctl_name       = KERN_SPARC_REBOOT,
508                 .procname       = "reboot-cmd",
509                 .data           = reboot_command,
510                 .maxlen         = 256,
511                 .mode           = 0644,
512                 .proc_handler   = &proc_dostring,
513                 .strategy       = &sysctl_string,
514         },
515         {
516                 .ctl_name       = KERN_SPARC_STOP_A,
517                 .procname       = "stop-a",
518                 .data           = &stop_a_enabled,
519                 .maxlen         = sizeof (int),
520                 .mode           = 0644,
521                 .proc_handler   = &proc_dointvec,
522         },
523         {
524                 .ctl_name       = KERN_SPARC_SCONS_PWROFF,
525                 .procname       = "scons-poweroff",
526                 .data           = &scons_pwroff,
527                 .maxlen         = sizeof (int),
528                 .mode           = 0644,
529                 .proc_handler   = &proc_dointvec,
530         },
531 #endif
532 #ifdef __hppa__
533         {
534                 .ctl_name       = KERN_HPPA_PWRSW,
535                 .procname       = "soft-power",
536                 .data           = &pwrsw_enabled,
537                 .maxlen         = sizeof (int),
538                 .mode           = 0644,
539                 .proc_handler   = &proc_dointvec,
540         },
541         {
542                 .ctl_name       = KERN_HPPA_UNALIGNED,
543                 .procname       = "unaligned-trap",
544                 .data           = &unaligned_enabled,
545                 .maxlen         = sizeof (int),
546                 .mode           = 0644,
547                 .proc_handler   = &proc_dointvec,
548         },
549 #endif
550         {
551                 .ctl_name       = KERN_CTLALTDEL,
552                 .procname       = "ctrl-alt-del",
553                 .data           = &C_A_D,
554                 .maxlen         = sizeof(int),
555                 .mode           = 0644,
556                 .proc_handler   = &proc_dointvec,
557         },
558 #ifdef CONFIG_FTRACE
559         {
560                 .ctl_name       = CTL_UNNUMBERED,
561                 .procname       = "ftrace_enabled",
562                 .data           = &ftrace_enabled,
563                 .maxlen         = sizeof(int),
564                 .mode           = 0644,
565                 .proc_handler   = &ftrace_enable_sysctl,
566         },
567 #endif
568 #ifdef CONFIG_KMOD
569         {
570                 .ctl_name       = KERN_MODPROBE,
571                 .procname       = "modprobe",
572                 .data           = &modprobe_path,
573                 .maxlen         = KMOD_PATH_LEN,
574                 .mode           = 0644,
575                 .proc_handler   = &proc_dostring,
576                 .strategy       = &sysctl_string,
577         },
578 #endif
579 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
580         {
581                 .ctl_name       = KERN_HOTPLUG,
582                 .procname       = "hotplug",
583                 .data           = &uevent_helper,
584                 .maxlen         = UEVENT_HELPER_PATH_LEN,
585                 .mode           = 0644,
586                 .proc_handler   = &proc_dostring,
587                 .strategy       = &sysctl_string,
588         },
589 #endif
590 #ifdef CONFIG_CHR_DEV_SG
591         {
592                 .ctl_name       = KERN_SG_BIG_BUFF,
593                 .procname       = "sg-big-buff",
594                 .data           = &sg_big_buff,
595                 .maxlen         = sizeof (int),
596                 .mode           = 0444,
597                 .proc_handler   = &proc_dointvec,
598         },
599 #endif
600 #ifdef CONFIG_BSD_PROCESS_ACCT
601         {
602                 .ctl_name       = KERN_ACCT,
603                 .procname       = "acct",
604                 .data           = &acct_parm,
605                 .maxlen         = 3*sizeof(int),
606                 .mode           = 0644,
607                 .proc_handler   = &proc_dointvec,
608         },
609 #endif
610 #ifdef CONFIG_MAGIC_SYSRQ
611         {
612                 .ctl_name       = KERN_SYSRQ,
613                 .procname       = "sysrq",
614                 .data           = &__sysrq_enabled,
615                 .maxlen         = sizeof (int),
616                 .mode           = 0644,
617                 .proc_handler   = &proc_dointvec,
618         },
619 #endif
620 #ifdef CONFIG_PROC_SYSCTL
621         {
622                 .procname       = "cad_pid",
623                 .data           = NULL,
624                 .maxlen         = sizeof (int),
625                 .mode           = 0600,
626                 .proc_handler   = &proc_do_cad_pid,
627         },
628 #endif
629         {
630                 .ctl_name       = KERN_MAX_THREADS,
631                 .procname       = "threads-max",
632                 .data           = &max_threads,
633                 .maxlen         = sizeof(int),
634                 .mode           = 0644,
635                 .proc_handler   = &proc_dointvec,
636         },
637         {
638                 .ctl_name       = KERN_RANDOM,
639                 .procname       = "random",
640                 .mode           = 0555,
641                 .child          = random_table,
642         },
643         {
644                 .ctl_name       = KERN_OVERFLOWUID,
645                 .procname       = "overflowuid",
646                 .data           = &overflowuid,
647                 .maxlen         = sizeof(int),
648                 .mode           = 0644,
649                 .proc_handler   = &proc_dointvec_minmax,
650                 .strategy       = &sysctl_intvec,
651                 .extra1         = &minolduid,
652                 .extra2         = &maxolduid,
653         },
654         {
655                 .ctl_name       = KERN_OVERFLOWGID,
656                 .procname       = "overflowgid",
657                 .data           = &overflowgid,
658                 .maxlen         = sizeof(int),
659                 .mode           = 0644,
660                 .proc_handler   = &proc_dointvec_minmax,
661                 .strategy       = &sysctl_intvec,
662                 .extra1         = &minolduid,
663                 .extra2         = &maxolduid,
664         },
665 #ifdef CONFIG_S390
666 #ifdef CONFIG_MATHEMU
667         {
668                 .ctl_name       = KERN_IEEE_EMULATION_WARNINGS,
669                 .procname       = "ieee_emulation_warnings",
670                 .data           = &sysctl_ieee_emulation_warnings,
671                 .maxlen         = sizeof(int),
672                 .mode           = 0644,
673                 .proc_handler   = &proc_dointvec,
674         },
675 #endif
676 #ifdef CONFIG_NO_IDLE_HZ
677         {
678                 .ctl_name       = KERN_HZ_TIMER,
679                 .procname       = "hz_timer",
680                 .data           = &sysctl_hz_timer,
681                 .maxlen         = sizeof(int),
682                 .mode           = 0644,
683                 .proc_handler   = &proc_dointvec,
684         },
685 #endif
686         {
687                 .ctl_name       = KERN_S390_USER_DEBUG_LOGGING,
688                 .procname       = "userprocess_debug",
689                 .data           = &sysctl_userprocess_debug,
690                 .maxlen         = sizeof(int),
691                 .mode           = 0644,
692                 .proc_handler   = &proc_dointvec,
693         },
694 #endif
695         {
696                 .ctl_name       = KERN_PIDMAX,
697                 .procname       = "pid_max",
698                 .data           = &pid_max,
699                 .maxlen         = sizeof (int),
700                 .mode           = 0644,
701                 .proc_handler   = &proc_dointvec_minmax,
702                 .strategy       = sysctl_intvec,
703                 .extra1         = &pid_max_min,
704                 .extra2         = &pid_max_max,
705         },
706         {
707                 .ctl_name       = KERN_PANIC_ON_OOPS,
708                 .procname       = "panic_on_oops",
709                 .data           = &panic_on_oops,
710                 .maxlen         = sizeof(int),
711                 .mode           = 0644,
712                 .proc_handler   = &proc_dointvec,
713         },
714 #if defined CONFIG_PRINTK
715         {
716                 .ctl_name       = KERN_PRINTK,
717                 .procname       = "printk",
718                 .data           = &console_loglevel,
719                 .maxlen         = 4*sizeof(int),
720                 .mode           = 0644,
721                 .proc_handler   = &proc_dointvec,
722         },
723         {
724                 .ctl_name       = KERN_PRINTK_RATELIMIT,
725                 .procname       = "printk_ratelimit",
726                 .data           = &printk_ratelimit_jiffies,
727                 .maxlen         = sizeof(int),
728                 .mode           = 0644,
729                 .proc_handler   = &proc_dointvec_jiffies,
730                 .strategy       = &sysctl_jiffies,
731         },
732         {
733                 .ctl_name       = KERN_PRINTK_RATELIMIT_BURST,
734                 .procname       = "printk_ratelimit_burst",
735                 .data           = &printk_ratelimit_burst,
736                 .maxlen         = sizeof(int),
737                 .mode           = 0644,
738                 .proc_handler   = &proc_dointvec,
739         },
740 #endif
741         {
742                 .ctl_name       = KERN_NGROUPS_MAX,
743                 .procname       = "ngroups_max",
744                 .data           = &ngroups_max,
745                 .maxlen         = sizeof (int),
746                 .mode           = 0444,
747                 .proc_handler   = &proc_dointvec,
748         },
749 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
750         {
751                 .ctl_name       = KERN_UNKNOWN_NMI_PANIC,
752                 .procname       = "unknown_nmi_panic",
753                 .data           = &unknown_nmi_panic,
754                 .maxlen         = sizeof (int),
755                 .mode           = 0644,
756                 .proc_handler   = &proc_dointvec,
757         },
758         {
759                 .procname       = "nmi_watchdog",
760                 .data           = &nmi_watchdog_enabled,
761                 .maxlen         = sizeof (int),
762                 .mode           = 0644,
763                 .proc_handler   = &proc_nmi_enabled,
764         },
765 #endif
766 #if defined(CONFIG_X86)
767         {
768                 .ctl_name       = KERN_PANIC_ON_NMI,
769                 .procname       = "panic_on_unrecovered_nmi",
770                 .data           = &panic_on_unrecovered_nmi,
771                 .maxlen         = sizeof(int),
772                 .mode           = 0644,
773                 .proc_handler   = &proc_dointvec,
774         },
775         {
776                 .ctl_name       = KERN_BOOTLOADER_TYPE,
777                 .procname       = "bootloader_type",
778                 .data           = &bootloader_type,
779                 .maxlen         = sizeof (int),
780                 .mode           = 0444,
781                 .proc_handler   = &proc_dointvec,
782         },
783         {
784                 .ctl_name       = CTL_UNNUMBERED,
785                 .procname       = "kstack_depth_to_print",
786                 .data           = &kstack_depth_to_print,
787                 .maxlen         = sizeof(int),
788                 .mode           = 0644,
789                 .proc_handler   = &proc_dointvec,
790         },
791         {
792                 .ctl_name       = CTL_UNNUMBERED,
793                 .procname       = "io_delay_type",
794                 .data           = &io_delay_type,
795                 .maxlen         = sizeof(int),
796                 .mode           = 0644,
797                 .proc_handler   = &proc_dointvec,
798         },
799 #endif
800 #if defined(CONFIG_MMU)
801         {
802                 .ctl_name       = KERN_RANDOMIZE,
803                 .procname       = "randomize_va_space",
804                 .data           = &randomize_va_space,
805                 .maxlen         = sizeof(int),
806                 .mode           = 0644,
807                 .proc_handler   = &proc_dointvec,
808         },
809 #endif
810 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
811         {
812                 .ctl_name       = KERN_SPIN_RETRY,
813                 .procname       = "spin_retry",
814                 .data           = &spin_retry,
815                 .maxlen         = sizeof (int),
816                 .mode           = 0644,
817                 .proc_handler   = &proc_dointvec,
818         },
819 #endif
820 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
821         {
822                 .procname       = "acpi_video_flags",
823                 .data           = &acpi_realmode_flags,
824                 .maxlen         = sizeof (unsigned long),
825                 .mode           = 0644,
826                 .proc_handler   = &proc_doulongvec_minmax,
827         },
828 #endif
829 #ifdef CONFIG_IA64
830         {
831                 .ctl_name       = KERN_IA64_UNALIGNED,
832                 .procname       = "ignore-unaligned-usertrap",
833                 .data           = &no_unaligned_warning,
834                 .maxlen         = sizeof (int),
835                 .mode           = 0644,
836                 .proc_handler   = &proc_dointvec,
837         },
838 #endif
839 #ifdef CONFIG_DETECT_SOFTLOCKUP
840         {
841                 .ctl_name       = CTL_UNNUMBERED,
842                 .procname       = "softlockup_thresh",
843                 .data           = &softlockup_thresh,
844                 .maxlen         = sizeof(unsigned long),
845                 .mode           = 0644,
846                 .proc_handler   = &proc_doulongvec_minmax,
847                 .strategy       = &sysctl_intvec,
848                 .extra1         = &one,
849                 .extra2         = &sixty,
850         },
851         {
852                 .ctl_name       = CTL_UNNUMBERED,
853                 .procname       = "hung_task_check_count",
854                 .data           = &sysctl_hung_task_check_count,
855                 .maxlen         = sizeof(unsigned long),
856                 .mode           = 0644,
857                 .proc_handler   = &proc_doulongvec_minmax,
858                 .strategy       = &sysctl_intvec,
859         },
860         {
861                 .ctl_name       = CTL_UNNUMBERED,
862                 .procname       = "hung_task_timeout_secs",
863                 .data           = &sysctl_hung_task_timeout_secs,
864                 .maxlen         = sizeof(unsigned long),
865                 .mode           = 0644,
866                 .proc_handler   = &proc_doulongvec_minmax,
867                 .strategy       = &sysctl_intvec,
868         },
869         {
870                 .ctl_name       = CTL_UNNUMBERED,
871                 .procname       = "hung_task_warnings",
872                 .data           = &sysctl_hung_task_warnings,
873                 .maxlen         = sizeof(unsigned long),
874                 .mode           = 0644,
875                 .proc_handler   = &proc_doulongvec_minmax,
876                 .strategy       = &sysctl_intvec,
877         },
878 #endif
879 #ifdef CONFIG_COMPAT
880         {
881                 .ctl_name       = KERN_COMPAT_LOG,
882                 .procname       = "compat-log",
883                 .data           = &compat_log,
884                 .maxlen         = sizeof (int),
885                 .mode           = 0644,
886                 .proc_handler   = &proc_dointvec,
887         },
888 #endif
889 #ifdef CONFIG_RT_MUTEXES
890         {
891                 .ctl_name       = KERN_MAX_LOCK_DEPTH,
892                 .procname       = "max_lock_depth",
893                 .data           = &max_lock_depth,
894                 .maxlen         = sizeof(int),
895                 .mode           = 0644,
896                 .proc_handler   = &proc_dointvec,
897         },
898 #endif
899 #ifdef CONFIG_PROC_FS
900         {
901                 .ctl_name       = CTL_UNNUMBERED,
902                 .procname       = "maps_protect",
903                 .data           = &maps_protect,
904                 .maxlen         = sizeof(int),
905                 .mode           = 0644,
906                 .proc_handler   = &proc_dointvec,
907         },
908 #endif
909         {
910                 .ctl_name       = CTL_UNNUMBERED,
911                 .procname       = "poweroff_cmd",
912                 .data           = &poweroff_cmd,
913                 .maxlen         = POWEROFF_CMD_PATH_LEN,
914                 .mode           = 0644,
915                 .proc_handler   = &proc_dostring,
916                 .strategy       = &sysctl_string,
917         },
918 /*
919  * NOTE: do not add new entries to this table unless you have read
920  * Documentation/sysctl/ctl_unnumbered.txt
921  */
922         { .ctl_name = 0 }
923 };
924 
925 static struct ctl_table vm_table[] = {
926         {
927                 .ctl_name       = VM_OVERCOMMIT_MEMORY,
928                 .procname       = "overcommit_memory",
929                 .data           = &sysctl_overcommit_memory,
930                 .maxlen         = sizeof(sysctl_overcommit_memory),
931                 .mode           = 0644,
932                 .proc_handler   = &proc_dointvec,
933         },
934         {
935                 .ctl_name       = VM_PANIC_ON_OOM,
936                 .procname       = "panic_on_oom",
937                 .data           = &sysctl_panic_on_oom,
938                 .maxlen         = sizeof(sysctl_panic_on_oom),
939                 .mode           = 0644,
940                 .proc_handler   = &proc_dointvec,
941         },
942         {
943                 .ctl_name       = CTL_UNNUMBERED,
944                 .procname       = "oom_kill_allocating_task",
945                 .data           = &sysctl_oom_kill_allocating_task,
946                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
947                 .mode           = 0644,
948                 .proc_handler   = &proc_dointvec,
949         },
950         {
951                 .ctl_name       = CTL_UNNUMBERED,
952                 .procname       = "oom_dump_tasks",
953                 .data           = &sysctl_oom_dump_tasks,
954                 .maxlen         = sizeof(sysctl_oom_dump_tasks),
955                 .mode           = 0644,
956                 .proc_handler   = &proc_dointvec,
957         },
958         {
959                 .ctl_name       = VM_OVERCOMMIT_RATIO,
960                 .procname       = "overcommit_ratio",
961                 .data           = &sysctl_overcommit_ratio,
962                 .maxlen         = sizeof(sysctl_overcommit_ratio),
963                 .mode           = 0644,
964                 .proc_handler   = &proc_dointvec,
965         },
966         {
967                 .ctl_name       = VM_PAGE_CLUSTER,
968                 .procname       = "page-cluster", 
969                 .data           = &page_cluster,
970                 .maxlen         = sizeof(int),
971                 .mode           = 0644,
972                 .proc_handler   = &proc_dointvec,
973         },
974         {
975                 .ctl_name       = VM_DIRTY_BACKGROUND,
976                 .procname       = "dirty_background_ratio",
977                 .data           = &dirty_background_ratio,
978                 .maxlen         = sizeof(dirty_background_ratio),
979                 .mode           = 0644,
980                 .proc_handler   = &proc_dointvec_minmax,
981                 .strategy       = &sysctl_intvec,
982                 .extra1         = &zero,
983                 .extra2         = &one_hundred,
984         },
985         {
986                 .ctl_name       = VM_DIRTY_RATIO,
987                 .procname       = "dirty_ratio",
988                 .data           = &vm_dirty_ratio,
989                 .maxlen         = sizeof(vm_dirty_ratio),
990                 .mode           = 0644,
991                 .proc_handler   = &dirty_ratio_handler,
992                 .strategy       = &sysctl_intvec,
993                 .extra1         = &zero,
994                 .extra2         = &one_hundred,
995         },
996         {
997                 .procname       = "dirty_writeback_centisecs",
998                 .data           = &dirty_writeback_interval,
999                 .maxlen         = sizeof(dirty_writeback_interval),
1000                 .mode           = 0644,
1001                 .proc_handler   = &dirty_writeback_centisecs_handler,
1002         },
1003         {
1004                 .procname       = "dirty_expire_centisecs",
1005                 .data           = &dirty_expire_interval,
1006                 .maxlen         = sizeof(dirty_expire_interval),
1007                 .mode           = 0644,
1008                 .proc_handler   = &proc_dointvec_userhz_jiffies,
1009         },
1010         {
1011                 .ctl_name       = VM_NR_PDFLUSH_THREADS,
1012                 .procname       = "nr_pdflush_threads",
1013                 .data           = &nr_pdflush_threads,
1014                 .maxlen         = sizeof nr_pdflush_threads,
1015                 .mode           = 0444 /* read-only*/,
1016                 .proc_handler   = &proc_dointvec,
1017         },
1018         {
1019                 .ctl_name       = VM_SWAPPINESS,
1020                 .procname       = "swappiness",
1021                 .data           = &vm_swappiness,
1022                 .maxlen         = sizeof(vm_swappiness),
1023                 .mode           = 0644,
1024                 .proc_handler   = &proc_dointvec_minmax,
1025                 .strategy       = &sysctl_intvec,
1026                 .extra1         = &zero,
1027                 .extra2         = &one_hundred,
1028         },
1029 #ifdef CONFIG_HUGETLB_PAGE
1030          {
1031                 .procname       = "nr_hugepages",
1032                 .data           = &max_huge_pages,
1033                 .maxlen         = sizeof(unsigned long),
1034                 .mode           = 0644,
1035                 .proc_handler   = &hugetlb_sysctl_handler,
1036                 .extra1         = (void *)&hugetlb_zero,
1037                 .extra2         = (void *)&hugetlb_infinity,
1038          },
1039          {
1040                 .ctl_name       = VM_HUGETLB_GROUP,
1041                 .procname       = "hugetlb_shm_group",
1042                 .data           = &sysctl_hugetlb_shm_group,
1043                 .maxlen         = sizeof(gid_t),
1044                 .mode           = 0644,
1045                 .proc_handler   = &proc_dointvec,
1046          },
1047          {
1048                 .ctl_name       = CTL_UNNUMBERED,
1049                 .procname       = "hugepages_treat_as_movable",
1050                 .data           = &hugepages_treat_as_movable,
1051                 .maxlen         = sizeof(int),
1052                 .mode           = 0644,
1053                 .proc_handler   = &hugetlb_treat_movable_handler,
1054         },
1055         {
1056                 .ctl_name       = CTL_UNNUMBERED,
1057                 .procname       = "nr_overcommit_hugepages",
1058                 .data           = &sysctl_overcommit_huge_pages,
1059                 .maxlen         = sizeof(sysctl_overcommit_huge_pages),
1060                 .mode           = 0644,
1061                 .proc_handler   = &hugetlb_overcommit_handler,
1062         },
1063 #endif
1064         {
1065                 .ctl_name       = VM_LOWMEM_RESERVE_RATIO,
1066                 .procname       = "lowmem_reserve_ratio",
1067                 .data           = &sysctl_lowmem_reserve_ratio,
1068                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
1069                 .mode           = 0644,
1070                 .proc_handler   = &lowmem_reserve_ratio_sysctl_handler,
1071                 .strategy       = &sysctl_intvec,
1072         },
1073         {
1074                 .ctl_name       = VM_DROP_PAGECACHE,
1075                 .procname       = "drop_caches",
1076                 .data           = &sysctl_drop_caches,
1077                 .maxlen         = sizeof(int),
1078                 .mode           = 0644,
1079                 .proc_handler   = drop_caches_sysctl_handler,
1080                 .strategy       = &sysctl_intvec,
1081         },
1082         {
1083                 .ctl_name       = VM_MIN_FREE_KBYTES,
1084                 .procname       = "min_free_kbytes",
1085                 .data           = &min_free_kbytes,
1086                 .maxlen         = sizeof(min_free_kbytes),
1087                 .mode           = 0644,
1088                 .proc_handler   = &min_free_kbytes_sysctl_handler,
1089                 .strategy       = &sysctl_intvec,
1090                 .extra1         = &zero,
1091         },
1092         {
1093                 .ctl_name       = VM_PERCPU_PAGELIST_FRACTION,
1094                 .procname       = "percpu_pagelist_fraction",
1095                 .data           = &percpu_pagelist_fraction,
1096                 .maxlen         = sizeof(percpu_pagelist_fraction),
1097                 .mode           = 0644,
1098                 .proc_handler   = &percpu_pagelist_fraction_sysctl_handler,
1099                 .strategy       = &sysctl_intvec,
1100                 .extra1         = &min_percpu_pagelist_fract,
1101         },
1102 #ifdef CONFIG_MMU
1103         {
1104                 .ctl_name       = VM_MAX_MAP_COUNT,
1105                 .procname       = "max_map_count",
1106                 .data           = &sysctl_max_map_count,
1107                 .maxlen         = sizeof(sysctl_max_map_count),
1108                 .mode           = 0644,
1109                 .proc_handler   = &proc_dointvec
1110         },
1111 #endif
1112         {
1113                 .ctl_name       = VM_LAPTOP_MODE,
1114                 .procname       = "laptop_mode",
1115                 .data           = &laptop_mode,
1116                 .maxlen         = sizeof(laptop_mode),
1117                 .mode           = 0644,
1118                 .proc_handler   = &proc_dointvec_jiffies,
1119                 .strategy       = &sysctl_jiffies,
1120         },
1121         {
1122                 .ctl_name       = VM_BLOCK_DUMP,
1123                 .procname       = "block_dump",
1124                 .data           = &block_dump,
1125                 .maxlen         = sizeof(block_dump),
1126                 .mode           = 0644,
1127                 .proc_handler   = &proc_dointvec,
1128                 .strategy       = &sysctl_intvec,
1129                 .extra1         = &zero,
1130         },
1131         {
1132                 .ctl_name       = VM_VFS_CACHE_PRESSURE,
1133                 .procname       = "vfs_cache_pressure",
1134                 .data           = &sysctl_vfs_cache_pressure,
1135                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
1136                 .mode           = 0644,
1137                 .proc_handler   = &proc_dointvec,
1138                 .strategy       = &sysctl_intvec,
1139                 .extra1         = &zero,
1140         },
1141 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1142         {
1143                 .ctl_name       = VM_LEGACY_VA_LAYOUT,
1144                 .procname       = "legacy_va_layout",
1145                 .data           = &sysctl_legacy_va_layout,
1146                 .maxlen         = sizeof(sysctl_legacy_va_layout),
1147                 .mode           = 0644,
1148                 .proc_handler   = &proc_dointvec,
1149                 .strategy       = &sysctl_intvec,
1150                 .extra1         = &zero,
1151         },
1152 #endif
1153 #ifdef CONFIG_NUMA
1154         {
1155                 .ctl_name       = VM_ZONE_RECLAIM_MODE,
1156                 .procname       = "zone_reclaim_mode",
1157                 .data           = &zone_reclaim_mode,
1158                 .maxlen         = sizeof(zone_reclaim_mode),
1159                 .mode           = 0644,
1160                 .proc_handler   = &proc_dointvec,
1161                 .strategy       = &sysctl_intvec,
1162                 .extra1         = &zero,
1163         },
1164         {
1165                 .ctl_name       = VM_MIN_UNMAPPED,
1166                 .procname       = "min_unmapped_ratio",
1167                 .data           = &sysctl_min_unmapped_ratio,
1168                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1169                 .mode           = 0644,
1170                 .proc_handler   = &sysctl_min_unmapped_ratio_sysctl_handler,
1171                 .strategy       = &sysctl_intvec,
1172                 .extra1         = &zero,
1173                 .extra2         = &one_hundred,
1174         },
1175         {
1176                 .ctl_name       = VM_MIN_SLAB,
1177                 .procname       = "min_slab_ratio",
1178                 .data           = &sysctl_min_slab_ratio,
1179                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1180                 .mode           = 0644,
1181                 .proc_handler   = &sysctl_min_slab_ratio_sysctl_handler,
1182                 .strategy       = &sysctl_intvec,
1183                 .extra1         = &zero,
1184                 .extra2         = &one_hundred,
1185         },
1186 #endif
1187 #ifdef CONFIG_SMP
1188         {
1189                 .ctl_name       = CTL_UNNUMBERED,
1190                 .procname       = "stat_interval",
1191                 .data           = &sysctl_stat_interval,
1192                 .maxlen         = sizeof(sysctl_stat_interval),
1193                 .mode           = 0644,
1194                 .proc_handler   = &proc_dointvec_jiffies,
1195                 .strategy       = &sysctl_jiffies,
1196         },
1197 #endif
1198 #ifdef CONFIG_SECURITY
1199         {
1200                 .ctl_name       = CTL_UNNUMBERED,
1201                 .procname       = "mmap_min_addr",
1202                 .data           = &mmap_min_addr,
1203                 .maxlen         = sizeof(unsigned long),
1204                 .mode           = 0644,
1205                 .proc_handler   = &proc_doulongvec_minmax,
1206         },
1207 #endif
1208 #ifdef CONFIG_NUMA
1209         {
1210                 .ctl_name       = CTL_UNNUMBERED,
1211                 .procname       = "numa_zonelist_order",
1212                 .data           = &numa_zonelist_order,
1213                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1214                 .mode           = 0644,
1215                 .proc_handler   = &numa_zonelist_order_handler,
1216                 .strategy       = &sysctl_string,
1217         },
1218 #endif
1219 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1220    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1221         {
1222                 .ctl_name       = VM_VDSO_ENABLED,
1223                 .procname       = "vdso_enabled",
1224                 .data           = &vdso_enabled,
1225                 .maxlen         = sizeof(vdso_enabled),
1226                 .mode           = 0644,
1227                 .proc_handler   = &proc_dointvec,
1228                 .strategy       = &sysctl_intvec,
1229                 .extra1         = &zero,
1230         },
1231 #endif
1232 #ifdef CONFIG_HIGHMEM
1233         {
1234                 .ctl_name       = CTL_UNNUMBERED,
1235                 .procname       = "highmem_is_dirtyable",
1236                 .data           = &vm_highmem_is_dirtyable,
1237                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
1238                 .mode           = 0644,
1239                 .proc_handler   = &proc_dointvec_minmax,
1240                 .strategy       = &sysctl_intvec,
1241                 .extra1         = &zero,
1242                 .extra2         = &one,
1243         },
1244 #endif
1245 /*
1246  * NOTE: do not add new entries to this table unless you have read
1247  * Documentation/sysctl/ctl_unnumbered.txt
1248  */
1249         { .ctl_name = 0 }
1250 };
1251 
1252 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1253 static struct ctl_table binfmt_misc_table[] = {
1254         { .ctl_name = 0 }
1255 };
1256 #endif
1257 
1258 static struct ctl_table fs_table[] = {
1259         {
1260                 .ctl_name       = FS_NRINODE,
1261                 .procname       = "inode-nr",
1262                 .data           = &inodes_stat,
1263                 .maxlen         = 2*sizeof(int),
1264                 .mode           = 0444,
1265                 .proc_handler   = &proc_dointvec,
1266         },
1267         {
1268                 .ctl_name       = FS_STATINODE,
1269                 .procname       = "inode-state",
1270                 .data           = &inodes_stat,
1271                 .maxlen         = 7*sizeof(int),
1272                 .mode           = 0444,
1273                 .proc_handler   = &proc_dointvec,
1274         },
1275         {
1276                 .procname       = "file-nr",
1277                 .data           = &files_stat,
1278                 .maxlen         = 3*sizeof(int),
1279                 .mode           = 0444,
1280                 .proc_handler   = &proc_nr_files,
1281         },
1282         {
1283                 .ctl_name       = FS_MAXFILE,
1284                 .procname       = "file-max",
1285                 .data           = &files_stat.max_files,
1286                 .maxlen         = sizeof(int),
1287                 .mode           = 0644,
1288                 .proc_handler   = &proc_dointvec,
1289         },
1290         {
1291                 .ctl_name       = CTL_UNNUMBERED,
1292                 .procname       = "nr_open",
1293                 .data           = &sysctl_nr_open,
1294                 .maxlen         = sizeof(int),
1295                 .mode           = 0644,
1296                 .proc_handler   = &proc_dointvec,
1297         },
1298         {
1299                 .ctl_name       = FS_DENTRY,
1300                 .procname       = "dentry-state",
1301                 .data           = &dentry_stat,
1302                 .maxlen         = 6*sizeof(int),
1303                 .mode           = 0444,
1304                 .proc_handler   = &proc_dointvec,
1305         },
1306         {
1307                 .ctl_name       = FS_OVERFLOWUID,
1308                 .procname       = "overflowuid",
1309                 .data           = &fs_overflowuid,
1310                 .maxlen         = sizeof(int),
1311                 .mode           = 0644,
1312                 .proc_handler   = &proc_dointvec_minmax,
1313                 .strategy       = &sysctl_intvec,
1314                 .extra1         = &minolduid,
1315                 .extra2         = &maxolduid,
1316         },
1317         {
1318                 .ctl_name       = FS_OVERFLOWGID,
1319                 .procname       = "overflowgid",
1320                 .data           = &fs_overflowgid,
1321                 .maxlen         = sizeof(int),
1322                 .mode           = 0644,
1323                 .proc_handler   = &proc_dointvec_minmax,
1324                 .strategy       = &sysctl_intvec,
1325                 .extra1         = &minolduid,
1326                 .extra2         = &maxolduid,
1327         },
1328         {
1329                 .ctl_name       = FS_LEASES,
1330                 .procname       = "leases-enable",
1331                 .data           = &leases_enable,
1332                 .maxlen         = sizeof(int),
1333                 .mode           = 0644,
1334                 .proc_handler   = &proc_dointvec,
1335         },
1336 #ifdef CONFIG_DNOTIFY
1337         {
1338                 .ctl_name       = FS_DIR_NOTIFY,
1339                 .procname       = "dir-notify-enable",
1340                 .data           = &dir_notify_enable,
1341                 .maxlen         = sizeof(int),
1342                 .mode           = 0644,
1343                 .proc_handler   = &proc_dointvec,
1344         },
1345 #endif
1346 #ifdef CONFIG_MMU
1347         {
1348                 .ctl_name       = FS_LEASE_TIME,
1349                 .procname       = "lease-break-time",
1350                 .data           = &lease_break_time,
1351                 .maxlen         = sizeof(int),
1352                 .mode           = 0644,
1353                 .proc_handler   = &proc_dointvec_minmax,
1354                 .strategy       = &sysctl_intvec,
1355                 .extra1         = &zero,
1356                 .extra2         = &two,
1357         },
1358         {
1359                 .procname       = "aio-nr",
1360                 .data           = &aio_nr,
1361                 .maxlen         = sizeof(aio_nr),
1362                 .mode           = 0444,
1363                 .proc_handler   = &proc_doulongvec_minmax,
1364         },
1365         {
1366                 .procname       = "aio-max-nr",
1367                 .data           = &aio_max_nr,
1368                 .maxlen         = sizeof(aio_max_nr),
1369                 .mode           = 0644,
1370                 .proc_handler   = &proc_doulongvec_minmax,
1371         },
1372 #ifdef CONFIG_INOTIFY_USER
1373         {
1374                 .ctl_name       = FS_INOTIFY,
1375                 .procname       = "inotify",
1376                 .mode           = 0555,
1377                 .child          = inotify_table,
1378         },
1379 #endif  
1380 #endif
1381         {
1382                 .ctl_name       = KERN_SETUID_DUMPABLE,
1383                 .procname       = "suid_dumpable",
1384                 .data           = &suid_dumpable,
1385                 .maxlen         = sizeof(int),
1386                 .mode           = 0644,
1387                 .proc_handler   = &proc_dointvec,
1388         },
1389 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1390         {
1391                 .ctl_name       = CTL_UNNUMBERED,
1392                 .procname       = "binfmt_misc",
1393                 .mode           = 0555,
1394                 .child          = binfmt_misc_table,
1395         },
1396 #endif
1397 /*
1398  * NOTE: do not add new entries to this table unless you have read
1399  * Documentation/sysctl/ctl_unnumbered.txt
1400  */
1401         { .ctl_name = 0 }
1402 };
1403 
1404 static struct ctl_table debug_table[] = {
1405 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1406         {
1407                 .ctl_name       = CTL_UNNUMBERED,
1408                 .procname       = "exception-trace",
1409                 .data           = &show_unhandled_signals,
1410                 .maxlen         = sizeof(int),
1411                 .mode           = 0644,
1412                 .proc_handler   = proc_dointvec
1413         },
1414 #endif
1415         { .ctl_name = 0 }
1416 };
1417 
1418 static struct ctl_table dev_table[] = {
1419         { .ctl_name = 0 }
1420 };
1421 
1422 static DEFINE_SPINLOCK(sysctl_lock);
1423 
1424 /* called under sysctl_lock */
1425 static int use_table(struct ctl_table_header *p)
1426 {
1427         if (unlikely(p->unregistering))
1428                 return 0;
1429         p->used++;
1430         return 1;
1431 }
1432 
1433 /* called under sysctl_lock */
1434 static void unuse_table(struct ctl_table_header *p)
1435 {
1436         if (!--p->used)
1437                 if (unlikely(p->unregistering))
1438                         complete(p->unregistering);
1439 }
1440 
1441 /* called under sysctl_lock, will reacquire if has to wait */
1442 static void start_unregistering(struct ctl_table_header *p)
1443 {
1444         /*
1445          * if p->used is 0, nobody will ever touch that entry again;
1446          * we'll eliminate all paths to it before dropping sysctl_lock
1447          */
1448         if (unlikely(p->used)) {
1449                 struct completion wait;
1450                 init_completion(&wait);
1451                 p->unregistering = &wait;
1452                 spin_unlock(&sysctl_lock);
1453                 wait_for_completion(&wait);
1454                 spin_lock(&sysctl_lock);
1455         }
1456         /*
1457          * do not remove from the list until nobody holds it; walking the
1458          * list in do_sysctl() relies on that.
1459          */
1460         list_del_init(&p->ctl_entry);
1461 }
1462 
1463 void sysctl_head_finish(struct ctl_table_header *head)
1464 {
1465         if (!head)
1466                 return;
1467         spin_lock(&sysctl_lock);
1468         unuse_table(head);
1469         spin_unlock(&sysctl_lock);
1470 }
1471 
1472 static struct list_head *
1473 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1474 {
1475         struct list_head *header_list;
1476         header_list = &root->header_list;
1477         if (root->lookup)
1478                 header_list = root->lookup(root, namespaces);
1479         return header_list;
1480 }
1481 
1482 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1483                                             struct ctl_table_header *prev)
1484 {
1485         struct ctl_table_root *root;
1486         struct list_head *header_list;
1487         struct ctl_table_header *head;
1488         struct list_head *tmp;
1489 
1490         spin_lock(&sysctl_lock);
1491         if (prev) {
1492                 head = prev;
1493                 tmp = &prev->ctl_entry;
1494                 unuse_table(prev);
1495                 goto next;
1496         }
1497         tmp = &root_table_header.ctl_entry;
1498         for (;;) {
1499                 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1500 
1501                 if (!use_table(head))
1502                         goto next;
1503                 spin_unlock(&sysctl_lock);
1504                 return head;
1505         next:
1506                 root = head->root;
1507                 tmp = tmp->next;
1508                 header_list = lookup_header_list(root, namespaces);
1509                 if (tmp != header_list)
1510                         continue;
1511 
1512                 do {
1513                         root = list_entry(root->root_list.next,
1514                                         struct ctl_table_root, root_list);
1515                         if (root == &sysctl_table_root)
1516                                 goto out;
1517                         header_list = lookup_header_list(root, namespaces);
1518                 } while (list_empty(header_list));
1519                 tmp = header_list->next;
1520         }
1521 out:
1522         spin_unlock(&sysctl_lock);
1523         return NULL;
1524 }
1525 
1526 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1527 {
1528         return __sysctl_head_next(current->nsproxy, prev);
1529 }
1530 
1531 void register_sysctl_root(struct ctl_table_root *root)
1532 {
1533         spin_lock(&sysctl_lock);
1534         list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1535         spin_unlock(&sysctl_lock);
1536 }
1537 
1538 #ifdef CONFIG_SYSCTL_SYSCALL
1539 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1540                void __user *newval, size_t newlen)
1541 {
1542         struct ctl_table_header *head;
1543         int error = -ENOTDIR;
1544 
1545         if (nlen <= 0 || nlen >= CTL_MAXNAME)
1546                 return -ENOTDIR;
1547         if (oldval) {
1548                 int old_len;
1549                 if (!oldlenp || get_user(old_len, oldlenp))
1550                         return -EFAULT;
1551         }
1552 
1553         for (head = sysctl_head_next(NULL); head;
1554                         head = sysctl_head_next(head)) {
1555                 error = parse_table(name, nlen, oldval, oldlenp, 
1556                                         newval, newlen, head->ctl_table);
1557                 if (error != -ENOTDIR) {
1558                         sysctl_head_finish(head);
1559                         break;
1560                 }
1561         }
1562         return error;
1563 }
1564 
1565 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1566 {
1567         struct __sysctl_args tmp;
1568         int error;
1569 
1570         if (copy_from_user(&tmp, args, sizeof(tmp)))
1571                 return -EFAULT;
1572 
1573         error = deprecated_sysctl_warning(&tmp);
1574         if (error)
1575                 goto out;
1576 
1577         lock_kernel();
1578         error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1579                           tmp.newval, tmp.newlen);
1580         unlock_kernel();
1581 out:
1582         return error;
1583 }
1584 #endif /* CONFIG_SYSCTL_SYSCALL */
1585 
1586 /*
1587  * sysctl_perm does NOT grant the superuser all rights automatically, because
1588  * some sysctl variables are readonly even to root.
1589  */
1590 
1591 static int test_perm(int mode, int op)
1592 {
1593         if (!current->euid)
1594                 mode >>= 6;
1595         else if (in_egroup_p(0))
1596                 mode >>= 3;
1597         if ((mode & op & 0007) == op)
1598                 return 0;
1599         return -EACCES;
1600 }
1601 
1602 int sysctl_perm(struct ctl_table *table, int op)
1603 {
1604         int error;
1605         error = security_sysctl(table, op);
1606         if (error)
1607                 return error;
1608         return test_perm(table->mode, op);
1609 }
1610 
1611 #ifdef CONFIG_SYSCTL_SYSCALL
1612 static int parse_table(int __user *name, int nlen,
1613                        void __user *oldval, size_t __user *oldlenp,
1614                        void __user *newval, size_t newlen,
1615                        struct ctl_table *table)
1616 {
1617         int n;
1618 repeat:
1619         if (!nlen)
1620                 return -ENOTDIR;
1621         if (get_user(n, name))
1622                 return -EFAULT;
1623         for ( ; table->ctl_name || table->procname; table++) {
1624                 if (!table->ctl_name)
1625                         continue;
1626                 if (n == table->ctl_name) {
1627                         int error;
1628                         if (table->child) {
1629                                 if (sysctl_perm(table, 001))
1630                                         return -EPERM;
1631                                 name++;
1632                                 nlen--;
1633                                 table = table->child;
1634                                 goto repeat;
1635                         }
1636                         error = do_sysctl_strategy(table, name, nlen,
1637                                                    oldval, oldlenp,
1638                                                    newval, newlen);
1639                         return error;
1640                 }
1641         }
1642         return -ENOTDIR;
1643 }
1644 
1645 /* Perform the actual read/write of a sysctl table entry. */
1646 int do_sysctl_strategy (struct ctl_table *table,
1647                         int __user *name, int nlen,
1648                         void __user *oldval, size_t __user *oldlenp,
1649                         void __user *newval, size_t newlen)
1650 {
1651         int op = 0, rc;
1652 
1653         if (oldval)
1654                 op |= 004;
1655         if (newval) 
1656                 op |= 002;
1657         if (sysctl_perm(table, op))
1658                 return -EPERM;
1659 
1660         if (table->strategy) {
1661                 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1662                                      newval, newlen);
1663                 if (rc < 0)
1664                         return rc;
1665                 if (rc > 0)
1666                         return 0;
1667         }
1668 
1669         /* If there is no strategy routine, or if the strategy returns
1670          * zero, proceed with automatic r/w */
1671         if (table->data && table->maxlen) {
1672                 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1673                                  newval, newlen);
1674                 if (rc < 0)
1675                         return rc;
1676         }
1677         return 0;
1678 }
1679 #endif /* CONFIG_SYSCTL_SYSCALL */
1680 
1681 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1682 {
1683         for (; table->ctl_name || table->procname; table++) {
1684                 table->parent = parent;
1685                 if (table->child)
1686                         sysctl_set_parent(table, table->child);
1687         }
1688 }
1689 
1690 static __init int sysctl_init(void)
1691 {
1692         int err;
1693         sysctl_set_parent(NULL, root_table);
1694         err = sysctl_check_table(current->nsproxy, root_table);
1695         return 0;
1696 }
1697 
1698 core_initcall(sysctl_init);
1699 
1700 /**
1701  * __register_sysctl_paths - register a sysctl hierarchy
1702  * @root: List of sysctl headers to register on
1703  * @namespaces: Data to compute which lists of sysctl entries are visible
1704  * @path: The path to the directory the sysctl table is in.
1705  * @table: the top-level table structure
1706  *
1707  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1708  * array. A completely 0 filled entry terminates the table.
1709  *
1710  * The members of the &struct ctl_table structure are used as follows:
1711  *
1712  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1713  *            must be unique within that level of sysctl
1714  *
1715  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1716  *            enter a sysctl file
1717  *
1718  * data - a pointer to data for use by proc_handler
1719  *
1720  * maxlen - the maximum size in bytes of the data
1721  *
1722  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1723  *
1724  * child - a pointer to the child sysctl table if this entry is a directory, or
1725  *         %NULL.
1726  *
1727  * proc_handler - the text handler routine (described below)
1728  *
1729  * strategy - the strategy routine (described below)
1730  *
1731  * de - for internal use by the sysctl routines
1732  *
1733  * extra1, extra2 - extra pointers usable by the proc handler routines
1734  *
1735  * Leaf nodes in the sysctl tree will be represented by a single file
1736  * under /proc; non-leaf nodes will be represented by directories.
1737  *
1738  * sysctl(2) can automatically manage read and write requests through
1739  * the sysctl table.  The data and maxlen fields of the ctl_table
1740  * struct enable minimal validation of the values being written to be
1741  * performed, and the mode field allows minimal authentication.
1742  *
1743  * More sophisticated management can be enabled by the provision of a
1744  * strategy routine with the table entry.  This will be called before
1745  * any automatic read or write of the data is performed.
1746  *
1747  * The strategy routine may return
1748  *
1749  * < 0 - Error occurred (error is passed to user process)
1750  *
1751  * 0   - OK - proceed with automatic read or write.
1752  *
1753  * > 0 - OK - read or write has been done by the strategy routine, so
1754  *       return immediately.
1755  *
1756  * There must be a proc_handler routine for any terminal nodes
1757  * mirrored under /proc/sys (non-terminals are handled by a built-in
1758  * directory handler).  Several default handlers are available to
1759  * cover common cases -
1760  *
1761  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1762  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1763  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1764  *
1765  * It is the handler's job to read the input buffer from user memory
1766  * and process it. The handler should return 0 on success.
1767  *
1768  * This routine returns %NULL on a failure to register, and a pointer
1769  * to the table header on success.
1770  */
1771 struct ctl_table_header *__register_sysctl_paths(
1772         struct ctl_table_root *root,
1773         struct nsproxy *namespaces,
1774         const struct ctl_path *path, struct ctl_table *table)
1775 {
1776         struct list_head *header_list;
1777         struct ctl_table_header *header;
1778         struct ctl_table *new, **prevp;
1779         unsigned int n, npath;
1780 
1781         /* Count the path components */
1782         for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1783                 ;
1784 
1785         /*
1786          * For each path component, allocate a 2-element ctl_table array.
1787          * The first array element will be filled with the sysctl entry
1788          * for this, the second will be the sentinel (ctl_name == 0).
1789          *
1790          * We allocate everything in one go so that we don't have to
1791          * worry about freeing additional memory in unregister_sysctl_table.
1792          */
1793         header = kzalloc(sizeof(struct ctl_table_header) +
1794                          (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1795         if (!header)
1796                 return NULL;
1797 
1798         new = (struct ctl_table *) (header + 1);
1799 
1800         /* Now connect the dots */
1801         prevp = &header->ctl_table;
1802         for (n = 0; n < npath; ++n, ++path) {
1803                 /* Copy the procname */
1804                 new->procname = path->procname;
1805                 new->ctl_name = path->ctl_name;
1806                 new->mode     = 0555;
1807 
1808                 *prevp = new;
1809                 prevp = &new->child;
1810 
1811                 new += 2;
1812         }
1813         *prevp = table;
1814         header->ctl_table_arg = table;
1815 
1816         INIT_LIST_HEAD(&header->ctl_entry);
1817         header->used = 0;
1818         header->unregistering = NULL;
1819         header->root = root;
1820         sysctl_set_parent(NULL, header->ctl_table);
1821         if (sysctl_check_table(namespaces, header->ctl_table)) {
1822                 kfree(header);
1823                 return NULL;
1824         }
1825         spin_lock(&sysctl_lock);
1826         header_list = lookup_header_list(root, namespaces);
1827         list_add_tail(&header->ctl_entry, header_list);
1828         spin_unlock(&sysctl_lock);
1829 
1830         return header;
1831 }
1832 
1833 /**
1834  * register_sysctl_table_path - register a sysctl table hierarchy
1835  * @path: The path to the directory the sysctl table is in.
1836  * @table: the top-level table structure
1837  *
1838  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1839  * array. A completely 0 filled entry terminates the table.
1840  *
1841  * See __register_sysctl_paths for more details.
1842  */
1843 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1844                                                 struct ctl_table *table)
1845 {
1846         return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1847                                         path, table);
1848 }
1849 
1850 /**
1851  * register_sysctl_table - register a sysctl table hierarchy
1852  * @table: the top-level table structure
1853  *
1854  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1855  * array. A completely 0 filled entry terminates the table.
1856  *
1857  * See register_sysctl_paths for more details.
1858  */
1859 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1860 {
1861         static const struct ctl_path null_path[] = { {} };
1862 
1863         return register_sysctl_paths(null_path, table);
1864 }
1865 
1866 /**
1867  * unregister_sysctl_table - unregister a sysctl table hierarchy
1868  * @header: the header returned from register_sysctl_table
1869  *
1870  * Unregisters the sysctl table and all children. proc entries may not
1871  * actually be removed until they are no longer used by anyone.
1872  */
1873 void unregister_sysctl_table(struct ctl_table_header * header)
1874 {
1875         might_sleep();
1876 
1877         if (header == NULL)
1878                 return;
1879 
1880         spin_lock(&sysctl_lock);
1881         start_unregistering(header);
1882         spin_unlock(&sysctl_lock);
1883         kfree(header);
1884 }
1885 
1886 #else /* !CONFIG_SYSCTL */
1887 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1888 {
1889         return NULL;
1890 }
1891 
1892 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1893                                                     struct ctl_table *table)
1894 {
1895         return NULL;
1896 }
1897 
1898 void unregister_sysctl_table(struct ctl_table_header * table)
1899 {
1900 }
1901 
1902 #endif /* CONFIG_SYSCTL */
1903 
1904 /*
1905  * /proc/sys support
1906  */
1907 
1908 #ifdef CONFIG_PROC_SYSCTL
1909 
1910 static int _proc_do_string(void* data, int maxlen, int write,
1911                            struct file *filp, void __user *buffer,
1912                            size_t *lenp, loff_t *ppos)
1913 {
1914         size_t len;
1915         char __user *p;
1916         char c;
1917 
1918         if (!data || !maxlen || !*lenp) {
1919                 *lenp = 0;
1920                 return 0;
1921         }
1922 
1923         if (write) {
1924                 len = 0;
1925                 p = buffer;
1926                 while (len < *lenp) {
1927                         if (get_user(c, p++))
1928                                 return -EFAULT;
1929                         if (c == 0 || c == '\n')
1930                                 break;
1931                         len++;
1932                 }
1933                 if (len >= maxlen)
1934                         len = maxlen-1;
1935                 if(copy_from_user(data, buffer, len))
1936                         return -EFAULT;
1937                 ((char *) data)[len] = 0;
1938                 *ppos += *lenp;
1939         } else {
1940                 len = strlen(data);
1941                 if (len > maxlen)
1942                         len = maxlen;
1943 
1944                 if (*ppos > len) {
1945                         *lenp = 0;
1946                         return 0;
1947                 }
1948 
1949                 data += *ppos;
1950                 len  -= *ppos;
1951 
1952                 if (len > *lenp)
1953                         len = *lenp;
1954                 if (len)
1955                         if(copy_to_user(buffer, data, len))
1956                                 return -EFAULT;
1957                 if (len < *lenp) {
1958                         if(put_user('\n', ((char __user *) buffer) + len))
1959                                 return -EFAULT;
1960                         len++;
1961                 }
1962                 *lenp = len;
1963                 *ppos += len;
1964         }
1965         return 0;
1966 }
1967 
1968 /**
1969  * proc_dostring - read a string sysctl
1970  * @table: the sysctl table
1971  * @write: %TRUE if this is a write to the sysctl file
1972  * @filp: the file structure
1973  * @buffer: the user buffer
1974  * @lenp: the size of the user buffer
1975  * @ppos: file position
1976  *
1977  * Reads/writes a string from/to the user buffer. If the kernel
1978  * buffer provided is not large enough to hold the string, the
1979  * string is truncated. The copied string is %NULL-terminated.
1980  * If the string is being read by the user process, it is copied
1981  * and a newline '\n' is added. It is truncated if the buffer is
1982  * not large enough.
1983  *
1984  * Returns 0 on success.
1985  */
1986 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1987                   void __user *buffer, size_t *lenp, loff_t *ppos)
1988 {
1989         return _proc_do_string(table->data, table->maxlen, write, filp,
1990                                buffer, lenp, ppos);
1991 }
1992 
1993 
1994 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1995                                  int *valp,
1996                                  int write, void *data)
1997 {
1998         if (write) {
1999                 *valp = *negp ? -*lvalp : *lvalp;
2000         } else {
2001                 int val = *valp;
2002                 if (val < 0) {
2003                         *negp = -1;
2004                         *lvalp = (unsigned long)-val;
2005                 } else {
2006                         *negp = 0;
2007                         *lvalp = (unsigned long)val;
2008                 }
2009         }
2010         return 0;
2011 }
2012 
2013 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2014                   int write, struct file *filp, void __user *buffer,
2015                   size_t *lenp, loff_t *ppos,
2016                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2017                               int write, void *data),
2018                   void *data)
2019 {
2020 #define TMPBUFLEN 21
2021         int *i, vleft, first=1, neg, val;
2022         unsigned long lval;
2023         size_t left, len;
2024         
2025         char buf[TMPBUFLEN], *p;
2026         char __user *s = buffer;
2027         
2028         if (!tbl_data || !table->maxlen || !*lenp ||
2029             (*ppos && !write)) {
2030                 *lenp = 0;
2031                 return 0;
2032         }
2033         
2034         i = (int *) tbl_data;
2035         vleft = table->maxlen / sizeof(*i);
2036         left = *lenp;
2037 
2038         if (!conv)
2039                 conv = do_proc_dointvec_conv;
2040 
2041         for (; left && vleft--; i++, first=0) {
2042                 if (write) {
2043                         while (left) {
2044                                 char c;
2045                                 if (get_user(c, s))
2046                                         return -EFAULT;
2047                                 if (!isspace(c))
2048                                         break;
2049                                 left--;
2050                                 s++;
2051                         }
2052                         if (!left)
2053                                 break;
2054                         neg = 0;
2055                         len = left;
2056                         if (len > sizeof(buf) - 1)
2057                                 len = sizeof(buf) - 1;
2058                         if (copy_from_user(buf, s, len))
2059                                 return -EFAULT;
2060                         buf[len] = 0;
2061                         p = buf;
2062                         if (*p == '-' && left > 1) {
2063                                 neg = 1;
2064                                 p++;
2065                         }
2066                         if (*p < '' || *p > '9')
2067                                 break;
2068 
2069                         lval = simple_strtoul(p, &p, 0);
2070 
2071                         len = p-buf;
2072                         if ((len < left) && *p && !isspace(*p))
2073                                 break;
2074                         if (neg)
2075                                 val = -val;
2076                         s += len;
2077                         left -= len;
2078 
2079                         if (conv(&neg, &lval, i, 1, data))
2080                                 break;
2081                 } else {
2082                         p = buf;
2083                         if (!first)
2084                                 *p++ = '\t';
2085         
2086                         if (conv(&neg, &lval, i, 0, data))
2087                                 break;
2088 
2089                         sprintf(p, "%s%lu", neg ? "-" : "", lval);
2090                         len = strlen(buf);
2091                         if (len > left)
2092                                 len = left;
2093                         if(copy_to_user(s, buf, len))
2094                                 return -EFAULT;
2095                         left -= len;
2096                         s += len;
2097                 }
2098         }
2099 
2100         if (!write && !first && left) {
2101                 if(put_user('\n', s))
2102                         return -EFAULT;
2103                 left--, s++;
2104         }
2105         if (write) {
2106                 while (left) {
2107                         char c;
2108                         if (get_user(c, s++))
2109                                 return -EFAULT;
2110                         if (!isspace(c))
2111                                 break;
2112                         left--;
2113                 }
2114         }
2115         if (write && first)
2116                 return -EINVAL;
2117         *lenp -= left;
2118         *ppos += *lenp;
2119         return 0;
2120 #undef TMPBUFLEN
2121 }
2122 
2123 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2124                   void __user *buffer, size_t *lenp, loff_t *ppos,
2125                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2126                               int write, void *data),
2127                   void *data)
2128 {
2129         return __do_proc_dointvec(table->data, table, write, filp,
2130                         buffer, lenp, ppos, conv, data);
2131 }
2132 
2133 /**
2134  * proc_dointvec - read a vector of integers
2135  * @table: the sysctl table
2136  * @write: %TRUE if this is a write to the sysctl file
2137  * @filp: the file structure
2138  * @buffer: the user buffer
2139  * @lenp: the size of the user buffer
2140  * @ppos: file position
2141  *
2142  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2143  * values from/to the user buffer, treated as an ASCII string. 
2144  *
2145  * Returns 0 on success.
2146  */
2147 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2148                      void __user *buffer, size_t *lenp, loff_t *ppos)
2149 {
2150     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2151                             NULL,NULL);
2152 }
2153 
2154 #define OP_SET  0
2155 #define OP_AND  1
2156 #define OP_OR   2
2157 
2158 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2159                                       int *valp,
2160                                       int write, void *data)
2161 {
2162         int op = *(int *)data;
2163         if (write) {
2164                 int val = *negp ? -*lvalp : *lvalp;
2165                 switch(op) {
2166                 case OP_SET:    *valp = val; break;
2167                 case OP_AND:    *valp &= val; break;
2168                 case OP_OR:     *valp |= val; break;
2169                 }
2170         } else {
2171                 int val = *valp;
2172                 if (val < 0) {
2173                         *negp = -1;
2174                         *lvalp = (unsigned long)-val;
2175                 } else {
2176                         *negp = 0;
2177                         *lvalp = (unsigned long)val;
2178                 }
2179         }
2180         return 0;
2181 }
2182 
2183 /*
2184  *      Taint values can only be increased
2185  */
2186 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2187                                void __user *buffer, size_t *lenp, loff_t *ppos)
2188 {
2189         int op;
2190 
2191         if (write && !capable(CAP_SYS_ADMIN))
2192                 return -EPERM;
2193 
2194         op = OP_OR;
2195         return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2196                                 do_proc_dointvec_bset_conv,&op);
2197 }
2198 
2199 struct do_proc_dointvec_minmax_conv_param {
2200         int *min;
2201         int *max;
2202 };
2203 
2204 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 
2205                                         int *valp, 
2206                                         int write, void *data)
2207 {
2208         struct do_proc_dointvec_minmax_conv_param *param = data;
2209         if (write) {
2210                 int val = *negp ? -*lvalp : *lvalp;
2211                 if ((param->min && *param->min > val) ||
2212                     (param->max && *param->max < val))
2213                         return -EINVAL;
2214                 *valp = val;
2215         } else {
2216                 int val = *valp;
2217                 if (val < 0) {
2218                         *negp = -1;
2219                         *lvalp = (unsigned long)-val;
2220                 } else {
2221                         *negp = 0;
2222                         *lvalp = (unsigned long)val;
2223                 }
2224         }
2225         return 0;
2226 }
2227 
2228 /**
2229  * proc_dointvec_minmax - read a vector of integers with min/max values
2230  * @table: the sysctl table
2231  * @write: %TRUE if this is a write to the sysctl file
2232  * @filp: the file structure
2233  * @buffer: the user buffer
2234  * @lenp: the size of the user buffer
2235  * @ppos: file position
2236  *
2237  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2238  * values from/to the user buffer, treated as an ASCII string.
2239  *
2240  * This routine will ensure the values are within the range specified by
2241  * table->extra1 (min) and table->extra2 (max).
2242  *
2243  * Returns 0 on success.
2244  */
2245 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2246                   void __user *buffer, size_t *lenp, loff_t *ppos)
2247 {
2248         struct do_proc_dointvec_minmax_conv_param param = {
2249                 .min = (int *) table->extra1,
2250                 .max = (int *) table->extra2,
2251         };
2252         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2253                                 do_proc_dointvec_minmax_conv, &param);
2254 }
2255 
2256 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2257                                      struct file *filp,
2258                                      void __user *buffer,
2259                                      size_t *lenp, loff_t *ppos,
2260                                      unsigned long convmul,
2261                                      unsigned long convdiv)
2262 {
2263 #define TMPBUFLEN 21
2264         unsigned long *i, *min, *max, val;
2265         int vleft, first=1, neg;
2266         size_t len, left;
2267         char buf[TMPBUFLEN], *p;
2268         char __user *s = buffer;
2269         
2270         if (!data || !table->maxlen || !*lenp ||
2271             (*ppos && !write)) {
2272                 *lenp = 0;
2273                 return 0;
2274         }
2275         
2276         i = (unsigned long *) data;
2277         min = (unsigned long *) table->extra1;
2278         max = (unsigned long *) table->extra2;
2279         vleft = table->maxlen / sizeof(unsigned long);
2280         left = *lenp;
2281         
2282         for (; left && vleft--; i++, min++, max++, first=0) {
2283                 if (write) {
2284                         while (left) {
2285                                 char c;
2286                                 if (get_user(c, s))
2287                                         return -EFAULT;
2288                                 if (!isspace(c))
2289                                         break;
2290                                 left--;
2291                                 s++;
2292                         }
2293                         if (!left)
2294                                 break;
2295                         neg = 0;
2296                         len = left;
2297                         if (len > TMPBUFLEN-1)
2298                                 len = TMPBUFLEN-1;
2299                         if (copy_from_user(buf, s, len))
2300                                 return -EFAULT;
2301                         buf[len] = 0;
2302                         p = buf;
2303                         if (*p == '-' && left > 1) {
2304                                 neg = 1;
2305                                 p++;
2306                         }
2307                         if (*p < '' || *p > '9')
2308                                 break;
2309                         val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2310                         len = p-buf;
2311                         if ((len < left) && *p && !isspace(*p))
2312                                 break;
2313                         if (neg)
2314                                 val = -val;
2315                         s += len;
2316                         left -= len;
2317 
2318                         if(neg)
2319                                 continue;
2320                         if ((min && val < *min) || (max && val > *max))
2321                                 continue;
2322                         *i = val;
2323                 } else {
2324                         p = buf;
2325                         if (!first)
2326                                 *p++ = '\t';
2327                         sprintf(p, "%lu", convdiv * (*i) / convmul);
2328                         len = strlen(buf);
2329                         if (len > left)
2330                                 len = left;
2331                         if(copy_to_user(s, buf, len))
2332                                 return -EFAULT;
2333                         left -= len;
2334                         s += len;
2335                 }
2336         }
2337 
2338         if (!write && !first && left) {
2339                 if(put_user('\n', s))
2340                         return -EFAULT;
2341                 left--, s++;
2342         }
2343         if (write) {
2344                 while (left) {
2345                         char c;
2346                         if (get_user(c, s++))
2347                                 return -EFAULT;
2348                         if (!isspace(c))
2349                                 break;
2350                         left--;
2351                 }
2352         }
2353         if (write && first)
2354                 return -EINVAL;
2355         *lenp -= left;
2356         *ppos += *lenp;
2357         return 0;
2358 #undef TMPBUFLEN
2359 }
2360 
2361 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2362                                      struct file *filp,
2363                                      void __user *buffer,
2364                                      size_t *lenp, loff_t *ppos,
2365                                      unsigned long convmul,
2366                                      unsigned long convdiv)
2367 {
2368         return __do_proc_doulongvec_minmax(table->data, table, write,
2369                         filp, buffer, lenp, ppos, convmul, convdiv);
2370 }
2371 
2372 /**
2373  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2374  * @table: the sysctl table
2375  * @write: %TRUE if this is a write to the sysctl file
2376  * @filp: the file structure
2377  * @buffer: the user buffer
2378  * @lenp: the size of the user buffer
2379  * @ppos: file position
2380  *
2381  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2382  * values from/to the user buffer, treated as an ASCII string.
2383  *
2384  * This routine will ensure the values are within the range specified by
2385  * table->extra1 (min) and table->extra2 (max).
2386  *
2387  * Returns 0 on success.
2388  */
2389 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2390                            void __user *buffer, size_t *lenp, loff_t *ppos)
2391 {
2392     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2393 }
2394 
2395 /**
2396  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2397  * @table: the sysctl table
2398  * @write: %TRUE if this is a write to the sysctl file
2399  * @filp: the file structure
2400  * @buffer: the user buffer
2401  * @lenp: the size of the user buffer
2402  * @ppos: file position
2403  *
2404  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2405  * values from/to the user buffer, treated as an ASCII string. The values
2406  * are treated as milliseconds, and converted to jiffies when they are stored.
2407  *
2408  * This routine will ensure the values are within the range specified by
2409  * table->extra1 (min) and table->extra2 (max).
2410  *
2411  * Returns 0 on success.
2412  */
2413 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2414                                       struct file *filp,
2415                                       void __user *buffer,
2416                                       size_t *lenp, loff_t *ppos)
2417 {
2418     return do_proc_doulongvec_minmax(table, write, filp, buffer,
2419                                      lenp, ppos, HZ, 1000l);
2420 }
2421 
2422 
2423 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2424                                          int *valp,
2425                                          int write, void *data)
2426 {
2427         if (write) {
2428                 if (*lvalp > LONG_MAX / HZ)
2429                         return 1;
2430                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2431         } else {
2432                 int val = *valp;
2433                 unsigned long lval;
2434                 if (val < 0) {
2435                         *negp = -1;
2436                         lval = (unsigned long)-val;
2437                 } else {
2438                         *negp = 0;
2439                         lval = (unsigned long)val;
2440                 }
2441                 *lvalp = lval / HZ;
2442         }
2443         return 0;
2444 }
2445 
2446 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2447                                                 int *valp,
2448                                                 int write, void *data)
2449 {
2450         if (write) {
2451                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2452                         return 1;
2453                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2454         } else {
2455                 int val = *valp;
2456                 unsigned long lval;
2457                 if (val < 0) {
2458                         *negp = -1;
2459                         lval = (unsigned long)-val;
2460                 } else {
2461                         *negp = 0;
2462                         lval = (unsigned long)val;
2463                 }
2464                 *lvalp = jiffies_to_clock_t(lval);
2465         }
2466         return 0;
2467 }
2468 
2469 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2470                                             int *valp,
2471                                             int write, void *data)
2472 {
2473         if (write) {
2474                 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2475         } else {
2476                 int val = *valp;
2477                 unsigned long lval;
2478                 if (val < 0) {
2479                         *negp = -1;
2480                         lval = (unsigned long)-val;
2481                 } else {
2482                         *negp = 0;
2483                         lval = (unsigned long)val;
2484                 }
2485                 *lvalp = jiffies_to_msecs(lval);
2486         }
2487         return 0;
2488 }
2489 
2490 /**
2491  * proc_dointvec_jiffies - read a vector of integers as seconds
2492  * @table: the sysctl table
2493  * @write: %TRUE if this is a write to the sysctl file
2494  * @filp: the file structure
2495  * @buffer: the user buffer
2496  * @lenp: the size of the user buffer
2497  * @ppos: file position
2498  *
2499  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2500  * values from/to the user buffer, treated as an ASCII string. 
2501  * The values read are assumed to be in seconds, and are converted into
2502  * jiffies.
2503  *
2504  * Returns 0 on success.
2505  */
2506 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2507                           void __user *buffer, size_t *lenp, loff_t *ppos)
2508 {
2509     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2510                             do_proc_dointvec_jiffies_conv,NULL);
2511 }
2512 
2513 /**
2514  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2515  * @table: the sysctl table
2516  * @write: %TRUE if this is a write to the sysctl file
2517  * @filp: the file structure
2518  * @buffer: the user buffer
2519  * @lenp: the size of the user buffer
2520  * @ppos: pointer to the file position
2521  *
2522  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2523  * values from/to the user buffer, treated as an ASCII string. 
2524  * The values read are assumed to be in 1/USER_HZ seconds, and 
2525  * are converted into jiffies.
2526  *
2527  * Returns 0 on success.
2528  */
2529 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2530                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2531 {
2532     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2533                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2534 }
2535 
2536 /**
2537  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2538  * @table: the sysctl table
2539  * @write: %TRUE if this is a write to the sysctl file
2540  * @filp: the file structure
2541  * @buffer: the user buffer
2542  * @lenp: the size of the user buffer
2543  * @ppos: file position
2544  * @ppos: the current position in the file
2545  *
2546  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2547  * values from/to the user buffer, treated as an ASCII string. 
2548  * The values read are assumed to be in 1/1000 seconds, and 
2549  * are converted into jiffies.
2550  *
2551  * Returns 0 on success.
2552  */
2553 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2554                              void __user *buffer, size_t *lenp, loff_t *ppos)
2555 {
2556         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2557                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2558 }
2559 
2560 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2561                            void __user *buffer, size_t *lenp, loff_t *ppos)
2562 {
2563         struct pid *new_pid;
2564         pid_t tmp;
2565         int r;
2566 
2567         tmp = pid_vnr(cad_pid);
2568 
2569         r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2570                                lenp, ppos, NULL, NULL);
2571         if (r || !write)
2572                 return r;
2573 
2574         new_pid = find_get_pid(tmp);
2575         if (!new_pid)
2576                 return -ESRCH;
2577 
2578         put_pid(xchg(&cad_pid, new_pid));
2579         return 0;
2580 }
2581 
2582 #else /* CONFIG_PROC_FS */
2583 
2584 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2585                   void __user *buffer, size_t *lenp, loff_t *ppos)
2586 {
2587         return -ENOSYS;
2588 }
2589 
2590 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2591                   void __user *buffer, size_t *lenp, loff_t *ppos)
2592 {
2593         return -ENOSYS;
2594 }
2595 
2596 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2597                     void __user *buffer, size_t *lenp, loff_t *ppos)
2598 {
2599         return -ENOSYS;
2600 }
2601 
2602 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2603                     void __user *buffer, size_t *lenp, loff_t *ppos)
2604 {
2605         return -ENOSYS;
2606 }
2607 
2608 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2609                     void __user *buffer, size_t *lenp, loff_t *ppos)
2610 {
2611         return -ENOSYS;
2612 }
2613 
2614 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2615                              void __user *buffer, size_t *lenp, loff_t *ppos)
2616 {
2617         return -ENOSYS;
2618 }
2619 
2620 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2621                     void __user *buffer, size_t *lenp, loff_t *ppos)
2622 {
2623         return -ENOSYS;
2624 }
2625 
2626 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2627                                       struct file *filp,
2628                                       void __user *buffer,
2629                                       size_t *lenp, loff_t *ppos)
2630 {
2631     return -ENOSYS;
2632 }
2633 
2634 
2635 #endif /* CONFIG_PROC_FS */
2636 
2637 
2638 #ifdef CONFIG_SYSCTL_SYSCALL
2639 /*
2640  * General sysctl support routines 
2641  */
2642 
2643 /* The generic sysctl data routine (used if no strategy routine supplied) */
2644 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2645                 void __user *oldval, size_t __user *oldlenp,
2646                 void __user *newval, size_t newlen)
2647 {
2648         size_t len;
2649 
2650         /* Get out of I don't have a variable */
2651         if (!table->data || !table->maxlen)
2652                 return -ENOTDIR;
2653 
2654         if (oldval && oldlenp) {
2655                 if (get_user(len, oldlenp))
2656                         return -EFAULT;
2657                 if (len) {
2658                         if (len > table->maxlen)
2659                                 len = table->maxlen;
2660                         if (copy_to_user(oldval, table->data, len))
2661                                 return -EFAULT;
2662                         if (put_user(len, oldlenp))
2663                                 return -EFAULT;
2664                 }
2665         }
2666 
2667         if (newval && newlen) {
2668                 if (newlen > table->maxlen)
2669                         newlen = table->maxlen;
2670 
2671                 if (copy_from_user(table->data, newval, newlen))
2672                         return -EFAULT;
2673         }
2674         return 1;
2675 }
2676 
2677 /* The generic string strategy routine: */
2678 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2679                   void __user *oldval, size_t __user *oldlenp,
2680                   void __user *newval, size_t newlen)
2681 {
2682         if (!table->data || !table->maxlen) 
2683                 return -ENOTDIR;
2684         
2685         if (oldval && oldlenp) {
2686                 size_t bufsize;
2687                 if (get_user(bufsize, oldlenp))
2688                         return -EFAULT;
2689                 if (bufsize) {
2690                         size_t len = strlen(table->data), copied;
2691 
2692                         /* This shouldn't trigger for a well-formed sysctl */
2693                         if (len > table->maxlen)
2694                                 len = table->maxlen;
2695 
2696                         /* Copy up to a max of bufsize-1 bytes of the string */
2697                         copied = (len >= bufsize) ? bufsize - 1 : len;
2698 
2699                         if (copy_to_user(oldval, table->data, copied) ||
2700                             put_user(0, (char __user *)(oldval + copied)))
2701                                 return -EFAULT;
2702                         if (put_user(len, oldlenp))
2703                                 return -EFAULT;
2704                 }
2705         }
2706         if (newval && newlen) {
2707                 size_t len = newlen;
2708                 if (len > table->maxlen)
2709                         len = table->maxlen;
2710                 if(copy_from_user(table->data, newval, len))
2711                         return -EFAULT;
2712                 if (len == table->maxlen)
2713                         len--;
2714                 ((char *) table->data)[len] = 0;
2715         }
2716         return 1;
2717 }
2718 
2719 /*
2720  * This function makes sure that all of the integers in the vector
2721  * are between the minimum and maximum values given in the arrays
2722  * table->extra1 and table->extra2, respectively.
2723  */
2724 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2725                 void __user *oldval, size_t __user *oldlenp,
2726                 void __user *newval, size_t newlen)
2727 {
2728 
2729         if (newval && newlen) {
2730                 int __user *vec = (int __user *) newval;
2731                 int *min = (int *) table->extra1;
2732                 int *max = (int *) table->extra2;
2733                 size_t length;
2734                 int i;
2735 
2736                 if (newlen % sizeof(int) != 0)
2737                         return -EINVAL;
2738 
2739                 if (!table->extra1 && !table->extra2)
2740                         return 0;
2741 
2742                 if (newlen > table->maxlen)
2743                         newlen = table->maxlen;
2744                 length = newlen / sizeof(int);
2745 
2746                 for (i = 0; i < length; i++) {
2747                         int value;
2748                         if (get_user(value, vec + i))
2749                                 return -EFAULT;
2750                         if (min && value < min[i])
2751                                 return -EINVAL;
2752                         if (max && value > max[i])
2753                                 return -EINVAL;
2754                 }
2755         }
2756         return 0;
2757 }
2758 
2759 /* Strategy function to convert jiffies to seconds */ 
2760 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2761                 void __user *oldval, size_t __user *oldlenp,
2762                 void __user *newval, size_t newlen)
2763 {
2764         if (oldval && oldlenp) {
2765                 size_t olen;
2766 
2767                 if (get_user(olen, oldlenp))
2768                         return -EFAULT;
2769                 if (olen) {
2770                         int val;
2771 
2772                         if (olen < sizeof(int))
2773                                 return -EINVAL;
2774 
2775                         val = *(int *)(table->data) / HZ;
2776                         if (put_user(val, (int __user *)oldval))
2777                                 return -EFAULT;
2778                         if (put_user(sizeof(int), oldlenp))
2779                                 return -EFAULT;
2780                 }
2781         }
2782         if (newval && newlen) { 
2783                 int new;
2784                 if (newlen != sizeof(int))
2785                         return -EINVAL; 
2786                 if (get_user(new, (int __user *)newval))
2787                         return -EFAULT;
2788                 *(int *)(table->data) = new*HZ; 
2789         }
2790         return 1;
2791 }
2792 
2793 /* Strategy function to convert jiffies to seconds */ 
2794 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2795                 void __user *oldval, size_t __user *oldlenp,
2796                 void __user *newval, size_t newlen)
2797 {
2798         if (oldval && oldlenp) {
2799                 size_t olen;
2800 
2801                 if (get_user(olen, oldlenp))
2802                         return -EFAULT;
2803                 if (olen) {
2804                         int val;
2805 
2806                         if (olen < sizeof(int))
2807                                 return -EINVAL;
2808 
2809                         val = jiffies_to_msecs(*(int *)(table->data));
2810                         if (put_user(val, (int __user *)oldval))
2811                                 return -EFAULT;
2812                         if (put_user(sizeof(int), oldlenp))
2813                                 return -EFAULT;
2814                 }
2815         }
2816         if (newval && newlen) { 
2817                 int new;
2818                 if (newlen != sizeof(int))
2819                         return -EINVAL; 
2820                 if (get_user(new, (int __user *)newval))
2821                         return -EFAULT;
2822                 *(int *)(table->data) = msecs_to_jiffies(new);
2823         }
2824         return 1;
2825 }
2826 
2827 
2828 
2829 #else /* CONFIG_SYSCTL_SYSCALL */
2830 
2831 
2832 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2833 {
2834         struct __sysctl_args tmp;
2835         int error;
2836 
2837         if (copy_from_user(&tmp, args, sizeof(tmp)))
2838                 return -EFAULT;
2839 
2840         error = deprecated_sysctl_warning(&tmp);
2841 
2842         /* If no error reading the parameters then just -ENOSYS ... */
2843         if (!error)
2844                 error = -ENOSYS;
2845 
2846         return error;
2847 }
2848 
2849 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2850                   void __user *oldval, size_t __user *oldlenp,
2851                   void __user *newval, size_t newlen)
2852 {
2853         return -ENOSYS;
2854 }
2855 
2856 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2857                   void __user *oldval, size_t __user *oldlenp,
2858                   void __user *newval, size_t newlen)
2859 {
2860         return -ENOSYS;
2861 }
2862 
2863 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2864                 void __user *oldval, size_t __user *oldlenp,
2865                 void __user *newval, size_t newlen)
2866 {
2867         return -ENOSYS;
2868 }
2869 
2870 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2871                 void __user *oldval, size_t __user *oldlenp,
2872                 void __user *newval, size_t newlen)
2873 {
2874         return -ENOSYS;
2875 }
2876 
2877 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2878                 void __user *oldval, size_t __user *oldlenp,
2879                 void __user *newval, size_t newlen)
2880 {
2881         return -ENOSYS;
2882 }
2883 
2884 #endif /* CONFIG_SYSCTL_SYSCALL */
2885 
2886 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2887 {
2888         static int msg_count;
2889         int name[CTL_MAXNAME];
2890         int i;
2891 
2892         /* Check args->nlen. */
2893         if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2894                 return -ENOTDIR;
2895 
2896         /* Read in the sysctl name for better debug message logging */
2897         for (i = 0; i < args->nlen; i++)
2898                 if (get_user(name[i], args->name + i))
2899                         return -EFAULT;
2900 
2901         /* Ignore accesses to kernel.version */
2902         if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2903                 return 0;
2904 
2905         if (msg_count < 5) {
2906                 msg_count++;
2907                 printk(KERN_INFO
2908                         "warning: process `%s' used the deprecated sysctl "
2909                         "system call with ", current->comm);
2910                 for (i = 0; i < args->nlen; i++)
2911                         printk("%d.", name[i]);
2912                 printk("\n");
2913         }
2914         return 0;
2915 }
2916 
2917 /*
2918  * No sense putting this after each symbol definition, twice,
2919  * exception granted :-)
2920  */
2921 EXPORT_SYMBOL(proc_dointvec);
2922 EXPORT_SYMBOL(proc_dointvec_jiffies);
2923 EXPORT_SYMBOL(proc_dointvec_minmax);
2924 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2925 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2926 EXPORT_SYMBOL(proc_dostring);
2927 EXPORT_SYMBOL(proc_doulongvec_minmax);
2928 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2929 EXPORT_SYMBOL(register_sysctl_table);
2930 EXPORT_SYMBOL(register_sysctl_paths);
2931 EXPORT_SYMBOL(sysctl_intvec);
2932 EXPORT_SYMBOL(sysctl_jiffies);
2933 EXPORT_SYMBOL(sysctl_ms_jiffies);
2934 EXPORT_SYMBOL(sysctl_string);
2935 EXPORT_SYMBOL(sysctl_data);
2936 EXPORT_SYMBOL(unregister_sysctl_table);
2937 
  This page was automatically generated by the LXR engine.